diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 12ab70bfc..740a97103 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -93,7 +93,7 @@ func (pm *Manager) GetChannelInfo(addr address.Address) (*ChannelInfo, error) { return pm.store.getChannelInfo(addr) } -// checks if the given voucher is valid (is or could become spendable at some point) +// CheckVoucherValid checks if the given voucher is valid (is or could become spendable at some point) func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error { _, err := pm.checkVoucherValid(ctx, ch, sv) return err @@ -159,7 +159,7 @@ func (pm *Manager) checkVoucherValid(ctx context.Context, ch address.Address, sv return pca, nil } -// checks if the given voucher is currently spendable +// CheckVoucherSpendable checks if the given voucher is currently spendable func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { owner, err := pm.getPaychOwner(ctx, ch) if err != nil { @@ -321,9 +321,9 @@ func (pm *Manager) NextNonceForLane(ctx context.Context, ch address.Address, lan var maxnonce uint64 for _, v := range vouchers { - if uint64(v.Voucher.Lane) == lane { - if uint64(v.Voucher.Nonce) > maxnonce { - maxnonce = uint64(v.Voucher.Nonce) + if v.Voucher.Lane == lane { + if v.Voucher.Nonce > maxnonce { + maxnonce = v.Voucher.Nonce } } } diff --git a/paychmgr/paych_test.go b/paychmgr/paych_test.go index 301621d7b..e39f43335 100644 --- a/paychmgr/paych_test.go +++ b/paychmgr/paych_test.go @@ -93,8 +93,8 @@ func TestPaychOutbound(t *testing.T) { toAcct := tutils.NewIDAddr(t, 202) sm := newMockStateManager() - sm.setAccountState(fromAcct, account.State{from}) - sm.setAccountState(toAcct, account.State{to}) + sm.setAccountState(fromAcct, account.State{Address: from}) + sm.setAccountState(toAcct, account.State{Address: to}) sm.setPaychState(ch, nil, paych.State{ From: fromAcct, To: toAcct, @@ -129,8 +129,8 @@ func TestPaychInbound(t *testing.T) { toAcct := tutils.NewIDAddr(t, 202) sm := newMockStateManager() - sm.setAccountState(fromAcct, account.State{from}) - sm.setAccountState(toAcct, account.State{to}) + sm.setAccountState(fromAcct, account.State{Address: from}) + sm.setAccountState(toAcct, account.State{Address: to}) sm.setPaychState(ch, nil, paych.State{ From: fromAcct, To: toAcct, @@ -167,8 +167,8 @@ func TestCheckVoucherValid(t *testing.T) { toAcct := tutils.NewActorAddr(t, "toAct") sm := newMockStateManager() - sm.setAccountState(fromAcct, account.State{from}) - sm.setAccountState(toAcct, account.State{to}) + sm.setAccountState(fromAcct, account.State{Address: from}) + sm.setAccountState(toAcct, account.State{Address: to}) tcases := []struct { name string @@ -281,6 +281,7 @@ func TestCheckVoucherValid(t *testing.T) { }} for _, tcase := range tcases { + tcase := tcase t.Run(tcase.name, func(t *testing.T) { store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore())) @@ -319,7 +320,7 @@ func TestAddVoucherDelta(t *testing.T) { ctx := context.Background() // Set up a manager with a single payment channel - mgr, ch, fromKeyPrivate := testSetupMgrWithChannel(t, ctx) + mgr, ch, fromKeyPrivate := testSetupMgrWithChannel(ctx, t) voucherLane := uint64(1) @@ -361,7 +362,7 @@ func TestAddVoucherNextLane(t *testing.T) { ctx := context.Background() // Set up a manager with a single payment channel - mgr, ch, fromKeyPrivate := testSetupMgrWithChannel(t, ctx) + mgr, ch, fromKeyPrivate := testSetupMgrWithChannel(ctx, t) minDelta := big.NewInt(0) voucherAmount := big.NewInt(2) @@ -402,7 +403,7 @@ func TestAddVoucherProof(t *testing.T) { ctx := context.Background() // Set up a manager with a single payment channel - mgr, ch, fromKeyPrivate := testSetupMgrWithChannel(t, ctx) + mgr, ch, fromKeyPrivate := testSetupMgrWithChannel(ctx, t) nonce := uint64(1) voucherAmount := big.NewInt(1) @@ -449,7 +450,7 @@ func TestAllocateLane(t *testing.T) { ctx := context.Background() // Set up a manager with a single payment channel - mgr, ch, _ := testSetupMgrWithChannel(t, ctx) + mgr, ch, _ := testSetupMgrWithChannel(ctx, t) // First lane should be 0 lane, err := mgr.AllocateLane(ch) @@ -466,7 +467,7 @@ func TestNextNonceForLane(t *testing.T) { ctx := context.Background() // Set up a manager with a single payment channel - mgr, ch, key := testSetupMgrWithChannel(t, ctx) + mgr, ch, key := testSetupMgrWithChannel(ctx, t) // Expect next nonce for non-existent lane to be 1 next, err := mgr.NextNonceForLane(ctx, ch, 1) @@ -506,7 +507,7 @@ func TestNextNonceForLane(t *testing.T) { require.EqualValues(t, next, 8) } -func testSetupMgrWithChannel(t *testing.T, ctx context.Context) (*Manager, address.Address, []byte) { +func testSetupMgrWithChannel(ctx context.Context, t *testing.T) (*Manager, address.Address, []byte) { fromKeyPrivate, fromKeyPublic := testGenerateKeyPair(t) ch := tutils.NewIDAddr(t, 100) @@ -516,8 +517,8 @@ func testSetupMgrWithChannel(t *testing.T, ctx context.Context) (*Manager, addre toAcct := tutils.NewActorAddr(t, "toAct") sm := newMockStateManager() - sm.setAccountState(fromAcct, account.State{from}) - sm.setAccountState(toAcct, account.State{to}) + sm.setAccountState(fromAcct, account.State{Address: from}) + sm.setAccountState(toAcct, account.State{Address: to}) act := &types.Actor{ Code: builtin.AccountActorCodeID, diff --git a/paychmgr/state.go b/paychmgr/state.go index dd67ee84b..3012be9cc 100644 --- a/paychmgr/state.go +++ b/paychmgr/state.go @@ -74,7 +74,7 @@ func nextLaneFromState(st *paych.State) uint64 { func findLane(states []*paych.LaneState, lane uint64) *paych.LaneState { var ls *paych.LaneState for _, laneState := range states { - if uint64(laneState.ID) == lane { + if laneState.ID == lane { ls = laneState break } diff --git a/paychmgr/store_test.go b/paychmgr/store_test.go index 6ef407f4f..094226464 100644 --- a/paychmgr/store_test.go +++ b/paychmgr/store_test.go @@ -60,7 +60,7 @@ func TestStore(t *testing.T) { require.Len(t, vouchers, 1) // Requesting voucher for non-existent channel should error - vouchers, err = store.VouchersForPaych(tutils.NewIDAddr(t, 300)) + _, err = store.VouchersForPaych(tutils.NewIDAddr(t, 300)) require.Equal(t, err, ErrChannelNotTracked) // Allocate lane for channel @@ -74,7 +74,7 @@ func TestStore(t *testing.T) { require.Equal(t, lane, uint64(1)) // Allocate next lane for non-existent channel should error - lane, err = store.AllocateLane(tutils.NewIDAddr(t, 300)) + _, err = store.AllocateLane(tutils.NewIDAddr(t, 300)) require.Equal(t, err, ErrChannelNotTracked) }