2021-11-03 20:31:33 +00:00
|
|
|
//stm: #unit
|
2020-07-09 20:35:43 +00:00
|
|
|
package paychmgr
|
|
|
|
|
|
|
|
import (
|
2020-08-20 16:09:52 +00:00
|
|
|
"bytes"
|
2020-07-09 20:35:43 +00:00
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
|
|
|
|
2020-07-09 20:35:43 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-09-16 04:06:04 +00:00
|
|
|
ds "github.com/ipfs/go-datastore"
|
|
|
|
ds_sync "github.com/ipfs/go-datastore/sync"
|
2020-07-09 20:35:43 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-09-16 04:06:04 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-09-16 04:06:04 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
2020-10-08 01:09:33 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
tutils "github.com/filecoin-project/specs-actors/v2/support/testing"
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2020-09-16 04:06:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
|
|
|
|
paychmock "github.com/filecoin-project/lotus/chain/actors/builtin/paych/mock"
|
2020-07-09 20:35:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-09-16 04:06:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/sigs"
|
2021-03-25 11:28:53 +00:00
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
2020-07-09 20:35:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckVoucherValid(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
fromKeyPrivate, fromKeyPublic := testGenerateKeyPair(t)
|
2020-08-17 15:13:13 +00:00
|
|
|
toKeyPrivate, toKeyPublic := testGenerateKeyPair(t)
|
2020-07-09 20:35:43 +00:00
|
|
|
randKeyPrivate, _ := testGenerateKeyPair(t)
|
|
|
|
|
|
|
|
ch := tutils.NewIDAddr(t, 100)
|
|
|
|
from := tutils.NewSECP256K1Addr(t, string(fromKeyPublic))
|
2020-08-17 15:13:13 +00:00
|
|
|
to := tutils.NewSECP256K1Addr(t, string(toKeyPublic))
|
2020-07-09 20:35:43 +00:00
|
|
|
fromAcct := tutils.NewActorAddr(t, "fromAct")
|
|
|
|
toAcct := tutils.NewActorAddr(t, "toAct")
|
|
|
|
|
2020-08-11 14:20:05 +00:00
|
|
|
mock := newMockManagerAPI()
|
2020-09-16 04:06:04 +00:00
|
|
|
mock.setAccountAddress(fromAcct, from)
|
|
|
|
mock.setAccountAddress(toAcct, to)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_VALID_001, @TOKEN_PAYCH_VOUCHER_VALID_002, @TOKEN_PAYCH_VOUCHER_VALID_003
|
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_VALID_004, @TOKEN_PAYCH_VOUCHER_VALID_005, @TOKEN_PAYCH_VOUCHER_VALID_006, @TOKEN_PAYCH_VOUCHER_VALID_007
|
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_VALID_009, @TOKEN_PAYCH_VOUCHER_VALID_010
|
2020-07-09 20:35:43 +00:00
|
|
|
tcases := []struct {
|
|
|
|
name string
|
|
|
|
expectError bool
|
|
|
|
key []byte
|
|
|
|
actorBalance big.Int
|
|
|
|
voucherAmount big.Int
|
|
|
|
voucherLane uint64
|
|
|
|
voucherNonce uint64
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates map[uint64]paych.LaneState
|
2020-07-09 20:35:43 +00:00
|
|
|
}{{
|
|
|
|
name: "passes when voucher amount < balance",
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
|
|
|
}, {
|
|
|
|
name: "fails when funds too low",
|
|
|
|
expectError: true,
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(5),
|
|
|
|
voucherAmount: big.NewInt(10),
|
|
|
|
}, {
|
|
|
|
name: "fails when invalid signature",
|
|
|
|
expectError: true,
|
|
|
|
key: randKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
2020-08-17 15:13:13 +00:00
|
|
|
}, {
|
|
|
|
name: "fails when signed by channel To account (instead of From account)",
|
|
|
|
expectError: true,
|
|
|
|
key: toKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
2020-07-09 20:35:43 +00:00
|
|
|
}, {
|
|
|
|
name: "fails when nonce too low",
|
|
|
|
expectError: true,
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
|
|
|
voucherLane: 1,
|
|
|
|
voucherNonce: 2,
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates: map[uint64]paych.LaneState{
|
2020-09-16 04:06:04 +00:00
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(2), 3),
|
2020-08-13 00:27:04 +00:00
|
|
|
},
|
2020-07-09 20:35:43 +00:00
|
|
|
}, {
|
|
|
|
name: "passes when nonce higher",
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
|
|
|
voucherLane: 1,
|
|
|
|
voucherNonce: 3,
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates: map[uint64]paych.LaneState{
|
2020-09-16 04:06:04 +00:00
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(2), 2),
|
2020-08-13 00:27:04 +00:00
|
|
|
},
|
2020-07-09 20:35:43 +00:00
|
|
|
}, {
|
|
|
|
name: "passes when nonce for different lane",
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
|
|
|
voucherLane: 2,
|
|
|
|
voucherNonce: 2,
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates: map[uint64]paych.LaneState{
|
2020-09-16 04:06:04 +00:00
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(2), 3),
|
2020-08-13 00:27:04 +00:00
|
|
|
},
|
2020-07-09 20:35:43 +00:00
|
|
|
}, {
|
|
|
|
name: "fails when voucher has higher nonce but lower value than lane state",
|
|
|
|
expectError: true,
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
|
|
|
voucherLane: 1,
|
|
|
|
voucherNonce: 3,
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates: map[uint64]paych.LaneState{
|
2020-09-16 04:06:04 +00:00
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(6), 2),
|
2020-08-13 00:27:04 +00:00
|
|
|
},
|
2020-07-09 20:35:43 +00:00
|
|
|
}, {
|
2020-07-10 18:06:52 +00:00
|
|
|
// voucher supersedes lane 1 redeemed so
|
|
|
|
// lane 1 effective redeemed = voucher amount
|
|
|
|
//
|
2020-09-14 08:11:11 +00:00
|
|
|
// required balance = voucher amt
|
2020-07-10 18:06:52 +00:00
|
|
|
// = 7
|
|
|
|
// So required balance: 7 < actor balance: 10
|
2020-09-14 08:11:11 +00:00
|
|
|
name: "passes when voucher total redeemed <= balance",
|
2020-07-09 20:35:43 +00:00
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
2020-07-10 18:06:52 +00:00
|
|
|
voucherAmount: big.NewInt(6),
|
2020-07-09 20:35:43 +00:00
|
|
|
voucherLane: 1,
|
2020-07-10 18:06:52 +00:00
|
|
|
voucherNonce: 2,
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates: map[uint64]paych.LaneState{
|
|
|
|
// Lane 1 (same as voucher lane 1)
|
2020-09-16 04:06:04 +00:00
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(4), 1),
|
2020-08-13 00:27:04 +00:00
|
|
|
},
|
2020-07-10 18:06:52 +00:00
|
|
|
}, {
|
2020-09-14 08:11:11 +00:00
|
|
|
// required balance = total redeemed
|
|
|
|
// = 6 (voucher lane 1) + 5 (lane 2)
|
2020-07-10 18:06:52 +00:00
|
|
|
// = 11
|
|
|
|
// So required balance: 11 > actor balance: 10
|
2020-09-14 08:11:11 +00:00
|
|
|
name: "fails when voucher total redeemed > balance",
|
2020-07-10 18:06:52 +00:00
|
|
|
expectError: true,
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(6),
|
|
|
|
voucherLane: 1,
|
|
|
|
voucherNonce: 1,
|
2020-08-13 00:27:04 +00:00
|
|
|
laneStates: map[uint64]paych.LaneState{
|
|
|
|
// Lane 2 (different from voucher lane 1)
|
2020-09-14 08:11:11 +00:00
|
|
|
2: paychmock.NewMockLaneState(big.NewInt(5), 1),
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
// voucher supersedes lane 1 redeemed so
|
|
|
|
// lane 1 effective redeemed = voucher amount
|
|
|
|
//
|
|
|
|
// required balance = total redeemed
|
|
|
|
// = 6 (new voucher lane 1) + 5 (lane 2)
|
|
|
|
// = 11
|
|
|
|
// So required balance: 11 > actor balance: 10
|
|
|
|
name: "fails when voucher total redeemed > balance",
|
|
|
|
expectError: true,
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(6),
|
|
|
|
voucherLane: 1,
|
|
|
|
voucherNonce: 2,
|
|
|
|
laneStates: map[uint64]paych.LaneState{
|
|
|
|
// Lane 1 (superseded by new voucher in voucher lane 1)
|
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(5), 1),
|
|
|
|
// Lane 2 (different from voucher lane 1)
|
|
|
|
2: paychmock.NewMockLaneState(big.NewInt(5), 1),
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
// voucher supersedes lane 1 redeemed so
|
|
|
|
// lane 1 effective redeemed = voucher amount
|
|
|
|
//
|
|
|
|
// required balance = total redeemed
|
|
|
|
// = 5 (new voucher lane 1) + 5 (lane 2)
|
|
|
|
// = 10
|
|
|
|
// So required balance: 10 <= actor balance: 10
|
|
|
|
name: "passes when voucher total redeemed <= balance",
|
|
|
|
expectError: false,
|
|
|
|
key: fromKeyPrivate,
|
|
|
|
actorBalance: big.NewInt(10),
|
|
|
|
voucherAmount: big.NewInt(5),
|
|
|
|
voucherLane: 1,
|
|
|
|
voucherNonce: 2,
|
|
|
|
laneStates: map[uint64]paych.LaneState{
|
|
|
|
// Lane 1 (superseded by new voucher in voucher lane 1)
|
|
|
|
1: paychmock.NewMockLaneState(big.NewInt(4), 1),
|
|
|
|
// Lane 2 (different from voucher lane 1)
|
|
|
|
2: paychmock.NewMockLaneState(big.NewInt(5), 1),
|
2020-08-13 00:27:04 +00:00
|
|
|
},
|
2020-07-09 20:35:43 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
for _, tcase := range tcases {
|
2020-07-09 22:49:43 +00:00
|
|
|
tcase := tcase
|
2020-07-09 20:35:43 +00:00
|
|
|
t.Run(tcase.name, func(t *testing.T) {
|
2020-08-17 15:13:13 +00:00
|
|
|
// Create an actor for the channel with the test case balance
|
2020-07-09 20:35:43 +00:00
|
|
|
act := &types.Actor{
|
|
|
|
Code: builtin.AccountActorCodeID,
|
|
|
|
Head: cid.Cid{},
|
|
|
|
Nonce: 0,
|
|
|
|
Balance: tcase.actorBalance,
|
|
|
|
}
|
2020-08-11 21:01:16 +00:00
|
|
|
|
2020-09-16 04:06:04 +00:00
|
|
|
mock.setPaychState(ch, act, paychmock.NewMockPayChState(
|
2020-09-14 08:11:11 +00:00
|
|
|
fromAcct, toAcct, abi.ChainEpoch(0), tcase.laneStates))
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
// Create a manager
|
2020-09-14 08:11:11 +00:00
|
|
|
store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore()))
|
2020-08-11 14:20:05 +00:00
|
|
|
mgr, err := newManager(store, mock)
|
2020-07-28 23:16:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-19 13:16:54 +00:00
|
|
|
// Add channel To address to wallet
|
|
|
|
mock.addWalletAddress(to)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2020-09-14 08:11:11 +00:00
|
|
|
// Create the test case signed voucher
|
2020-08-17 15:13:13 +00:00
|
|
|
sv := createTestVoucher(t, ch, tcase.voucherLane, tcase.voucherNonce, tcase.voucherAmount, tcase.key)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
// Check the voucher's validity
|
2020-07-09 20:35:43 +00:00
|
|
|
err = mgr.CheckVoucherValid(ctx, ch, sv)
|
|
|
|
if tcase.expectError {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:33:44 +00:00
|
|
|
func TestCreateVoucher(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-09-01 14:33:44 +00:00
|
|
|
|
|
|
|
// Create a voucher in lane 1
|
|
|
|
voucherLane1Amt := big.NewInt(5)
|
2022-04-20 21:34:28 +00:00
|
|
|
voucher := paychtypes.SignedVoucher{
|
2020-09-01 14:33:44 +00:00
|
|
|
Lane: 1,
|
|
|
|
Amount: voucherLane1Amt,
|
|
|
|
}
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_CREATE_001
|
2020-09-01 14:33:44 +00:00
|
|
|
res, err := s.mgr.CreateVoucher(ctx, s.ch, voucher)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, res.Voucher)
|
|
|
|
require.Equal(t, s.ch, res.Voucher.ChannelAddr)
|
|
|
|
require.Equal(t, voucherLane1Amt, res.Voucher.Amount)
|
|
|
|
require.EqualValues(t, 0, res.Shortfall.Int64())
|
|
|
|
|
|
|
|
nonce := res.Voucher.Nonce
|
|
|
|
|
|
|
|
// Create a voucher in lane 1 again, with a higher amount
|
|
|
|
voucherLane1Amt = big.NewInt(8)
|
2022-04-20 21:34:28 +00:00
|
|
|
voucher = paychtypes.SignedVoucher{
|
2020-09-01 14:33:44 +00:00
|
|
|
Lane: 1,
|
|
|
|
Amount: voucherLane1Amt,
|
|
|
|
}
|
|
|
|
res, err = s.mgr.CreateVoucher(ctx, s.ch, voucher)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, res.Voucher)
|
|
|
|
require.Equal(t, s.ch, res.Voucher.ChannelAddr)
|
|
|
|
require.Equal(t, voucherLane1Amt, res.Voucher.Amount)
|
|
|
|
require.EqualValues(t, 0, res.Shortfall.Int64())
|
|
|
|
require.Equal(t, nonce+1, res.Voucher.Nonce)
|
|
|
|
|
|
|
|
// Create a voucher in lane 2 that covers all the remaining funds
|
|
|
|
// in the channel
|
|
|
|
voucherLane2Amt := big.Sub(s.amt, voucherLane1Amt)
|
2022-04-20 21:34:28 +00:00
|
|
|
voucher = paychtypes.SignedVoucher{
|
2020-09-01 14:33:44 +00:00
|
|
|
Lane: 2,
|
|
|
|
Amount: voucherLane2Amt,
|
|
|
|
}
|
|
|
|
res, err = s.mgr.CreateVoucher(ctx, s.ch, voucher)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, res.Voucher)
|
|
|
|
require.Equal(t, s.ch, res.Voucher.ChannelAddr)
|
|
|
|
require.Equal(t, voucherLane2Amt, res.Voucher.Amount)
|
|
|
|
require.EqualValues(t, 0, res.Shortfall.Int64())
|
|
|
|
|
|
|
|
// Create a voucher in lane 2 that exceeds the remaining funds in the
|
|
|
|
// channel
|
|
|
|
voucherLane2Amt = big.Add(voucherLane2Amt, big.NewInt(1))
|
2022-04-20 21:34:28 +00:00
|
|
|
voucher = paychtypes.SignedVoucher{
|
2020-09-01 14:33:44 +00:00
|
|
|
Lane: 2,
|
|
|
|
Amount: voucherLane2Amt,
|
|
|
|
}
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_CREATE_004
|
2020-09-01 14:33:44 +00:00
|
|
|
res, err = s.mgr.CreateVoucher(ctx, s.ch, voucher)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Expect a shortfall value equal to the amount required to add the voucher
|
|
|
|
// to the channel
|
|
|
|
require.Nil(t, res.Voucher)
|
|
|
|
require.EqualValues(t, 1, res.Shortfall.Int64())
|
|
|
|
}
|
|
|
|
|
2020-07-09 20:35:43 +00:00
|
|
|
func TestAddVoucherDelta(t *testing.T) {
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_LIST_VOUCHERS_001
|
2020-07-09 20:35:43 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
|
|
|
voucherLane := uint64(1)
|
|
|
|
|
|
|
|
// Expect error when adding a voucher whose amount is less than minDelta
|
|
|
|
minDelta := big.NewInt(2)
|
|
|
|
nonce := uint64(1)
|
|
|
|
voucherAmount := big.NewInt(1)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err := s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
// Expect success when adding a voucher whose amount is equal to minDelta
|
|
|
|
nonce++
|
|
|
|
voucherAmount = big.NewInt(2)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
delta, err := s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, delta.Int64(), 2)
|
|
|
|
|
|
|
|
// Check that delta is correct when there's an existing voucher
|
|
|
|
nonce++
|
|
|
|
voucherAmount = big.NewInt(5)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
delta, err = s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, delta.Int64(), 3)
|
|
|
|
|
|
|
|
// Check that delta is correct when voucher added to a different lane
|
|
|
|
nonce = uint64(1)
|
|
|
|
voucherAmount = big.NewInt(6)
|
|
|
|
voucherLane = uint64(2)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
delta, err = s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, delta.Int64(), 6)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddVoucherNextLane(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
|
|
|
minDelta := big.NewInt(0)
|
|
|
|
voucherAmount := big.NewInt(2)
|
|
|
|
|
2020-07-09 21:20:17 +00:00
|
|
|
// Add a voucher in lane 2
|
2020-07-09 20:35:43 +00:00
|
|
|
nonce := uint64(1)
|
|
|
|
voucherLane := uint64(2)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err := s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-12-14 16:48:17 +00:00
|
|
|
ci, err := s.mgr.GetChannelInfo(ctx, s.ch)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, ci.NextLane, 3)
|
|
|
|
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_ALLOCATE_LANE_001
|
2020-08-13 14:14:11 +00:00
|
|
|
// Allocate a lane (should be lane 3)
|
2021-12-14 16:48:17 +00:00
|
|
|
lane, err := s.mgr.AllocateLane(ctx, s.ch)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, lane, 3)
|
|
|
|
|
2021-12-14 16:48:17 +00:00
|
|
|
ci, err = s.mgr.GetChannelInfo(ctx, s.ch)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, ci.NextLane, 4)
|
|
|
|
|
2020-07-09 21:20:17 +00:00
|
|
|
// Add a voucher in lane 1
|
2020-07-09 20:35:43 +00:00
|
|
|
voucherLane = uint64(1)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err = s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-12-14 16:48:17 +00:00
|
|
|
ci, err = s.mgr.GetChannelInfo(ctx, s.ch)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.EqualValues(t, ci.NextLane, 4)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2020-08-13 14:14:11 +00:00
|
|
|
// Add a voucher in lane 7
|
|
|
|
voucherLane = uint64(7)
|
2020-09-01 14:33:44 +00:00
|
|
|
sv = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err = s.mgr.AddVoucherOutbound(ctx, s.ch, sv, nil, minDelta)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-12-14 16:48:17 +00:00
|
|
|
ci, err = s.mgr.GetChannelInfo(ctx, s.ch)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.EqualValues(t, ci.NextLane, 8)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllocateLane(t *testing.T) {
|
2021-12-14 16:48:17 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2020-08-13 14:14:11 +00:00
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-08-13 14:14:11 +00:00
|
|
|
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_ALLOCATE_LANE_001
|
2020-08-13 14:14:11 +00:00
|
|
|
// First lane should be 0
|
2021-12-14 16:48:17 +00:00
|
|
|
lane, err := s.mgr.AllocateLane(ctx, s.ch)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, lane, 0)
|
|
|
|
|
|
|
|
// Next lane should be 1
|
2021-12-14 16:48:17 +00:00
|
|
|
lane, err = s.mgr.AllocateLane(ctx, s.ch)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, lane, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllocateLaneWithExistingLaneState(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
fromKeyPrivate, fromKeyPublic := testGenerateKeyPair(t)
|
2020-08-13 14:14:11 +00:00
|
|
|
|
|
|
|
ch := tutils.NewIDAddr(t, 100)
|
|
|
|
from := tutils.NewSECP256K1Addr(t, string(fromKeyPublic))
|
|
|
|
to := tutils.NewSECP256K1Addr(t, "secpTo")
|
|
|
|
fromAcct := tutils.NewActorAddr(t, "fromAct")
|
|
|
|
toAcct := tutils.NewActorAddr(t, "toAct")
|
|
|
|
|
|
|
|
mock := newMockManagerAPI()
|
2020-09-16 04:06:04 +00:00
|
|
|
mock.setAccountAddress(fromAcct, from)
|
|
|
|
mock.setAccountAddress(toAcct, to)
|
2020-08-17 15:13:13 +00:00
|
|
|
mock.addWalletAddress(to)
|
2020-08-13 14:14:11 +00:00
|
|
|
|
|
|
|
store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore()))
|
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
// Create a channel that will be retrieved from state
|
2020-08-13 14:14:11 +00:00
|
|
|
actorBalance := big.NewInt(10)
|
|
|
|
|
|
|
|
act := &types.Actor{
|
|
|
|
Code: builtin.AccountActorCodeID,
|
|
|
|
Head: cid.Cid{},
|
|
|
|
Nonce: 0,
|
|
|
|
Balance: actorBalance,
|
|
|
|
}
|
|
|
|
|
2020-09-14 08:11:11 +00:00
|
|
|
mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), make(map[uint64]paych.LaneState)))
|
2020-08-13 14:14:11 +00:00
|
|
|
|
|
|
|
mgr, err := newManager(store, mock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
// Create a voucher on lane 2
|
|
|
|
// (also reads the channel from state and puts it in the store)
|
|
|
|
voucherLane := uint64(2)
|
|
|
|
minDelta := big.NewInt(0)
|
|
|
|
nonce := uint64(2)
|
|
|
|
voucherAmount := big.NewInt(5)
|
|
|
|
sv := createTestVoucher(t, ch, voucherLane, nonce, voucherAmount, fromKeyPrivate)
|
|
|
|
_, err = mgr.AddVoucherInbound(ctx, ch, sv, nil, minDelta)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_ALLOCATE_LANE_001
|
2020-08-17 15:13:13 +00:00
|
|
|
// Allocate lane should return the next lane (lane 3)
|
2021-12-14 16:48:17 +00:00
|
|
|
lane, err := mgr.AllocateLane(ctx, ch)
|
2020-08-13 14:14:11 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, 3, lane)
|
2020-07-09 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
func TestAddVoucherInboundWalletKey(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
fromKeyPrivate, fromKeyPublic := testGenerateKeyPair(t)
|
|
|
|
|
|
|
|
ch := tutils.NewIDAddr(t, 100)
|
|
|
|
from := tutils.NewSECP256K1Addr(t, string(fromKeyPublic))
|
|
|
|
to := tutils.NewSECP256K1Addr(t, "secpTo")
|
|
|
|
fromAcct := tutils.NewActorAddr(t, "fromAct")
|
|
|
|
toAcct := tutils.NewActorAddr(t, "toAct")
|
|
|
|
|
|
|
|
// Create an actor for the channel in state
|
|
|
|
|
|
|
|
mock := newMockManagerAPI()
|
2020-09-14 08:11:11 +00:00
|
|
|
|
2020-09-16 04:06:04 +00:00
|
|
|
mock.setAccountAddress(fromAcct, from)
|
|
|
|
mock.setAccountAddress(toAcct, to)
|
|
|
|
|
2022-01-06 18:51:26 +00:00
|
|
|
act := &types.Actor{
|
|
|
|
Code: builtin.AccountActorCodeID,
|
|
|
|
Head: cid.Cid{},
|
|
|
|
Nonce: 0,
|
|
|
|
Balance: types.NewInt(20),
|
|
|
|
}
|
2020-09-14 08:11:11 +00:00
|
|
|
mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), make(map[uint64]paych.LaneState)))
|
2020-08-17 15:13:13 +00:00
|
|
|
|
|
|
|
// Create a manager
|
|
|
|
store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore()))
|
|
|
|
mgr, err := newManager(store, mock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Add a voucher
|
|
|
|
nonce := uint64(1)
|
|
|
|
voucherLane := uint64(1)
|
|
|
|
minDelta := big.NewInt(0)
|
|
|
|
voucherAmount := big.NewInt(2)
|
|
|
|
sv := createTestVoucher(t, ch, voucherLane, nonce, voucherAmount, fromKeyPrivate)
|
|
|
|
_, err = mgr.AddVoucherInbound(ctx, ch, sv, nil, minDelta)
|
|
|
|
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_CREATE_006
|
2020-08-17 15:13:13 +00:00
|
|
|
// Should fail because there is no wallet key matching the channel To
|
|
|
|
// address (ie, the channel is not "owned" by this node)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
// Add wallet key for To address
|
|
|
|
mock.addWalletAddress(to)
|
|
|
|
|
|
|
|
// Add voucher again
|
|
|
|
sv = createTestVoucher(t, ch, voucherLane, nonce, voucherAmount, fromKeyPrivate)
|
|
|
|
_, err = mgr.AddVoucherInbound(ctx, ch, sv, nil, minDelta)
|
|
|
|
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @TOKEN_PAYCH_VOUCHER_CREATE_001
|
2020-08-17 15:13:13 +00:00
|
|
|
// Should now pass because there is a wallet key matching the channel To
|
|
|
|
// address
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2020-08-20 16:09:52 +00:00
|
|
|
func TestBestSpendable(t *testing.T) {
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_LIST_VOUCHERS_001
|
2020-08-20 16:09:52 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
|
|
|
// Add vouchers to lane 1 with amounts: [1, 2, 3]
|
|
|
|
voucherLane := uint64(1)
|
|
|
|
minDelta := big.NewInt(0)
|
|
|
|
nonce := uint64(1)
|
|
|
|
voucherAmount := big.NewInt(1)
|
2020-09-01 14:33:44 +00:00
|
|
|
svL1V1 := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err := s.mgr.AddVoucherInbound(ctx, s.ch, svL1V1, nil, minDelta)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
nonce++
|
|
|
|
voucherAmount = big.NewInt(2)
|
2020-09-01 14:33:44 +00:00
|
|
|
svL1V2 := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err = s.mgr.AddVoucherInbound(ctx, s.ch, svL1V2, nil, minDelta)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
nonce++
|
|
|
|
voucherAmount = big.NewInt(3)
|
2020-09-01 14:33:44 +00:00
|
|
|
svL1V3 := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err = s.mgr.AddVoucherInbound(ctx, s.ch, svL1V3, nil, minDelta)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Add voucher to lane 2 with amounts: [2]
|
|
|
|
voucherLane = uint64(2)
|
|
|
|
nonce = uint64(1)
|
|
|
|
voucherAmount = big.NewInt(2)
|
2020-09-01 14:33:44 +00:00
|
|
|
svL2V1 := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
_, err = s.mgr.AddVoucherInbound(ctx, s.ch, svL2V1, nil, minDelta)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Return success exit code from calls to check if voucher is spendable
|
2020-09-01 14:33:44 +00:00
|
|
|
bsapi := newMockBestSpendableAPI(s.mgr)
|
|
|
|
s.mock.setCallResponse(&api.InvocResult{
|
2020-08-20 16:09:52 +00:00
|
|
|
MsgRct: &types.MessageReceipt{
|
|
|
|
ExitCode: 0,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_BEST_SPENDABLE_001
|
2020-08-20 16:09:52 +00:00
|
|
|
// Verify best spendable vouchers on each lane
|
2020-09-01 14:33:44 +00:00
|
|
|
vouchers, err := BestSpendableByLane(ctx, bsapi, s.ch)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, vouchers, 2)
|
|
|
|
|
|
|
|
vchr, ok := vouchers[1]
|
|
|
|
require.True(t, ok)
|
|
|
|
require.EqualValues(t, 3, vchr.Amount.Int64())
|
|
|
|
|
|
|
|
vchr, ok = vouchers[2]
|
|
|
|
require.True(t, ok)
|
|
|
|
require.EqualValues(t, 2, vchr.Amount.Int64())
|
|
|
|
|
|
|
|
// Submit voucher from lane 2
|
2020-09-01 14:33:44 +00:00
|
|
|
_, err = s.mgr.SubmitVoucher(ctx, s.ch, svL2V1, nil, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Best spendable voucher should no longer include lane 2
|
|
|
|
// (because voucher has not been submitted)
|
2020-09-01 14:33:44 +00:00
|
|
|
vouchers, err = BestSpendableByLane(ctx, bsapi, s.ch)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, vouchers, 1)
|
|
|
|
|
|
|
|
// Submit first voucher from lane 1
|
2020-09-01 14:33:44 +00:00
|
|
|
_, err = s.mgr.SubmitVoucher(ctx, s.ch, svL1V1, nil, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Best spendable voucher for lane 1 should still be highest value voucher
|
2020-09-01 14:33:44 +00:00
|
|
|
vouchers, err = BestSpendableByLane(ctx, bsapi, s.ch)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, vouchers, 1)
|
|
|
|
|
|
|
|
vchr, ok = vouchers[1]
|
|
|
|
require.True(t, ok)
|
|
|
|
require.EqualValues(t, 3, vchr.Amount.Int64())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckSpendable(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
|
|
|
// Create voucher with Extra
|
|
|
|
voucherLane := uint64(1)
|
|
|
|
nonce := uint64(1)
|
|
|
|
voucherAmount := big.NewInt(1)
|
2021-02-19 12:56:08 +00:00
|
|
|
voucher := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
2020-09-30 16:35:42 +00:00
|
|
|
// Add voucher
|
2020-08-20 16:09:52 +00:00
|
|
|
minDelta := big.NewInt(0)
|
2020-09-30 16:35:42 +00:00
|
|
|
_, err := s.mgr.AddVoucherInbound(ctx, s.ch, voucher, nil, minDelta)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Return success exit code from VM call, which indicates that voucher is
|
|
|
|
// spendable
|
|
|
|
successResponse := &api.InvocResult{
|
|
|
|
MsgRct: &types.MessageReceipt{
|
|
|
|
ExitCode: 0,
|
|
|
|
},
|
|
|
|
}
|
2020-09-01 14:33:44 +00:00
|
|
|
s.mock.setCallResponse(successResponse)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @TOKEN_PAYCH_CHECK_SPENDABLE_001
|
2020-08-20 16:09:52 +00:00
|
|
|
// Check that spendable is true
|
|
|
|
secret := []byte("secret")
|
2020-09-30 16:35:42 +00:00
|
|
|
spendable, err := s.mgr.CheckVoucherSpendable(ctx, s.ch, voucher, secret, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, spendable)
|
|
|
|
|
2020-09-30 16:35:42 +00:00
|
|
|
// Check that the secret was passed through correctly
|
2020-09-01 14:33:44 +00:00
|
|
|
lastCall := s.mock.getLastCall()
|
2022-04-20 21:34:28 +00:00
|
|
|
var p paychtypes.UpdateChannelStateParams
|
2020-08-20 16:09:52 +00:00
|
|
|
err = p.UnmarshalCBOR(bytes.NewReader(lastCall.Params))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, secret, p.Secret)
|
|
|
|
|
|
|
|
// Check that if VM call returns non-success exit code, spendable is false
|
2020-09-01 14:33:44 +00:00
|
|
|
s.mock.setCallResponse(&api.InvocResult{
|
2020-08-20 16:09:52 +00:00
|
|
|
MsgRct: &types.MessageReceipt{
|
|
|
|
ExitCode: 1,
|
|
|
|
},
|
|
|
|
})
|
2020-09-01 14:33:44 +00:00
|
|
|
spendable, err = s.mgr.CheckVoucherSpendable(ctx, s.ch, voucher, secret, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, spendable)
|
|
|
|
|
|
|
|
// Return success exit code (indicating voucher is spendable)
|
2020-09-01 14:33:44 +00:00
|
|
|
s.mock.setCallResponse(successResponse)
|
|
|
|
spendable, err = s.mgr.CheckVoucherSpendable(ctx, s.ch, voucher, secret, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, spendable)
|
|
|
|
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @TOKEN_PAYCH_CHECK_SPENDABLE_002
|
2020-08-20 16:09:52 +00:00
|
|
|
// Check that voucher is no longer spendable once it has been submitted
|
2020-09-01 14:33:44 +00:00
|
|
|
_, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-01 14:33:44 +00:00
|
|
|
spendable, err = s.mgr.CheckVoucherSpendable(ctx, s.ch, voucher, secret, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, spendable)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubmitVoucher(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// Set up a manager with a single payment channel
|
2020-09-14 08:11:11 +00:00
|
|
|
s := testSetupMgrWithChannel(t)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
|
|
|
// Create voucher with Extra
|
|
|
|
voucherLane := uint64(1)
|
|
|
|
nonce := uint64(1)
|
|
|
|
voucherAmount := big.NewInt(1)
|
2021-02-19 12:56:08 +00:00
|
|
|
voucher := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
2020-09-30 16:35:42 +00:00
|
|
|
// Add voucher
|
2020-08-20 16:09:52 +00:00
|
|
|
minDelta := big.NewInt(0)
|
2020-09-30 16:35:42 +00:00
|
|
|
_, err := s.mgr.AddVoucherInbound(ctx, s.ch, voucher, nil, minDelta)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Submit voucher
|
2021-02-19 12:56:08 +00:00
|
|
|
submitCid, err := s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-30 16:35:42 +00:00
|
|
|
// Check that the secret was passed through correctly
|
2020-09-01 14:33:44 +00:00
|
|
|
msg := s.mock.pushedMessages(submitCid)
|
2022-04-20 21:34:28 +00:00
|
|
|
var p paychtypes.UpdateChannelStateParams
|
2020-08-20 16:09:52 +00:00
|
|
|
err = p.UnmarshalCBOR(bytes.NewReader(msg.Message.Params))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Submit a voucher without first adding it
|
|
|
|
nonce++
|
|
|
|
voucherAmount = big.NewInt(3)
|
2021-02-19 12:56:08 +00:00
|
|
|
voucher = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
|
|
|
|
submitCid, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-01 14:33:44 +00:00
|
|
|
msg = s.mock.pushedMessages(submitCid)
|
2022-04-20 21:34:28 +00:00
|
|
|
var p3 paychtypes.UpdateChannelStateParams
|
2020-08-20 16:09:52 +00:00
|
|
|
err = p3.UnmarshalCBOR(bytes.NewReader(msg.Message.Params))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-12-14 15:56:16 +00:00
|
|
|
//stm: @TOKEN_PAYCH_LIST_VOUCHERS_001
|
2020-08-20 16:09:52 +00:00
|
|
|
// Verify that vouchers are marked as submitted
|
2020-09-01 14:33:44 +00:00
|
|
|
vis, err := s.mgr.ListVouchers(ctx, s.ch)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-30 16:35:42 +00:00
|
|
|
require.Len(t, vis, 2)
|
2020-08-20 16:09:52 +00:00
|
|
|
|
|
|
|
for _, vi := range vis {
|
|
|
|
require.True(t, vi.Submitted)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempting to submit the same voucher again should fail
|
2021-02-19 12:56:08 +00:00
|
|
|
_, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
|
2020-08-20 16:09:52 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:33:44 +00:00
|
|
|
type testScaffold struct {
|
|
|
|
mgr *Manager
|
|
|
|
mock *mockManagerAPI
|
|
|
|
ch address.Address
|
|
|
|
amt big.Int
|
|
|
|
fromAcct address.Address
|
|
|
|
fromKeyPrivate []byte
|
2020-07-09 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 08:11:11 +00:00
|
|
|
func testSetupMgrWithChannel(t *testing.T) *testScaffold {
|
2020-07-09 20:35:43 +00:00
|
|
|
fromKeyPrivate, fromKeyPublic := testGenerateKeyPair(t)
|
|
|
|
|
|
|
|
ch := tutils.NewIDAddr(t, 100)
|
|
|
|
from := tutils.NewSECP256K1Addr(t, string(fromKeyPublic))
|
|
|
|
to := tutils.NewSECP256K1Addr(t, "secpTo")
|
|
|
|
fromAcct := tutils.NewActorAddr(t, "fromAct")
|
|
|
|
toAcct := tutils.NewActorAddr(t, "toAct")
|
|
|
|
|
2020-08-11 14:20:05 +00:00
|
|
|
mock := newMockManagerAPI()
|
2020-09-16 04:06:04 +00:00
|
|
|
mock.setAccountAddress(fromAcct, from)
|
|
|
|
mock.setAccountAddress(toAcct, to)
|
2020-07-09 20:35:43 +00:00
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
// Create channel in state
|
2020-09-01 14:33:44 +00:00
|
|
|
balance := big.NewInt(20)
|
2020-07-09 20:35:43 +00:00
|
|
|
act := &types.Actor{
|
|
|
|
Code: builtin.AccountActorCodeID,
|
|
|
|
Head: cid.Cid{},
|
|
|
|
Nonce: 0,
|
2020-09-01 14:33:44 +00:00
|
|
|
Balance: balance,
|
2020-07-09 20:35:43 +00:00
|
|
|
}
|
2020-09-14 08:11:11 +00:00
|
|
|
mock.setPaychState(ch, act, paychmock.NewMockPayChState(fromAcct, toAcct, abi.ChainEpoch(0), make(map[uint64]paych.LaneState)))
|
2020-07-09 20:35:43 +00:00
|
|
|
|
|
|
|
store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore()))
|
2020-08-11 14:20:05 +00:00
|
|
|
mgr, err := newManager(store, mock)
|
2020-07-28 23:16:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-17 15:13:13 +00:00
|
|
|
// Create the channel in the manager's store
|
|
|
|
ci := &ChannelInfo{
|
|
|
|
Channel: &ch,
|
|
|
|
Control: fromAcct,
|
|
|
|
Target: toAcct,
|
|
|
|
Direction: DirOutbound,
|
|
|
|
}
|
2021-12-14 17:01:45 +00:00
|
|
|
err = mgr.store.putChannelInfo(context.Background(), ci)
|
2020-07-09 20:35:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-17 15:13:13 +00:00
|
|
|
|
2020-09-01 14:33:44 +00:00
|
|
|
// Add the from signing key to the wallet
|
|
|
|
mock.addSigningKey(fromKeyPrivate)
|
|
|
|
|
|
|
|
return &testScaffold{
|
|
|
|
mgr: mgr,
|
|
|
|
mock: mock,
|
|
|
|
ch: ch,
|
|
|
|
amt: balance,
|
|
|
|
fromAcct: fromAcct,
|
|
|
|
fromKeyPrivate: fromKeyPrivate,
|
|
|
|
}
|
2020-07-09 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testGenerateKeyPair(t *testing.T) ([]byte, []byte) {
|
|
|
|
priv, err := sigs.Generate(crypto.SigTypeSecp256k1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
pub, err := sigs.ToPublic(crypto.SigTypeSecp256k1, priv)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return priv, pub
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paychtypes.SignedVoucher {
|
|
|
|
sv := &paychtypes.SignedVoucher{
|
2020-07-15 09:12:03 +00:00
|
|
|
ChannelAddr: ch,
|
2020-07-16 15:24:55 +00:00
|
|
|
Lane: voucherLane,
|
|
|
|
Nonce: nonce,
|
|
|
|
Amount: voucherAmount,
|
2020-07-09 20:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
signingBytes, err := sv.SigningBytes()
|
|
|
|
require.NoError(t, err)
|
|
|
|
sig, err := sigs.Sign(crypto.SigTypeSecp256k1, key, signingBytes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
sv.Signature = sig
|
|
|
|
return sv
|
|
|
|
}
|
2020-08-20 16:09:52 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paychtypes.SignedVoucher { //nolint:deadcode
|
|
|
|
sv := &paychtypes.SignedVoucher{
|
2020-08-20 16:09:52 +00:00
|
|
|
ChannelAddr: ch,
|
|
|
|
Lane: voucherLane,
|
|
|
|
Nonce: nonce,
|
|
|
|
Amount: voucherAmount,
|
2022-04-20 21:34:28 +00:00
|
|
|
Extra: &paychtypes.ModVerifyParams{
|
2020-08-20 16:09:52 +00:00
|
|
|
Actor: tutils.NewActorAddr(t, "act"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
signingBytes, err := sv.SigningBytes()
|
|
|
|
require.NoError(t, err)
|
|
|
|
sig, err := sigs.Sign(crypto.SigTypeSecp256k1, key, signingBytes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
sv.Signature = sig
|
|
|
|
|
|
|
|
return sv
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockBestSpendableAPI struct {
|
|
|
|
mgr *Manager
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*paychtypes.SignedVoucher, error) {
|
2020-08-20 16:09:52 +00:00
|
|
|
vi, err := m.mgr.ListVouchers(ctx, ch)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
out := make([]*paychtypes.SignedVoucher, len(vi))
|
2020-08-20 16:09:52 +00:00
|
|
|
for k, v := range vi {
|
|
|
|
out[k] = v.Voucher
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *paychtypes.SignedVoucher, secret []byte, proof []byte) (bool, error) {
|
2020-08-20 16:09:52 +00:00
|
|
|
return m.mgr.CheckVoucherSpendable(ctx, ch, voucher, secret, proof)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockBestSpendableAPI(mgr *Manager) BestSpendableAPI {
|
|
|
|
return &mockBestSpendableAPI{mgr: mgr}
|
|
|
|
}
|