mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
feat: Jest Test Runner (#2170)
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
import { assert } from 'chai'
|
||||
import _ from 'lodash'
|
||||
import { ValidationError } from 'xrpl-local'
|
||||
import { Transaction } from 'xrpl-local/models/transactions'
|
||||
import Wallet from 'xrpl-local/Wallet'
|
||||
import cloneDeep from 'lodash/cloneDeep'
|
||||
|
||||
import { ValidationError } from '../../src'
|
||||
import { Transaction } from '../../src/models/transactions'
|
||||
import Wallet from '../../src/Wallet'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import {
|
||||
setupClient,
|
||||
teardownClient,
|
||||
type XrplTestContext,
|
||||
} from '../setupClient'
|
||||
import { assertRejects } from '../testUtils'
|
||||
|
||||
describe('client.submit', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
let testContext: XrplTestContext
|
||||
|
||||
beforeEach(async () => {
|
||||
testContext = await setupClient()
|
||||
})
|
||||
afterEach(async () => teardownClient(testContext))
|
||||
|
||||
describe('submit unsigned transactions', function () {
|
||||
const publicKey =
|
||||
@@ -29,17 +37,23 @@ describe('client.submit', function () {
|
||||
}
|
||||
|
||||
it('should submit an unsigned transaction', async function () {
|
||||
const tx = _.cloneDeep(transaction)
|
||||
const tx = cloneDeep(transaction)
|
||||
|
||||
const wallet = new Wallet(publicKey, privateKey)
|
||||
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('submit', rippled.submit.success)
|
||||
testContext.mockRippled!.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
testContext.mockRippled!.addResponse('ledger', rippled.ledger.normal)
|
||||
testContext.mockRippled!.addResponse(
|
||||
'server_info',
|
||||
rippled.server_info.normal,
|
||||
)
|
||||
testContext.mockRippled!.addResponse('submit', rippled.submit.success)
|
||||
|
||||
try {
|
||||
const response = await this.client.submit(tx, { wallet })
|
||||
const response = await testContext.client.submit(tx, { wallet })
|
||||
assert(response.result.engine_result, 'tesSUCCESS')
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- error type thrown can be any
|
||||
@@ -48,14 +62,14 @@ describe('client.submit', function () {
|
||||
})
|
||||
|
||||
it('should throw a ValidationError when submitting an unsigned transaction without a wallet', async function () {
|
||||
const tx: Transaction = _.cloneDeep(transaction)
|
||||
const tx: Transaction = cloneDeep(transaction)
|
||||
delete tx.SigningPubKey
|
||||
delete tx.TxnSignature
|
||||
|
||||
this.mockRippled.addResponse('submit', rippled.submit.success)
|
||||
testContext.mockRippled!.addResponse('submit', rippled.submit.success)
|
||||
|
||||
await assertRejects(
|
||||
this.client.submit(tx),
|
||||
testContext.client.submit(tx),
|
||||
ValidationError,
|
||||
'Wallet must be provided when submitting an unsigned transaction',
|
||||
)
|
||||
@@ -80,10 +94,10 @@ describe('client.submit', function () {
|
||||
it('should submit a signed transaction', async function () {
|
||||
const signedTx = { ...signedTransaction }
|
||||
|
||||
this.mockRippled.addResponse('submit', rippled.submit.success)
|
||||
testContext.mockRippled!.addResponse('submit', rippled.submit.success)
|
||||
|
||||
try {
|
||||
const response = await this.client.submit(signedTx)
|
||||
const response = await testContext.client.submit(signedTx)
|
||||
assert(response.result.engine_result, 'tesSUCCESS')
|
||||
} catch (_error) {
|
||||
assert(false, 'Did not expect an error to be thrown')
|
||||
@@ -94,10 +108,10 @@ describe('client.submit', function () {
|
||||
const signedTxEncoded =
|
||||
'1200002400000001201B00003018614000000001312D0068400000000000000C7321030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D74473045022100B3D311371EDAB371CD8F2B661A04B800B61D4B132E09B7B0712D3B2F11B1758302203906B44C4A150311D74FF6A35B146763C0B5B40AC30BD815113F058AA17B3E6381142AF1861DEC1316AEEC995C94FF9E2165B1B784608314FDB08D07AAA0EB711793A3027304D688E10C3648'
|
||||
|
||||
this.mockRippled.addResponse('submit', rippled.submit.success)
|
||||
testContext.mockRippled!.addResponse('submit', rippled.submit.success)
|
||||
|
||||
try {
|
||||
const response = await this.client.submit(signedTxEncoded)
|
||||
const response = await testContext.client.submit(signedTxEncoded)
|
||||
assert(response.result.engine_result, 'tesSUCCESS')
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- error type thrown can be any
|
||||
|
||||
Reference in New Issue
Block a user