From a940b7c408e6dfc49ecae356f133e6f7e31dc229 Mon Sep 17 00:00:00 2001 From: Phu Pham Date: Tue, 6 Jun 2023 12:12:41 -0400 Subject: [PATCH] fix test mock setup --- packages/xrpl/test/client/autofill.test.ts | 31 +++++++++++++------ packages/xrpl/test/fixtures/rippled/index.ts | 2 ++ .../fixtures/rippled/serverInfoNetworkID.json | 31 +++++++++++++++++++ packages/xrpl/test/setupClient.ts | 5 ++- 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 packages/xrpl/test/fixtures/rippled/serverInfoNetworkID.json diff --git a/packages/xrpl/test/client/autofill.test.ts b/packages/xrpl/test/client/autofill.test.ts index 3ef293fd..2d4db695 100644 --- a/packages/xrpl/test/client/autofill.test.ts +++ b/packages/xrpl/test/client/autofill.test.ts @@ -24,6 +24,23 @@ const HOOKS_TESTNET_ID = 21338 describe('client.autofill', function () { let testContext: XrplTestContext + async function setupMockRippledVersionAndID( + buildVersion: string, + networkID: number, + ): Promise { + await testContext.client.disconnect() + rippled.server_info.withNetworkId.result.info.build_version = buildVersion + rippled.server_info.withNetworkId.result.info.network_id = networkID + testContext.client.on('connected', () => { + testContext.mockRippled?.addResponse( + 'server_info', + rippled.server_info.withNetworkId, + ) + }) + + await testContext.client.connect() + } + beforeEach(async () => { testContext = await setupClient() }) @@ -65,8 +82,7 @@ describe('client.autofill', function () { }) it('overrides network ID if > 1024 and version is later than 1.11.0', async function () { - testContext.client.networkID = 1025 - testContext.client.buildVersion = '1.11.1' + await setupMockRippledVersionAndID('1.11.1', 1025) const tx: Payment = { TransactionType: 'Payment', Account: 'XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi', @@ -84,8 +100,7 @@ describe('client.autofill', function () { }) it('ignores network ID if > 1024 but version is earlier than 1.11.0', async function () { - testContext.client.networkID = 1025 - testContext.client.buildVersion = '1.10.1' + await setupMockRippledVersionAndID('1.10.0', 1025) const tx: Payment = { TransactionType: 'Payment', Account: 'XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi', @@ -102,9 +117,8 @@ describe('client.autofill', function () { assert.strictEqual(txResult.NetworkID, undefined) }) - it('ignores network ID if < 1024', async function () { - testContext.client.networkID = 1023 - testContext.client.buildVersion = '1.11.1' + it('ignores network ID if <= 1024', async function () { + await setupMockRippledVersionAndID('1.11.1', 1023) const tx: Payment = { TransactionType: 'Payment', Account: 'XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi', @@ -122,8 +136,7 @@ describe('client.autofill', function () { }) it('override network ID for hooks testnet', async function () { - testContext.client.networkID = HOOKS_TESTNET_ID - testContext.client.buildVersion = '1.10.1' + await setupMockRippledVersionAndID('1.10.1', HOOKS_TESTNET_ID) const tx: Payment = { TransactionType: 'Payment', Account: 'XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi', diff --git a/packages/xrpl/test/fixtures/rippled/index.ts b/packages/xrpl/test/fixtures/rippled/index.ts index 757f8fa0..1d48f12c 100644 --- a/packages/xrpl/test/fixtures/rippled/index.ts +++ b/packages/xrpl/test/fixtures/rippled/index.ts @@ -12,6 +12,7 @@ import iouPartialPayment from './partialPaymentIOU.json' import xrpPartialPayment from './partialPaymentXRP.json' import normalServerInfo from './serverInfo.json' import highLoadFactor from './serverInfoHighLoadFactor.json' +import withNetworkIDServerInfo from './serverInfoNetworkID.json' import consensusStream from './streams/consensusPhase.json' import ledgerStream from './streams/ledger.json' import manifestStream from './streams/manifest.json' @@ -84,6 +85,7 @@ const ledger_data = { const server_info = { normal: normalServerInfo, highLoadFactor, + withNetworkId: withNetworkIDServerInfo, } const tx = { diff --git a/packages/xrpl/test/fixtures/rippled/serverInfoNetworkID.json b/packages/xrpl/test/fixtures/rippled/serverInfoNetworkID.json new file mode 100644 index 00000000..2d9e45c4 --- /dev/null +++ b/packages/xrpl/test/fixtures/rippled/serverInfoNetworkID.json @@ -0,0 +1,31 @@ +{ + "id": 0, + "status": "success", + "type": "response", + "result": { + "info": { + "build_version": "1.11.0-rc2", + "complete_ledgers": "37621036-38327626", + "hostid": "JANE", + "io_latency_ms": 1, + "last_close": { + "converge_time_s": 2, + "proposers": 6 + }, + "load_factor": 1, + "network_id": 1, + "peers": 113, + "pubkey_node": "n9L6MAkAvZKakewLSJPkCKLxuSQ9jrYXJBd2L4fouhpXauyFh6ZM", + "server_state": "full", + "validated_ledger": { + "age": 0, + "base_fee_xrp": 0.00001, + "hash": "A219F66BB8C9992E80A3C93A5EA408CD54B8F47F2AC1246C271C495F833752BA", + "reserve_base_xrp": 10, + "reserve_inc_xrp": 2, + "seq": 38327626 + }, + "validation_quorum": 5 + } + } +} diff --git a/packages/xrpl/test/setupClient.ts b/packages/xrpl/test/setupClient.ts index ce3c2f97..4441e11d 100644 --- a/packages/xrpl/test/setupClient.ts +++ b/packages/xrpl/test/setupClient.ts @@ -32,7 +32,10 @@ async function setupMockRippledConnection( }) context.client.on('connected', () => { - context.mockRippled?.addResponse('server_info', rippled.server_info.normal) + context.mockRippled?.addResponse( + 'server_info', + rippled.server_info.withNetworkId, + ) }) return context.client.connect().then(() => context)