mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
test: fix Escrow integration tests (#2305)
* improve runtime of TrustSet integ test * fix EscrowFinish test * finish EscrowCancel test * add comment * fix linter issues * fix browser tests --------- Co-authored-by: Caleb Kniffen <ckniffen@ripple.com> Co-authored-by: justinr1234 <justinr1234@gmail.com>
This commit is contained in:
@@ -2,3 +2,5 @@ dist
|
|||||||
node_modules
|
node_modules
|
||||||
.github
|
.github
|
||||||
.vscode
|
.vscode
|
||||||
|
karma.config.js
|
||||||
|
karma-setup.js
|
||||||
|
|||||||
@@ -30,5 +30,15 @@ module.exports = function (config) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
browsers: ['ChromeHeadless'],
|
browsers: ['ChromeHeadless'],
|
||||||
|
// runs only one browser at a time
|
||||||
|
concurrency: 1,
|
||||||
|
// CI mode
|
||||||
|
singleRun: true,
|
||||||
|
client: {
|
||||||
|
jasmine: {
|
||||||
|
// ensures that tests are run in order instead of a random order
|
||||||
|
random: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
/* eslint-disable import/export -- Tells webpack which files exist. */
|
/* eslint-disable import/export -- Tells webpack which files exist. */
|
||||||
|
|
||||||
|
// These go first because they're affected by the `ledger_accept`s
|
||||||
|
export * from './transactions/escrowFinish.test'
|
||||||
|
export * from './transactions/escrowCancel.test'
|
||||||
|
|
||||||
|
// Transactions
|
||||||
export * from './transactions/accountSet.test'
|
export * from './transactions/accountSet.test'
|
||||||
export * from './transactions/checkCancel.test'
|
export * from './transactions/checkCancel.test'
|
||||||
export * from './transactions/checkCash.test'
|
export * from './transactions/checkCash.test'
|
||||||
export * from './transactions/checkCreate.test'
|
export * from './transactions/checkCreate.test'
|
||||||
export * from './transactions/depositPreauth.test'
|
export * from './transactions/depositPreauth.test'
|
||||||
export * from './transactions/escrowCancel.test'
|
|
||||||
export * from './transactions/escrowCreate.test'
|
export * from './transactions/escrowCreate.test'
|
||||||
export * from './transactions/escrowFinish.test'
|
|
||||||
export * from './transactions/offerCancel.test'
|
export * from './transactions/offerCancel.test'
|
||||||
export * from './transactions/offerCreate.test'
|
export * from './transactions/offerCreate.test'
|
||||||
export * from './transactions/payment.test'
|
export * from './transactions/payment.test'
|
||||||
@@ -16,6 +20,7 @@ export * from './transactions/paymentChannelFund.test'
|
|||||||
export * from './transactions/signerListSet.test'
|
export * from './transactions/signerListSet.test'
|
||||||
export * from './transactions/trustSet.test'
|
export * from './transactions/trustSet.test'
|
||||||
|
|
||||||
|
// Requests
|
||||||
export * from './requests/accountChannels.test'
|
export * from './requests/accountChannels.test'
|
||||||
export * from './requests/accountCurrencies.test'
|
export * from './requests/accountCurrencies.test'
|
||||||
export * from './requests/accountInfo.test'
|
export * from './requests/accountInfo.test'
|
||||||
|
|||||||
@@ -8,21 +8,13 @@ import {
|
|||||||
type XrplIntegrationTestContext,
|
type XrplIntegrationTestContext,
|
||||||
} from '../setup'
|
} from '../setup'
|
||||||
import {
|
import {
|
||||||
// calculateWaitTimeForTransaction,
|
calculateWaitTimeForTransaction,
|
||||||
generateFundedWallet,
|
generateFundedWallet,
|
||||||
// getXRPBalance,
|
getXRPBalance,
|
||||||
testTransaction,
|
testTransaction,
|
||||||
submitTransaction,
|
sendLedgerAccept,
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
|
|
||||||
// TODO: Fix these tests
|
|
||||||
// NOTE: Because ledger accept is called among multiple tests, the actual ledger close time is not
|
|
||||||
// accurate. It can end up very far into the future. This means that the CancelAfter timer can potentially
|
|
||||||
// need to wait for several minutes to be able to properly complete. Since we are not testing the functionaity
|
|
||||||
// of rippled in this library, only that we are submitting commands properly, we can just test that the EscrowCancel
|
|
||||||
// command was successfully received. If in the future we isolate tests to run on their own rippled instance,
|
|
||||||
// we can uncomment the code in this file to test that the escrow was actually cancelled.
|
|
||||||
|
|
||||||
// how long before each test case times out
|
// how long before each test case times out
|
||||||
const TIMEOUT = 50000
|
const TIMEOUT = 50000
|
||||||
|
|
||||||
@@ -48,7 +40,7 @@ describe('EscrowCancel', function () {
|
|||||||
})
|
})
|
||||||
).result.ledger.close_time
|
).result.ledger.close_time
|
||||||
|
|
||||||
// const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
|
const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
|
||||||
|
|
||||||
const createTx: EscrowCreate = {
|
const createTx: EscrowCreate = {
|
||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
@@ -61,10 +53,10 @@ describe('EscrowCancel', function () {
|
|||||||
|
|
||||||
await testTransaction(testContext.client, createTx, testContext.wallet)
|
await testTransaction(testContext.client, createTx, testContext.wallet)
|
||||||
|
|
||||||
// const initialBalanceWallet1 = await getXRPBalance(
|
const initialBalanceWallet1 = await getXRPBalance(
|
||||||
// testContext.client,
|
testContext.client,
|
||||||
// wallet1,
|
wallet1,
|
||||||
// )
|
)
|
||||||
|
|
||||||
// check that the object was actually created
|
// check that the object was actually created
|
||||||
const accountObjects = (
|
const accountObjects = (
|
||||||
@@ -96,29 +88,25 @@ describe('EscrowCancel', function () {
|
|||||||
|
|
||||||
// We set the CancelAfter timer to be 3 seconds after the last ledger close_time. We need to wait this long
|
// We set the CancelAfter timer to be 3 seconds after the last ledger close_time. We need to wait this long
|
||||||
// before we can cancel the escrow.
|
// before we can cancel the escrow.
|
||||||
// const cancelAfterTimerPromise = new Promise((resolve) => {
|
const cancelAfterTimerPromise = new Promise((resolve) => {
|
||||||
// setTimeout(resolve, waitTimeInMs)
|
setTimeout(resolve, waitTimeInMs)
|
||||||
// })
|
})
|
||||||
|
|
||||||
// Make sure we wait long enough before canceling the escrow.
|
// Make sure we wait long enough before canceling the escrow.
|
||||||
// await cancelAfterTimerPromise
|
await cancelAfterTimerPromise
|
||||||
|
|
||||||
// await testTransaction(testContext.client, cancelTx, testContext.wallet, {
|
// rippled uses the close time of the previous ledger
|
||||||
// count: 20,
|
await sendLedgerAccept(testContext.client)
|
||||||
// delayMs: 2000,
|
await testTransaction(testContext.client, cancelTx, testContext.wallet, {
|
||||||
// })
|
count: 20,
|
||||||
|
delayMs: 2000,
|
||||||
await submitTransaction({
|
|
||||||
client: testContext.client,
|
|
||||||
transaction: cancelTx,
|
|
||||||
wallet: testContext.wallet,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Make sure the Destination wallet did not receive any XRP.
|
// Make sure the Destination wallet did not receive any XRP.
|
||||||
// assert.equal(
|
assert.equal(
|
||||||
// await getXRPBalance(testContext.client, wallet1),
|
await getXRPBalance(testContext.client, wallet1),
|
||||||
// initialBalanceWallet1,
|
initialBalanceWallet1,
|
||||||
// )
|
)
|
||||||
},
|
},
|
||||||
TIMEOUT,
|
TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
calculateWaitTimeForTransaction,
|
calculateWaitTimeForTransaction,
|
||||||
generateFundedWallet,
|
generateFundedWallet,
|
||||||
getXRPBalance,
|
getXRPBalance,
|
||||||
|
sendLedgerAccept,
|
||||||
testTransaction,
|
testTransaction,
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
|
|
||||||
@@ -84,6 +85,8 @@ describe('EscrowFinish', function () {
|
|||||||
|
|
||||||
await finishAfterPromise
|
await finishAfterPromise
|
||||||
|
|
||||||
|
// rippled uses the close time of the previous ledger
|
||||||
|
await sendLedgerAccept(testContext.client)
|
||||||
await testTransaction(testContext.client, finishTx, testContext.wallet)
|
await testTransaction(testContext.client, finishTx, testContext.wallet)
|
||||||
|
|
||||||
const expectedBalance = String(Number(initialBalance) + Number(AMOUNT))
|
const expectedBalance = String(Number(initialBalance) + Number(AMOUNT))
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { TrustSet, percentToQuality } from '../../../src'
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
import { TrustSet, percentToQuality, Wallet } from '../../../src'
|
||||||
import serverUrl from '../serverUrl'
|
import serverUrl from '../serverUrl'
|
||||||
import {
|
import {
|
||||||
setupClient,
|
setupClient,
|
||||||
@@ -12,16 +14,21 @@ const TIMEOUT = 20000
|
|||||||
|
|
||||||
describe('TrustSet', function () {
|
describe('TrustSet', function () {
|
||||||
let testContext: XrplIntegrationTestContext
|
let testContext: XrplIntegrationTestContext
|
||||||
|
let wallet2: Wallet | undefined
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
testContext = await setupClient(serverUrl)
|
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))
|
afterEach(async () => teardownClient(testContext))
|
||||||
|
|
||||||
it(
|
it(
|
||||||
'base',
|
'base',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
assert(wallet2 != null)
|
||||||
const tx: TrustSet = {
|
const tx: TrustSet = {
|
||||||
TransactionType: 'TrustSet',
|
TransactionType: 'TrustSet',
|
||||||
Account: testContext.wallet.classicAddress,
|
Account: testContext.wallet.classicAddress,
|
||||||
@@ -40,14 +47,14 @@ describe('TrustSet', function () {
|
|||||||
it(
|
it(
|
||||||
'Quality < 1',
|
'Quality < 1',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
assert(wallet2 != null)
|
||||||
const tx: TrustSet = {
|
const tx: TrustSet = {
|
||||||
TransactionType: 'TrustSet',
|
TransactionType: 'TrustSet',
|
||||||
Account: testContext.wallet.address,
|
Account: testContext.wallet.address,
|
||||||
QualityIn: percentToQuality('99%'),
|
QualityIn: percentToQuality('99%'),
|
||||||
QualityOut: percentToQuality('99%'),
|
QualityOut: percentToQuality('99%'),
|
||||||
LimitAmount: {
|
LimitAmount: {
|
||||||
currency: 'USD',
|
currency: 'BTC',
|
||||||
issuer: wallet2.address,
|
issuer: wallet2.address,
|
||||||
value: '100',
|
value: '100',
|
||||||
},
|
},
|
||||||
@@ -61,14 +68,14 @@ describe('TrustSet', function () {
|
|||||||
it(
|
it(
|
||||||
'Quality > 1',
|
'Quality > 1',
|
||||||
async () => {
|
async () => {
|
||||||
const wallet2 = await generateFundedWallet(testContext.client)
|
assert(wallet2 != null)
|
||||||
const tx: TrustSet = {
|
const tx: TrustSet = {
|
||||||
TransactionType: 'TrustSet',
|
TransactionType: 'TrustSet',
|
||||||
QualityIn: percentToQuality('101%'),
|
QualityIn: percentToQuality('101%'),
|
||||||
QualityOut: percentToQuality('101%'),
|
QualityOut: percentToQuality('101%'),
|
||||||
Account: testContext.wallet.address,
|
Account: testContext.wallet.address,
|
||||||
LimitAmount: {
|
LimitAmount: {
|
||||||
currency: 'USD',
|
currency: 'ETH',
|
||||||
issuer: wallet2.address,
|
issuer: wallet2.address,
|
||||||
value: '100',
|
value: '100',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { hashSignedTx } from '../../src/utils/hashes'
|
|||||||
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
|
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
|
||||||
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
||||||
|
|
||||||
async function sendLedgerAccept(client: Client): Promise<unknown> {
|
export async function sendLedgerAccept(client: Client): Promise<unknown> {
|
||||||
return client.connection.request({ command: 'ledger_accept' })
|
return client.connection.request({ command: 'ledger_accept' })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +253,6 @@ export async function testTransaction(
|
|||||||
},
|
},
|
||||||
): Promise<SubmitResponse> {
|
): Promise<SubmitResponse> {
|
||||||
// Accept any un-validated changes.
|
// Accept any un-validated changes.
|
||||||
await ledgerAccept(client)
|
|
||||||
|
|
||||||
// sign/submit the transaction
|
// sign/submit the transaction
|
||||||
const response = await submitTransaction({
|
const response = await submitTransaction({
|
||||||
|
|||||||
Reference in New Issue
Block a user