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:
Mayukha Vadari
2023-05-31 12:46:00 -04:00
committed by GitHub
parent 70a9ab0510
commit c647be701e
7 changed files with 57 additions and 43 deletions

View File

@@ -1,12 +1,16 @@
/* 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/checkCancel.test'
export * from './transactions/checkCash.test'
export * from './transactions/checkCreate.test'
export * from './transactions/depositPreauth.test'
export * from './transactions/escrowCancel.test'
export * from './transactions/escrowCreate.test'
export * from './transactions/escrowFinish.test'
export * from './transactions/offerCancel.test'
export * from './transactions/offerCreate.test'
export * from './transactions/payment.test'
@@ -16,6 +20,7 @@ export * from './transactions/paymentChannelFund.test'
export * from './transactions/signerListSet.test'
export * from './transactions/trustSet.test'
// Requests
export * from './requests/accountChannels.test'
export * from './requests/accountCurrencies.test'
export * from './requests/accountInfo.test'

View File

@@ -8,21 +8,13 @@ import {
type XrplIntegrationTestContext,
} from '../setup'
import {
// calculateWaitTimeForTransaction,
calculateWaitTimeForTransaction,
generateFundedWallet,
// getXRPBalance,
getXRPBalance,
testTransaction,
submitTransaction,
sendLedgerAccept,
} 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
const TIMEOUT = 50000
@@ -48,7 +40,7 @@ describe('EscrowCancel', function () {
})
).result.ledger.close_time
// const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
const createTx: EscrowCreate = {
Account: testContext.wallet.classicAddress,
@@ -61,10 +53,10 @@ describe('EscrowCancel', function () {
await testTransaction(testContext.client, createTx, testContext.wallet)
// const initialBalanceWallet1 = await getXRPBalance(
// testContext.client,
// wallet1,
// )
const initialBalanceWallet1 = await getXRPBalance(
testContext.client,
wallet1,
)
// check that the object was actually created
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
// before we can cancel the escrow.
// const cancelAfterTimerPromise = new Promise((resolve) => {
// setTimeout(resolve, waitTimeInMs)
// })
const cancelAfterTimerPromise = new Promise((resolve) => {
setTimeout(resolve, waitTimeInMs)
})
// Make sure we wait long enough before canceling the escrow.
// await cancelAfterTimerPromise
await cancelAfterTimerPromise
// await testTransaction(testContext.client, cancelTx, testContext.wallet, {
// count: 20,
// delayMs: 2000,
// })
await submitTransaction({
client: testContext.client,
transaction: cancelTx,
wallet: testContext.wallet,
// rippled uses the close time of the previous ledger
await sendLedgerAccept(testContext.client)
await testTransaction(testContext.client, cancelTx, testContext.wallet, {
count: 20,
delayMs: 2000,
})
// Make sure the Destination wallet did not receive any XRP.
// assert.equal(
// await getXRPBalance(testContext.client, wallet1),
// initialBalanceWallet1,
// )
assert.equal(
await getXRPBalance(testContext.client, wallet1),
initialBalanceWallet1,
)
},
TIMEOUT,
)

View File

@@ -11,6 +11,7 @@ import {
calculateWaitTimeForTransaction,
generateFundedWallet,
getXRPBalance,
sendLedgerAccept,
testTransaction,
} from '../utils'
@@ -84,6 +85,8 @@ describe('EscrowFinish', function () {
await finishAfterPromise
// rippled uses the close time of the previous ledger
await sendLedgerAccept(testContext.client)
await testTransaction(testContext.client, finishTx, testContext.wallet)
const expectedBalance = String(Number(initialBalance) + Number(AMOUNT))

View File

@@ -1,4 +1,6 @@
import { TrustSet, percentToQuality } from '../../../src'
import { assert } from 'chai'
import { TrustSet, percentToQuality, Wallet } from '../../../src'
import serverUrl from '../serverUrl'
import {
setupClient,
@@ -12,16 +14,21 @@ const TIMEOUT = 20000
describe('TrustSet', 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))
it(
'base',
async () => {
const wallet2 = await generateFundedWallet(testContext.client)
assert(wallet2 != null)
const tx: TrustSet = {
TransactionType: 'TrustSet',
Account: testContext.wallet.classicAddress,
@@ -40,14 +47,14 @@ describe('TrustSet', function () {
it(
'Quality < 1',
async () => {
const wallet2 = await generateFundedWallet(testContext.client)
assert(wallet2 != null)
const tx: TrustSet = {
TransactionType: 'TrustSet',
Account: testContext.wallet.address,
QualityIn: percentToQuality('99%'),
QualityOut: percentToQuality('99%'),
LimitAmount: {
currency: 'USD',
currency: 'BTC',
issuer: wallet2.address,
value: '100',
},
@@ -61,14 +68,14 @@ describe('TrustSet', function () {
it(
'Quality > 1',
async () => {
const wallet2 = await generateFundedWallet(testContext.client)
assert(wallet2 != null)
const tx: TrustSet = {
TransactionType: 'TrustSet',
QualityIn: percentToQuality('101%'),
QualityOut: percentToQuality('101%'),
Account: testContext.wallet.address,
LimitAmount: {
currency: 'USD',
currency: 'ETH',
issuer: wallet2.address,
value: '100',
},

View File

@@ -18,7 +18,7 @@ import { hashSignedTx } from '../../src/utils/hashes'
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
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' })
}
@@ -253,7 +253,6 @@ export async function testTransaction(
},
): Promise<SubmitResponse> {
// Accept any un-validated changes.
await ledgerAccept(client)
// sign/submit the transaction
const response = await submitTransaction({