Skip to content

Commit

Permalink
test(system): check feePayers signature (#22389)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7b9a89b)
  • Loading branch information
JulianToledano authored and mergify[bot] committed Oct 28, 2024
1 parent 2ff319c commit 7e9f5b4
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/systemtests/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,56 @@ func TestTxEncodeandDecode(t *testing.T) {
decodedTx := cli.RunCommandWithArgs("tx", "decode", encodedText)
require.Equal(t, gjson.Get(decodedTx, "body.memo").String(), memoText)
}

func TestTxWithFeePayer(t *testing.T) {
// Scenario:
// send a tx with FeePayer without his signature
// check tx fails
// send tx with feePayers signature
// check tx executed ok
// check fees had been deducted from feePayers balance

sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose).WithRunErrorsIgnored()

// add sender and feePayer accounts
senderAddr := cli.AddKey("sender")
sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", senderAddr, "10000000stake"},
)
feePayerAddr := cli.AddKey("feePayer")
sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", feePayerAddr, "10000000stake"},
)

sut.StartChain(t)

// send a tx with FeePayer without his signature
rsp := cli.RunCommandWithArgs(cli.withTXFlags(
"tx", "bank", "send", senderAddr, "cosmos108jsm625z3ejy63uef2ke7t67h6nukt4ty93nr", "1000stake", "--fees", "1000000stake", "--fee-payer", feePayerAddr,
)...)
RequireTxFailure(t, rsp, "invalid number of signatures")

// send tx with feePayers signature
rsp = cli.RunCommandWithArgs(cli.withTXFlags(
"tx", "bank", "send", senderAddr, "cosmos108jsm625z3ejy63uef2ke7t67h6nukt4ty93nr", "1000stake", "--fees", "1000000stake", "--fee-payer", feePayerAddr, "--generate-only",
)...)
tempFile := StoreTempFile(t, []byte(rsp))

rsp = cli.RunCommandWithArgs(cli.withTXFlags(
"tx", "sign", tempFile.Name(), "--from", senderAddr, "--sign-mode", "amino-json",
)...)
tempFile = StoreTempFile(t, []byte(rsp))

rsp = cli.RunCommandWithArgs(cli.withTXFlags(
"tx", "sign", tempFile.Name(), "--from", feePayerAddr, "--sign-mode", "amino-json",
)...)
tempFile = StoreTempFile(t, []byte(rsp))

rsp = cli.RunAndWait([]string{"tx", "broadcast", tempFile.Name()}...)
RequireTxSuccess(t, rsp)

// Query to check fee has been deducted from feePayer
balance := cli.QueryBalance(feePayerAddr, authTestDenom)
assert.Equal(t, balance, int64(9000000))
}

0 comments on commit 7e9f5b4

Please sign in to comment.