2022-08-29 14:25:30 +00:00
|
|
|
// stm: #unit
|
2019-12-01 23:11:43 +00:00
|
|
|
package messagepool
|
2019-12-01 22:22:10 +00:00
|
|
|
|
|
|
|
import (
|
2020-04-17 20:44:13 +00:00
|
|
|
"context"
|
2019-12-02 22:28:28 +00:00
|
|
|
"fmt"
|
2020-08-25 02:02:06 +00:00
|
|
|
"sort"
|
2019-12-01 22:22:10 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2021-09-02 16:07:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-10-08 01:09:33 +00:00
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
2020-10-08 01:09:33 +00:00
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
|
2021-06-08 13:20:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-09-02 16:07:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
2020-08-25 10:16:55 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
2019-12-01 22:22:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types/mock"
|
|
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
2020-01-31 00:20:04 +00:00
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
2019-12-01 22:22:10 +00:00
|
|
|
)
|
|
|
|
|
2020-08-01 23:29:26 +00:00
|
|
|
func init() {
|
|
|
|
_ = logging.SetLogLevel("*", "INFO")
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
type testMpoolAPI struct {
|
2019-12-01 22:22:10 +00:00
|
|
|
cb func(rev, app []*types.TipSet) error
|
|
|
|
|
|
|
|
bmsgs map[cid.Cid][]*types.SignedMessage
|
|
|
|
statenonce map[address.Address]uint64
|
2020-08-06 14:08:02 +00:00
|
|
|
balance map[address.Address]types.BigInt
|
2019-12-02 22:28:28 +00:00
|
|
|
|
|
|
|
tipsets []*types.TipSet
|
2020-08-25 10:57:02 +00:00
|
|
|
|
|
|
|
published int
|
2020-09-05 19:15:18 +00:00
|
|
|
|
|
|
|
baseFee types.BigInt
|
2019-12-01 22:22:10 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 16:38:41 +00:00
|
|
|
func newTestMpoolAPI() *testMpoolAPI {
|
2020-08-25 02:02:06 +00:00
|
|
|
tma := &testMpoolAPI{
|
2019-12-01 22:22:10 +00:00
|
|
|
bmsgs: make(map[cid.Cid][]*types.SignedMessage),
|
|
|
|
statenonce: make(map[address.Address]uint64),
|
2020-08-06 14:08:02 +00:00
|
|
|
balance: make(map[address.Address]types.BigInt),
|
2020-09-05 19:15:18 +00:00
|
|
|
baseFee: types.NewInt(100),
|
2019-12-01 22:22:10 +00:00
|
|
|
}
|
2020-08-25 02:02:06 +00:00
|
|
|
genesis := mock.MkBlock(nil, 1, 1)
|
2020-08-25 02:12:33 +00:00
|
|
|
tma.tipsets = append(tma.tipsets, mock.TipSet(genesis))
|
2020-08-25 02:02:06 +00:00
|
|
|
return tma
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tma *testMpoolAPI) nextBlock() *types.BlockHeader {
|
2020-08-25 02:12:33 +00:00
|
|
|
newBlk := mock.MkBlock(tma.tipsets[len(tma.tipsets)-1], 1, 1)
|
|
|
|
tma.tipsets = append(tma.tipsets, mock.TipSet(newBlk))
|
|
|
|
return newBlk
|
2019-12-01 22:22:10 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 17:46:26 +00:00
|
|
|
func (tma *testMpoolAPI) nextBlockWithHeight(height uint64) *types.BlockHeader {
|
|
|
|
newBlk := mock.MkBlock(tma.tipsets[len(tma.tipsets)-1], 1, 1)
|
|
|
|
newBlk.Height = abi.ChainEpoch(height)
|
|
|
|
tma.tipsets = append(tma.tipsets, mock.TipSet(newBlk))
|
|
|
|
return newBlk
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
func (tma *testMpoolAPI) applyBlock(t *testing.T, b *types.BlockHeader) {
|
2019-12-01 22:22:10 +00:00
|
|
|
t.Helper()
|
|
|
|
if err := tma.cb(nil, []*types.TipSet{mock.TipSet(b)}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
func (tma *testMpoolAPI) revertBlock(t *testing.T, b *types.BlockHeader) {
|
2019-12-02 22:28:28 +00:00
|
|
|
t.Helper()
|
|
|
|
if err := tma.cb([]*types.TipSet{mock.TipSet(b)}, nil); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
func (tma *testMpoolAPI) setStateNonce(addr address.Address, v uint64) {
|
2019-12-01 22:22:10 +00:00
|
|
|
tma.statenonce[addr] = v
|
|
|
|
}
|
|
|
|
|
2020-08-06 14:08:02 +00:00
|
|
|
func (tma *testMpoolAPI) setBalance(addr address.Address, v uint64) {
|
|
|
|
tma.balance[addr] = types.FromFil(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tma *testMpoolAPI) setBalanceRaw(addr address.Address, v types.BigInt) {
|
|
|
|
tma.balance[addr] = v
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
func (tma *testMpoolAPI) setBlockMessages(h *types.BlockHeader, msgs ...*types.SignedMessage) {
|
2019-12-01 22:22:10 +00:00
|
|
|
tma.bmsgs[h.Cid()] = msgs
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
func (tma *testMpoolAPI) SubscribeHeadChanges(cb func(rev, app []*types.TipSet) error) *types.TipSet {
|
2019-12-01 22:22:10 +00:00
|
|
|
tma.cb = cb
|
2020-08-25 02:02:06 +00:00
|
|
|
return tma.tipsets[0]
|
2019-12-01 22:22:10 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 10:04:04 +00:00
|
|
|
func (tma *testMpoolAPI) PutMessage(ctx context.Context, m types.ChainMsg) (cid.Cid, error) {
|
2019-12-01 22:22:10 +00:00
|
|
|
return cid.Undef, nil
|
|
|
|
}
|
2021-07-17 17:33:56 +00:00
|
|
|
|
2021-05-07 14:38:40 +00:00
|
|
|
func (tma *testMpoolAPI) IsLite() bool {
|
|
|
|
return false
|
|
|
|
}
|
2019-12-01 22:22:10 +00:00
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
func (tma *testMpoolAPI) PubSubPublish(string, []byte) error {
|
2020-08-25 10:57:02 +00:00
|
|
|
tma.published++
|
2019-12-01 22:22:10 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:02:06 +00:00
|
|
|
func (tma *testMpoolAPI) GetActorAfter(addr address.Address, ts *types.TipSet) (*types.Actor, error) {
|
2020-08-25 10:16:55 +00:00
|
|
|
// regression check for load bug
|
|
|
|
if ts == nil {
|
|
|
|
panic("GetActorAfter called with nil tipset")
|
|
|
|
}
|
|
|
|
|
2020-08-06 14:08:02 +00:00
|
|
|
balance, ok := tma.balance[addr]
|
|
|
|
if !ok {
|
2020-08-06 19:25:30 +00:00
|
|
|
balance = types.NewInt(1000e6)
|
2020-08-06 14:08:02 +00:00
|
|
|
tma.balance[addr] = balance
|
|
|
|
}
|
2020-08-25 02:02:06 +00:00
|
|
|
|
|
|
|
msgs := make([]*types.SignedMessage, 0)
|
|
|
|
for _, b := range ts.Blocks() {
|
|
|
|
for _, m := range tma.bmsgs[b.Cid()] {
|
|
|
|
if m.Message.From == addr {
|
|
|
|
msgs = append(msgs, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(msgs, func(i, j int) bool {
|
|
|
|
return msgs[i].Message.Nonce < msgs[j].Message.Nonce
|
|
|
|
})
|
|
|
|
|
|
|
|
nonce := tma.statenonce[addr]
|
|
|
|
|
|
|
|
for _, m := range msgs {
|
|
|
|
if m.Message.Nonce != nonce {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
nonce++
|
|
|
|
}
|
|
|
|
|
2019-12-01 22:22:10 +00:00
|
|
|
return &types.Actor{
|
2020-10-08 01:09:33 +00:00
|
|
|
Code: builtin2.StorageMarketActorCodeID,
|
2020-08-25 02:02:06 +00:00
|
|
|
Nonce: nonce,
|
2020-08-06 14:08:02 +00:00
|
|
|
Balance: balance,
|
2019-12-01 22:22:10 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-31 22:12:42 +00:00
|
|
|
func (tma *testMpoolAPI) StateAccountKeyAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
2020-04-17 20:44:13 +00:00
|
|
|
if addr.Protocol() != address.BLS && addr.Protocol() != address.SECP256K1 {
|
|
|
|
return address.Undef, fmt.Errorf("given address was not a key addr")
|
|
|
|
}
|
|
|
|
return addr, nil
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:04:04 +00:00
|
|
|
func (tma *testMpoolAPI) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
2019-12-01 22:22:10 +00:00
|
|
|
return nil, tma.bmsgs[h.Cid()], nil
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:04:04 +00:00
|
|
|
func (tma *testMpoolAPI) MessagesForTipset(ctx context.Context, ts *types.TipSet) ([]types.ChainMsg, error) {
|
2019-12-01 22:22:10 +00:00
|
|
|
if len(ts.Blocks()) != 1 {
|
|
|
|
panic("cant deal with multiblock tipsets in this test")
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:04:04 +00:00
|
|
|
bm, sm, err := tma.MessagesForBlock(ctx, ts.Blocks()[0])
|
2019-12-01 22:22:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-03-25 19:13:09 +00:00
|
|
|
var out []types.ChainMsg
|
2019-12-01 22:22:10 +00:00
|
|
|
for _, m := range bm {
|
|
|
|
out = append(out, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, m := range sm {
|
|
|
|
out = append(out, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:53:31 +00:00
|
|
|
func (tma *testMpoolAPI) LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
|
2019-12-02 22:28:28 +00:00
|
|
|
for _, ts := range tma.tipsets {
|
2019-12-16 19:22:56 +00:00
|
|
|
if types.CidArrsEqual(tsk.Cids(), ts.Cids()) {
|
2019-12-02 22:28:28 +00:00
|
|
|
return ts, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("tipset not found")
|
2019-12-02 20:46:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 22:40:25 +00:00
|
|
|
func (tma *testMpoolAPI) ChainComputeBaseFee(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
2020-09-05 19:15:18 +00:00
|
|
|
return tma.baseFee, nil
|
2020-08-06 22:40:25 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 22:22:10 +00:00
|
|
|
func assertNonce(t *testing.T, mp *MessagePool, addr address.Address, val uint64) {
|
|
|
|
t.Helper()
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_GET_NONCE_001
|
2021-06-01 19:06:58 +00:00
|
|
|
n, err := mp.GetNonce(context.TODO(), addr, types.EmptyTSK)
|
2019-12-01 22:22:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if n != val {
|
|
|
|
t.Fatalf("expected nonce of %d, got %d", val, n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustAdd(t *testing.T, mp *MessagePool, msg *types.SignedMessage) {
|
|
|
|
t.Helper()
|
2021-05-18 18:56:42 +00:00
|
|
|
if err := mp.Add(context.TODO(), msg); err != nil {
|
2019-12-01 22:22:10 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessagePool(t *testing.T) {
|
2022-02-02 16:08:50 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_GET_NONCE_001
|
|
|
|
|
2020-06-02 16:38:41 +00:00
|
|
|
tma := newTestMpoolAPI()
|
2019-12-01 22:22:10 +00:00
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2019-12-01 22:22:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:02:06 +00:00
|
|
|
a := tma.nextBlock()
|
2019-12-01 22:22:10 +00:00
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
sender, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
2019-12-01 22:22:10 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
target := mock.Address(1001)
|
|
|
|
|
|
|
|
var msgs []*types.SignedMessage
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
msgs = append(msgs, mock.MkMessage(sender, target, uint64(i), w))
|
|
|
|
}
|
|
|
|
|
|
|
|
tma.setStateNonce(sender, 0)
|
|
|
|
assertNonce(t, mp, sender, 0)
|
|
|
|
mustAdd(t, mp, msgs[0])
|
|
|
|
assertNonce(t, mp, sender, 1)
|
|
|
|
mustAdd(t, mp, msgs[1])
|
|
|
|
assertNonce(t, mp, sender, 2)
|
|
|
|
|
|
|
|
tma.setBlockMessages(a, msgs[0], msgs[1])
|
|
|
|
tma.applyBlock(t, a)
|
|
|
|
|
|
|
|
assertNonce(t, mp, sender, 2)
|
|
|
|
}
|
2019-12-02 22:28:28 +00:00
|
|
|
|
2021-06-08 13:20:10 +00:00
|
|
|
func TestCheckMessageBig(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2021-06-08 13:20:10 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
|
|
|
msg := &types.Message{
|
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Value: types.NewInt(1),
|
|
|
|
Nonce: 0,
|
2021-07-15 16:02:02 +00:00
|
|
|
GasLimit: 60000000,
|
2021-06-08 13:20:10 +00:00
|
|
|
GasFeeCap: types.NewInt(100),
|
|
|
|
GasPremium: types.NewInt(1),
|
|
|
|
Params: make([]byte, 41<<10), // 41KiB payload
|
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
sm := &types.SignedMessage{
|
|
|
|
Message: *msg,
|
|
|
|
Signature: *sig,
|
|
|
|
}
|
|
|
|
mustAdd(t, mp, sm)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
msg := &types.Message{
|
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Value: types.NewInt(1),
|
|
|
|
Nonce: 0,
|
|
|
|
GasLimit: 50000000,
|
|
|
|
GasFeeCap: types.NewInt(100),
|
|
|
|
GasPremium: types.NewInt(1),
|
|
|
|
Params: make([]byte, 64<<10), // 64KiB payload
|
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
sm := &types.SignedMessage{
|
|
|
|
Message: *msg,
|
|
|
|
Signature: *sig,
|
|
|
|
}
|
2022-02-02 16:08:50 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
2021-06-08 13:20:10 +00:00
|
|
|
err = mp.Add(context.TODO(), sm)
|
|
|
|
assert.ErrorIs(t, err, ErrMessageTooBig)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:35:54 +00:00
|
|
|
func TestMessagePoolMessagesInEachBlock(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 02:35:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
a := tma.nextBlock()
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
sender, err := w.WalletNew(context.Background(), types.KTBLS)
|
2020-08-25 02:35:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
target := mock.Address(1001)
|
|
|
|
|
|
|
|
var msgs []*types.SignedMessage
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
m := mock.MkMessage(sender, target, uint64(i), w)
|
|
|
|
msgs = append(msgs, m)
|
|
|
|
mustAdd(t, mp, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
tma.setStateNonce(sender, 0)
|
|
|
|
|
|
|
|
tma.setBlockMessages(a, msgs[0], msgs[1])
|
|
|
|
tma.applyBlock(t, a)
|
|
|
|
tsa := mock.TipSet(a)
|
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_001
|
2021-05-18 18:56:42 +00:00
|
|
|
_, _ = mp.Pending(context.TODO())
|
2020-08-25 02:35:54 +00:00
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_SELECT_001
|
2021-05-30 19:20:47 +00:00
|
|
|
selm, _ := mp.SelectMessages(context.Background(), tsa, 1)
|
2020-08-25 02:35:54 +00:00
|
|
|
if len(selm) == 0 {
|
|
|
|
t.Fatal("should have returned the rest of the messages")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 22:28:28 +00:00
|
|
|
func TestRevertMessages(t *testing.T) {
|
2020-08-25 10:03:50 +00:00
|
|
|
futureDebug = true
|
|
|
|
defer func() {
|
|
|
|
futureDebug = false
|
|
|
|
}()
|
|
|
|
|
2020-06-02 16:38:41 +00:00
|
|
|
tma := newTestMpoolAPI()
|
2019-12-02 22:28:28 +00:00
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2019-12-02 22:28:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:02:06 +00:00
|
|
|
a := tma.nextBlock()
|
|
|
|
b := tma.nextBlock()
|
2019-12-02 22:28:28 +00:00
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
sender, err := w.WalletNew(context.Background(), types.KTBLS)
|
2019-12-02 22:28:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
target := mock.Address(1001)
|
|
|
|
|
|
|
|
var msgs []*types.SignedMessage
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
msgs = append(msgs, mock.MkMessage(sender, target, uint64(i), w))
|
|
|
|
}
|
|
|
|
|
|
|
|
tma.setBlockMessages(a, msgs[0])
|
|
|
|
tma.setBlockMessages(b, msgs[1], msgs[2], msgs[3])
|
|
|
|
|
|
|
|
mustAdd(t, mp, msgs[0])
|
|
|
|
mustAdd(t, mp, msgs[1])
|
|
|
|
mustAdd(t, mp, msgs[2])
|
|
|
|
mustAdd(t, mp, msgs[3])
|
|
|
|
|
|
|
|
tma.setStateNonce(sender, 0)
|
|
|
|
tma.applyBlock(t, a)
|
|
|
|
assertNonce(t, mp, sender, 4)
|
|
|
|
|
|
|
|
tma.setStateNonce(sender, 1)
|
|
|
|
tma.applyBlock(t, b)
|
|
|
|
assertNonce(t, mp, sender, 4)
|
|
|
|
tma.setStateNonce(sender, 0)
|
|
|
|
tma.revertBlock(t, b)
|
|
|
|
|
|
|
|
assertNonce(t, mp, sender, 4)
|
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_001
|
2021-05-18 18:56:42 +00:00
|
|
|
p, _ := mp.Pending(context.TODO())
|
2020-08-25 02:02:06 +00:00
|
|
|
fmt.Printf("%+v\n", p)
|
2019-12-03 21:09:39 +00:00
|
|
|
if len(p) != 3 {
|
2019-12-02 22:28:28 +00:00
|
|
|
t.Fatal("expected three messages in mempool")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-01 22:54:21 +00:00
|
|
|
|
|
|
|
func TestPruningSimple(t *testing.T) {
|
2020-09-01 14:57:52 +00:00
|
|
|
oldMaxNonceGap := MaxNonceGap
|
|
|
|
MaxNonceGap = 1000
|
|
|
|
defer func() {
|
|
|
|
MaxNonceGap = oldMaxNonceGap
|
|
|
|
}()
|
|
|
|
|
2020-08-01 22:54:21 +00:00
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-01 22:54:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:02:06 +00:00
|
|
|
a := tma.nextBlock()
|
2020-08-01 23:25:13 +00:00
|
|
|
tma.applyBlock(t, a)
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
sender, err := w.WalletNew(context.Background(), types.KTBLS)
|
2020-08-01 22:54:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-08-26 11:58:32 +00:00
|
|
|
tma.setBalance(sender, 1) // in FIL
|
2020-08-01 22:54:21 +00:00
|
|
|
target := mock.Address(1001)
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
smsg := mock.MkMessage(sender, target, uint64(i), w)
|
2021-05-18 18:56:42 +00:00
|
|
|
if err := mp.Add(context.TODO(), smsg); err != nil {
|
2020-08-01 22:54:21 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 10; i < 50; i++ {
|
|
|
|
smsg := mock.MkMessage(sender, target, uint64(i), w)
|
2021-05-18 18:56:42 +00:00
|
|
|
if err := mp.Add(context.TODO(), smsg); err != nil {
|
2020-08-01 22:54:21 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 15:32:15 +00:00
|
|
|
mp.cfg.SizeLimitHigh = 40
|
|
|
|
mp.cfg.SizeLimitLow = 10
|
2020-08-01 22:54:21 +00:00
|
|
|
|
|
|
|
mp.Prune()
|
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_001
|
2021-05-18 18:56:42 +00:00
|
|
|
msgs, _ := mp.Pending(context.TODO())
|
2020-08-01 22:54:21 +00:00
|
|
|
if len(msgs) != 5 {
|
2020-08-01 23:25:13 +00:00
|
|
|
t.Fatal("expected only 5 messages in pool, got: ", len(msgs))
|
2020-08-01 22:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-25 10:16:55 +00:00
|
|
|
|
|
|
|
func TestLoadLocal(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 10:16:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// the actors
|
|
|
|
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:16:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:16:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-26 11:58:32 +00:00
|
|
|
tma.setBalance(a1, 1) // in FIL
|
|
|
|
tma.setBalance(a2, 1) // in FIL
|
2020-10-08 01:09:33 +00:00
|
|
|
gasLimit := gasguess.Costs[gasguess.CostKey{Code: builtin2.StorageMarketActorCodeID, M: 2}]
|
2020-08-25 10:16:55 +00:00
|
|
|
msgs := make(map[cid.Cid]struct{})
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w1, a1, a2, uint64(i), gasLimit, uint64(i+1))
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
2021-05-18 18:56:42 +00:00
|
|
|
cid, err := mp.Push(context.TODO(), m)
|
2020-08-25 10:16:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
msgs[cid] = struct{}{}
|
|
|
|
}
|
2020-08-25 11:03:49 +00:00
|
|
|
err = mp.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-08-25 10:16:55 +00:00
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err = New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 10:16:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_001
|
2021-05-18 18:56:42 +00:00
|
|
|
pmsgs, _ := mp.Pending(context.TODO())
|
2020-08-25 10:16:55 +00:00
|
|
|
if len(msgs) != len(pmsgs) {
|
|
|
|
t.Fatalf("expected %d messages, but got %d", len(msgs), len(pmsgs))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, m := range pmsgs {
|
|
|
|
cid := m.Cid()
|
|
|
|
_, ok := msgs[cid]
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("unknown message")
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(msgs, cid)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(msgs) > 0 {
|
|
|
|
t.Fatalf("not all messages were laoded; missing %d messages", len(msgs))
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 10:24:11 +00:00
|
|
|
|
|
|
|
func TestClearAll(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// the actors
|
|
|
|
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-26 11:58:32 +00:00
|
|
|
tma.setBalance(a1, 1) // in FIL
|
|
|
|
tma.setBalance(a2, 1) // in FIL
|
2020-10-08 01:09:33 +00:00
|
|
|
gasLimit := gasguess.Costs[gasguess.CostKey{Code: builtin2.StorageMarketActorCodeID, M: 2}]
|
2020-08-25 10:24:11 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w1, a1, a2, uint64(i), gasLimit, uint64(i+1))
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
2021-05-18 18:56:42 +00:00
|
|
|
_, err := mp.Push(context.TODO(), m)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w2, a2, a1, uint64(i), gasLimit, uint64(i+1))
|
|
|
|
mustAdd(t, mp, m)
|
|
|
|
}
|
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_CLEAR_001
|
2021-05-29 00:35:50 +00:00
|
|
|
mp.Clear(context.Background(), true)
|
2020-08-25 10:24:11 +00:00
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_001
|
2021-05-18 18:56:42 +00:00
|
|
|
pending, _ := mp.Pending(context.TODO())
|
2020-08-25 10:24:11 +00:00
|
|
|
if len(pending) > 0 {
|
|
|
|
t.Fatalf("cleared the mpool, but got %d pending messages", len(pending))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClearNonLocal(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// the actors
|
|
|
|
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-26 11:58:32 +00:00
|
|
|
tma.setBalance(a1, 1) // in FIL
|
|
|
|
tma.setBalance(a2, 1) // in FIL
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
gasLimit := gasguess.Costs[gasguess.CostKey{Code: builtin2.StorageMarketActorCodeID, M: 2}]
|
2020-08-25 10:24:11 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w1, a1, a2, uint64(i), gasLimit, uint64(i+1))
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
2021-05-18 18:56:42 +00:00
|
|
|
_, err := mp.Push(context.TODO(), m)
|
2020-08-25 10:24:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w2, a2, a1, uint64(i), gasLimit, uint64(i+1))
|
|
|
|
mustAdd(t, mp, m)
|
|
|
|
}
|
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_CLEAR_001
|
2021-05-29 00:35:50 +00:00
|
|
|
mp.Clear(context.Background(), false)
|
2020-08-25 10:24:11 +00:00
|
|
|
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_001
|
2021-05-18 18:56:42 +00:00
|
|
|
pending, _ := mp.Pending(context.TODO())
|
2020-08-25 10:24:11 +00:00
|
|
|
if len(pending) != 10 {
|
|
|
|
t.Fatalf("expected 10 pending messages, but got %d instead", len(pending))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, m := range pending {
|
|
|
|
if m.Message.From != a1 {
|
|
|
|
t.Fatalf("expected message from %s but got one from %s instead", a1, m.Message.From)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 10:29:09 +00:00
|
|
|
|
|
|
|
func TestUpdates(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-12-14 15:45:38 +00:00
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 10:29:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// the actors
|
|
|
|
w1, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a1, err := w1.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:29:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w2, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
a2, err := w2.WalletNew(context.Background(), types.KTSecp256k1)
|
2020-08-25 10:29:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.TODO())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
ch, err := mp.Updates(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
gasLimit := gasguess.Costs[gasguess.CostKey{Code: builtin2.StorageMarketActorCodeID, M: 2}]
|
2020-08-26 11:58:32 +00:00
|
|
|
|
|
|
|
tma.setBalance(a1, 1) // in FIL
|
|
|
|
tma.setBalance(a2, 1) // in FIL
|
|
|
|
|
2020-08-25 10:29:09 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w1, a1, a2, uint64(i), gasLimit, uint64(i+1))
|
2021-12-14 23:56:05 +00:00
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
2021-05-18 18:56:42 +00:00
|
|
|
_, err := mp.Push(context.TODO(), m)
|
2020-08-25 10:29:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, ok := <-ch
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("expected update, but got a closed channel instead")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 11:03:49 +00:00
|
|
|
err = mp.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-08-25 10:29:09 +00:00
|
|
|
_, ok := <-ch
|
|
|
|
if ok {
|
|
|
|
t.Fatal("expected closed channel, but got an update instead")
|
|
|
|
}
|
|
|
|
}
|
2022-02-02 16:08:50 +00:00
|
|
|
|
|
|
|
func TestMessageBelowMinGasFee(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
// fee is just below minimum gas fee
|
|
|
|
fee := minimumBaseFee.Uint64() - 1
|
|
|
|
{
|
|
|
|
msg := &types.Message{
|
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Value: types.NewInt(1),
|
|
|
|
Nonce: 0,
|
|
|
|
GasLimit: 50000000,
|
|
|
|
GasFeeCap: types.NewInt(fee),
|
|
|
|
GasPremium: types.NewInt(1),
|
|
|
|
Params: make([]byte, 32<<10),
|
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
sm := &types.SignedMessage{
|
|
|
|
Message: *msg,
|
|
|
|
Signature: *sig,
|
|
|
|
}
|
|
|
|
err = mp.Add(context.TODO(), sm)
|
|
|
|
assert.ErrorIs(t, err, ErrGasFeeCapTooLow)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageValueTooHigh(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
totalFil := types.TotalFilecoinInt
|
|
|
|
extra := types.NewInt(1)
|
|
|
|
|
|
|
|
value := types.BigAdd(totalFil, extra)
|
|
|
|
{
|
|
|
|
msg := &types.Message{
|
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Value: value,
|
|
|
|
Nonce: 0,
|
|
|
|
GasLimit: 50000000,
|
|
|
|
GasFeeCap: types.NewInt(minimumBaseFee.Uint64()),
|
|
|
|
GasPremium: types.NewInt(1),
|
|
|
|
Params: make([]byte, 32<<10),
|
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
sm := &types.SignedMessage{
|
|
|
|
Message: *msg,
|
|
|
|
Signature: *sig,
|
|
|
|
}
|
|
|
|
err = mp.Add(context.TODO(), sm)
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageSignatureInvalid(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
|
|
|
msg := &types.Message{
|
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Value: types.NewInt(1),
|
|
|
|
Nonce: 0,
|
|
|
|
GasLimit: 50000000,
|
|
|
|
GasFeeCap: types.NewInt(minimumBaseFee.Uint64()),
|
|
|
|
GasPremium: types.NewInt(1),
|
|
|
|
Params: make([]byte, 32<<10),
|
|
|
|
}
|
|
|
|
|
|
|
|
badSig := &crypto.Signature{
|
|
|
|
Type: crypto.SigTypeSecp256k1,
|
|
|
|
Data: make([]byte, 0),
|
|
|
|
}
|
|
|
|
sm := &types.SignedMessage{
|
|
|
|
Message: *msg,
|
|
|
|
Signature: *badSig,
|
|
|
|
}
|
|
|
|
err = mp.Add(context.TODO(), sm)
|
|
|
|
assert.Error(t, err)
|
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
|
|
|
assert.Contains(t, err.Error(), "invalid signature length")
|
2022-02-02 16:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddMessageTwice(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
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
|
|
|
msg := &types.Message{
|
|
|
|
To: to,
|
|
|
|
From: from,
|
|
|
|
Value: types.NewInt(1),
|
|
|
|
Nonce: 0,
|
|
|
|
GasLimit: 50000000,
|
|
|
|
GasFeeCap: types.NewInt(minimumBaseFee.Uint64()),
|
|
|
|
GasPremium: types.NewInt(1),
|
|
|
|
Params: make([]byte, 32<<10),
|
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := w.WalletSign(context.TODO(), from, msg.Cid().Bytes(), api.MsgMeta{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
sm := &types.SignedMessage{
|
|
|
|
Message: *msg,
|
|
|
|
Signature: *sig,
|
|
|
|
}
|
2022-02-02 16:08:50 +00:00
|
|
|
mustAdd(t, mp, sm)
|
|
|
|
|
|
|
|
err = mp.Add(context.TODO(), sm)
|
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
|
|
|
assert.Contains(t, err.Error(), "with nonce 0 already in mpool")
|
2022-02-02 16:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddMessageTwiceNonceGap(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
|
|
|
// create message with invalid nonce (1)
|
|
|
|
sm := makeTestMessage(w, from, to, 1, 50_000_000, minimumBaseFee.Uint64())
|
|
|
|
mustAdd(t, mp, sm)
|
|
|
|
|
|
|
|
// then try to add message again
|
|
|
|
err = mp.Add(context.TODO(), sm)
|
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
|
|
|
assert.Contains(t, err.Error(), "unfulfilled nonce gap")
|
2022-02-02 16:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddMessageTwiceCidDiff(t *testing.T) {
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
|
|
|
sm := makeTestMessage(w, from, to, 0, 50_000_000, minimumBaseFee.Uint64())
|
|
|
|
mustAdd(t, mp, sm)
|
|
|
|
|
|
|
|
// Create message with different data, so CID is different
|
|
|
|
sm2 := makeTestMessage(w, from, to, 0, 50_000_001, minimumBaseFee.Uint64())
|
|
|
|
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
// then try to add message again
|
|
|
|
err = mp.Add(context.TODO(), sm2)
|
2022-02-09 18:54:45 +00:00
|
|
|
// assert.Contains(t, err.Error(), "replace by fee has too low GasPremium")
|
|
|
|
assert.Error(t, err)
|
2022-02-02 16:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddMessageTwiceCidDiffReplaced(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
|
|
|
sm := makeTestMessage(w, from, to, 0, 50_000_000, minimumBaseFee.Uint64())
|
|
|
|
mustAdd(t, mp, sm)
|
|
|
|
|
|
|
|
// Create message with different data, so CID is different
|
|
|
|
sm2 := makeTestMessage(w, from, to, 0, 50_000_000, minimumBaseFee.Uint64()*2)
|
|
|
|
mustAdd(t, mp, sm2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveMessage(t *testing.T) {
|
|
|
|
//stm: @CHAIN_MEMPOOL_PUSH_001
|
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(wallet.NewMemKeyStore())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
from, err := w.WalletNew(context.Background(), types.KTBLS)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
tma.setBalance(from, 1000e9)
|
|
|
|
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
|
|
|
mp, err := New(context.Background(), tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
to := mock.Address(1001)
|
|
|
|
|
|
|
|
{
|
|
|
|
sm := makeTestMessage(w, from, to, 0, 50_000_000, minimumBaseFee.Uint64())
|
|
|
|
mustAdd(t, mp, sm)
|
|
|
|
|
|
|
|
//stm: @CHAIN_MEMPOOL_REMOVE_001
|
|
|
|
// remove message for sender
|
|
|
|
mp.Remove(context.TODO(), from, sm.Message.Nonce, true)
|
|
|
|
|
|
|
|
//stm: @CHAIN_MEMPOOL_PENDING_FOR_001
|
|
|
|
// check messages in pool: should be none present
|
|
|
|
msgs := mp.pendingFor(context.TODO(), from)
|
|
|
|
assert.Len(t, msgs, 0)
|
|
|
|
}
|
|
|
|
}
|