Skip to content

Commit 1437bf0

Browse files
committed
itest: add options to helper function PublishAndLogTransfer
1 parent e5bf0e5 commit 1437bf0

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

itest/multisig.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,58 @@ func FinalizePacket(t *testing.T, lnd *rpc.HarnessRPC,
490490
return signedPacket
491491
}
492492

493+
// PublishAndLogTransferOption defines a functional option for
494+
// PublishAndLogTransfer.
495+
type PublishAndLogTransferOption func(*publishAndLogTransferOptions)
496+
497+
// publishAndLogTransferOptions contains the options for PublishAndLogTransfer.
498+
type publishAndLogTransferOptions struct {
499+
// skipAnchorTxBroadcast indicates whether to skip the broadcast of
500+
// the anchor transaction.
501+
skipAnchorTxBroadcast bool
502+
503+
// label is the label to use for the transfer.
504+
label string
505+
}
506+
507+
// defaultPublishAndLogTransferOptions returns the default options for
508+
// PublishAndLogTransfer.
509+
func defaultPublishAndLogTransferOptions() *publishAndLogTransferOptions {
510+
return &publishAndLogTransferOptions{}
511+
}
512+
513+
// withSkipAnchorTxBroadcast is an option for PublishAndLogTransfer that
514+
// indicates whether to skip the broadcast of the anchor transaction.
515+
func withSkipAnchorTxBroadcast() PublishAndLogTransferOption {
516+
return func(opts *publishAndLogTransferOptions) {
517+
opts.skipAnchorTxBroadcast = true
518+
}
519+
}
520+
521+
// withLabel is an option for PublishAndLogTransfer that sets the label for
522+
// the transfer.
523+
func withLabel(label string) PublishAndLogTransferOption {
524+
return func(opts *publishAndLogTransferOptions) {
525+
opts.label = label
526+
}
527+
}
528+
493529
// PublishAndLogTransfer is a helper function that invokes the
494530
// PublishAndLogTransfer RPC endpoint on the specified tapd node. This endpoint
495531
// performs a pre-anchored transfer.
496532
func PublishAndLogTransfer(t *testing.T, tapd commands.RpcClientsBundle,
497533
btcPkt *psbt.Packet, activeAssets []*tappsbt.VPacket,
498534
passiveAssets []*tappsbt.VPacket,
499-
commitResp *wrpc.CommitVirtualPsbtsResponse) *taprpc.SendAssetResponse {
535+
commitResp *wrpc.CommitVirtualPsbtsResponse,
536+
opts ...PublishAndLogTransferOption) *taprpc.SendAssetResponse {
500537

501538
t.Helper()
502539

540+
options := defaultPublishAndLogTransferOptions()
541+
for _, opt := range opts {
542+
opt(options)
543+
}
544+
503545
ctxb := context.Background()
504546
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
505547
defer cancel()
@@ -509,11 +551,13 @@ func PublishAndLogTransfer(t *testing.T, tapd commands.RpcClientsBundle,
509551
require.NoError(t, err)
510552

511553
request := &wrpc.PublishAndLogRequest{
512-
AnchorPsbt: buf.Bytes(),
513-
VirtualPsbts: make([][]byte, len(activeAssets)),
514-
PassiveAssetPsbts: make([][]byte, len(passiveAssets)),
515-
ChangeOutputIndex: commitResp.ChangeOutputIndex,
516-
LndLockedUtxos: commitResp.LndLockedUtxos,
554+
AnchorPsbt: buf.Bytes(),
555+
VirtualPsbts: make([][]byte, len(activeAssets)),
556+
PassiveAssetPsbts: make([][]byte, len(passiveAssets)),
557+
ChangeOutputIndex: commitResp.ChangeOutputIndex,
558+
LndLockedUtxos: commitResp.LndLockedUtxos,
559+
SkipAnchorTxBroadcast: options.skipAnchorTxBroadcast,
560+
Label: options.label,
517561
}
518562

519563
for idx := range activeAssets {

0 commit comments

Comments
 (0)