From 60cbcd6088e5568aeb695bacc64ffbb02e57bdd0 Mon Sep 17 00:00:00 2001 From: Deniz Mert Edincik Date: Tue, 24 Oct 2023 23:06:14 +0200 Subject: [PATCH 1/4] 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") }) From b0e215d0244cba5b0a23d1f9b221d697cbef9ea1 Mon Sep 17 00:00:00 2001 From: Deniz Mert Edincik Date: Tue, 24 Oct 2023 23:24:30 +0200 Subject: [PATCH 2/4] tests --- internal/transactions/transactions_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index cb459f8ae..5c0660bcb 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -189,19 +189,20 @@ 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) { + t.Run("Fail signer not used and payer flag 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 + }) + t.Run("Fail signer not used and proposer flag not set", func(t *testing.T) { sendFlags.Proposer = "" sendFlags.Payer = config.DefaultEmulator.ServiceAccount - _, err = send([]string{""}, command.GlobalFlags{}, util.NoLogger, srv.Mock, state) + _, 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) { From 74daf20c0e9ab664201ed35df7a836236e7e9fe5 Mon Sep 17 00:00:00 2001 From: Bjarte Stien Karlsen Date: Wed, 25 Oct 2023 12:53:02 +0200 Subject: [PATCH 3/4] try to update to setup@v4 of go to fix the testing issues, can be a chache issue --- .github/workflows/ci.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f814f5906..6fec4eb05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,15 +15,9 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 with: go-version: '1.19' - - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - name: Run tests run: | make ci @@ -40,7 +34,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: go-version: '1.19' - name: generate From b1331cef1a62bc30dd6fc365003bc6387422e1cf Mon Sep 17 00:00:00 2001 From: Bjarte Stien Karlsen Date: Wed, 25 Oct 2023 13:58:05 +0200 Subject: [PATCH 4/4] rename sendFlags -> flags --- internal/transactions/transactions_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index ac1be36b1..e4dcd3c84 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -192,24 +192,24 @@ func Test_Send(t *testing.T) { }) t.Run("Fail signer not used and payer flag not set", func(t *testing.T) { - sendFlags.Payer = "" - sendFlags.Proposer = config.DefaultEmulator.ServiceAccount + flags.Payer = "" + flags.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 + flags.Signer = "" // reset }) t.Run("Fail signer not used and proposer flag not set", func(t *testing.T) { - sendFlags.Proposer = "" - sendFlags.Payer = config.DefaultEmulator.ServiceAccount + flags.Proposer = "" + flags.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 + flags.Signer = "" // reset }) t.Run("Fail loading transaction file", func(t *testing.T) { - sendFlags.Proposer = config.DefaultEmulator.ServiceAccount - sendFlags.Payer = config.DefaultEmulator.ServiceAccount + flags.Proposer = config.DefaultEmulator.ServiceAccount + flags.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") })