Merge pull request #7038 from filecoin-project/spike/restrict-api-versions
Strict major minor version checking on v0 and v1 apis
This commit is contained in:
commit
ce58b119bf
@ -253,7 +253,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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
@ -17,7 +18,7 @@ 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)
|
||||
|
||||
// Create some wallets on the node to use for testing multisig
|
||||
|
@ -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 <creator> <receiver>
|
||||
@ -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 <creator> <receiver> <amount>
|
||||
|
Loading…
Reference in New Issue
Block a user