Skip to content

Commit

Permalink
Merge pull request ElementsProject#241 from YusukeShimizu/flake-waitswap
Browse files Browse the repository at this point in the history
Wait for swap in State_SwapInSender_AwaitAgreement if it exists
  • Loading branch information
wtogami committed Sep 11, 2023
2 parents 7908667 + a6636a0 commit 8802cf2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/bitcoin_cln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Test_OnlyOneActiveSwapPerChannelCln(t *testing.T) {
t.Logf("GOT: %v", response)

assert.EqualValues(t, N_SWAPS-1, nErr, "expected nswaps-1=%d errors, got: %d", N_SWAPS-1, nErr)
assert.EqualValues(t, len(response.Swaps), 1, "expected only 1 active swap, got: %d", len(response.Swaps))
assert.EqualValues(t, 1, len(response.Swaps), "expected only 1 active swap, got: %d", len(response.Swaps))
}

func Test_ClnCln_Bitcoin_SwapIn(t *testing.T) {
Expand Down
18 changes: 15 additions & 3 deletions test/bitcoin_lnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"sync/atomic"
"testing"
"time"

"github.com/elementsproject/peerswap/peerswaprpc"
"github.com/elementsproject/peerswap/swap"
Expand Down Expand Up @@ -109,10 +110,21 @@ func Test_OnlyOneActiveSwapPerChannelLnd(t *testing.T) {
}
wg.Wait()

res, err := peerswapds[1].PeerswapClient.ListActiveSwaps(ctx, &peerswaprpc.ListSwapsRequest{})
assert.NoError(t, err)
assert.EqualValues(t, N_SWAPS-1, nErr, "expected nswaps-1=%d errors, got: %d", N_SWAPS-1, nErr)
assert.EqualValues(t, len(res.Swaps), 1, "expected only 1 active swap, got: %d - %v", len(res.Swaps), res)
err = testframework.WaitForWithErr(func() (bool, error) {
res, err := peerswapds[1].PeerswapClient.ListActiveSwaps(ctx, &peerswaprpc.ListSwapsRequest{})
if err != nil {
return false, err
}
for _, r := range res.Swaps {
if r.State == string(swap.State_SwapInSender_AwaitAgreement) {
return false, nil
}
}
assert.EqualValues(t, 1, len(res.Swaps), "expected only 1 active swap, got: %d - %v", len(res.Swaps), res)
return true, nil
}, 2*time.Second)
assert.NoError(t, err)
}

func Test_LndLnd_Bitcoin_SwapIn(t *testing.T) {
Expand Down

0 comments on commit 8802cf2

Please sign in to comment.