From 3bb5d4eb8f585f2439bab9131c994316bb322e89 Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Wed, 11 Aug 2021 16:40:14 -0400 Subject: [PATCH 1/4] Strict major minor version checking on v0 and v1 apis --- cli/util/api.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cli/util/api.go b/cli/util/api.go index 207283fd1..5aeb8376c 100644 --- a/cli/util/api.go +++ b/cli/util/api.go @@ -236,7 +236,19 @@ func GetFullNodeAPI(ctx *cli.Context) (v0api.FullNode, jsonrpc.ClientCloser, err _, _ = fmt.Fprintln(ctx.App.Writer, "using full node API v0 endpoint:", addr) } - return client.NewFullNodeRPCV0(ctx.Context, addr, headers) + v0API, closer, err := client.NewFullNodeRPCV0(ctx.Context, addr, headers) + if err != nil { + return nil, nil, err + } + + v, err := v0API.Version(ctx.Context) + if err != nil { + return nil, nil, err + } + if !v.APIVersion.EqMajorMinor(api.FullAPIVersion0) { + return nil, nil, xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", api.FullAPIVersion0, v.APIVersion) + } + return v0API, closer, nil } func GetFullNodeAPIV1(ctx *cli.Context) (v1api.FullNode, jsonrpc.ClientCloser, error) { @@ -253,7 +265,19 @@ func GetFullNodeAPIV1(ctx *cli.Context) (v1api.FullNode, jsonrpc.ClientCloser, e _, _ = fmt.Fprintln(ctx.App.Writer, "using full node API v1 endpoint:", addr) } - return client.NewFullNodeRPCV1(ctx.Context, addr, headers) + v1API, closer, err := client.NewFullNodeRPCV1(ctx.Context, addr, headers) + if err != nil { + return nil, nil, err + } + + v, err := v1API.Version(ctx.Context) + if err != nil { + return nil, nil, err + } + if !v.APIVersion.EqMajorMinor(api.FullAPIVersion1) { + return nil, nil, xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", api.FullAPIVersion1, v.APIVersion) + } + return v1API, closer, nil } type GetStorageMinerOptions struct { From 73a644f3206f7ec8a47f15f9a41a026760e30358 Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Thu, 12 Aug 2021 13:09:43 -0400 Subject: [PATCH 2/4] Review response --- cli/util/api.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cli/util/api.go b/cli/util/api.go index 5aeb8376c..c2e250e27 100644 --- a/cli/util/api.go +++ b/cli/util/api.go @@ -236,19 +236,7 @@ func GetFullNodeAPI(ctx *cli.Context) (v0api.FullNode, jsonrpc.ClientCloser, err _, _ = fmt.Fprintln(ctx.App.Writer, "using full node API v0 endpoint:", addr) } - v0API, closer, err := client.NewFullNodeRPCV0(ctx.Context, addr, headers) - if err != nil { - return nil, nil, err - } - - v, err := v0API.Version(ctx.Context) - if err != nil { - return nil, nil, err - } - if !v.APIVersion.EqMajorMinor(api.FullAPIVersion0) { - return nil, nil, xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", api.FullAPIVersion0, v.APIVersion) - } - return v0API, closer, nil + return client.NewFullNodeRPCV0(ctx.Context, addr, headers) } func GetFullNodeAPIV1(ctx *cli.Context) (v1api.FullNode, jsonrpc.ClientCloser, error) { From c8720fef02e66b48c317246db9bf23e949ffd24f Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Thu, 12 Aug 2021 14:01:24 -0400 Subject: [PATCH 3/4] Fix tests --- itests/kit/client.go | 2 +- itests/kit/mockcli.go | 5 ++++- itests/multisig/suite.go | 3 +++ itests/paych_cli_test.go | 9 +++++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/itests/kit/client.go b/itests/kit/client.go index bd81e0c04..c9f8946ec 100644 --- a/itests/kit/client.go +++ b/itests/kit/client.go @@ -26,7 +26,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode) defer cancel() // Create mock CLI - mockCLI := NewMockCLI(ctx, t, cmds) + mockCLI := NewMockCLI(ctx, t, cmds, api.NodeFull) clientCLI := mockCLI.Client(clientNode.ListenAddr) // Get the Miner address diff --git a/itests/kit/mockcli.go b/itests/kit/mockcli.go index c0f218920..5a09a9af8 100644 --- a/itests/kit/mockcli.go +++ b/itests/kit/mockcli.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/filecoin-project/lotus/api" "github.com/multiformats/go-multiaddr" "github.com/stretchr/testify/require" lcli "github.com/urfave/cli/v2" @@ -19,7 +20,7 @@ type MockCLI struct { out *bytes.Buffer } -func NewMockCLI(ctx context.Context, t *testing.T, cmds []*lcli.Command) *MockCLI { +func NewMockCLI(ctx context.Context, t *testing.T, cmds []*lcli.Command, nodeType api.NodeType) *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{ @@ -31,6 +32,8 @@ func NewMockCLI(ctx context.Context, t *testing.T, cmds []*lcli.Command) *MockCL }, Commands: cmds, } + // Set node type + api.RunningNodeType = nodeType var out bytes.Buffer app.Writer = &out diff --git a/itests/multisig/suite.go b/itests/multisig/suite.go index 86a8ab738..e24d9d5e7 100644 --- a/itests/multisig/suite.go +++ b/itests/multisig/suite.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/itests/kit" @@ -19,6 +20,8 @@ func RunMultisigTests(t *testing.T, client *kit.TestFullNode) { ctx := context.Background() mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) clientCLI := mockCLI.Client(client.ListenAddr) + // msig tests run against a full node + api.RunningNodeType = api.NodeFull // Create some wallets on the node to use for testing multisig var walletAddrs []address.Address diff --git a/itests/paych_cli_test.go b/itests/paych_cli_test.go index 82955e6c1..17e7bcbf6 100644 --- a/itests/paych_cli_test.go +++ b/itests/paych_cli_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/itests/kit" @@ -42,7 +43,7 @@ func TestPaymentChannelsBasic(t *testing.T) { creatorAddr, receiverAddr := startPaychCreatorReceiverMiner(ctx, t, &paymentCreator, &paymentReceiver, blocktime) // Create mock CLI - mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) + mockCLI := kit.NewMockCLI(ctx, t, cli.Commands, api.NodeFull) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr) @@ -98,7 +99,7 @@ func TestPaymentChannelStatus(t *testing.T) { creatorAddr, receiverAddr := startPaychCreatorReceiverMiner(ctx, t, &paymentCreator, &paymentReceiver, blocktime) // Create mock CLI - mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) + mockCLI := kit.NewMockCLI(ctx, t, cli.Commands, api.NodeFull) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) // creator: paych status-by-from-to @@ -178,7 +179,7 @@ func TestPaymentChannelVouchers(t *testing.T) { creatorAddr, receiverAddr := startPaychCreatorReceiverMiner(ctx, t, &paymentCreator, &paymentReceiver, blocktime) // Create mock CLI - mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) + mockCLI := kit.NewMockCLI(ctx, t, cli.Commands, api.NodeFull) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr) @@ -310,7 +311,7 @@ func TestPaymentChannelVoucherCreateShortfall(t *testing.T) { creatorAddr, receiverAddr := startPaychCreatorReceiverMiner(ctx, t, &paymentCreator, &paymentReceiver, blocktime) // Create mock CLI - mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) + mockCLI := kit.NewMockCLI(ctx, t, cli.Commands, api.NodeFull) creatorCLI := mockCLI.Client(paymentCreator.ListenAddr) // creator: paych add-funds From 2d8c9bba990ff67266fc5c8bb554cc7ecfcbbebf Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Thu, 12 Aug 2021 14:03:19 -0400 Subject: [PATCH 4/4] more fix --- itests/multisig/suite.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/itests/multisig/suite.go b/itests/multisig/suite.go index e24d9d5e7..55400a99c 100644 --- a/itests/multisig/suite.go +++ b/itests/multisig/suite.go @@ -18,10 +18,8 @@ import ( func RunMultisigTests(t *testing.T, client *kit.TestFullNode) { // Create mock CLI ctx := context.Background() - mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) + mockCLI := kit.NewMockCLI(ctx, t, cli.Commands, api.NodeFull) clientCLI := mockCLI.Client(client.ListenAddr) - // msig tests run against a full node - api.RunningNodeType = api.NodeFull // Create some wallets on the node to use for testing multisig var walletAddrs []address.Address