From 1d897a4128334bda95f680292dd5cf74ed4961ff Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Tue, 7 Jan 2025 10:40:46 -0800 Subject: [PATCH 1/7] update models for RippleState flags. New integration test for SetTrust transaction integration test for OfferCreate txn (negative case) update to the unit test of TrustSet transaction --- .ci-config/rippled.cfg | 1 + packages/xrpl/HISTORY.md | 3 + .../xrpl/src/models/ledger/RippleState.ts | 4 ++ .../xrpl/src/models/transactions/trustSet.ts | 8 +++ .../transactions/offerCreate.test.ts | 61 ++++++++++++++++++- .../integration/transactions/trustSet.test.ts | 41 +++++++++++++ packages/xrpl/test/models/trustSet.test.ts | 5 ++ 7 files changed, 121 insertions(+), 2 deletions(-) diff --git a/.ci-config/rippled.cfg b/.ci-config/rippled.cfg index 673c1e3505..80878e01c2 100644 --- a/.ci-config/rippled.cfg +++ b/.ci-config/rippled.cfg @@ -188,3 +188,4 @@ fixNFTokenPageLinks fixInnerObjTemplate2 fixEnforceNFTokenTrustline fixReducedOffersV2 +DeepFreeze diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index b834707f69..90a5b6c267 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -4,6 +4,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ## Unreleased Changes +### Added +* Support for XLS-77d Deep-Freeze amendment + ## 4.1.0 (2024-12-23) ### Added diff --git a/packages/xrpl/src/models/ledger/RippleState.ts b/packages/xrpl/src/models/ledger/RippleState.ts index 907907e010..0250e63c13 100644 --- a/packages/xrpl/src/models/ledger/RippleState.ts +++ b/packages/xrpl/src/models/ledger/RippleState.ts @@ -77,4 +77,8 @@ export enum RippleStateFlags { lsfHighFreeze = 0x00800000, // True, trust line to AMM. Used by client apps to identify payments via AMM. lsfAMMNode = 0x01000000, + // True, low side has set deep freeze flag + lsfLowDeepFreeze = 0x02000000, + // True, high side has set deep freeze flag + lsfHighDeepFreeze = 0x04000000, } diff --git a/packages/xrpl/src/models/transactions/trustSet.ts b/packages/xrpl/src/models/transactions/trustSet.ts index f584261af3..e27ca43306 100644 --- a/packages/xrpl/src/models/transactions/trustSet.ts +++ b/packages/xrpl/src/models/transactions/trustSet.ts @@ -30,6 +30,10 @@ export enum TrustSetFlags { tfSetFreeze = 0x00100000, /** Unfreeze the trust line. */ tfClearFreeze = 0x00200000, + /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ + tfSetDeepFreeze = 0x00400000, + /** Clear a Deep-Frozen trust line */ + tfClearDeepFreeze = 0x00800000, } /** @@ -89,6 +93,10 @@ export interface TrustSetFlagsInterface extends GlobalFlags { tfSetFreeze?: boolean /** Unfreeze the trust line. */ tfClearFreeze?: boolean + /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ + tfSetDeepFreeze?: boolean + /** Clear a Deep-Frozen trust line */ + tfClearDeepFreeze?: boolean } /** diff --git a/packages/xrpl/test/integration/transactions/offerCreate.test.ts b/packages/xrpl/test/integration/transactions/offerCreate.test.ts index 7d7bf0f2bf..d681006725 100644 --- a/packages/xrpl/test/integration/transactions/offerCreate.test.ts +++ b/packages/xrpl/test/integration/transactions/offerCreate.test.ts @@ -1,22 +1,31 @@ import { assert } from 'chai' -import { OfferCreate } from '../../../src' +import { OfferCreate, TrustSet, Wallet } from '../../../src' import serverUrl from '../serverUrl' import { setupClient, teardownClient, type XrplIntegrationTestContext, } from '../setup' -import { testTransaction } from '../utils' +import { + testTransaction, + generateFundedWallet, + submitTransaction, +} from '../utils' // how long before each test case times out const TIMEOUT = 20000 describe('OfferCreate', function () { let testContext: XrplIntegrationTestContext + let wallet2: Wallet | undefined beforeEach(async () => { testContext = await setupClient(serverUrl) + if (!wallet2) { + // eslint-disable-next-line require-atomic-updates -- race condition doesn't really matter + wallet2 = await generateFundedWallet(testContext.client) + } }) afterEach(async () => teardownClient(testContext)) @@ -49,4 +58,52 @@ describe('OfferCreate', function () { }, TIMEOUT, ) + + it( + 'OfferCreate with Deep-Frozen trust-line must fail', + async () => { + assert(wallet2 != null) + + // deep-freeze the trust line + const trust_set_tx: TrustSet = { + TransactionType: 'TrustSet', + Account: testContext.wallet.classicAddress, + LimitAmount: { + currency: 'USD', + issuer: wallet2.classicAddress, + value: '10', + }, + Flags: { + tfSetFreeze: true, + tfSetDeepFreeze: true, + }, + } + + await testTransaction( + testContext.client, + trust_set_tx, + testContext.wallet, + ) + + const offer_create_tx: OfferCreate = { + TransactionType: 'OfferCreate', + Account: testContext.wallet.classicAddress, + TakerGets: '13100000', + TakerPays: { + currency: 'USD', + issuer: wallet2.classicAddress, + value: '10', + }, + } + + const response = await submitTransaction({ + client: testContext.client, + transaction: offer_create_tx, + wallet: testContext.wallet, + }) + + assert.equal(response.result.engine_result, 'tecFROZEN') + }, + TIMEOUT, + ) }) diff --git a/packages/xrpl/test/integration/transactions/trustSet.test.ts b/packages/xrpl/test/integration/transactions/trustSet.test.ts index 7736d0d107..f44311fba0 100644 --- a/packages/xrpl/test/integration/transactions/trustSet.test.ts +++ b/packages/xrpl/test/integration/transactions/trustSet.test.ts @@ -85,4 +85,45 @@ describe('TrustSet', function () { }, TIMEOUT, ) + + it( + 'Create a Deep-Frozen trust line', + async () => { + assert(wallet2 != null) + // preemptively deep-freeze a trust line with the specified counter-party/currency-code + const tx: TrustSet = { + TransactionType: 'TrustSet', + Account: testContext.wallet.classicAddress, + LimitAmount: { + currency: 'USD', + issuer: wallet2.classicAddress, + value: '10', + }, + Flags: { + tfSetFreeze: true, + tfSetDeepFreeze: true, + }, + } + + const response = await testTransaction( + testContext.client, + tx, + testContext.wallet, + ) + assert.equal(response.result.engine_result, 'tesSUCCESS') + + // assert that the trust line is deep-frozen + const trustLine = await testContext.client.request({ + command: 'account_lines', + account: testContext.wallet.classicAddress, + }) + + // assert that the TrustLine is deep-frozen + assert.equal(trustLine.result.lines[0].freeze, true) + + // Keshava: ensure that account_lines RPC response contains a deep_freeze flag + // assert.equal(trustLine.result.lines[0].deep_freeze, true) + }, + TIMEOUT, + ) }) diff --git a/packages/xrpl/test/models/trustSet.test.ts b/packages/xrpl/test/models/trustSet.test.ts index ce1b05ebcd..b634cc04da 100644 --- a/packages/xrpl/test/models/trustSet.test.ts +++ b/packages/xrpl/test/models/trustSet.test.ts @@ -22,6 +22,11 @@ describe('TrustSet', function () { }, QualityIn: 1234, QualityOut: 4321, + // an example of deep-frozen trust line + Flags: { + tfSetFreeze: true, + tfSetDeepFreeze: true, + }, } as any }) From e942a4f9a5f00e0f9a051730043f36fe20ade4d9 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Wed, 15 Jan 2025 14:39:36 -0800 Subject: [PATCH 2/7] address PR suggestions --- .../transactions/offerCreate.test.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/xrpl/test/integration/transactions/offerCreate.test.ts b/packages/xrpl/test/integration/transactions/offerCreate.test.ts index d681006725..86b5a8cda6 100644 --- a/packages/xrpl/test/integration/transactions/offerCreate.test.ts +++ b/packages/xrpl/test/integration/transactions/offerCreate.test.ts @@ -18,16 +18,19 @@ const TIMEOUT = 20000 describe('OfferCreate', function () { let testContext: XrplIntegrationTestContext - let wallet2: Wallet | undefined + let wallet_deep_freeze_trustline: Wallet | undefined - beforeEach(async () => { + beforeAll(async () => { testContext = await setupClient(serverUrl) - if (!wallet2) { + if (!wallet_deep_freeze_trustline) { // eslint-disable-next-line require-atomic-updates -- race condition doesn't really matter - wallet2 = await generateFundedWallet(testContext.client) + wallet_deep_freeze_trustline = await generateFundedWallet( + testContext.client, + ) } }) - afterEach(async () => teardownClient(testContext)) + + afterAll(async () => teardownClient(testContext)) it( 'base', @@ -62,7 +65,7 @@ describe('OfferCreate', function () { it( 'OfferCreate with Deep-Frozen trust-line must fail', async () => { - assert(wallet2 != null) + assert(wallet_deep_freeze_trustline != null) // deep-freeze the trust line const trust_set_tx: TrustSet = { @@ -70,7 +73,7 @@ describe('OfferCreate', function () { Account: testContext.wallet.classicAddress, LimitAmount: { currency: 'USD', - issuer: wallet2.classicAddress, + issuer: wallet_deep_freeze_trustline.classicAddress, value: '10', }, Flags: { @@ -91,7 +94,7 @@ describe('OfferCreate', function () { TakerGets: '13100000', TakerPays: { currency: 'USD', - issuer: wallet2.classicAddress, + issuer: wallet_deep_freeze_trustline.classicAddress, value: '10', }, } From bb1463bdb52acd637f3e66e0583042a6e387d400 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:39:29 -0800 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> --- .../test/integration/transactions/offerCreate.test.ts | 2 +- .../xrpl/test/integration/transactions/trustSet.test.ts | 8 ++++---- packages/xrpl/test/models/trustSet.test.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/xrpl/test/integration/transactions/offerCreate.test.ts b/packages/xrpl/test/integration/transactions/offerCreate.test.ts index 86b5a8cda6..fb242544ff 100644 --- a/packages/xrpl/test/integration/transactions/offerCreate.test.ts +++ b/packages/xrpl/test/integration/transactions/offerCreate.test.ts @@ -63,7 +63,7 @@ describe('OfferCreate', function () { ) it( - 'OfferCreate with Deep-Frozen trust-line must fail', + 'OfferCreate with Deep-Frozen trustline must fail', async () => { assert(wallet_deep_freeze_trustline != null) diff --git a/packages/xrpl/test/integration/transactions/trustSet.test.ts b/packages/xrpl/test/integration/transactions/trustSet.test.ts index f44311fba0..2ae977e9d2 100644 --- a/packages/xrpl/test/integration/transactions/trustSet.test.ts +++ b/packages/xrpl/test/integration/transactions/trustSet.test.ts @@ -87,10 +87,10 @@ describe('TrustSet', function () { ) it( - 'Create a Deep-Frozen trust line', + 'Create a Deep-Frozen trustline', async () => { assert(wallet2 != null) - // preemptively deep-freeze a trust line with the specified counter-party/currency-code + // preemptively deep-freeze a trustline with the specified counter-party/currency-code const tx: TrustSet = { TransactionType: 'TrustSet', Account: testContext.wallet.classicAddress, @@ -112,13 +112,13 @@ describe('TrustSet', function () { ) assert.equal(response.result.engine_result, 'tesSUCCESS') - // assert that the trust line is deep-frozen + // assert that the trustline is deep-frozen const trustLine = await testContext.client.request({ command: 'account_lines', account: testContext.wallet.classicAddress, }) - // assert that the TrustLine is deep-frozen + // assert that the trustLine is deep-frozen assert.equal(trustLine.result.lines[0].freeze, true) // Keshava: ensure that account_lines RPC response contains a deep_freeze flag diff --git a/packages/xrpl/test/models/trustSet.test.ts b/packages/xrpl/test/models/trustSet.test.ts index b634cc04da..fe6cba9524 100644 --- a/packages/xrpl/test/models/trustSet.test.ts +++ b/packages/xrpl/test/models/trustSet.test.ts @@ -22,7 +22,7 @@ describe('TrustSet', function () { }, QualityIn: 1234, QualityOut: 4321, - // an example of deep-frozen trust line + // an example of deep-frozen trustline Flags: { tfSetFreeze: true, tfSetDeepFreeze: true, From c9ecd33eb88848d25d1dca2a24c5270ac356cb04 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 31 Jan 2025 09:43:19 -0800 Subject: [PATCH 4/7] address PR comments --- .../xrpl/src/models/transactions/trustSet.ts | 2 ++ .../integration/transactions/trustSet.test.ts | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/xrpl/src/models/transactions/trustSet.ts b/packages/xrpl/src/models/transactions/trustSet.ts index e27ca43306..11ef1fb7c9 100644 --- a/packages/xrpl/src/models/transactions/trustSet.ts +++ b/packages/xrpl/src/models/transactions/trustSet.ts @@ -31,6 +31,7 @@ export enum TrustSetFlags { /** Unfreeze the trust line. */ tfClearFreeze = 0x00200000, /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ + /** Allowed only if the trustline is already regularly frozen, or if tfSetFreeze is set in the same transaction. */ tfSetDeepFreeze = 0x00400000, /** Clear a Deep-Frozen trust line */ tfClearDeepFreeze = 0x00800000, @@ -94,6 +95,7 @@ export interface TrustSetFlagsInterface extends GlobalFlags { /** Unfreeze the trust line. */ tfClearFreeze?: boolean /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ + /** Allowed only if the trustline is already regularly frozen, or if tfSetFreeze is set in the same transaction. */ tfSetDeepFreeze?: boolean /** Clear a Deep-Frozen trust line */ tfClearDeepFreeze?: boolean diff --git a/packages/xrpl/test/integration/transactions/trustSet.test.ts b/packages/xrpl/test/integration/transactions/trustSet.test.ts index 2ae977e9d2..14d059ba00 100644 --- a/packages/xrpl/test/integration/transactions/trustSet.test.ts +++ b/packages/xrpl/test/integration/transactions/trustSet.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai' -import { TrustSet, percentToQuality, Wallet } from '../../../src' +import { TrustSet, percentToQuality, Wallet, TrustSetFlags } from '../../../src' import serverUrl from '../serverUrl' import { setupClient, @@ -8,7 +8,7 @@ import { type XrplIntegrationTestContext, } from '../setup' import { generateFundedWallet, testTransaction } from '../utils' - +import RippleState from '../../../src/models/ledger/RippleState' // how long before each test case times out const TIMEOUT = 20000 @@ -90,7 +90,7 @@ describe('TrustSet', function () { 'Create a Deep-Frozen trustline', async () => { assert(wallet2 != null) - // preemptively deep-freeze a trustline with the specified counter-party/currency-code + // deep-freeze a trustline with the specified counter-party/currency-code const tx: TrustSet = { TransactionType: 'TrustSet', Account: testContext.wallet.classicAddress, @@ -112,17 +112,21 @@ describe('TrustSet', function () { ) assert.equal(response.result.engine_result, 'tesSUCCESS') - // assert that the trustline is deep-frozen + // assert that the trustline is frozen const trustLine = await testContext.client.request({ command: 'account_lines', account: testContext.wallet.classicAddress, }) - - // assert that the trustLine is deep-frozen assert.equal(trustLine.result.lines[0].freeze, true) - // Keshava: ensure that account_lines RPC response contains a deep_freeze flag - // assert.equal(trustLine.result.lines[0].deep_freeze, true) + // verify that the trust-line is deep-frozen + // this operation cannot be done with the account_lines RPC + const account_objects = await testContext.client.request({ + command: 'account_objects', + account: testContext.wallet.classicAddress, + }) + assert.isTrue(((account_objects.result.account_objects[0] as RippleState).Flags & TrustSetFlags.tfSetDeepFreeze) != 0) + }, TIMEOUT, ) From 3e8b7265f8d0f6e23e3bf1bbdc225c646846b7ab Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 31 Jan 2025 09:44:28 -0800 Subject: [PATCH 5/7] Update packages/xrpl/src/models/transactions/trustSet.ts Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> --- packages/xrpl/src/models/transactions/trustSet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/trustSet.ts b/packages/xrpl/src/models/transactions/trustSet.ts index 11ef1fb7c9..c5112d4f5a 100644 --- a/packages/xrpl/src/models/transactions/trustSet.ts +++ b/packages/xrpl/src/models/transactions/trustSet.ts @@ -33,7 +33,7 @@ export enum TrustSetFlags { /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ /** Allowed only if the trustline is already regularly frozen, or if tfSetFreeze is set in the same transaction. */ tfSetDeepFreeze = 0x00400000, - /** Clear a Deep-Frozen trust line */ + /** Clear a Deep-Frozen trustline */ tfClearDeepFreeze = 0x00800000, } From bc43fad76671f54ef0bd49a6c8c2c22df33580a7 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 31 Jan 2025 09:45:20 -0800 Subject: [PATCH 6/7] Update packages/xrpl/src/models/transactions/trustSet.ts Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> --- packages/xrpl/src/models/transactions/trustSet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/trustSet.ts b/packages/xrpl/src/models/transactions/trustSet.ts index c5112d4f5a..2c68e85d43 100644 --- a/packages/xrpl/src/models/transactions/trustSet.ts +++ b/packages/xrpl/src/models/transactions/trustSet.ts @@ -94,7 +94,7 @@ export interface TrustSetFlagsInterface extends GlobalFlags { tfSetFreeze?: boolean /** Unfreeze the trust line. */ tfClearFreeze?: boolean - /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ + /** Deep-Freeze the trustline -- disallow sending and receiving the said IssuedCurrency */ /** Allowed only if the trustline is already regularly frozen, or if tfSetFreeze is set in the same transaction. */ tfSetDeepFreeze?: boolean /** Clear a Deep-Frozen trust line */ From 4080c6f96c4fb9e50335bd66f00a4dd7791b36df Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Fri, 31 Jan 2025 09:46:28 -0800 Subject: [PATCH 7/7] Update packages/xrpl/src/models/transactions/trustSet.ts Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> --- packages/xrpl/src/models/transactions/trustSet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/src/models/transactions/trustSet.ts b/packages/xrpl/src/models/transactions/trustSet.ts index 2c68e85d43..229143fb9e 100644 --- a/packages/xrpl/src/models/transactions/trustSet.ts +++ b/packages/xrpl/src/models/transactions/trustSet.ts @@ -30,7 +30,7 @@ export enum TrustSetFlags { tfSetFreeze = 0x00100000, /** Unfreeze the trust line. */ tfClearFreeze = 0x00200000, - /** Deep-Freeze the trust line -- disallow sending and recieving the said IssuedCurrency */ + /** Deep-Freeze the trustline -- disallow sending and receiving the said IssuedCurrency */ /** Allowed only if the trustline is already regularly frozen, or if tfSetFreeze is set in the same transaction. */ tfSetDeepFreeze = 0x00400000, /** Clear a Deep-Frozen trustline */