2021-05-17 12:28:09 +00:00
|
|
|
package itests
|
2020-10-15 10:15:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 20:32:10 +00:00
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
2020-10-15 10:15:21 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2021-05-17 12:28:09 +00:00
|
|
|
"github.com/filecoin-project/lotus/cli"
|
2021-06-18 18:45:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2021-05-18 20:32:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-10-15 10:15:21 +00:00
|
|
|
)
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
// TestMultisig does a basic test to exercise the multisig CLI commands
|
2020-10-15 10:15:21 +00:00
|
|
|
func TestMultisig(t *testing.T) {
|
2021-06-18 18:45:29 +00:00
|
|
|
kit.QuietMiningLogs()
|
2020-10-15 10:15:21 +00:00
|
|
|
|
2021-06-14 12:03:08 +00:00
|
|
|
blockTime := 5 * time.Millisecond
|
2021-06-18 18:45:29 +00:00
|
|
|
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
|
2021-06-14 12:03:08 +00:00
|
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-18 18:23:32 +00:00
|
|
|
runMultisigTests(t, client)
|
2021-05-19 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
func runMultisigTests(t *testing.T, clientNode *kit.TestFullNode) {
|
2021-05-18 20:32:10 +00:00
|
|
|
// Create mock CLI
|
2021-05-19 16:14:14 +00:00
|
|
|
ctx := context.Background()
|
2021-06-18 18:45:29 +00:00
|
|
|
mockCLI := kit.NewMockCLI(ctx, t, cli.Commands)
|
2021-05-18 20:32:10 +00:00
|
|
|
clientCLI := mockCLI.Client(clientNode.ListenAddr)
|
|
|
|
|
|
|
|
// Create some wallets on the node to use for testing multisig
|
|
|
|
var walletAddrs []address.Address
|
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
addr, err := clientNode.WalletNew(ctx, types.KTSecp256k1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
walletAddrs = append(walletAddrs, addr)
|
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
kit.SendFunds(ctx, t, clientNode, addr, types.NewInt(1e15))
|
2021-05-18 20:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create an msig with three of the addresses and threshold of two sigs
|
|
|
|
// msig create --required=2 --duration=50 --value=1000attofil <addr1> <addr2> <addr3>
|
|
|
|
amtAtto := types.NewInt(1000)
|
|
|
|
threshold := 2
|
|
|
|
paramDuration := "--duration=50"
|
|
|
|
paramRequired := fmt.Sprintf("--required=%d", threshold)
|
|
|
|
paramValue := fmt.Sprintf("--value=%dattofil", amtAtto)
|
|
|
|
out := clientCLI.RunCmd(
|
|
|
|
"msig", "create",
|
|
|
|
paramRequired,
|
|
|
|
paramDuration,
|
|
|
|
paramValue,
|
|
|
|
walletAddrs[0].String(),
|
|
|
|
walletAddrs[1].String(),
|
|
|
|
walletAddrs[2].String(),
|
|
|
|
)
|
|
|
|
fmt.Println(out)
|
|
|
|
|
|
|
|
// Extract msig robust address from output
|
|
|
|
expCreateOutPrefix := "Created new multisig:"
|
|
|
|
require.Regexp(t, regexp.MustCompile(expCreateOutPrefix), out)
|
|
|
|
parts := strings.Split(strings.TrimSpace(strings.Replace(out, expCreateOutPrefix, "", -1)), " ")
|
|
|
|
require.Len(t, parts, 2)
|
|
|
|
msigRobustAddr := parts[1]
|
|
|
|
fmt.Println("msig robust address:", msigRobustAddr)
|
|
|
|
|
|
|
|
// Propose to add a new address to the msig
|
|
|
|
// msig add-propose --from=<addr> <msig> <addr>
|
|
|
|
paramFrom := fmt.Sprintf("--from=%s", walletAddrs[0])
|
|
|
|
out = clientCLI.RunCmd(
|
|
|
|
"msig", "add-propose",
|
|
|
|
paramFrom,
|
|
|
|
msigRobustAddr,
|
|
|
|
walletAddrs[3].String(),
|
|
|
|
)
|
|
|
|
fmt.Println(out)
|
|
|
|
|
|
|
|
// msig inspect <msig>
|
|
|
|
out = clientCLI.RunCmd("msig", "inspect", "--vesting", "--decode-params", msigRobustAddr)
|
|
|
|
fmt.Println(out)
|
|
|
|
|
|
|
|
// Expect correct balance
|
|
|
|
require.Regexp(t, regexp.MustCompile("Balance: 0.000000000000001 FIL"), out)
|
|
|
|
// Expect 1 transaction
|
|
|
|
require.Regexp(t, regexp.MustCompile(`Transactions:\s*1`), out)
|
|
|
|
// Expect transaction to be "AddSigner"
|
|
|
|
require.Regexp(t, regexp.MustCompile(`AddSigner`), out)
|
|
|
|
|
|
|
|
// Approve adding the new address
|
|
|
|
// msig add-approve --from=<addr> <msig> <addr> 0 <addr> false
|
|
|
|
txnID := "0"
|
|
|
|
paramFrom = fmt.Sprintf("--from=%s", walletAddrs[1])
|
|
|
|
out = clientCLI.RunCmd(
|
|
|
|
"msig", "add-approve",
|
|
|
|
paramFrom,
|
|
|
|
msigRobustAddr,
|
|
|
|
walletAddrs[0].String(),
|
|
|
|
txnID,
|
|
|
|
walletAddrs[3].String(),
|
|
|
|
"false",
|
|
|
|
)
|
|
|
|
fmt.Println(out)
|
2020-10-15 10:15:21 +00:00
|
|
|
}
|