mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 11:45:49 +00:00
Add integration tests for Transaction methods (#1636)
Add tx, submit, and submit_multisign integration tests, along with browser tests.
This commit is contained in:
committed by
Mayukha Vadari
parent
2a93f85f41
commit
b5b2909fed
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
101
test/integration/requests/multisign.ts
Normal file
101
test/integration/requests/multisign.ts
Normal file
@@ -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)
|
||||
})
|
||||
})
|
||||
76
test/integration/requests/submit.ts
Normal file
76
test/integration/requests/submit.ts
Normal file
@@ -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)
|
||||
})
|
||||
})
|
||||
63
test/integration/requests/tx.ts
Normal file
63
test/integration/requests/tx.ts
Normal file
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -22,6 +22,9 @@
|
||||
<script src="../testCompiledForWeb/payment.js"></script>
|
||||
<script src="../testCompiledForWeb/signerListSet.js"></script>
|
||||
<script src="../testCompiledForWeb/utility.js"></script>
|
||||
<script src="../testCompiledForWeb/tx.js"></script>
|
||||
<script src="../testCompiledForWeb/submit.js"></script>
|
||||
<script src="../testCompiledForWeb/multisign.js"></script>
|
||||
<script src="../testCompiledForWeb/integration.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user