Skip to content

Commit 23039a9

Browse files
guggeroRoasbeefgijswijsGeorgeTsagk
committed
itest: add custom channel integration test
Co-authored-by: Olaoluwa Osuntokun <laolu32@gmail.com> Co-authored-by: Gijs van Dam <gijs@lightning.engineering> Co-authored-by: George Tsagkarelis <george.tsagkarelis@gmail.com>
1 parent 3be9f30 commit 23039a9

11 files changed

+6509
-14
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
88
github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c
99
github.com/btcsuite/btcwallet/walletdb v1.4.4
10+
github.com/davecgh/go-spew v1.1.1
1011
github.com/go-errors/errors v1.0.1
1112
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0
1213
github.com/improbable-eng/grpc-web v0.12.0
@@ -35,6 +36,7 @@ require (
3536
github.com/urfave/cli v1.22.9
3637
go.etcd.io/bbolt v1.3.11
3738
golang.org/x/crypto v0.31.0
39+
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
3840
golang.org/x/net v0.27.0
3941
golang.org/x/sync v0.10.0
4042
google.golang.org/grpc v1.65.0
@@ -73,7 +75,6 @@ require (
7375
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
7476
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
7577
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
76-
github.com/davecgh/go-spew v1.1.1 // indirect
7778
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
7879
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
7980
github.com/decred/dcrd/lru v1.1.2 // indirect
@@ -201,7 +202,6 @@ require (
201202
go.uber.org/mock v0.4.0 // indirect
202203
go.uber.org/multierr v1.6.0 // indirect
203204
go.uber.org/zap v1.23.0 // indirect
204-
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
205205
golang.org/x/mod v0.17.0 // indirect
206206
golang.org/x/sys v0.28.0 // indirect
207207
golang.org/x/term v0.27.0 // indirect

itest/assertions.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ package itest
33
import (
44
"context"
55
"fmt"
6+
"testing"
67

78
"github.com/btcsuite/btcd/chaincfg/chainhash"
89
"github.com/btcsuite/btcd/wire"
10+
"github.com/lightninglabs/taproot-assets/taprpc"
911
"github.com/lightningnetwork/lnd/channeldb"
1012
"github.com/lightningnetwork/lnd/lnrpc"
13+
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
1114
"github.com/lightningnetwork/lnd/lntest"
1215
"github.com/lightningnetwork/lnd/lntest/wait"
1316
"github.com/stretchr/testify/require"
17+
"google.golang.org/protobuf/proto"
1418
)
1519

1620
// shutdownAndAssert shuts down the given node and asserts that no errors
@@ -172,24 +176,25 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
172176
// block.
173177
block := mineBlocks(t, net, 1, 1)[0]
174178

175-
closingTxid, err := net.WaitForChannelClose(closeUpdates)
179+
closingUpdate, err := net.WaitForChannelClose(closeUpdates)
176180
require.NoError(t.t, err, "error while waiting for channel close")
177181

182+
closingTxid, err := chainhash.NewHash(closingUpdate.ClosingTxid)
183+
require.NoError(t.t, err)
178184
assertTxInBlock(t, block, closingTxid)
179185

180186
// Finally, the transaction should no longer be in the waiting close
181187
// state as we've just mined a block that should include the closing
182188
// transaction.
183189
err = wait.Predicate(func() bool {
184-
pendingChansRequest := &lnrpc.PendingChannelsRequest{}
185-
pendingChanResp, err := node.PendingChannels(
186-
ctx, pendingChansRequest,
190+
resp, err := node.PendingChannels(
191+
ctx, &lnrpc.PendingChannelsRequest{},
187192
)
188193
if err != nil {
189194
return false
190195
}
191196

192-
for _, pendingClose := range pendingChanResp.WaitingCloseChannels {
197+
for _, pendingClose := range resp.WaitingCloseChannels {
193198
if pendingClose.Channel.ChannelPoint == chanPointStr {
194199
return false
195200
}
@@ -203,3 +208,34 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
203208

204209
return closingTxid
205210
}
211+
212+
func assertSweepExists(t *testing.T, node *HarnessNode,
213+
witnessType walletrpc.WitnessType) {
214+
215+
ctxb := context.Background()
216+
err := wait.NoError(func() error {
217+
pendingSweeps, err := node.WalletKitClient.PendingSweeps(
218+
ctxb, &walletrpc.PendingSweepsRequest{},
219+
)
220+
if err != nil {
221+
return err
222+
}
223+
224+
for _, sweep := range pendingSweeps.PendingSweeps {
225+
if sweep.WitnessType == witnessType {
226+
return nil
227+
}
228+
}
229+
230+
return fmt.Errorf("failed to find second level sweep: %v",
231+
toProtoJSON(t, pendingSweeps))
232+
}, defaultTimeout)
233+
require.NoError(t, err)
234+
}
235+
236+
func toProtoJSON(t *testing.T, resp proto.Message) string {
237+
jsonBytes, err := taprpc.ProtoJSONMarshalOpts.Marshal(resp)
238+
require.NoError(t, err)
239+
240+
return string(jsonBytes)
241+
}

0 commit comments

Comments
 (0)