Files
xahau.js/test/integration/submitAndWait.ts
Omar Khan 09a0f2bbcb refactor: simplify submit transaction methods (#1725)
* To simplify submit transaction requests by having only one version of them that supports both signed/unsigned transactions, the signed versions of them (submitSigned(), submitSignedReliable()) are deleted.

* Their signed logic is merged into submit() and submitAndWait() (renamed from submitReliable()).

* Change order of submit method params to be consistent.

* Add a SubmitOptions method param to include options for wallet to sign a transaction, and booleans to autofill/failHard a transaction.
2021-10-15 19:10:35 -04:00

93 lines
3.2 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-misused-promises -- supposed to return a promise here */
/* eslint-disable no-restricted-syntax -- not sure why this rule is here, definitely not needed here */
import { assert } from 'chai'
import _ from 'lodash'
import { AccountSet, convertStringToHex, ValidationError } from 'xrpl-local'
import { assertRejects } from '../testUtils'
import serverUrl from './serverUrl'
import { setupClient, teardownClient } from './setup'
import { ledgerAccept } from './utils'
// how long before each test case times out
const TIMEOUT = 60000
describe('client.submitAndWait', function () {
this.timeout(TIMEOUT)
beforeEach(_.partial(setupClient, serverUrl))
afterEach(teardownClient)
it('submitAndWait an unsigned transaction', async function () {
const accountSet: AccountSet = {
TransactionType: 'AccountSet',
Account: this.wallet.classicAddress,
Domain: convertStringToHex('example.com'),
}
const responsePromise = this.client.submitAndWait(accountSet, {
wallet: this.wallet,
})
const ledgerPromise = setTimeout(ledgerAccept, 1000, this.client)
return Promise.all([responsePromise, ledgerPromise]).then(
([response, _ledger]) => {
assert.equal(response.type, 'response')
assert.equal(response.result.validated, true)
},
)
})
it('should throw a ValidationError when submitting an unsigned transaction without a wallet', async function () {
const accountSet: AccountSet = {
TransactionType: 'AccountSet',
Account: this.wallet.classicAddress,
Domain: convertStringToHex('example.com'),
}
await assertRejects(
this.client.submitAndWait(accountSet),
ValidationError,
'Wallet must be provided when submitting an unsigned transaction',
)
})
it('submitAndWait a signed transaction', async function () {
const accountSet: AccountSet = {
TransactionType: 'AccountSet',
Account: this.wallet.classicAddress,
Domain: convertStringToHex('example.com'),
}
const { tx_blob: signedAccountSet } = this.wallet.sign(
await this.client.autofill(accountSet),
)
const responsePromise = this.client.submitAndWait(signedAccountSet)
const ledgerPromise = setTimeout(ledgerAccept, 1000, this.client)
return Promise.all([responsePromise, ledgerPromise]).then(
([response, _ledger]) => {
assert.equal(response.type, 'response')
assert.equal(response.result.validated, true)
},
)
})
it('submitAndWait a signed transaction longer', async function () {
const accountSet: AccountSet = {
TransactionType: 'AccountSet',
Account: this.wallet.classicAddress,
Domain: convertStringToHex('example.com'),
}
const { tx_blob: signedAccountSet } = this.wallet.sign(
await this.client.autofill(accountSet),
)
const responsePromise = this.client.submitAndWait(signedAccountSet)
const ledgerPromise = setTimeout(ledgerAccept, 5000, this.client)
return Promise.all([responsePromise, ledgerPromise]).then(
([response, _ledger]) => {
assert.equal(response.type, 'response')
assert.equal(response.result.validated, true)
},
)
})
})