2020-08-25 10:57:02 +00:00
|
|
|
package messagepool
|
|
|
|
|
|
|
|
import (
|
2020-09-04 20:17:28 +00:00
|
|
|
"context"
|
2020-08-25 10:57:02 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
|
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
2020-08-25 10:57:02 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
2020-10-11 18:12:01 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-08-25 10:57:02 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepubMessages(t *testing.T) {
|
2020-09-02 06:14:35 +00:00
|
|
|
oldRepublishBatchDelay := RepublishBatchDelay
|
2020-09-01 22:17:22 +00:00
|
|
|
RepublishBatchDelay = time.Microsecond
|
|
|
|
defer func() {
|
|
|
|
RepublishBatchDelay = oldRepublishBatchDelay
|
|
|
|
}()
|
|
|
|
|
2020-08-25 10:57:02 +00:00
|
|
|
tma := newTestMpoolAPI()
|
|
|
|
ds := datastore.NewMapDatastore()
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
mp, err := New(tma, ds, filcns.DefaultUpgradeSchedule(), "mptest", nil)
|
2020-08-25 10:57:02 +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:57:02 +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:57:02 +00:00
|
|
|
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-25 10:57:02 +00:00
|
|
|
|
|
|
|
tma.setBalance(a1, 1) // in FIL
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
m := makeTestMessage(w1, a1, a2, uint64(i), gasLimit, uint64(i+1))
|
2021-05-18 18:56:42 +00:00
|
|
|
_, err := mp.Push(context.TODO(), m)
|
2020-08-25 10:57:02 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if tma.published != 10 {
|
|
|
|
t.Fatalf("expected to have published 10 messages, but got %d instead", tma.published)
|
|
|
|
}
|
|
|
|
|
|
|
|
mp.repubTrigger <- struct{}{}
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
if tma.published != 20 {
|
|
|
|
t.Fatalf("expected to have published 20 messages, but got %d instead", tma.published)
|
|
|
|
}
|
|
|
|
}
|