From 60cbcd6088e5568aeb695bacc64ffbb02e57bdd0 Mon Sep 17 00:00:00 2001 From: Deniz Mert Edincik Date: Tue, 24 Oct 2023 23:06:14 +0200 Subject: [PATCH] add verification for missing flags --- flowkit/gateway/mocks/Gateway.go | 11 +++++------ flowkit/mocks/Services.go | 12 +++++------- internal/transactions/send.go | 10 ++++++++-- internal/transactions/transactions_test.go | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/flowkit/gateway/mocks/Gateway.go b/flowkit/gateway/mocks/Gateway.go index 3d04bfa04..5fd4ba569 100644 --- a/flowkit/gateway/mocks/Gateway.go +++ b/flowkit/gateway/mocks/Gateway.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.28.2. DO NOT EDIT. +// Code generated by mockery v2.36.0. DO NOT EDIT. package mocks @@ -432,13 +432,12 @@ func (_m *Gateway) SendSignedTransaction(_a0 *flow.Transaction) (*flow.Transacti return r0, r1 } -type mockConstructorTestingTNewGateway interface { +// NewGateway creates a new instance of Gateway. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGateway(t interface { mock.TestingT Cleanup(func()) -} - -// NewGateway creates a new instance of Gateway. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewGateway(t mockConstructorTestingTNewGateway) *Gateway { +}) *Gateway { mock := &Gateway{} mock.Mock.Test(t) diff --git a/flowkit/mocks/Services.go b/flowkit/mocks/Services.go index 1605a8f41..d78805928 100644 --- a/flowkit/mocks/Services.go +++ b/flowkit/mocks/Services.go @@ -1,10 +1,9 @@ -// Code generated by mockery v2.28.2. DO NOT EDIT. +// Code generated by mockery v2.36.0. DO NOT EDIT. package mocks import ( cadence "github.com/onflow/cadence" - accounts "github.com/onflow/flow-cli/flowkit/accounts" config "github.com/onflow/flow-cli/flowkit/config" @@ -609,13 +608,12 @@ func (_m *Services) SignTransactionPayload(_a0 context.Context, _a1 *accounts.Ac return r0, r1 } -type mockConstructorTestingTNewServices interface { +// NewServices creates a new instance of Services. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewServices(t interface { mock.TestingT Cleanup(func()) -} - -// NewServices creates a new instance of Services. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewServices(t mockConstructorTestingTNewServices) *Services { +}) *Services { mock := &Services{} mock.Mock.Test(t) diff --git a/internal/transactions/send.go b/internal/transactions/send.go index 78f036fc1..6a6d73a0e 100644 --- a/internal/transactions/send.go +++ b/internal/transactions/send.go @@ -95,8 +95,14 @@ func send( signerName := sendFlags.Signer - if signerName == "" && proposer == nil && payer == nil && len(authorizers) == 0 { - signerName = state.Config().Emulators.Default().ServiceAccount + if signerName == "" { + if proposer == nil && payer == nil && len(authorizers) == 0 { + signerName = state.Config().Emulators.Default().ServiceAccount + } else { + if proposer == nil || payer == nil { + return nil, fmt.Errorf("proposer/payer flags are required when signer flag is not used") + } + } } if signerName != "" { diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index 84f5900c0..cb459f8ae 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -189,7 +189,24 @@ func Test_Send(t *testing.T) { sendFlags.Signer = "" // reset }) + t.Run("Fail signer not used and payer and proposer flags not set", func(t *testing.T) { + sendFlags.Payer = "" + sendFlags.Proposer = config.DefaultEmulator.ServiceAccount + _, err := send([]string{""}, command.GlobalFlags{}, util.NoLogger, srv.Mock, state) + assert.EqualError(t, err, "proposer/payer flags are required when signer flag is not used") + sendFlags.Signer = "" // reset + + sendFlags.Proposer = "" + sendFlags.Payer = config.DefaultEmulator.ServiceAccount + _, err = send([]string{""}, command.GlobalFlags{}, util.NoLogger, srv.Mock, state) + assert.EqualError(t, err, "proposer/payer flags are required when signer flag is not used") + sendFlags.Signer = "" // reset + + }) + t.Run("Fail loading transaction file", func(t *testing.T) { + sendFlags.Proposer = config.DefaultEmulator.ServiceAccount + sendFlags.Payer = config.DefaultEmulator.ServiceAccount _, err := send([]string{"invalid"}, command.GlobalFlags{}, util.NoLogger, srv.Mock, state) assert.EqualError(t, err, "error loading transaction file: open invalid: file does not exist") })