mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-03 10:35:49 +00:00
test: add integration tests for sidechain transactions (#2301)
* add XChainCreateBridge integration test * add XChainCreateClaimID integration test * add XChainCommit integration test * add XChainAccountCreateCommit integration test * simplify tests * add XChainModifyBridge integration test * add XChainAddAccountCreateAttestation integration test * add XChainAddClaimAttestation integration test * improve SignerListSet integration test * rename variable to match * add XChainClaim integration test * clean up * add IOU attestation test * fix integration tests issues * minor refactors * fix bug * [WIP] switch to one bridge for all integration tests * clean up * fix tests * fix + clean up tests
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
import { Client, Wallet } from '../../src'
|
||||
import { assert } from 'chai'
|
||||
|
||||
import {
|
||||
Client,
|
||||
SignerListSet,
|
||||
Wallet,
|
||||
XChainBridge,
|
||||
XChainCreateBridge,
|
||||
} from '../../src'
|
||||
|
||||
import serverUrl from './serverUrl'
|
||||
import { fundAccount } from './utils'
|
||||
import {
|
||||
GENESIS_ACCOUNT,
|
||||
fundAccount,
|
||||
generateFundedWallet,
|
||||
testTransaction,
|
||||
} from './utils'
|
||||
|
||||
interface TestBridge {
|
||||
xchainBridge: XChainBridge
|
||||
witness: Wallet
|
||||
signatureReward: string
|
||||
}
|
||||
|
||||
export interface XrplIntegrationTestContext {
|
||||
client: Client
|
||||
@@ -32,15 +51,86 @@ async function connectWithRetry(client: Client, tries = 0): Promise<void> {
|
||||
export async function setupClient(
|
||||
server = serverUrl,
|
||||
): Promise<XrplIntegrationTestContext> {
|
||||
const context: XrplIntegrationTestContext = {
|
||||
client: new Client(server, { timeout: 200000 }),
|
||||
wallet: Wallet.generate(),
|
||||
}
|
||||
return connectWithRetry(context.client).then(async () => {
|
||||
await fundAccount(context.client, context.wallet, {
|
||||
const client = new Client(server, { timeout: 200000 })
|
||||
const wallet = Wallet.generate()
|
||||
return connectWithRetry(client).then(async () => {
|
||||
await fundAccount(client, wallet, {
|
||||
count: 20,
|
||||
delayMs: 1000,
|
||||
})
|
||||
const context: XrplIntegrationTestContext = {
|
||||
client,
|
||||
wallet,
|
||||
}
|
||||
return context
|
||||
})
|
||||
}
|
||||
|
||||
export async function setupBridge(client: Client): Promise<TestBridge> {
|
||||
const doorAccount = await generateFundedWallet(client)
|
||||
const signatureReward = '200'
|
||||
const xchainBridge: XChainBridge = {
|
||||
LockingChainDoor: doorAccount.classicAddress,
|
||||
LockingChainIssue: { currency: 'XRP' },
|
||||
IssuingChainDoor: GENESIS_ACCOUNT,
|
||||
IssuingChainIssue: { currency: 'XRP' },
|
||||
}
|
||||
const setupTx: XChainCreateBridge = {
|
||||
TransactionType: 'XChainCreateBridge',
|
||||
Account: doorAccount.classicAddress,
|
||||
XChainBridge: xchainBridge,
|
||||
SignatureReward: signatureReward,
|
||||
MinAccountCreateAmount: '10000000',
|
||||
}
|
||||
|
||||
await testTransaction(client, setupTx, doorAccount)
|
||||
|
||||
// confirm that the transaction actually went through
|
||||
const accountObjectsResponse = await client.request({
|
||||
command: 'account_objects',
|
||||
account: doorAccount.classicAddress,
|
||||
type: 'bridge',
|
||||
})
|
||||
assert.lengthOf(
|
||||
accountObjectsResponse.result.account_objects,
|
||||
1,
|
||||
'Should be exactly one bridge owned by the account',
|
||||
)
|
||||
|
||||
const witnessWallet = await generateFundedWallet(client)
|
||||
|
||||
const signerTx: SignerListSet = {
|
||||
TransactionType: 'SignerListSet',
|
||||
Account: doorAccount.classicAddress,
|
||||
SignerEntries: [
|
||||
{
|
||||
SignerEntry: {
|
||||
Account: witnessWallet.classicAddress,
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
SignerQuorum: 1,
|
||||
}
|
||||
await testTransaction(client, signerTx, doorAccount)
|
||||
|
||||
const signerAccountInfoResponse = await client.request({
|
||||
command: 'account_info',
|
||||
account: doorAccount.classicAddress,
|
||||
signer_lists: true,
|
||||
})
|
||||
const signerListInfo =
|
||||
signerAccountInfoResponse.result.account_data.signer_lists?.[0]
|
||||
assert.deepEqual(
|
||||
signerListInfo?.SignerEntries,
|
||||
signerTx.SignerEntries,
|
||||
'SignerEntries were not set properly',
|
||||
)
|
||||
assert.equal(
|
||||
signerListInfo?.SignerQuorum,
|
||||
signerTx.SignerQuorum,
|
||||
'SignerQuorum was not set properly',
|
||||
)
|
||||
|
||||
return { xchainBridge, witness: witnessWallet, signatureReward }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user