@@ -3,6 +3,7 @@ package sweepbatcher
33import (
44 "context"
55 "fmt"
6+ "sync"
67 "testing"
78
89 "github.com/btcsuite/btcd/btcutil"
@@ -630,6 +631,9 @@ type mockPresigner struct {
630631
631632 // failAt is optional index of a call at which it fails, 1 based.
632633 failAt int
634+
635+ // mu protects the state.
636+ mu sync.Mutex
633637}
634638
635639// SignTx memorizes the value of the output and fails if the number of
@@ -639,6 +643,9 @@ func (p *mockPresigner) SignTx(ctx context.Context,
639643 minRelayFee , feeRate chainfee.SatPerKWeight ,
640644 loadOnly bool ) (* wire.MsgTx , error ) {
641645
646+ p .mu .Lock ()
647+ defer p .mu .Unlock ()
648+
642649 if ctx .Err () != nil {
643650 return nil , ctx .Err ()
644651 }
@@ -1037,7 +1044,8 @@ func TestPresign(t *testing.T) {
10371044 },
10381045
10391046 {
1040- name : "small amount => fewer steps until clamped" ,
1047+ name : "small amount => fewer steps until " +
1048+ "clamped" ,
10411049 presigner : & mockPresigner {},
10421050 primarySweepID : op1 ,
10431051 sweeps : []sweep {
@@ -1085,10 +1093,29 @@ func TestPresign(t *testing.T) {
10851093 destAddr : destAddr ,
10861094 nextBlockFeeRate : chainfee .FeePerKwFloor ,
10871095 minRelayFeeRate : chainfee .FeePerKwFloor ,
1088- wantErr : "for feeRate 363 sat/kw " ,
1096+ wantErr : "test error in SignTx " ,
10891097 },
10901098 }
10911099
1100+ type pair struct {
1101+ output btcutil.Amount
1102+ lockTime uint32
1103+ }
1104+
1105+ zip := func (outputs []btcutil.Amount , lockTimes []uint32 ) []pair {
1106+ require .Equal (t , len (outputs ), len (lockTimes ))
1107+
1108+ pairs := make ([]pair , len (outputs ))
1109+ for i , output := range outputs {
1110+ pairs [i ] = pair {
1111+ output : output ,
1112+ lockTime : lockTimes [i ],
1113+ }
1114+ }
1115+
1116+ return pairs
1117+ }
1118+
10921119 for _ , tc := range cases {
10931120 t .Run (tc .name , func (t * testing.T ) {
10941121 err := presign (
@@ -1102,8 +1129,11 @@ func TestPresign(t *testing.T) {
11021129 } else {
11031130 require .NoError (t , err )
11041131 p := tc .presigner .(* mockPresigner )
1105- require .Equal (t , tc .wantOutputs , p .outputs )
1106- require .Equal (t , tc .wantLockTimes , p .lockTimes )
1132+ require .ElementsMatch (
1133+ t ,
1134+ zip (tc .wantOutputs , tc .wantLockTimes ),
1135+ zip (p .outputs , p .lockTimes ),
1136+ )
11071137 }
11081138 })
11091139 }
0 commit comments