Skip to content

Commit

Permalink
add verification for missing flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesign committed Oct 24, 2023
1 parent daa1550 commit 60cbcd6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
11 changes: 5 additions & 6 deletions flowkit/gateway/mocks/Gateway.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions flowkit/mocks/Services.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions internal/transactions/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
17 changes: 17 additions & 0 deletions internal/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 195 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
assert.EqualError(t, err, "proposer/payer flags are required when signer flag is not used")

Check failure on line 196 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
sendFlags.Signer = "" // reset

sendFlags.Proposer = ""

Check failure on line 199 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
sendFlags.Payer = config.DefaultEmulator.ServiceAccount
_, err = send([]string{""}, command.GlobalFlags{}, util.NoLogger, srv.Mock, state)

Check failure on line 201 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
assert.EqualError(t, err, "proposer/payer flags are required when signer flag is not used")

Check failure on line 202 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
sendFlags.Signer = "" // reset

})

Check failure on line 205 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags

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)

Check failure on line 210 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
assert.EqualError(t, err, "error loading transaction file: open invalid: file does not exist")

Check failure on line 211 in internal/transactions/transactions_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: sendFlags
})
Expand Down

0 comments on commit 60cbcd6

Please sign in to comment.