mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
fix test mock setup
This commit is contained in:
@@ -24,6 +24,23 @@ const HOOKS_TESTNET_ID = 21338
|
||||
describe('client.autofill', function () {
|
||||
let testContext: XrplTestContext
|
||||
|
||||
async function setupMockRippledVersionAndID(
|
||||
buildVersion: string,
|
||||
networkID: number,
|
||||
): Promise<void> {
|
||||
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',
|
||||
|
||||
2
packages/xrpl/test/fixtures/rippled/index.ts
vendored
2
packages/xrpl/test/fixtures/rippled/index.ts
vendored
@@ -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 = {
|
||||
|
||||
31
packages/xrpl/test/fixtures/rippled/serverInfoNetworkID.json
vendored
Normal file
31
packages/xrpl/test/fixtures/rippled/serverInfoNetworkID.json
vendored
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user