79453663b3
* 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>
583 lines
18 KiB
Go
583 lines
18 KiB
Go
//stm: #unit
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
"github.com/filecoin-project/lotus/api"
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
"github.com/filecoin-project/lotus/chain/types/mock"
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStat(t *testing.T) {
|
|
|
|
t.Run("local", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolStat))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// add blocks to the chain
|
|
first := mock.TipSet(mock.MkBlock(nil, 5, 4))
|
|
head := mock.TipSet(mock.MkBlock(first, 15, 7))
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
// mock actor to return for the sender
|
|
actor := types.Actor{Nonce: 2, Balance: big.NewInt(200000)}
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().ChainHead(ctx).Return(head, nil),
|
|
mockApi.EXPECT().ChainGetTipSet(ctx, head.Parents()).Return(first, nil),
|
|
mockApi.EXPECT().WalletList(ctx).Return([]address.Address{senderAddr, toAddr}, nil),
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
mockApi.EXPECT().StateGetActor(ctx, senderAddr, head.Key()).Return(&actor, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_STAT_002
|
|
err = app.Run([]string{"mpool", "stat", "--basefee-lookback", "1", "--local"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), "Nonce past: 1")
|
|
})
|
|
|
|
t.Run("all", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolStat))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// add blocks to the chain
|
|
first := mock.TipSet(mock.MkBlock(nil, 5, 4))
|
|
head := mock.TipSet(mock.MkBlock(first, 15, 7))
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
// mock actor to return for the sender
|
|
actor := types.Actor{Nonce: 2, Balance: big.NewInt(200000)}
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().ChainHead(ctx).Return(head, nil),
|
|
mockApi.EXPECT().ChainGetTipSet(ctx, head.Parents()).Return(first, nil),
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
mockApi.EXPECT().StateGetActor(ctx, senderAddr, head.Key()).Return(&actor, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_STAT_001
|
|
err = app.Run([]string{"mpool", "stat", "--basefee-lookback", "1"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), "Nonce past: 1")
|
|
})
|
|
}
|
|
|
|
func TestPending(t *testing.T) {
|
|
t.Run("all", func(t *testing.T) {
|
|
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolPending))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_PENDING_001
|
|
err = app.Run([]string{"mpool", "pending", "--cids"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("local", func(t *testing.T) {
|
|
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolPending))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().WalletList(ctx).Return([]address.Address{senderAddr}, nil),
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_PENDING_002
|
|
err = app.Run([]string{"mpool", "pending", "--local"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("to", func(t *testing.T) {
|
|
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolPending))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_PENDING_003
|
|
err = app.Run([]string{"mpool", "pending", "--to", sm.Message.To.String()})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("from", func(t *testing.T) {
|
|
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolPending))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_PENDING_004
|
|
err = app.Run([]string{"mpool", "pending", "--from", sm.Message.From.String()})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
}
|
|
|
|
func TestReplace(t *testing.T) {
|
|
t.Run("manual", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolReplaceCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().ChainGetMessage(ctx, sm.Cid()).Return(&sm.Message, nil),
|
|
mockApi.EXPECT().ChainHead(ctx).Return(nil, nil),
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
mockApi.EXPECT().WalletSignMessage(ctx, sm.Message.From, &sm.Message).Return(sm, nil),
|
|
mockApi.EXPECT().MpoolPush(ctx, sm).Return(sm.Cid(), nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_REPLACE_002
|
|
err = app.Run([]string{"mpool", "replace", "--gas-premium", "1", "--gas-feecap", "100", sm.Cid().String()})
|
|
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("auto", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolReplaceCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
// gas fee param should be equal to the one passed in the cli invocation (used below)
|
|
maxFee := "1000000"
|
|
parsedFee, err := types.ParseFIL(maxFee)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mss := api.MessageSendSpec{MaxFee: abi.TokenAmount(parsedFee)}
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().ChainGetMessage(ctx, sm.Cid()).Return(&sm.Message, nil),
|
|
mockApi.EXPECT().ChainHead(ctx).Return(nil, nil),
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
// use gomock.any to match the message in expected api calls
|
|
// since the replace function modifies the message between calls, it would be pointless to try to match the exact argument
|
|
mockApi.EXPECT().GasEstimateMessageGas(ctx, gomock.Any(), &mss, types.EmptyTSK).Return(&sm.Message, nil),
|
|
mockApi.EXPECT().WalletSignMessage(ctx, sm.Message.From, gomock.Any()).Return(sm, nil),
|
|
mockApi.EXPECT().MpoolPush(ctx, sm).Return(sm.Cid(), nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_REPLACE_002
|
|
err = app.Run([]string{"mpool", "replace", "--auto", "--fee-limit", maxFee, sm.Cid().String()})
|
|
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("sender / nonce", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolReplaceCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
// gas fee param should be equal to the one passed in the cli invocation (used below)
|
|
maxFee := "1000000"
|
|
parsedFee, err := types.ParseFIL(maxFee)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mss := api.MessageSendSpec{MaxFee: abi.TokenAmount(parsedFee)}
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().ChainHead(ctx).Return(nil, nil),
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
// use gomock.any to match the message in expected api calls
|
|
// since the replace function modifies the message between calls, it would be pointless to try to match the exact argument
|
|
mockApi.EXPECT().GasEstimateMessageGas(ctx, gomock.Any(), &mss, types.EmptyTSK).Return(&sm.Message, nil),
|
|
mockApi.EXPECT().WalletSignMessage(ctx, sm.Message.From, gomock.Any()).Return(sm, nil),
|
|
mockApi.EXPECT().MpoolPush(ctx, sm).Return(sm.Cid(), nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_REPLACE_001
|
|
err = app.Run([]string{"mpool", "replace", "--auto", "--fee-limit", maxFee, sm.Message.From.String(), fmt.Sprint(sm.Message.Nonce)})
|
|
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
}
|
|
|
|
func TestFindMsg(t *testing.T) {
|
|
t.Run("from", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolFindCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_FIND_001
|
|
err = app.Run([]string{"mpool", "find", "--from", sm.Message.From.String()})
|
|
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("to", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolFindCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_FIND_002
|
|
err = app.Run([]string{"mpool", "find", "--to", sm.Message.To.String()})
|
|
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
|
|
t.Run("method", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolFindCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 1, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_FIND_003
|
|
err = app.Run([]string{"mpool", "find", "--method", sm.Message.Method.String()})
|
|
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, buf.String(), sm.Cid().String())
|
|
})
|
|
}
|
|
|
|
func TestGasPerf(t *testing.T) {
|
|
t.Run("all", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolGasPerfCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// add blocks to the chain
|
|
first := mock.TipSet(mock.MkBlock(nil, 5, 4))
|
|
head := mock.TipSet(mock.MkBlock(first, 15, 7))
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 13, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
mockApi.EXPECT().ChainHead(ctx).Return(head, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_GAS_PERF_002
|
|
err = app.Run([]string{"mpool", "gas-perf", "--all", "true"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), sm.Message.From.String())
|
|
assert.Contains(t, buf.String(), fmt.Sprint(sm.Message.Nonce))
|
|
})
|
|
|
|
t.Run("local", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolGasPerfCmd))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
// add blocks to the chain
|
|
first := mock.TipSet(mock.MkBlock(nil, 5, 4))
|
|
head := mock.TipSet(mock.MkBlock(first, 15, 7))
|
|
|
|
// create a signed message to be returned as a pending message
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
toAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sm := mock.MkMessage(senderAddr, toAddr, 13, w)
|
|
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolPending(ctx, types.EmptyTSK).Return([]*types.SignedMessage{sm}, nil),
|
|
mockApi.EXPECT().WalletList(ctx).Return([]address.Address{senderAddr}, nil),
|
|
mockApi.EXPECT().ChainHead(ctx).Return(head, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_GAS_PERF_001
|
|
err = app.Run([]string{"mpool", "gas-perf"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), sm.Message.From.String())
|
|
assert.Contains(t, buf.String(), fmt.Sprint(sm.Message.Nonce))
|
|
})
|
|
}
|
|
|
|
func TestConfig(t *testing.T) {
|
|
t.Run("get", func(t *testing.T) {
|
|
app, mockApi, buf, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolConfig))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
mpoolCfg := &types.MpoolConfig{PriorityAddrs: []address.Address{senderAddr}, SizeLimitHigh: 1234567, SizeLimitLow: 6, ReplaceByFeeRatio: 0.25}
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolGetConfig(ctx).Return(mpoolCfg, nil),
|
|
)
|
|
|
|
//stm: @CLI_MEMPOOL_CONFIG_001
|
|
err = app.Run([]string{"mpool", "config"})
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, buf.String(), mpoolCfg.PriorityAddrs[0].String())
|
|
assert.Contains(t, buf.String(), fmt.Sprint(mpoolCfg.SizeLimitHigh))
|
|
assert.Contains(t, buf.String(), fmt.Sprint(mpoolCfg.SizeLimitLow))
|
|
assert.Contains(t, buf.String(), fmt.Sprint(mpoolCfg.ReplaceByFeeRatio))
|
|
})
|
|
|
|
t.Run("set", func(t *testing.T) {
|
|
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("mpool", MpoolConfig))
|
|
defer done()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
w, _ := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
senderAddr, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
mpoolCfg := &types.MpoolConfig{PriorityAddrs: []address.Address{senderAddr}, SizeLimitHigh: 234567, SizeLimitLow: 3, ReplaceByFeeRatio: 0.33}
|
|
gomock.InOrder(
|
|
mockApi.EXPECT().MpoolSetConfig(ctx, mpoolCfg).Return(nil),
|
|
)
|
|
|
|
bytes, err := json.Marshal(mpoolCfg)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
//stm: @CLI_MEMPOOL_CONFIG_002
|
|
err = app.Run([]string{"mpool", "config", string(bytes)})
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|