Skip to content

Commit

Permalink
Merge pull request #1246 from onflow/bluesign/crash_fix_payer_proposer
Browse files Browse the repository at this point in the history
Crash fix for transaction send with missing flags
  • Loading branch information
chasefleming authored Oct 25, 2023
2 parents 4edd362 + b1331ce commit a211267
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,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-
go-version: '1.19'
- name: Run tests
run: |
make ci
Expand All @@ -43,7 +37,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
Expand Down
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 @@ -104,8 +104,14 @@ func SendTransaction(code []byte, args []string, location string, flow flowkit.S

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
18 changes: 18 additions & 0 deletions internal/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,25 @@ func Test_Send(t *testing.T) {
flags.Signer = "" // reset
})

t.Run("Fail signer not used and payer flag not set", func(t *testing.T) {
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")
flags.Signer = "" // reset
})

t.Run("Fail signer not used and proposer flag not set", func(t *testing.T) {
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")
flags.Signer = "" // reset
})

t.Run("Fail loading transaction file", func(t *testing.T) {
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")
})
Expand Down

0 comments on commit a211267

Please sign in to comment.