test: SignerListSet transaction integration tests (#1621)

* add tests

* clean up helper functions

* fix account funding

* remove unneeded method

* use new wallets for each test

* automatically fund wallets

* fix TODO
This commit is contained in:
Mayukha Vadari
2021-09-17 10:35:17 -04:00
parent e53df109b0
commit 05e1d4d3c5
7 changed files with 97 additions and 112 deletions

View File

@@ -3,16 +3,9 @@ import { assert } from 'chai'
import _ from 'lodash'
import { decode } from 'ripple-binary-codec'
import { Client, SubmitResponse, Wallet } from 'xrpl-local'
import {
validatePayment,
Payment,
Transaction,
} from 'xrpl-local/models/transactions'
import { Client, Wallet } from 'xrpl-local'
import { Payment, Transaction } from 'xrpl-local/models/transactions'
import { computeSignedTransactionHash } from 'xrpl-local/utils/hashes'
import { sign } from 'xrpl-local/wallet/signer'
import { walletAddress, walletSecret } from './wallet'
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
@@ -22,33 +15,21 @@ export async function ledgerAccept(client: Client): Promise<void> {
await client.connection.request(request)
}
// TODO: replace with `client.submitTransaction` once that has been merged
export async function submitTransaction(
client: Client,
secret: string,
transaction: Transaction,
): Promise<SubmitResponse> {
const wallet = Wallet.fromSeed(secret)
const tx = await client.autofill(transaction)
const signedTxEncoded: string = sign(wallet, tx)
return client.request({ command: 'submit', tx_blob: signedTxEncoded })
}
export async function fundAccount(
client: Client,
account: string,
wallet: Wallet,
): Promise<void> {
const payment: Payment = {
TransactionType: 'Payment',
Account: masterAccount,
Destination: account,
Destination: wallet.getClassicAddress(),
// 2 times the amount needed for a new account (20 XRP)
Amount: '400000000',
}
const paymentTx = await client.autofill(payment)
validatePayment(paymentTx)
const response = await submitTransaction(client, masterSecret, paymentTx)
const response = await client.submitTransaction(
Wallet.fromSeed(masterSecret),
payment,
)
if (response.result.engine_result !== 'tesSUCCESS') {
// eslint-disable-next-line no-console -- happens only when something goes wrong
console.log(response)
@@ -59,16 +40,13 @@ export async function fundAccount(
}
export async function verifySubmittedTransaction(
testcase: Mocha.Context,
tx: Transaction,
options: { minLedgerVersion: number; maxLedgerVersion?: number },
client: Client,
tx: Transaction | string,
): Promise<void> {
const hash = computeSignedTransactionHash(tx)
const data = await testcase.client.request({
const data = await client.request({
command: 'tx',
transaction: hash,
min_ledger: options.minLedgerVersion,
max_ledger: options.maxLedgerVersion,
})
assert(data.result)
@@ -81,46 +59,30 @@ export async function verifySubmittedTransaction(
'meta',
'validated',
]),
tx,
typeof tx === 'string' ? decode(tx) : tx,
)
if (typeof data.result.meta === 'object') {
assert.strictEqual(data.result.meta.TransactionResult, 'tesSUCCESS')
} else {
assert.strictEqual(data.result.meta, 'tesSUCCESS')
}
if (testcase.transactions != null) {
testcase.transactions.push(hash)
}
}
export async function testTransaction(
testcase: Mocha.Context,
lastClosedLedgerVersion: number,
txData: Transaction,
address = walletAddress,
secret = walletSecret,
client: Client,
transaction: Transaction,
wallet: Wallet,
): Promise<void> {
assert.strictEqual(txData.Account, address)
const client: Client = testcase.client
const signedData = sign(Wallet.fromSeed(secret), txData)
// sign/submit the transaction
const response = await client.submitTransaction(wallet, transaction)
const attemptedResponse = await client.request({
command: 'submit',
tx_blob: signedData,
})
const submittedResponse = testcase.test?.title.includes('multisign')
? await ledgerAccept(client).then(() => attemptedResponse)
: attemptedResponse
// check that the transaction was successful
assert.equal(response.status, 'success')
assert.equal(response.type, 'response')
assert.equal(response.result.engine_result, 'tesSUCCESS')
assert.strictEqual(submittedResponse.result.engine_result, 'tesSUCCESS')
const options = {
minLedgerVersion: lastClosedLedgerVersion,
maxLedgerVersion: txData.LastLedgerSequence,
}
await ledgerAccept(testcase.client)
await verifySubmittedTransaction(
testcase,
decode(signedData) as unknown as Transaction,
options,
)
// check that the transaction is on the ledger
const signedTx = _.omit(response.result.tx_json, 'hash')
await ledgerAccept(client)
await verifySubmittedTransaction(client, signedTx as Transaction)
}