-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4421 from filecoin-project/fix/lite-msig-inspect
Ensure msig inspect cli works with lotus-lite
- Loading branch information
Showing
12 changed files
with
396 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/lotus/api/test" | ||
clitest "github.com/filecoin-project/lotus/cli/test" | ||
builder "github.com/filecoin-project/lotus/node/test" | ||
) | ||
|
||
// TestMultisig does a basic test to exercise the multisig CLI | ||
// commands | ||
func TestMultisig(t *testing.T) { | ||
_ = os.Setenv("BELLMAN_NO_GPU", "1") | ||
|
||
blocktime := 5 * time.Millisecond | ||
ctx := context.Background() | ||
nodes, _ := startNodes(ctx, t, blocktime) | ||
clientNode := nodes[0] | ||
clitest.RunMultisigTest(t, Commands, clientNode) | ||
} | ||
|
||
func startNodes(ctx context.Context, t *testing.T, blocktime time.Duration) ([]test.TestNode, []address.Address) { | ||
n, sn := builder.RPCMockSbBuilder(t, test.OneFull, test.OneMiner) | ||
|
||
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 | ||
bm := test.NewBlockMiner(ctx, t, miner, blocktime) | ||
bm.MineBlocks() | ||
|
||
// Get the creator's address | ||
creatorAddr, err := full.WalletDefaultAddress(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Create mock CLI | ||
return n, []address.Address{creatorAddr} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package test | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/multiformats/go-multiaddr" | ||
"github.com/stretchr/testify/require" | ||
lcli "github.com/urfave/cli/v2" | ||
) | ||
|
||
type mockCLI struct { | ||
t *testing.T | ||
cmds []*lcli.Command | ||
cctx *lcli.Context | ||
out *bytes.Buffer | ||
} | ||
|
||
func newMockCLI(t *testing.T, cmds []*lcli.Command) *mockCLI { | ||
// Create a CLI App with an --api-url flag so that we can specify which node | ||
// the command should be executed against | ||
app := &lcli.App{ | ||
Flags: []lcli.Flag{ | ||
&lcli.StringFlag{ | ||
Name: "api-url", | ||
Hidden: true, | ||
}, | ||
}, | ||
Commands: cmds, | ||
} | ||
|
||
var out bytes.Buffer | ||
app.Writer = &out | ||
app.Setup() | ||
|
||
cctx := lcli.NewContext(app, &flag.FlagSet{}, nil) | ||
return &mockCLI{t: t, cmds: cmds, cctx: cctx, out: &out} | ||
} | ||
|
||
func (c *mockCLI) client(addr multiaddr.Multiaddr) *mockCLIClient { | ||
return &mockCLIClient{t: c.t, cmds: c.cmds, addr: addr, cctx: c.cctx, out: c.out} | ||
} | ||
|
||
// mockCLIClient runs commands against a particular node | ||
type mockCLIClient struct { | ||
t *testing.T | ||
cmds []*lcli.Command | ||
addr multiaddr.Multiaddr | ||
cctx *lcli.Context | ||
out *bytes.Buffer | ||
} | ||
|
||
func (c *mockCLIClient) run(cmd []string, params []string, args []string) string { | ||
// Add parameter --api-url=<node api listener address> | ||
apiFlag := "--api-url=" + c.addr.String() | ||
params = append([]string{apiFlag}, params...) | ||
|
||
err := c.cctx.App.Run(append(append(cmd, params...), args...)) | ||
require.NoError(c.t, err) | ||
|
||
// Get the output | ||
str := strings.TrimSpace(c.out.String()) | ||
c.out.Reset() | ||
return str | ||
} | ||
|
||
func (c *mockCLIClient) runCmd(input []string) string { | ||
cmd := c.cmdByNameSub(input[0], input[1]) | ||
out, err := c.runCmdRaw(cmd, input[2:]) | ||
require.NoError(c.t, err) | ||
|
||
return out | ||
} | ||
|
||
func (c *mockCLIClient) cmdByNameSub(name string, sub string) *lcli.Command { | ||
for _, c := range c.cmds { | ||
if c.Name == name { | ||
for _, s := range c.Subcommands { | ||
if s.Name == sub { | ||
return s | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *mockCLIClient) runCmdRaw(cmd *lcli.Command, input []string) (string, error) { | ||
// prepend --api-url=<node api listener address> | ||
apiFlag := "--api-url=" + c.addr.String() | ||
input = append([]string{apiFlag}, input...) | ||
|
||
fs := c.flagSet(cmd) | ||
err := fs.Parse(input) | ||
require.NoError(c.t, err) | ||
|
||
err = cmd.Action(lcli.NewContext(c.cctx.App, fs, c.cctx)) | ||
|
||
// Get the output | ||
str := strings.TrimSpace(c.out.String()) | ||
c.out.Reset() | ||
return str, err | ||
} | ||
|
||
func (c *mockCLIClient) flagSet(cmd *lcli.Command) *flag.FlagSet { | ||
// Apply app level flags (so we can process --api-url flag) | ||
fs := &flag.FlagSet{} | ||
for _, f := range c.cctx.App.Flags { | ||
err := f.Apply(fs) | ||
if err != nil { | ||
c.t.Fatal(err) | ||
} | ||
} | ||
// Apply command level flags | ||
for _, f := range cmd.Flags { | ||
err := f.Apply(fs) | ||
if err != nil { | ||
c.t.Fatal(err) | ||
} | ||
} | ||
return fs | ||
} |
Oops, something went wrong.