fix more paychmgr tests

This commit is contained in:
vyzo 2021-12-14 19:01:45 +02:00
parent e1634128c1
commit f00698aafd
4 changed files with 39 additions and 36 deletions

View File

@ -748,7 +748,7 @@ func testSetupMgrWithChannel(t *testing.T) *testScaffold {
Target: toAcct,
Direction: DirOutbound,
}
err = mgr.store.putChannelInfo(ci)
err = mgr.store.putChannelInfo(context.Background(), ci)
require.NoError(t, err)
// Add the from signing key to the wallet

View File

@ -87,7 +87,7 @@ func TestPaychGetCreateChannelThenAddFunds(t *testing.T) {
require.NoError(t, err)
// Should have no channels yet (message sent but channel not created)
cis, err := mgr.ListChannels()
cis, err := mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 0)
@ -112,7 +112,7 @@ func TestPaychGetCreateChannelThenAddFunds(t *testing.T) {
require.NotEqual(t, createMsgCid, addFundsMsgCid)
// Should have one channel, whose address is the channel that was created
cis, err := mgr.ListChannels()
cis, err := mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
@ -121,7 +121,7 @@ func TestPaychGetCreateChannelThenAddFunds(t *testing.T) {
// channel).
// PendingAmount should be amount sent in second GetPaych
// (second GetPaych triggered add funds, which has not yet been confirmed)
ci, err := mgr.GetChannelInfo(ch)
ci, err := mgr.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.EqualValues(t, 10, ci.Amount.Int64())
require.EqualValues(t, 5, ci.PendingAmount.Int64())
@ -135,13 +135,13 @@ func TestPaychGetCreateChannelThenAddFunds(t *testing.T) {
require.NoError(t, err)
// Should still have one channel
cis, err = mgr.ListChannels()
cis, err = mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
// Channel amount should include last amount sent to GetPaych
ci, err = mgr.GetChannelInfo(ch)
ci, err = mgr.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.EqualValues(t, 15, ci.Amount.Int64())
require.EqualValues(t, 0, ci.PendingAmount.Int64())
@ -203,12 +203,12 @@ func TestPaychGetCreateChannelWithErrorThenCreateAgain(t *testing.T) {
require.NoError(t, err)
// Should have one channel, whose address is the channel that was created
cis, err := mgr.ListChannels()
cis, err := mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
ci, err := mgr.GetChannelInfo(ch)
ci, err := mgr.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.Equal(t, amt2, ci.Amount)
}()
@ -259,12 +259,12 @@ func TestPaychGetRecoverAfterError(t *testing.T) {
require.NoError(t, err)
// Should have one channel, whose address is the channel that was created
cis, err := mgr.ListChannels()
cis, err := mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
ci, err := mgr.GetChannelInfo(ch)
ci, err := mgr.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.Equal(t, amt2, ci.Amount)
require.EqualValues(t, 0, ci.PendingAmount.Int64())
@ -311,12 +311,12 @@ func TestPaychGetRecoverAfterAddFundsError(t *testing.T) {
require.Error(t, err)
// Should have one channel, whose address is the channel that was created
cis, err := mgr.ListChannels()
cis, err := mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
ci, err := mgr.GetChannelInfo(ch)
ci, err := mgr.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.Equal(t, amt, ci.Amount)
require.EqualValues(t, 0, ci.PendingAmount.Int64())
@ -338,13 +338,13 @@ func TestPaychGetRecoverAfterAddFundsError(t *testing.T) {
require.NoError(t, err)
// Should have one channel, whose address is the channel that was created
cis, err = mgr.ListChannels()
cis, err = mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
// Amount should include amount for successful add funds msg
ci, err = mgr.GetChannelInfo(ch)
ci, err = mgr.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.Equal(t, amt.Int64()+amt3.Int64(), ci.Amount.Int64())
require.EqualValues(t, 0, ci.PendingAmount.Int64())
@ -384,7 +384,7 @@ func TestPaychGetRestartAfterCreateChannelMsg(t *testing.T) {
require.NoError(t, err)
// Should have no channels yet (message sent but channel not created)
cis, err := mgr2.ListChannels()
cis, err := mgr2.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 0)
@ -409,7 +409,7 @@ func TestPaychGetRestartAfterCreateChannelMsg(t *testing.T) {
require.NotEqual(t, createMsgCid, addFundsMsgCid)
// Should have one channel, whose address is the channel that was created
cis, err := mgr2.ListChannels()
cis, err := mgr2.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
@ -418,7 +418,7 @@ func TestPaychGetRestartAfterCreateChannelMsg(t *testing.T) {
// channel).
// PendingAmount should be amount sent in second GetPaych
// (second GetPaych triggered add funds, which has not yet been confirmed)
ci, err := mgr2.GetChannelInfo(ch)
ci, err := mgr2.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.EqualValues(t, 10, ci.Amount.Int64())
require.EqualValues(t, 5, ci.PendingAmount.Int64())
@ -481,13 +481,13 @@ func TestPaychGetRestartAfterAddFundsMsg(t *testing.T) {
require.NoError(t, err)
// Should have one channel, whose address is the channel that was created
cis, err := mgr2.ListChannels()
cis, err := mgr2.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 1)
require.Equal(t, ch, cis[0])
// Amount should include amount for successful add funds msg
ci, err := mgr2.GetChannelInfo(ch)
ci, err := mgr2.GetChannelInfo(ctx, ch)
require.NoError(t, err)
require.Equal(t, amt.Int64()+amt2.Int64(), ci.Amount.Int64())
require.EqualValues(t, 0, ci.PendingAmount.Int64())
@ -917,7 +917,7 @@ func TestPaychAvailableFunds(t *testing.T) {
require.NoError(t, err)
// No channel created yet so available funds should be all zeroes
av, err := mgr.AvailableFundsByFromTo(from, to)
av, err := mgr.AvailableFundsByFromTo(ctx, from, to)
require.NoError(t, err)
require.Nil(t, av.Channel)
require.Nil(t, av.PendingWaitSentinel)
@ -932,7 +932,7 @@ func TestPaychAvailableFunds(t *testing.T) {
require.NoError(t, err)
// Available funds should reflect create channel message sent
av, err = mgr.AvailableFundsByFromTo(from, to)
av, err = mgr.AvailableFundsByFromTo(ctx, from, to)
require.NoError(t, err)
require.Nil(t, av.Channel)
require.EqualValues(t, 0, av.ConfirmedAmt.Int64())
@ -961,7 +961,7 @@ func TestPaychAvailableFunds(t *testing.T) {
waitForQueueSize(t, mgr, from, to, 1)
// Available funds should now include queued funds
av, err = mgr.AvailableFundsByFromTo(from, to)
av, err = mgr.AvailableFundsByFromTo(ctx, from, to)
require.NoError(t, err)
require.Nil(t, av.Channel)
require.NotNil(t, av.PendingWaitSentinel)
@ -996,7 +996,7 @@ func TestPaychAvailableFunds(t *testing.T) {
// Available funds should now include the channel and also a wait sentinel
// for the add funds message
av, err = mgr.AvailableFunds(ch)
av, err = mgr.AvailableFunds(ctx, ch)
require.NoError(t, err)
require.NotNil(t, av.Channel)
require.NotNil(t, av.PendingWaitSentinel)
@ -1018,7 +1018,7 @@ func TestPaychAvailableFunds(t *testing.T) {
require.NoError(t, err)
// Available funds should no longer have a wait sentinel
av, err = mgr.AvailableFunds(ch)
av, err = mgr.AvailableFunds(ctx, ch)
require.NoError(t, err)
require.NotNil(t, av.Channel)
require.Nil(t, av.PendingWaitSentinel)
@ -1039,7 +1039,7 @@ func TestPaychAvailableFunds(t *testing.T) {
_, err = mgr.AddVoucherOutbound(ctx, ch, voucher, nil, types.NewInt(0))
require.NoError(t, err)
av, err = mgr.AvailableFunds(ch)
av, err = mgr.AvailableFunds(ctx, ch)
require.NoError(t, err)
require.NotNil(t, av.Channel)
require.Nil(t, av.PendingWaitSentinel)

View File

@ -63,7 +63,7 @@ func TestPaychSettle(t *testing.T) {
require.NotEqual(t, ch, ch2)
// There should now be two channels
cis, err := mgr.ListChannels()
cis, err := mgr.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, cis, 2)
}

View File

@ -1,6 +1,7 @@
package paychmgr
import (
"context"
"testing"
"github.com/filecoin-project/go-address"
@ -12,8 +13,10 @@ import (
)
func TestStore(t *testing.T) {
ctx := context.Background()
store := NewStore(ds_sync.MutexWrap(ds.NewMapDatastore()))
addrs, err := store.ListChannels()
addrs, err := store.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, addrs, 0)
@ -38,19 +41,19 @@ func TestStore(t *testing.T) {
}
// Track the channel
_, err = store.TrackChannel(ci)
_, err = store.TrackChannel(ctx, ci)
require.NoError(t, err)
// Tracking same channel again should error
_, err = store.TrackChannel(ci)
_, err = store.TrackChannel(ctx, ci)
require.Error(t, err)
// Track another channel
_, err = store.TrackChannel(ci2)
_, err = store.TrackChannel(ctx, ci2)
require.NoError(t, err)
// List channels should include all channels
addrs, err = store.ListChannels()
addrs, err = store.ListChannels(ctx)
require.NoError(t, err)
require.Len(t, addrs, 2)
t0100, err := address.NewIDAddress(100)
@ -61,25 +64,25 @@ func TestStore(t *testing.T) {
require.Contains(t, addrs, t0200)
// Request vouchers for channel
vouchers, err := store.VouchersForPaych(*ci.Channel)
vouchers, err := store.VouchersForPaych(ctx, *ci.Channel)
require.NoError(t, err)
require.Len(t, vouchers, 1)
// Requesting voucher for non-existent channel should error
_, err = store.VouchersForPaych(tutils.NewIDAddr(t, 300))
_, err = store.VouchersForPaych(ctx, tutils.NewIDAddr(t, 300))
require.Equal(t, err, ErrChannelNotTracked)
// Allocate lane for channel
lane, err := store.AllocateLane(*ci.Channel)
lane, err := store.AllocateLane(ctx, *ci.Channel)
require.NoError(t, err)
require.Equal(t, lane, uint64(0))
// Allocate next lane for channel
lane, err = store.AllocateLane(*ci.Channel)
lane, err = store.AllocateLane(ctx, *ci.Channel)
require.NoError(t, err)
require.Equal(t, lane, uint64(1))
// Allocate next lane for non-existent channel should error
_, err = store.AllocateLane(tutils.NewIDAddr(t, 300))
_, err = store.AllocateLane(ctx, tutils.NewIDAddr(t, 300))
require.Equal(t, err, ErrChannelNotTracked)
}