Skip to content

Commit

Permalink
Add insufficient resource fee test
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Dec 20, 2023
1 parent d38ab7f commit 7fef1aa
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions cmd/soroban-rpc/internal/test/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,57 @@ func TestSendTransactionBadSequence(t *testing.T) {
assert.Equal(t, xdr.TransactionResultCodeTxBadSeq, errorResult.Result.Code)
}

func TestSendTransactionFailedInsufficientResourceFee(t *testing.T) {
test := NewTest(t)

ch := jhttp.NewChannel(test.sorobanRPCURL(), nil)
client := jrpc2.NewClient(ch, nil)

kp := keypair.Root(StandaloneNetworkPassphrase)
address := kp.Address()
account := txnbuild.NewSimpleAccount(address, 0)

contractBinary := getHelloWorldContract(t)
params := preflightTransactionParams(t, client, txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createInstallContractCodeOperation(account.AccountID, contractBinary),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})

// make the transaction fail due to insufficient resource fees
params.Operations[0].(*txnbuild.InvokeHostFunction).Ext.SorobanData.ResourceFee /= 2

tx, err := txnbuild.NewTransaction(params)
assert.NoError(t, err)

assert.NoError(t, err)
tx, err = tx.Sign(StandaloneNetworkPassphrase, kp)
assert.NoError(t, err)
b64, err := tx.Base64()
assert.NoError(t, err)

request := methods.SendTransactionRequest{Transaction: b64}
var result methods.SendTransactionResponse
err = client.CallResult(context.Background(), "sendTransaction", request, &result)
assert.NoError(t, err)

assert.Equal(t, proto.TXStatusError, result.Status)
var errorResult xdr.TransactionResult
assert.NoError(t, xdr.SafeUnmarshalBase64(result.ErrorResultXDR, &errorResult))
assert.Equal(t, xdr.TransactionResultCodeTxSorobanInvalid, errorResult.Result.Code)

hash, err := tx.HashHex(StandaloneNetworkPassphrase)
assert.NoError(t, err)
// This fails:
getTransaction(t, client, hash)
}

func TestSendTransactionFailedInLedger(t *testing.T) {
test := NewTest(t)

Expand Down

0 comments on commit 7fef1aa

Please sign in to comment.