Aliter: Implement DeliverMax alias in Payment transactions, through autofill method (#2689)

Co-authored-by: Omar Khan <khancodegt@gmail.com>
This commit is contained in:
Chenna Keshava B S
2024-06-27 09:46:49 -07:00
committed by GitHub
parent a0678857a1
commit 39fed49654
3 changed files with 173 additions and 10 deletions

View File

@@ -1,4 +1,6 @@
import { Payment } from '../../../src'
import { assert } from 'chai'
import { Payment, Wallet } from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
@@ -12,24 +14,92 @@ const TIMEOUT = 20000
describe('Payment', function () {
let testContext: XrplIntegrationTestContext
let paymentTx: Payment
const AMOUNT = '10000000'
// This wallet is used for DeliverMax related tests
let senderWallet: Wallet
beforeEach(async () => {
testContext = await setupClient(serverUrl)
// this payment transaction JSON needs to be refreshed before every test.
// Because, we tinker with Amount and DeliverMax fields in the API v2 tests
paymentTx = {
TransactionType: 'Payment',
Account: senderWallet.classicAddress,
Amount: AMOUNT,
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
}
})
afterEach(async () => teardownClient(testContext))
beforeAll(async () => {
testContext = await setupClient(serverUrl)
senderWallet = await generateFundedWallet(testContext.client)
})
afterAll(async () => teardownClient(testContext))
it(
'base',
async () => {
const wallet2 = await generateFundedWallet(testContext.client)
const tx: Payment = {
TransactionType: 'Payment',
Account: testContext.wallet.classicAddress,
Destination: wallet2.classicAddress,
Destination: senderWallet.classicAddress,
Amount: '1000',
}
await testTransaction(testContext.client, tx, testContext.wallet)
},
TIMEOUT,
)
it(
'Validate Payment transaction API v2: Payment Transaction: Specify Only Amount field',
async () => {
const result = await testTransaction(
testContext.client,
paymentTx,
senderWallet,
)
assert.equal(result.result.engine_result_code, 0)
assert.equal((result.result.tx_json as Payment).Amount, AMOUNT)
},
TIMEOUT,
)
it(
'Validate Payment transaction API v2: Payment Transaction: Specify Only DeliverMax field',
async () => {
// @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions
paymentTx.DeliverMax = paymentTx.Amount
// @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions
delete paymentTx.Amount
const result = await testTransaction(
testContext.client,
paymentTx,
senderWallet,
)
assert.equal(result.result.engine_result_code, 0)
assert.equal((result.result.tx_json as Payment).Amount, AMOUNT)
},
TIMEOUT,
)
it(
'Validate Payment transaction API v2: Payment Transaction: identical DeliverMax and Amount fields',
async () => {
// @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions
paymentTx.DeliverMax = paymentTx.Amount
const result = await testTransaction(
testContext.client,
paymentTx,
senderWallet,
)
assert.equal(result.result.engine_result_code, 0)
assert.equal((result.result.tx_json as Payment).Amount, AMOUNT)
},
TIMEOUT,
)
})