Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 28 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
829de40
autofill function: populates and validates Payment transactions in ri…
ckeshava May 2, 2024
1312556
unit tests for Payment txn
ckeshava May 2, 2024
8347cb0
implementation of DeliverMax alias in Payment transactions
ckeshava May 3, 2024
7213301
use const, instead of 'let' in variable declarations
ckeshava May 3, 2024
9ed4834
ignnore linter errors on `any` type-erasure
ckeshava May 9, 2024
778d3a2
[FIX] rectify linter warnings
ckeshava May 9, 2024
b16a322
Merge branch 'main' into autofill-temp
ckeshava May 9, 2024
9632c55
Merge branch 'main' into autofill-temp
ckeshava Jun 4, 2024
0895d05
address PR comments
ckeshava Jun 6, 2024
5f218b2
simplify if-conditions
ckeshava Jun 7, 2024
4fabd79
Merge remote-tracking branch 'upstream/main' into autofill-temp
ckeshava Jun 7, 2024
e27d23e
- remove extraneous comment
ckeshava Jun 7, 2024
60f3e6f
disable linter errors for longer functions
ckeshava Jun 10, 2024
71bc89c
Update packages/xrpl/src/client/index.ts
ckeshava Jun 10, 2024
aedab81
integration tests pertaining to DeliverMax
ckeshava Jun 10, 2024
b0b5c4b
fix browser test failures: avoid throwing ValidationError inside paym…
ckeshava Jun 11, 2024
c8c2072
remove commented code
ckeshava Jun 11, 2024
9708845
Merge branch 'main' into autofill-temp
ckeshava Jun 11, 2024
b854a2d
[DRAFT] negative integration test -- fails jasmine browser test
ckeshava Jun 12, 2024
dfb2f9a
remove the integration test with differing DeliverMax and Amount fiel…
ckeshava Jun 13, 2024
c49957c
address PR comments: remove underscores in variable names
ckeshava Jun 14, 2024
28d1ef4
address omar PR comments -- simplify the structure of the tests
ckeshava Jun 14, 2024
0d3d409
Update packages/xrpl/test/integration/transactions/payment.test.ts
ckeshava Jun 14, 2024
d661fe6
Update packages/xrpl/test/integration/transactions/payment.test.ts
ckeshava Jun 14, 2024
4b69021
Update packages/xrpl/test/integration/transactions/payment.test.ts
ckeshava Jun 14, 2024
270567d
Update packages/xrpl/src/client/index.ts
ckeshava Jun 14, 2024
bc803a8
address PR comments -- use beforeAll() construct
ckeshava Jun 14, 2024
07804f2
Merge branch 'main' into autofill-temp
ckeshava Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/xrpl/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ class Client extends EventEmitter<EventTypes> {
): Promise<T> {
const tx = { ...transaction }

// the below two functions accept only Transaction objects.
khancode marked this conversation as resolved.
Show resolved Hide resolved
setValidAddresses(tx)

setTransactionFlagsToNumber(tx)

const promises: Array<Promise<void>> = []
Expand All @@ -666,7 +666,35 @@ class Client extends EventEmitter<EventTypes> {
promises.push(checkAccountDeleteBlockers(this, tx))
}

return Promise.all(promises).then(() => tx)
// further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any
ckeshava marked this conversation as resolved.
Show resolved Hide resolved
let tx_ = tx as any

if (tx_.TransactionType === 'Payment') {
if (tx_.Amount == null) {
// If only DeliverMax is provided, use it to populate the Amount field
if (tx_.DeliverMax != null) {
tx_.Amount = tx_.DeliverMax
}
}

// If Amount is not identical to DeliverMax, throw an error
ckeshava marked this conversation as resolved.
Show resolved Hide resolved
if (
tx_.DeliverMax != null &&
tx_.Amount != null &&
tx_.Amount !== tx_.DeliverMax
) {
throw new ValidationError(
'PaymentTransaction: Amount and DeliverMax fields must be identical',
ckeshava marked this conversation as resolved.
Show resolved Hide resolved
)
}

// remove the DeliverMax field
if (tx_.DeliverMax != null) {
delete tx_.DeliverMax
}
}

return Promise.all(promises).then(() => tx_)
}

/**
Expand Down
116 changes: 116 additions & 0 deletions packages/xrpl/test/client/autofill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Payment,
Transaction,
} from '../../src'
import { ValidationError } from '../../src/errors'
import rippled from '../fixtures/rippled'
import {
setupClient,
Expand Down Expand Up @@ -46,6 +47,121 @@ describe('client.autofill', function () {
})
afterEach(async () => teardownClient(testContext))

it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () {
ckeshava marked this conversation as resolved.
Show resolved Hide resolved
const amount_ = '1234'
const paytxn = {
TransactionType: 'Payment',
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
Amount: amount_,
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
DestinationTag: 1,
Fee: '12',
Flags: 2147483648,
LastLedgerSequence: 65953073,
Sequence: 65923914,
SigningPubKey:
'02F9E33F16DF9507705EC954E3F94EB5F10D1FC4A354606DBE6297DBB1096FE654',
TxnSignature:
'3045022100E3FAE0EDEC3D6A8FF6D81BC9CF8288A61B7EEDE8071E90FF9314CB4621058D10022043545CF631706D700CEE65A1DB83EFDD185413808292D9D90F14D87D3DC2D8CB',
InvoiceID:
'6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B',
Paths: [
[{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }],
],
SendMax: '100000000',
} as any
const txResult = await testContext.client.autofill(paytxn)

assert.strictEqual(txResult.Amount, amount_)
})

it('Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', async function () {
const amount_ = '1234'
const paytxn = {
TransactionType: 'Payment',
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
DeliverMax: amount_,
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
DestinationTag: 1,
Fee: '12',
Flags: 2147483648,
LastLedgerSequence: 65953073,
Sequence: 65923914,
SigningPubKey:
'02F9E33F16DF9507705EC954E3F94EB5F10D1FC4A354606DBE6297DBB1096FE654',
TxnSignature:
'3045022100E3FAE0EDEC3D6A8FF6D81BC9CF8288A61B7EEDE8071E90FF9314CB4621058D10022043545CF631706D700CEE65A1DB83EFDD185413808292D9D90F14D87D3DC2D8CB',
InvoiceID:
'6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B',
Paths: [
[{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }],
],
SendMax: '100000000',
} as any
const txResult = await testContext.client.autofill(paytxn)

assert.strictEqual(txResult.Amount, amount_)
})

it('Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', async function () {
const amount_ = '1234'
const paytxn = {
TransactionType: 'Payment',
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
DeliverMax: amount_,
Amount: amount_,
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
DestinationTag: 1,
Fee: '12',
Flags: 2147483648,
LastLedgerSequence: 65953073,
Sequence: 65923914,
SigningPubKey:
'02F9E33F16DF9507705EC954E3F94EB5F10D1FC4A354606DBE6297DBB1096FE654',
TxnSignature:
'3045022100E3FAE0EDEC3D6A8FF6D81BC9CF8288A61B7EEDE8071E90FF9314CB4621058D10022043545CF631706D700CEE65A1DB83EFDD185413808292D9D90F14D87D3DC2D8CB',
InvoiceID:
'6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B',
Paths: [
[{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }],
],
SendMax: '100000000',
} as any
const txResult = await testContext.client.autofill(paytxn)

assert.strictEqual(txResult.Amount, amount_)
assert.strictEqual('DeliverMax' in txResult, false)
})

it('Validate Payment transaction v2 API: Payment Transaction: differing DeliverMax and Amount fields', async function () {
const amount_ = '1234'
const deliverMax_ = '5678'
const paytxn = {
TransactionType: 'Payment',
Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
DeliverMax: deliverMax_,
Amount: amount_,
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
DestinationTag: 1,
Fee: '12',
Flags: 2147483648,
LastLedgerSequence: 65953073,
Sequence: 65923914,
SigningPubKey:
'02F9E33F16DF9507705EC954E3F94EB5F10D1FC4A354606DBE6297DBB1096FE654',
TxnSignature:
'3045022100E3FAE0EDEC3D6A8FF6D81BC9CF8288A61B7EEDE8071E90FF9314CB4621058D10022043545CF631706D700CEE65A1DB83EFDD185413808292D9D90F14D87D3DC2D8CB',
InvoiceID:
'6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B',
Paths: [
[{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }],
],
khancode marked this conversation as resolved.
Show resolved Hide resolved
SendMax: '100000000',
} as any

await assertRejects(testContext.client.autofill(paytxn), ValidationError)
})

it('should not autofill if fields are present', async function () {
const tx: Transaction = {
TransactionType: 'DepositPreauth',
Expand Down
Loading