2021-05-18 21:01:10 +00:00
|
|
|
package kit
|
2020-10-20 15:08:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-10-26 11:01:33 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
|
2020-10-20 15:08:25 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
)
|
|
|
|
|
2021-05-19 10:47:37 +00:00
|
|
|
func StartOneNodeOneMiner(ctx context.Context, t *testing.T, blocktime time.Duration) (TestFullNode, address.Address) {
|
2021-05-20 11:17:41 +00:00
|
|
|
n, sn := RPCMockMinerBuilder(t, OneFull, OneMiner)
|
2020-10-20 15:08:25 +00:00
|
|
|
|
|
|
|
full := n[0]
|
|
|
|
miner := sn[0]
|
|
|
|
|
|
|
|
// Get everyone connected
|
|
|
|
addrs, err := full.NetAddrsListen(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := miner.NetConnect(ctx, addrs); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start mining blocks
|
2021-05-19 09:51:32 +00:00
|
|
|
bm := NewBlockMiner(t, miner)
|
|
|
|
bm.MineBlocks(ctx, blocktime)
|
2020-11-12 15:23:46 +00:00
|
|
|
t.Cleanup(bm.Stop)
|
2020-10-20 15:08:25 +00:00
|
|
|
|
|
|
|
// Get the full node's wallet address
|
|
|
|
fullAddr, err := full.WalletDefaultAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create mock CLI
|
|
|
|
return full, fullAddr
|
|
|
|
}
|
2020-10-26 11:01:33 +00:00
|
|
|
|
2021-05-19 10:47:37 +00:00
|
|
|
func StartTwoNodesOneMiner(ctx context.Context, t *testing.T, blocktime time.Duration) ([]TestFullNode, []address.Address) {
|
2021-05-20 11:17:41 +00:00
|
|
|
n, sn := RPCMockMinerBuilder(t, TwoFull, OneMiner)
|
2020-10-26 11:01:33 +00:00
|
|
|
|
|
|
|
fullNode1 := n[0]
|
|
|
|
fullNode2 := n[1]
|
|
|
|
miner := sn[0]
|
|
|
|
|
|
|
|
// Get everyone connected
|
|
|
|
addrs, err := fullNode1.NetAddrsListen(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := fullNode2.NetConnect(ctx, addrs); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := miner.NetConnect(ctx, addrs); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start mining blocks
|
2021-05-19 09:51:32 +00:00
|
|
|
bm := NewBlockMiner(t, miner)
|
|
|
|
bm.MineBlocks(ctx, blocktime)
|
2020-11-12 15:23:46 +00:00
|
|
|
t.Cleanup(bm.Stop)
|
2020-10-26 11:01:33 +00:00
|
|
|
|
|
|
|
// Send some funds to register the second node
|
|
|
|
fullNodeAddr2, err := fullNode2.WalletNew(ctx, types.KTSecp256k1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
SendFunds(ctx, t, fullNode1, fullNodeAddr2, abi.NewTokenAmount(1e18))
|
2020-10-26 11:01:33 +00:00
|
|
|
|
|
|
|
// Get the first node's address
|
|
|
|
fullNodeAddr1, err := fullNode1.WalletDefaultAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create mock CLI
|
|
|
|
return n, []address.Address{fullNodeAddr1, fullNodeAddr2}
|
|
|
|
}
|