From b5b2909fed883d54006af754e3195560bd3b5322 Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Fri, 24 Sep 2021 08:40:56 -0700 Subject: [PATCH] Add integration tests for Transaction methods (#1636) Add tx, submit, and submit_multisign integration tests, along with browser tests. --- src/models/methods/submit.ts | 2 +- src/models/methods/submitMultisigned.ts | 2 +- src/models/methods/tx.ts | 4 +- test/integration/requests/multisign.ts | 101 ++++++++++++++++++++++++ test/integration/requests/submit.ts | 76 ++++++++++++++++++ test/integration/requests/tx.ts | 63 +++++++++++++++ test/localIntegrationRunner.html | 3 + 7 files changed, 247 insertions(+), 4 deletions(-) create mode 100644 test/integration/requests/multisign.ts create mode 100644 test/integration/requests/submit.ts create mode 100644 test/integration/requests/tx.ts diff --git a/src/models/methods/submit.ts b/src/models/methods/submit.ts index da1ab1b2..e7d07d8a 100644 --- a/src/models/methods/submit.ts +++ b/src/models/methods/submit.ts @@ -14,7 +14,7 @@ export interface SubmitResponse extends BaseResponse { engine_result_code: number engine_result_message: string tx_blob: string - tx_json: Transaction + tx_json: Transaction & { hash?: string } accepted: boolean account_sequence_available: number account_sequence_next: number diff --git a/src/models/methods/submitMultisigned.ts b/src/models/methods/submitMultisigned.ts index 50113c4f..7c1c9bae 100644 --- a/src/models/methods/submitMultisigned.ts +++ b/src/models/methods/submitMultisigned.ts @@ -14,6 +14,6 @@ export interface SubmitMultisignedResponse extends BaseResponse { engine_result_code: number engine_result_message: string tx_blob: string - tx_json: Transaction + tx_json: Transaction & { hash?: string } } } diff --git a/src/models/methods/tx.ts b/src/models/methods/tx.ts index abc5141d..fb7805ca 100644 --- a/src/models/methods/tx.ts +++ b/src/models/methods/tx.ts @@ -14,8 +14,8 @@ export interface TxRequest extends BaseRequest { export interface TxResponse extends BaseResponse { result: { hash: string - ledger_index: number - meta: TransactionMetadata | string + ledger_index?: number + meta?: TransactionMetadata | string validated?: boolean } & Transaction searched_all?: boolean diff --git a/test/integration/requests/multisign.ts b/test/integration/requests/multisign.ts new file mode 100644 index 00000000..8928fae0 --- /dev/null +++ b/test/integration/requests/multisign.ts @@ -0,0 +1,101 @@ +import { assert } from 'chai' +import _ from 'lodash' +import { decode } from 'ripple-binary-codec/dist' + +import { + AccountSet, + Client, + SignerListSet, + SubmitMultisignedRequest, + Transaction, + SubmitMultisignedResponse, + computeSignedTransactionHash, +} from 'xrpl-local' +import { convertStringToHex } from 'xrpl-local/utils' +import { multisign, sign } from 'xrpl-local/wallet/signer' + +import serverUrl from '../serverUrl' +import { setupClient, suiteClientSetup, teardownClient } from '../setup' +import { + generateFundedWallet, + ledgerAccept, + testTransaction, + verifySubmittedTransaction, +} from '../utils' + +// how long before each test case times out +const TIMEOUT = 20000 + +describe('submit_multisigned', function () { + this.timeout(TIMEOUT) + + before(suiteClientSetup) + beforeEach(_.partial(setupClient, serverUrl)) + afterEach(teardownClient) + + it('submit_multisigned transaction', async function () { + const client: Client = this.client + const signerWallet1 = await generateFundedWallet(this.client) + const signerWallet2 = await generateFundedWallet(this.client) + + // set up the multisigners for the account + const signerListSet: SignerListSet = { + TransactionType: 'SignerListSet', + Account: this.wallet.getClassicAddress(), + SignerEntries: [ + { + SignerEntry: { + Account: signerWallet1.getClassicAddress(), + SignerWeight: 1, + }, + }, + { + SignerEntry: { + Account: signerWallet2.getClassicAddress(), + SignerWeight: 1, + }, + }, + ], + SignerQuorum: 2, + } + await testTransaction(this.client, signerListSet, this.wallet) + + // try to multisign + const accountSet: AccountSet = { + TransactionType: 'AccountSet', + Account: this.wallet.getClassicAddress(), + Domain: convertStringToHex('example.com'), + } + const accountSetTx = await client.autofill(accountSet, 2) + const signed1 = sign(signerWallet1, accountSetTx, true) + const signed2 = sign(signerWallet2, accountSetTx, true) + const multisigned = multisign([signed1, signed2]) + const multisignedRequest: SubmitMultisignedRequest = { + command: 'submit_multisigned', + tx_json: decode(multisigned) as unknown as Transaction, + } + const submitResponse = await client.request(multisignedRequest) + await ledgerAccept(client) + assert.strictEqual(submitResponse.result.engine_result, 'tesSUCCESS') + await verifySubmittedTransaction(this.client, multisigned) + + const expectedResponse: SubmitMultisignedResponse = { + id: submitResponse.id, + status: 'success', + type: 'response', + result: { + engine_result: 'tesSUCCESS', + engine_result_code: 0, + engine_result_message: + 'The transaction was applied. Only final in a validated ledger.', + tx_blob: multisigned, + tx_json: { + ...(decode(multisigned) as unknown as Transaction), + hash: computeSignedTransactionHash(multisigned), + }, + }, + } + + assert.deepEqual(submitResponse, expectedResponse) + }) +}) diff --git a/test/integration/requests/submit.ts b/test/integration/requests/submit.ts new file mode 100644 index 00000000..8fcffb36 --- /dev/null +++ b/test/integration/requests/submit.ts @@ -0,0 +1,76 @@ +import { assert } from 'chai' +import _ from 'lodash' +import { decode } from 'ripple-binary-codec/dist' + +import { + AccountSet, + SubmitRequest, + SubmitResponse, + computeSignedTransactionHash, + Transaction, +} from 'xrpl-local' +import { convertStringToHex } from 'xrpl-local/utils' + +import serverUrl from '../serverUrl' +import { setupClient, suiteClientSetup, teardownClient } from '../setup' +import { ledgerAccept, verifySubmittedTransaction } from '../utils' + +// how long before each test case times out +const TIMEOUT = 20000 + +describe('submit', function () { + this.timeout(TIMEOUT) + + before(suiteClientSetup) + beforeEach(_.partial(setupClient, serverUrl)) + afterEach(teardownClient) + + it('submit', async function () { + const accountSet: AccountSet = { + TransactionType: 'AccountSet', + Account: this.wallet.getClassicAddress(), + Domain: convertStringToHex('example.com'), + } + + const autofilledTx = await this.client.autofill(accountSet) + const signedTx = this.wallet.signTransaction(autofilledTx) + const submitRequest: SubmitRequest = { + command: 'submit', + tx_blob: signedTx, + } + const submitResponse = await this.client.request(submitRequest) + assert.equal(submitResponse.status, 'success') + + await ledgerAccept(this.client) + await verifySubmittedTransaction(this.client, signedTx) + + const expectedResponse: SubmitResponse = { + id: submitResponse.id, + type: 'response', + status: 'success', + result: { + engine_result: 'tesSUCCESS', + engine_result_code: 0, + engine_result_message: + 'The transaction was applied. Only final in a validated ledger.', + tx_blob: signedTx, + tx_json: { + ...(decode(signedTx) as unknown as Transaction), + hash: computeSignedTransactionHash(signedTx), + }, + accepted: true, + account_sequence_available: + submitResponse.result.account_sequence_available, + account_sequence_next: submitResponse.result.account_sequence_next, + applied: true, + broadcast: submitResponse.result.broadcast, + kept: true, + queued: false, + open_ledger_cost: submitResponse.result.open_ledger_cost, + validated_ledger_index: submitResponse.result.validated_ledger_index, + }, + } + + assert.deepEqual(submitResponse, expectedResponse) + }) +}) diff --git a/test/integration/requests/tx.ts b/test/integration/requests/tx.ts new file mode 100644 index 00000000..79fe01e5 --- /dev/null +++ b/test/integration/requests/tx.ts @@ -0,0 +1,63 @@ +import { assert } from 'chai' +import _ from 'lodash' + +import { + AccountSet, + computeSignedTransactionHash, + SubmitResponse, + TxResponse, +} from 'xrpl-local' +import { convertStringToHex } from 'xrpl-local/utils' + +import serverUrl from '../serverUrl' +import { setupClient, suiteClientSetup, teardownClient } from '../setup' + +// how long before each test case times out +const TIMEOUT = 20000 + +describe('tx', function () { + this.timeout(TIMEOUT) + + before(suiteClientSetup) + beforeEach(_.partial(setupClient, serverUrl)) + afterEach(teardownClient) + + it('base', async function () { + const account = this.wallet.getClassicAddress() + const accountSet: AccountSet = { + TransactionType: 'AccountSet', + Account: account, + Domain: convertStringToHex('example.com'), + } + + const response: SubmitResponse = await this.client.submitTransaction( + this.wallet, + accountSet, + ) + + const hash = computeSignedTransactionHash(response.result.tx_blob) + const txResponse = await this.client.request({ + command: 'tx', + transaction: hash, + }) + + const expectedResponse: TxResponse = { + id: txResponse.id, + type: 'response', + status: 'success', + result: { + ...accountSet, + Fee: txResponse.result.Fee, + Flags: 0, + LastLedgerSequence: txResponse.result.LastLedgerSequence, + Sequence: txResponse.result.Sequence, + SigningPubKey: this.wallet.publicKey, + TxnSignature: txResponse.result.TxnSignature, + hash: computeSignedTransactionHash(response.result.tx_blob), + validated: false, + }, + } + + assert.deepEqual(txResponse, expectedResponse) + }) +}) diff --git a/test/localIntegrationRunner.html b/test/localIntegrationRunner.html index b56fa3c6..642e52f6 100644 --- a/test/localIntegrationRunner.html +++ b/test/localIntegrationRunner.html @@ -22,6 +22,9 @@ + + +