lotus/itests/get_messages_in_ts_test.go

113 lines
3.0 KiB
Go
Raw Permalink Normal View History

2022-08-29 14:25:30 +00:00
// stm: #integration
2021-07-06 03:48:48 +00:00
package itests
import (
"context"
2021-07-06 05:54:21 +00:00
"testing"
2022-06-14 15:00:51 +00:00
"time"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/big"
2021-07-06 05:54:21 +00:00
2021-07-06 03:48:48 +00:00
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/itests/kit"
)
func TestChainGetMessagesInTs(t *testing.T) {
2021-12-13 12:41:04 +00:00
//stm: @CHAIN_SYNCER_LOAD_GENESIS_001, @CHAIN_SYNCER_FETCH_TIPSET_001,
//stm: @CHAIN_SYNCER_START_001, @CHAIN_SYNCER_SYNC_001, @BLOCKCHAIN_BEACON_VALIDATE_BLOCK_VALUES_01
//stm: @CHAIN_SYNCER_COLLECT_CHAIN_001, @CHAIN_SYNCER_COLLECT_HEADERS_001, @CHAIN_SYNCER_VALIDATE_TIPSET_001
//stm: @CHAIN_SYNCER_NEW_PEER_HEAD_001, @CHAIN_SYNCER_VALIDATE_MESSAGE_META_001, @CHAIN_SYNCER_STOP_001
2021-12-14 10:33:33 +00:00
//stm: @CHAIN_INCOMING_HANDLE_INCOMING_BLOCKS_001, @CHAIN_INCOMING_VALIDATE_BLOCK_PUBSUB_001, @CHAIN_INCOMING_VALIDATE_MESSAGE_PUBSUB_001
2021-07-06 03:48:48 +00:00
ctx := context.Background()
kit.QuietMiningLogs()
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs())
ens.InterconnectAll().BeginMining(10 * time.Millisecond)
// create a new address where to send funds.
addr, err := client.WalletNew(ctx, types.KTBLS)
require.NoError(t, err)
// get the existing balance from the default wallet to then split it.
bal, err := client.WalletBalance(ctx, client.DefaultKey.Address)
require.NoError(t, err)
const iterations = 100
// we'll send half our balance (saving the other half for gas),
// in `iterations` increments.
toSend := big.Div(bal, big.NewInt(2))
each := big.Div(toSend, big.NewInt(iterations))
waitAllCh := make(chan struct{})
go func() {
2021-07-06 05:34:54 +00:00
headChangeCh, err := client.ChainNotify(ctx)
2021-07-06 03:48:48 +00:00
require.NoError(t, err)
2021-07-06 05:34:54 +00:00
<-headChangeCh //skip hccurrent
2021-07-06 03:48:48 +00:00
count := 0
for {
select {
2021-07-06 05:34:54 +00:00
case headChanges := <-headChangeCh:
2021-07-06 03:48:48 +00:00
for _, change := range headChanges {
if change.Type == store.HCApply {
msgs, err := client.ChainGetMessagesInTipset(ctx, change.Val.Key())
require.NoError(t, err)
count += len(msgs)
if count == iterations {
waitAllCh <- struct{}{}
}
}
}
}
}
}()
var sms []*types.SignedMessage
for i := 0; i < iterations; i++ {
msg := &types.Message{
From: client.DefaultKey.Address,
To: addr,
Value: each,
}
sm, err := client.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err)
require.EqualValues(t, i, sm.Message.Nonce)
sms = append(sms, sm)
}
select {
2021-07-06 05:34:54 +00:00
case <-waitAllCh:
case <-time.After(time.Minute):
t.Errorf("timeout to wait for pack messages")
2021-07-06 03:48:48 +00:00
}
for _, sm := range sms {
2021-12-10 15:08:25 +00:00
//stm: @CHAIN_STATE_WAIT_MSG_001
2021-07-06 03:48:48 +00:00
msgLookup, err := client.StateWaitMsg(ctx, sm.Cid(), 3, api.LookbackNoLimit, true)
require.NoError(t, err)
ts, err := client.ChainGetTipSet(ctx, msgLookup.TipSet)
require.NoError(t, err)
msgs, err := client.ChainGetMessagesInTipset(ctx, ts.Parents())
require.NoError(t, err)
var found bool
for _, msg := range msgs {
if msg.Cid == sm.Cid() {
found = true
}
}
require.EqualValues(t, true, found, "expect got message in tipset %v", msgLookup.TipSet)
}
}