From 829de40cfb412e52c12a007a176f71f7f144f9c3 Mon Sep 17 00:00:00 2001 From: Chenna Keshava Date: Thu, 2 May 2024 14:29:57 -0700 Subject: [PATCH 01/23] autofill function: populates and validates Payment transactions in rippled v2 --- packages/xrpl/src/client/index.ts | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 5d2c881592..a62ae07be6 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -643,11 +643,14 @@ class Client extends EventEmitter { transaction: T, signersCount?: number, ): Promise { - const tx = { ...transaction } + const tx_ = { ...transaction } - setValidAddresses(tx) + // the below two functions accept only Transaction objects. + setValidAddresses(tx_) + setTransactionFlagsToNumber(tx_) - setTransactionFlagsToNumber(tx) + // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any + let tx = tx_ as any const promises: Array> = [] if (tx.NetworkID == null) { @@ -666,6 +669,31 @@ class Client extends EventEmitter { promises.push(checkAccountDeleteBlockers(this, tx)) } + 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 + if ( + tx.DeliverMax != null && + tx.Amount != null && + tx.Amount !== tx.DeliverMax + ) { + throw new ValidationError( + 'PaymentTransaction: Amount and DeliverMax fields must be identical', + ) + } + + // remove the DeliverMax field + if (tx.DeliverMax != null) { + delete tx.DeliverMax + } + return Promise.all(promises).then(() => tx) } From 13125564baafcc013c9f911bd647ab577c80608f Mon Sep 17 00:00:00 2001 From: Chenna Keshava Date: Thu, 2 May 2024 15:34:19 -0700 Subject: [PATCH 02/23] unit tests for Payment txn --- packages/xrpl/src/client/index.ts | 28 ++-- packages/xrpl/test/client/autofill.test.ts | 144 +++++++++++++++++++++ 2 files changed, 158 insertions(+), 14 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index a62ae07be6..0d62ca3f4d 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -676,22 +676,22 @@ class Client extends EventEmitter { tx.Amount = tx.DeliverMax } } - } - // If Amount is not identical to DeliverMax, throw an error - if ( - tx.DeliverMax != null && - tx.Amount != null && - tx.Amount !== tx.DeliverMax - ) { - throw new ValidationError( - 'PaymentTransaction: Amount and DeliverMax fields must be identical', - ) - } + // If Amount is not identical to DeliverMax, throw an error + if ( + tx.DeliverMax != null && + tx.Amount != null && + tx.Amount !== tx.DeliverMax + ) { + throw new ValidationError( + 'PaymentTransaction: Amount and DeliverMax fields must be identical', + ) + } - // remove the DeliverMax field - if (tx.DeliverMax != null) { - delete tx.DeliverMax + // remove the DeliverMax field + if (tx.DeliverMax != null) { + delete tx.DeliverMax + } } return Promise.all(promises).then(() => tx) diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index 65ba0d214b..d74e05aec2 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -7,6 +7,7 @@ import { Payment, Transaction, } from '../../src' +import { ValidationError } from '../../src/errors' import rippled from '../fixtures/rippled' import { setupClient, @@ -46,6 +47,149 @@ describe('client.autofill', function () { }) afterEach(async () => teardownClient(testContext)) + it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () { + 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' }], + ], + SendMax: '100000000', + } as any + + await assertRejects(testContext.client.autofill(paytxn), ValidationError) + }) + + it('Validate Payment transaction v2 API: Payment Transaction: both DeliverMax and Amount fields are absent', async function () { + const paytxn = { + TransactionType: 'Payment', + Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', + 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 + + console.log(await testContext.client.autofill(paytxn)) + + // this assertion is not triggered, JSON is not validated against transaction model + await assertRejects(testContext.client.autofill(paytxn), XrplError) + }) + it('should not autofill if fields are present', async function () { const tx: Transaction = { TransactionType: 'DepositPreauth', From 8347cb06a75884e5ed42c2b5868558979dcd9304 Mon Sep 17 00:00:00 2001 From: Chenna Keshava Date: Fri, 3 May 2024 09:39:21 -0700 Subject: [PATCH 03/23] implementation of DeliverMax alias in Payment transactions --- packages/xrpl/src/client/index.ts | 32 +++++++++++----------- packages/xrpl/test/client/autofill.test.ts | 28 ------------------- 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 0d62ca3f4d..c2ef47ed73 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -643,14 +643,11 @@ class Client extends EventEmitter { transaction: T, signersCount?: number, ): Promise { - const tx_ = { ...transaction } + const tx = { ...transaction } // the below two functions accept only Transaction objects. - setValidAddresses(tx_) - setTransactionFlagsToNumber(tx_) - - // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any - let tx = tx_ as any + setValidAddresses(tx) + setTransactionFlagsToNumber(tx) const promises: Array> = [] if (tx.NetworkID == null) { @@ -669,19 +666,22 @@ class Client extends EventEmitter { promises.push(checkAccountDeleteBlockers(this, tx)) } - if (tx.TransactionType === 'Payment') { - if (tx.Amount == null) { + // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any + 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 (tx_.DeliverMax != null) { + tx_.Amount = tx_.DeliverMax } } // If Amount is not identical to DeliverMax, throw an error if ( - tx.DeliverMax != null && - tx.Amount != null && - tx.Amount !== tx.DeliverMax + tx_.DeliverMax != null && + tx_.Amount != null && + tx_.Amount !== tx_.DeliverMax ) { throw new ValidationError( 'PaymentTransaction: Amount and DeliverMax fields must be identical', @@ -689,12 +689,12 @@ class Client extends EventEmitter { } // remove the DeliverMax field - if (tx.DeliverMax != null) { - delete tx.DeliverMax + if (tx_.DeliverMax != null) { + delete tx_.DeliverMax } } - return Promise.all(promises).then(() => tx) + return Promise.all(promises).then(() => tx_) } /** diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index d74e05aec2..68025fad81 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -162,34 +162,6 @@ describe('client.autofill', function () { await assertRejects(testContext.client.autofill(paytxn), ValidationError) }) - it('Validate Payment transaction v2 API: Payment Transaction: both DeliverMax and Amount fields are absent', async function () { - const paytxn = { - TransactionType: 'Payment', - Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', - 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 - - console.log(await testContext.client.autofill(paytxn)) - - // this assertion is not triggered, JSON is not validated against transaction model - await assertRejects(testContext.client.autofill(paytxn), XrplError) - }) - it('should not autofill if fields are present', async function () { const tx: Transaction = { TransactionType: 'DepositPreauth', From 7213301af2d7b2c9757e35ac37008c471963c2cc Mon Sep 17 00:00:00 2001 From: Chenna Keshava Date: Fri, 3 May 2024 09:52:57 -0700 Subject: [PATCH 04/23] use const, instead of 'let' in variable declarations --- packages/xrpl/src/client/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index c2ef47ed73..605501cee5 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -667,7 +667,7 @@ class Client extends EventEmitter { } // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any - let tx_ = tx as any + const tx_ = tx as any if (tx_.TransactionType === 'Payment') { if (tx_.Amount == null) { From 9ed4834abda8c21892a0614f42ae69dca6125154 Mon Sep 17 00:00:00 2001 From: Chenna Keshava Date: Thu, 9 May 2024 10:55:27 -0700 Subject: [PATCH 05/23] ignnore linter errors on `any` type-erasure --- packages/xrpl/src/client/index.ts | 12 ++++++++++++ packages/xrpl/test/client/autofill.test.ts | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 605501cee5..66c89210b9 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -639,6 +639,7 @@ class Client extends EventEmitter { * Only used for multisigned transactions. * @returns The autofilled transaction. */ + // eslint-disable @typescript-eslint/max-lines-per-function public async autofill( transaction: T, signersCount?: number, @@ -667,20 +668,28 @@ class Client extends EventEmitter { } // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment -- `any` type is required to perform non-protocol modifications to the JSON object const tx_ = tx as any + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A transaction JSON must contain TransactionType field if (tx_.TransactionType === 'Payment') { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON must contain Amount field if (tx_.Amount == null) { // If only DeliverMax is provided, use it to populate the Amount field + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON might contain Amount field if (tx_.DeliverMax != null) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical tx_.Amount = tx_.DeliverMax } } // If Amount is not identical to DeliverMax, throw an error if ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.DeliverMax != null && + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount != null && + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount !== tx_.DeliverMax ) { throw new ValidationError( @@ -689,11 +698,14 @@ class Client extends EventEmitter { } // remove the DeliverMax field + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field if (tx_.DeliverMax != null) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field delete tx_.DeliverMax } } + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/promise-function-async -- Please ensure that tx_ is a serializable transaction return Promise.all(promises).then(() => tx_) } diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index 68025fad81..f17a83525d 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -69,6 +69,7 @@ describe('client.autofill', function () { [{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }], ], SendMax: '100000000', + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type } as any const txResult = await testContext.client.autofill(paytxn) @@ -97,6 +98,7 @@ describe('client.autofill', function () { [{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }], ], SendMax: '100000000', + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type } as any const txResult = await testContext.client.autofill(paytxn) @@ -126,6 +128,7 @@ describe('client.autofill', function () { [{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }], ], SendMax: '100000000', + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type } as any const txResult = await testContext.client.autofill(paytxn) @@ -157,6 +160,7 @@ describe('client.autofill', function () { [{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }], ], SendMax: '100000000', + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type } as any await assertRejects(testContext.client.autofill(paytxn), ValidationError) From 778d3a25771e397aa59985f8f72d6db43133dd41 Mon Sep 17 00:00:00 2001 From: Chenna Keshava Date: Thu, 9 May 2024 11:06:15 -0700 Subject: [PATCH 06/23] [FIX] rectify linter warnings --- packages/xrpl/src/client/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 66c89210b9..01a7993707 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -639,7 +639,7 @@ class Client extends EventEmitter { * Only used for multisigned transactions. * @returns The autofilled transaction. */ - // eslint-disable @typescript-eslint/max-lines-per-function + // eslint-disable-next-line max-lines-per-function, complexity -- handling v2 Payment transaction API requires more logic public async autofill( transaction: T, signersCount?: number, @@ -668,16 +668,21 @@ class Client extends EventEmitter { } // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment -- `any` type is required to perform non-protocol modifications to the JSON object + // eslint-disable-next-line max-len -- elaborate comment + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions -- `any` type is required to perform non-protocol modifications to the JSON object const tx_ = tx as any + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A transaction JSON must contain TransactionType field if (tx_.TransactionType === 'Payment') { + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON must contain Amount field if (tx_.Amount == null) { // If only DeliverMax is provided, use it to populate the Amount field - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON might contain Amount field + // eslint-disable-next-line max-len -- elaborate comment + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, max-depth -- A Payment transaction JSON might contain Amount field if (tx_.DeliverMax != null) { + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical tx_.Amount = tx_.DeliverMax } @@ -685,10 +690,13 @@ class Client extends EventEmitter { // If Amount is not identical to DeliverMax, throw an error if ( + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.DeliverMax != null && + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount != null && + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount !== tx_.DeliverMax ) { @@ -698,13 +706,16 @@ class Client extends EventEmitter { } // remove the DeliverMax field + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field if (tx_.DeliverMax != null) { + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field delete tx_.DeliverMax } } + // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/promise-function-async -- Please ensure that tx_ is a serializable transaction return Promise.all(promises).then(() => tx_) } From 0895d0597b830ed3fd715e6550169a896514d178 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Thu, 6 Jun 2024 13:42:07 -0700 Subject: [PATCH 07/23] address PR comments --- packages/xrpl/src/client/index.ts | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 01a7993707..d286c8b705 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -639,6 +639,7 @@ class Client extends EventEmitter { * Only used for multisigned transactions. * @returns The autofilled transaction. */ + /* eslint-disable max-len -- Long linter directives are needed to perform type-erasure in this function */ // eslint-disable-next-line max-lines-per-function, complexity -- handling v2 Payment transaction API requires more logic public async autofill( transaction: T, @@ -668,57 +669,44 @@ class Client extends EventEmitter { } // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions -- `any` type is required to perform non-protocol modifications to the JSON object const tx_ = tx as any - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A transaction JSON must contain TransactionType field if (tx_.TransactionType === 'Payment') { - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON must contain Amount field - if (tx_.Amount == null) { + if (tx_.Amount == null && tx_.DeliverMax != null) { // If only DeliverMax is provided, use it to populate the Amount field - // eslint-disable-next-line max-len -- elaborate comment - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, max-depth -- A Payment transaction JSON might contain Amount field - if (tx_.DeliverMax != null) { - // eslint-disable-next-line max-len -- elaborate comment - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical - tx_.Amount = tx_.DeliverMax - } + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical + tx_.Amount = tx_.DeliverMax } // If Amount is not identical to DeliverMax, throw an error if ( - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.DeliverMax != null && - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount != null && - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount !== tx_.DeliverMax ) { throw new ValidationError( - 'PaymentTransaction: Amount and DeliverMax fields must be identical', + 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', ) } // remove the DeliverMax field - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field if (tx_.DeliverMax != null) { - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field delete tx_.DeliverMax } } - // eslint-disable-next-line max-len -- elaborate comment // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/promise-function-async -- Please ensure that tx_ is a serializable transaction return Promise.all(promises).then(() => tx_) } + /* eslint-enable max-len */ /** * Submits a signed/unsigned transaction. From 5f218b2086887c0ae4746391eebfdca2e30b5909 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 7 Jun 2024 14:14:00 -0700 Subject: [PATCH 08/23] simplify if-conditions --- packages/xrpl/src/client/index.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index d286c8b705..dedb383439 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -640,14 +640,13 @@ class Client extends EventEmitter { * @returns The autofilled transaction. */ /* eslint-disable max-len -- Long linter directives are needed to perform type-erasure in this function */ - // eslint-disable-next-line max-lines-per-function, complexity -- handling v2 Payment transaction API requires more logic + // eslint-disable-next-line complexity -- handling v2 Payment transaction API requires more logic public async autofill( transaction: T, signersCount?: number, ): Promise { const tx = { ...transaction } - // the below two functions accept only Transaction objects. setValidAddresses(tx) setTransactionFlagsToNumber(tx) @@ -673,9 +672,9 @@ class Client extends EventEmitter { const tx_ = tx as any // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A transaction JSON must contain TransactionType field - if (tx_.TransactionType === 'Payment') { + if (tx_.TransactionType === 'Payment' && tx_.DeliverMax != null) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON must contain Amount field - if (tx_.Amount == null && tx_.DeliverMax != null) { + if (tx_.Amount == null) { // If only DeliverMax is provided, use it to populate the Amount field // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical tx_.Amount = tx_.DeliverMax @@ -683,8 +682,6 @@ class Client extends EventEmitter { // If Amount is not identical to DeliverMax, throw an error if ( - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields - tx_.DeliverMax != null && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields tx_.Amount != null && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields @@ -696,11 +693,9 @@ class Client extends EventEmitter { } // remove the DeliverMax field + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field - if (tx_.DeliverMax != null) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field - delete tx_.DeliverMax - } + delete tx_.DeliverMax } // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/promise-function-async -- Please ensure that tx_ is a serializable transaction From e27d23e200f07a3c315bbe9c0a0ca63a15dd2269 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 7 Jun 2024 16:59:46 -0700 Subject: [PATCH 09/23] - remove extraneous comment - refactor tests to use a common payment transaction json --- packages/xrpl/src/client/index.ts | 2 - packages/xrpl/test/client/autofill.test.ts | 104 +++++---------------- 2 files changed, 23 insertions(+), 83 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index dedb383439..afb6cdd3a7 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -692,8 +692,6 @@ class Client extends EventEmitter { ) } - // remove the DeliverMax field - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field delete tx_.DeliverMax } diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index f17a83525d..57f5c4aa1a 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -24,6 +24,8 @@ const HOOKS_TESTNET_ID = 21338 describe('client.autofill', function () { let testContext: XrplTestContext + let paytxn + let amount_: string async function setupMockRippledVersionAndID( buildVersion: string, @@ -44,12 +46,8 @@ describe('client.autofill', function () { beforeEach(async () => { testContext = await setupClient() - }) - afterEach(async () => teardownClient(testContext)) - - it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () { - const amount_ = '1234' - const paytxn = { + amount_ = '1234' + paytxn = { TransactionType: 'Payment', Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', Amount: amount_, @@ -71,99 +69,43 @@ describe('client.autofill', function () { SendMax: '100000000', // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type } as any + }) + afterEach(async () => teardownClient(testContext)) + + it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () { 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', - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type - } as any - const txResult = await testContext.client.autofill(paytxn) + const payment_txn = paytxn + payment_txn.DeliverMax = payment_txn.Amount + delete payment_txn.Amount + const txResult = await testContext.client.autofill(payment_txn) 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', - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type - } as any - const txResult = await testContext.client.autofill(paytxn) + const payment_txn = paytxn + payment_txn.DeliverMax = payment_txn.Amount + + const txResult = await testContext.client.autofill(payment_txn) 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' }], - ], - SendMax: '100000000', - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type - } as any + const payment_txn = paytxn + payment_txn.DeliverMax = '6789' + payment_txn.Amount = '1234' - await assertRejects(testContext.client.autofill(paytxn), ValidationError) + await assertRejects( + testContext.client.autofill(payment_txn), + ValidationError, + ) }) it('should not autofill if fields are present', async function () { From 60f3e6fecc11db6d846b348731b29c38059796b0 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Mon, 10 Jun 2024 10:16:42 -0700 Subject: [PATCH 10/23] disable linter errors for longer functions do not use type-erasure, instead disable linter warnings on unsafe-assignments --- packages/xrpl/src/client/index.ts | 46 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index afb6cdd3a7..a30c857774 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -226,7 +226,7 @@ class Client extends EventEmitter { * const client = new Client('wss://s.altnet.rippletest.net:51233') * ``` */ - // eslint-disable-next-line max-lines-per-function -- okay because we have to set up all the connection handlers + /* eslint-disable max-lines-per-function -- the constructor requires more lines to implement the logic */ public constructor(server: string, options: ClientOptions = {}) { super() if (typeof server !== 'string' || !/wss?(?:\+unix)?:\/\//u.exec(server)) { @@ -290,6 +290,7 @@ class Client extends EventEmitter { this.emit('path_find', path) }) } + /* eslint-enable max-lines-per-function */ /** * Get the url that the client is connected to. @@ -639,7 +640,7 @@ class Client extends EventEmitter { * Only used for multisigned transactions. * @returns The autofilled transaction. */ - /* eslint-disable max-len -- Long linter directives are needed to perform type-erasure in this function */ + // eslint-disable-next-line complexity -- handling v2 Payment transaction API requires more logic public async autofill( transaction: T, @@ -667,39 +668,35 @@ class Client extends EventEmitter { promises.push(checkAccountDeleteBlockers(this, tx)) } - // further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions -- `any` type is required to perform non-protocol modifications to the JSON object - const tx_ = tx as any - - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A transaction JSON must contain TransactionType field - if (tx_.TransactionType === 'Payment' && tx_.DeliverMax != null) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON must contain Amount field - if (tx_.Amount == null) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property + // @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level + if (tx.TransactionType === 'Payment' && tx.DeliverMax != null) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- This is a valid null check for Amount + if (tx.Amount == null) { // If only DeliverMax is provided, use it to populate the Amount field - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical - tx_.Amount = tx_.DeliverMax + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property + // @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- DeliverMax is a known RPC-level property + tx.Amount = tx.DeliverMax } // If Amount is not identical to DeliverMax, throw an error - if ( - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields - tx_.Amount != null && - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields - tx_.Amount !== tx_.DeliverMax - ) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property + // @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- This is a valid null check for Amount + if (tx.Amount != null && tx.Amount !== tx.DeliverMax) { throw new ValidationError( 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', ) } - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field - delete tx_.DeliverMax + // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property + // @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level + delete tx.DeliverMax } - // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/promise-function-async -- Please ensure that tx_ is a serializable transaction - return Promise.all(promises).then(() => tx_) + return Promise.all(promises).then(() => tx) } - /* eslint-enable max-len */ /** * Submits a signed/unsigned transaction. @@ -941,7 +938,7 @@ class Client extends EventEmitter { * @param options.limit - Limit number of balances to return. * @returns An array of XRP/non-XRP balances for the given account. */ - // eslint-disable-next-line max-lines-per-function -- Longer definition is required for end users to see the definition. + /* eslint-disable max-lines-per-function -- getBalances requires more lines to implement logic */ public async getBalances( address: string, options: { @@ -989,6 +986,7 @@ class Client extends EventEmitter { ) return balances.slice(0, options.limit) } + /* eslint-enable max-lines-per-function */ /** * Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook From 71bc89ca72df417570470649a356cdc7ed0e9b07 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:13:04 -0700 Subject: [PATCH 11/23] Update packages/xrpl/src/client/index.ts Co-authored-by: Omar Khan --- packages/xrpl/src/client/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index a30c857774..3b6b590321 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -680,7 +680,6 @@ class Client extends EventEmitter { tx.Amount = tx.DeliverMax } - // If Amount is not identical to DeliverMax, throw an error // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore type-assertions on the DeliverMax property // @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- This is a valid null check for Amount From aedab815822bc0586512977d473458a81c4baa19 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Mon, 10 Jun 2024 15:16:00 -0700 Subject: [PATCH 12/23] integration tests pertaining to DeliverMax --- .../integration/transactions/payment.test.ts | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 333c6278cc..6fb534b54e 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -1,4 +1,8 @@ +import { assert } from 'chai' + import { Payment } from '../../../src' +// import { autofill } from '../../../src/client/index' +import { ValidationError } from '../../../src/errors' import serverUrl from '../serverUrl' import { setupClient, @@ -12,9 +16,21 @@ const TIMEOUT = 20000 describe('Payment', function () { let testContext: XrplIntegrationTestContext + let payment_txn_example + let amount_: string + // This wallet is used for DeliverMax related tests + let payment_txn_wallet beforeEach(async () => { testContext = await setupClient(serverUrl) + amount_ = '200000000' + payment_txn_wallet = await generateFundedWallet(testContext.client) + payment_txn_example = { + TransactionType: 'Payment', + Account: payment_txn_wallet.classicAddress, + Amount: amount_, + Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', + } }) afterEach(async () => teardownClient(testContext)) @@ -32,4 +48,79 @@ describe('Payment', function () { }, TIMEOUT, ) + + it( + 'Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', + async () => { + const result = await testTransaction( + testContext.client, + payment_txn_example, + payment_txn_wallet, + ) + + assert.equal(result.result.engine_result_code, 0) + assert.equal((result.result.tx_json as Payment).Amount, amount_) + }, + TIMEOUT, + ) + + it( + 'Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', + async () => { + const payment_txn = payment_txn_example + payment_txn.DeliverMax = payment_txn.Amount + delete payment_txn.Amount + + const result = await testTransaction( + testContext.client, + payment_txn, + payment_txn_wallet, + ) + + assert.equal(result.result.engine_result_code, 0) + assert.equal((result.result.tx_json as Payment).Amount, amount_) + }, + TIMEOUT, + ) + + it( + 'Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', + async () => { + const payment_txn = payment_txn_example + payment_txn.DeliverMax = payment_txn.Amount + + const result = await testTransaction( + testContext.client, + payment_txn, + payment_txn_wallet, + ) + + assert.equal(result.result.engine_result_code, 0) + assert.equal((result.result.tx_json as Payment).Amount, amount_) + }, + TIMEOUT, + ) + + it( + 'Validate Payment transaction v2 API: Payment Transaction: differing DeliverMax and Amount fields', + async () => { + const payment_txn = payment_txn_example + // Different from the Amount field + payment_txn.DeliverMax = '9999' + + try { + await testTransaction( + testContext.client, + payment_txn, + payment_txn_wallet, + ) + } catch (err) { + assert.equal( + (err as ValidationError).message, + 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', + ) + } + }, + TIMEOUT, + ) }) From b0b5c4bbc7e605e04bcb6aff2314f734033de8e4 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Tue, 11 Jun 2024 16:23:24 -0700 Subject: [PATCH 13/23] fix browser test failures: avoid throwing ValidationError inside payment integration tests --- packages/xrpl/src/client/index.ts | 1 + .../integration/transactions/payment.test.ts | 39 ++++++++----------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 3b6b590321..8f13797b24 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -639,6 +639,7 @@ class Client extends EventEmitter { * @param signersCount - The expected number of signers for this transaction. * Only used for multisigned transactions. * @returns The autofilled transaction. + * @throws ValidationError If Amount and DeliverMax fields are not identical in a Payment Transaction */ // eslint-disable-next-line complexity -- handling v2 Payment transaction API requires more logic diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 6fb534b54e..d6aeafe42b 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -1,8 +1,8 @@ import { assert } from 'chai' import { Payment } from '../../../src' -// import { autofill } from '../../../src/client/index' -import { ValidationError } from '../../../src/errors' +// import { ValidationError } from '../../../src/errors' +// import { assertRejects } from '../../testUtils' import serverUrl from '../serverUrl' import { setupClient, @@ -101,26 +101,19 @@ describe('Payment', function () { TIMEOUT, ) - it( - 'Validate Payment transaction v2 API: Payment Transaction: differing DeliverMax and Amount fields', - async () => { - const payment_txn = payment_txn_example - // Different from the Amount field - payment_txn.DeliverMax = '9999' + // it( + // 'Validate Payment transaction v2 API: Payment Transaction: differing DeliverMax and Amount fields', + // async () => { + // const payment_txn = payment_txn_example + // // Different from the Amount field + // payment_txn.DeliverMax = '9999' - try { - await testTransaction( - testContext.client, - payment_txn, - payment_txn_wallet, - ) - } catch (err) { - assert.equal( - (err as ValidationError).message, - 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', - ) - } - }, - TIMEOUT, - ) + // await assertRejects( + // testTransaction(testContext.client, payment_txn, payment_txn_wallet), + // ValidationError, + // 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', + // ) + // }, + // TIMEOUT, + // ) }) From c8c2072007fdc771e3f61064d6a7282c34b3899d Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Tue, 11 Jun 2024 16:44:58 -0700 Subject: [PATCH 14/23] remove commented code --- .../integration/transactions/payment.test.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index d6aeafe42b..474abb2dd4 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -100,20 +100,4 @@ describe('Payment', function () { }, TIMEOUT, ) - - // it( - // 'Validate Payment transaction v2 API: Payment Transaction: differing DeliverMax and Amount fields', - // async () => { - // const payment_txn = payment_txn_example - // // Different from the Amount field - // payment_txn.DeliverMax = '9999' - - // await assertRejects( - // testTransaction(testContext.client, payment_txn, payment_txn_wallet), - // ValidationError, - // 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', - // ) - // }, - // TIMEOUT, - // ) }) From b854a2dbed2e43a72be0886934b7317ff274c595 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Wed, 12 Jun 2024 13:59:27 -0700 Subject: [PATCH 15/23] [DRAFT] negative integration test -- fails jasmine browser test --- .../integration/transactions/payment.test.ts | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 474abb2dd4..1677119b50 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -1,7 +1,7 @@ import { assert } from 'chai' import { Payment } from '../../../src' -// import { ValidationError } from '../../../src/errors' +import { ValidationError } from '../../../src/errors' // import { assertRejects } from '../../testUtils' import serverUrl from '../serverUrl' import { @@ -100,4 +100,50 @@ describe('Payment', function () { }, TIMEOUT, ) + + // it('fails', () => { + // try { + // Promise.reject(new Error('No')) + // } catch (error) { + // assert(error instanceof Error) + // } + // }) + + it( + 'Payment transaction with differing DeliverMax and Amount fields', + async () => { + const payment_txn = payment_txn_example + payment_txn.DeliverMax = '7890' + + // testTransaction(testContext.client, payment_txn, payment_txn_wallet) + // .then((response) => { + // throw Error(`A error is supposed to be thrown, but got ${response}`) + // }) + // .catch((error) => { + // console.log(`Error-v1! ${error}`) // error is printed correctly + // assert(error instanceof ValidationError) + // assert.equal( + // error.message, + // 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', + // ) + // }) + + try { + await testTransaction( + testContext.client, + payment_txn, + payment_txn_wallet, + ) + } catch (error) { + await teardownClient(testContext) + console.log(`Error-v2! ${error}`) // error is printed correctly + assert(error instanceof ValidationError) + assert.equal( + error.message, + 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', + ) + } + }, + TIMEOUT, + ) }) From dfb2f9a2691730b0e6ad5392ca69632a6ac708a2 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Thu, 13 Jun 2024 14:11:02 -0700 Subject: [PATCH 16/23] remove the integration test with differing DeliverMax and Amount fields -- it does not pertain to rippled code include type annotation in the payment integration test cases --- packages/xrpl/src/client/index.ts | 6 +- .../integration/transactions/payment.test.ts | 57 ++----------------- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 8f13797b24..09882abc83 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -685,8 +685,10 @@ class Client extends EventEmitter { // @ts-expect-error -- DeliverMax property exists only at the RPC level, not at the protocol level // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- This is a valid null check for Amount if (tx.Amount != null && tx.Amount !== tx.DeliverMax) { - throw new ValidationError( - 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', + return Promise.reject( + new ValidationError( + 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', + ), ) } diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 1677119b50..0a5f032290 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -1,8 +1,6 @@ import { assert } from 'chai' -import { Payment } from '../../../src' -import { ValidationError } from '../../../src/errors' -// import { assertRejects } from '../../testUtils' +import { Payment, Wallet } from '../../../src' import serverUrl from '../serverUrl' import { setupClient, @@ -16,10 +14,10 @@ const TIMEOUT = 20000 describe('Payment', function () { let testContext: XrplIntegrationTestContext - let payment_txn_example + let payment_txn_example: Payment let amount_: string // This wallet is used for DeliverMax related tests - let payment_txn_wallet + let payment_txn_wallet: Wallet beforeEach(async () => { testContext = await setupClient(serverUrl) @@ -68,7 +66,9 @@ describe('Payment', function () { 'Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', async () => { const payment_txn = payment_txn_example + // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions payment_txn.DeliverMax = payment_txn.Amount + // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions delete payment_txn.Amount const result = await testTransaction( @@ -87,6 +87,7 @@ describe('Payment', function () { 'Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', async () => { const payment_txn = payment_txn_example + // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions payment_txn.DeliverMax = payment_txn.Amount const result = await testTransaction( @@ -100,50 +101,4 @@ describe('Payment', function () { }, TIMEOUT, ) - - // it('fails', () => { - // try { - // Promise.reject(new Error('No')) - // } catch (error) { - // assert(error instanceof Error) - // } - // }) - - it( - 'Payment transaction with differing DeliverMax and Amount fields', - async () => { - const payment_txn = payment_txn_example - payment_txn.DeliverMax = '7890' - - // testTransaction(testContext.client, payment_txn, payment_txn_wallet) - // .then((response) => { - // throw Error(`A error is supposed to be thrown, but got ${response}`) - // }) - // .catch((error) => { - // console.log(`Error-v1! ${error}`) // error is printed correctly - // assert(error instanceof ValidationError) - // assert.equal( - // error.message, - // 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', - // ) - // }) - - try { - await testTransaction( - testContext.client, - payment_txn, - payment_txn_wallet, - ) - } catch (error) { - await teardownClient(testContext) - console.log(`Error-v2! ${error}`) // error is printed correctly - assert(error instanceof ValidationError) - assert.equal( - error.message, - 'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided', - ) - } - }, - TIMEOUT, - ) }) From c49957c13fdc6eee0393057a662500d8af08084f Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 14 Jun 2024 10:30:25 -0700 Subject: [PATCH 17/23] address PR comments: remove underscores in variable names --- .../integration/transactions/payment.test.ts | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 0a5f032290..176556886b 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -14,19 +14,18 @@ const TIMEOUT = 20000 describe('Payment', function () { let testContext: XrplIntegrationTestContext - let payment_txn_example: Payment - let amount_: string + let paymentTxExample: Payment + const AMOUNT = '200000000' // This wallet is used for DeliverMax related tests - let payment_txn_wallet: Wallet + let paymentTxWallet: Wallet beforeEach(async () => { testContext = await setupClient(serverUrl) - amount_ = '200000000' - payment_txn_wallet = await generateFundedWallet(testContext.client) - payment_txn_example = { + paymentTxWallet = await generateFundedWallet(testContext.client) + paymentTxExample = { TransactionType: 'Payment', - Account: payment_txn_wallet.classicAddress, - Amount: amount_, + Account: paymentTxWallet.classicAddress, + Amount: AMOUNT, Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', } }) @@ -52,12 +51,12 @@ describe('Payment', function () { async () => { const result = await testTransaction( testContext.client, - payment_txn_example, - payment_txn_wallet, + paymentTxExample, + paymentTxWallet, ) assert.equal(result.result.engine_result_code, 0) - assert.equal((result.result.tx_json as Payment).Amount, amount_) + assert.equal((result.result.tx_json as Payment).Amount, AMOUNT) }, TIMEOUT, ) @@ -65,20 +64,20 @@ describe('Payment', function () { it( 'Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', async () => { - const payment_txn = payment_txn_example + const paymentTx = paymentTxExample // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions - payment_txn.DeliverMax = payment_txn.Amount + paymentTx.DeliverMax = paymentTx.Amount // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions - delete payment_txn.Amount + delete paymentTx.Amount const result = await testTransaction( testContext.client, - payment_txn, - payment_txn_wallet, + paymentTx, + paymentTxWallet, ) assert.equal(result.result.engine_result_code, 0) - assert.equal((result.result.tx_json as Payment).Amount, amount_) + assert.equal((result.result.tx_json as Payment).Amount, AMOUNT) }, TIMEOUT, ) @@ -86,18 +85,18 @@ describe('Payment', function () { it( 'Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', async () => { - const payment_txn = payment_txn_example + const paymentTx = paymentTxExample // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions - payment_txn.DeliverMax = payment_txn.Amount + paymentTx.DeliverMax = paymentTx.Amount const result = await testTransaction( testContext.client, - payment_txn, - payment_txn_wallet, + paymentTx, + paymentTxWallet, ) assert.equal(result.result.engine_result_code, 0) - assert.equal((result.result.tx_json as Payment).Amount, amount_) + assert.equal((result.result.tx_json as Payment).Amount, AMOUNT) }, TIMEOUT, ) From 28d1ef47d738527dc4d4774c81629f0bae8dc521 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 14 Jun 2024 15:45:58 -0700 Subject: [PATCH 18/23] address omar PR comments -- simplify the structure of the tests --- packages/xrpl/test/client/autofill.test.ts | 46 +++++++++---------- .../integration/transactions/payment.test.ts | 8 ++-- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index 57f5c4aa1a..93589e26ef 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -24,8 +24,8 @@ const HOOKS_TESTNET_ID = 21338 describe('client.autofill', function () { let testContext: XrplTestContext - let paytxn - let amount_: string + const AMOUNT = '1234' + let paymentTx: Payment async function setupMockRippledVersionAndID( buildVersion: string, @@ -46,11 +46,10 @@ describe('client.autofill', function () { beforeEach(async () => { testContext = await setupClient() - amount_ = '1234' - paytxn = { + paymentTx = { TransactionType: 'Payment', Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', - Amount: amount_, + Amount: AMOUNT, Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', DestinationTag: 1, Fee: '12', @@ -67,45 +66,42 @@ describe('client.autofill', function () { [{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }], ], SendMax: '100000000', - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Represent transaction JSON with `any` type - } as any + } }) afterEach(async () => teardownClient(testContext)) it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () { - const txResult = await testContext.client.autofill(paytxn) + const txResult = await testContext.client.autofill(paymentTx) - assert.strictEqual(txResult.Amount, amount_) + assert.strictEqual(txResult.Amount, AMOUNT) }) it('Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', async function () { - const payment_txn = paytxn - payment_txn.DeliverMax = payment_txn.Amount - delete payment_txn.Amount - const txResult = await testContext.client.autofill(payment_txn) + // @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 txResult = await testContext.client.autofill(paymentTx) - assert.strictEqual(txResult.Amount, amount_) + assert.strictEqual(txResult.Amount, AMOUNT) }) it('Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', async function () { - const payment_txn = paytxn - payment_txn.DeliverMax = payment_txn.Amount + // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions + paymentTx.DeliverMax = paymentTx.Amount - const txResult = await testContext.client.autofill(payment_txn) + const txResult = await testContext.client.autofill(paymentTx) - assert.strictEqual(txResult.Amount, amount_) + 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 payment_txn = paytxn - payment_txn.DeliverMax = '6789' - payment_txn.Amount = '1234' + // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions + paymentTx.DeliverMax = '6789' + paymentTx.Amount = '1234' - await assertRejects( - testContext.client.autofill(payment_txn), - ValidationError, - ) + await assertRejects(testContext.client.autofill(paymentTx), ValidationError) }) it('should not autofill if fields are present', async function () { diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 176556886b..efe4a4dff1 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -14,7 +14,7 @@ const TIMEOUT = 20000 describe('Payment', function () { let testContext: XrplIntegrationTestContext - let paymentTxExample: Payment + let paymentTx: Payment const AMOUNT = '200000000' // This wallet is used for DeliverMax related tests let paymentTxWallet: Wallet @@ -22,7 +22,7 @@ describe('Payment', function () { beforeEach(async () => { testContext = await setupClient(serverUrl) paymentTxWallet = await generateFundedWallet(testContext.client) - paymentTxExample = { + paymentTx = { TransactionType: 'Payment', Account: paymentTxWallet.classicAddress, Amount: AMOUNT, @@ -51,7 +51,7 @@ describe('Payment', function () { async () => { const result = await testTransaction( testContext.client, - paymentTxExample, + paymentTx, paymentTxWallet, ) @@ -64,7 +64,6 @@ describe('Payment', function () { it( 'Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', async () => { - const paymentTx = paymentTxExample // @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 @@ -85,7 +84,6 @@ describe('Payment', function () { it( 'Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', async () => { - const paymentTx = paymentTxExample // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions paymentTx.DeliverMax = paymentTx.Amount From 0d3d409dc7601a6a57d31f425de57b21880affc9 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:21:47 -0700 Subject: [PATCH 19/23] Update packages/xrpl/test/integration/transactions/payment.test.ts Co-authored-by: Omar Khan --- packages/xrpl/test/integration/transactions/payment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index efe4a4dff1..9cc247e7c1 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -47,7 +47,7 @@ describe('Payment', function () { ) it( - 'Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', + 'Validate Payment transaction API v2: Payment Transaction: Specify Only Amount field', async () => { const result = await testTransaction( testContext.client, From d661fe610228247997fb5b507b652d99aaa57493 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:21:56 -0700 Subject: [PATCH 20/23] Update packages/xrpl/test/integration/transactions/payment.test.ts Co-authored-by: Omar Khan --- packages/xrpl/test/integration/transactions/payment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 9cc247e7c1..b556c850f1 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -62,7 +62,7 @@ describe('Payment', function () { ) it( - 'Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', + '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 From 4b69021f2790d0ce7cea3020cc5ee64f6e5e634f Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:22:04 -0700 Subject: [PATCH 21/23] Update packages/xrpl/test/integration/transactions/payment.test.ts Co-authored-by: Omar Khan --- packages/xrpl/test/integration/transactions/payment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index b556c850f1..8bcf55da73 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -82,7 +82,7 @@ describe('Payment', function () { ) it( - 'Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', + '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 From 270567dd77b9e4a6d4a6abe30dc0683258ac3ccf Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:22:34 -0700 Subject: [PATCH 22/23] Update packages/xrpl/src/client/index.ts Co-authored-by: Omar Khan --- packages/xrpl/src/client/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/client/index.ts b/packages/xrpl/src/client/index.ts index 09882abc83..1e6b89288c 100644 --- a/packages/xrpl/src/client/index.ts +++ b/packages/xrpl/src/client/index.ts @@ -642,7 +642,7 @@ class Client extends EventEmitter { * @throws ValidationError If Amount and DeliverMax fields are not identical in a Payment Transaction */ - // eslint-disable-next-line complexity -- handling v2 Payment transaction API requires more logic + // eslint-disable-next-line complexity -- handling Payment transaction API v2 requires more logic public async autofill( transaction: T, signersCount?: number, From bc803a8459441eddcae76919cd1e3c6283220172 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 14 Jun 2024 16:38:02 -0700 Subject: [PATCH 23/23] address PR comments -- use beforeAll() construct --- packages/xrpl/test/client/autofill.test.ts | 15 ++++++----- .../integration/transactions/payment.test.ts | 26 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index 93589e26ef..8371557196 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -44,8 +44,12 @@ describe('client.autofill', function () { await testContext.client.connect() } - beforeEach(async () => { + beforeAll(async () => { testContext = await setupClient() + }) + afterAll(async () => teardownClient(testContext)) + + beforeEach(async () => { paymentTx = { TransactionType: 'Payment', Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', @@ -68,15 +72,14 @@ describe('client.autofill', function () { SendMax: '100000000', } }) - afterEach(async () => teardownClient(testContext)) - it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () { + it('Validate Payment transaction API v2: Payment Transaction: Specify Only Amount field', async function () { const txResult = await testContext.client.autofill(paymentTx) assert.strictEqual(txResult.Amount, AMOUNT) }) - it('Validate Payment transaction v2 API: Payment Transaction: Specify Only DeliverMax field', async function () { + it('Validate Payment transaction API v2: Payment Transaction: Specify Only DeliverMax field', async function () { // @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 @@ -86,7 +89,7 @@ describe('client.autofill', function () { assert.strictEqual(txResult.Amount, AMOUNT) }) - it('Validate Payment transaction v2 API: Payment Transaction: identical DeliverMax and Amount fields', async function () { + it('Validate Payment transaction API v2: Payment Transaction: identical DeliverMax and Amount fields', async function () { // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions paymentTx.DeliverMax = paymentTx.Amount @@ -96,7 +99,7 @@ describe('client.autofill', function () { assert.strictEqual('DeliverMax' in txResult, false) }) - it('Validate Payment transaction v2 API: Payment Transaction: differing DeliverMax and Amount fields', async function () { + it('Validate Payment transaction API v2: Payment Transaction: differing DeliverMax and Amount fields', async function () { // @ts-expect-error -- DeliverMax is a non-protocol, RPC level field in Payment transactions paymentTx.DeliverMax = '6789' paymentTx.Amount = '1234' diff --git a/packages/xrpl/test/integration/transactions/payment.test.ts b/packages/xrpl/test/integration/transactions/payment.test.ts index 8bcf55da73..391ab317b2 100644 --- a/packages/xrpl/test/integration/transactions/payment.test.ts +++ b/packages/xrpl/test/integration/transactions/payment.test.ts @@ -15,30 +15,34 @@ const TIMEOUT = 20000 describe('Payment', function () { let testContext: XrplIntegrationTestContext let paymentTx: Payment - const AMOUNT = '200000000' + const AMOUNT = '10000000' // This wallet is used for DeliverMax related tests - let paymentTxWallet: Wallet + let senderWallet: Wallet beforeEach(async () => { - testContext = await setupClient(serverUrl) - paymentTxWallet = await generateFundedWallet(testContext.client) + // 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: paymentTxWallet.classicAddress, + 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) @@ -52,7 +56,7 @@ describe('Payment', function () { const result = await testTransaction( testContext.client, paymentTx, - paymentTxWallet, + senderWallet, ) assert.equal(result.result.engine_result_code, 0) @@ -72,7 +76,7 @@ describe('Payment', function () { const result = await testTransaction( testContext.client, paymentTx, - paymentTxWallet, + senderWallet, ) assert.equal(result.result.engine_result_code, 0) @@ -90,7 +94,7 @@ describe('Payment', function () { const result = await testTransaction( testContext.client, paymentTx, - paymentTxWallet, + senderWallet, ) assert.equal(result.result.engine_result_code, 0)