mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-04 13:05:49 +00:00
test: add failed test if a method isn't tested (#1744)
* add skip tests * add client.requestAll tests * remove skip * remove unneeded code * cleanup * fix comment
This commit is contained in:
35
test/client/requestAll.ts
Normal file
35
test/client/requestAll.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
|
||||
const rippledResponse = function (request: Request): Record<string, unknown> {
|
||||
if ('marker' in request) {
|
||||
return rippled.ledger_data.last_page
|
||||
}
|
||||
return rippled.ledger_data.first_page
|
||||
}
|
||||
|
||||
describe('client.requestAll', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
it('requests the next page', async function () {
|
||||
this.mockRippled.addResponse('ledger_data', rippledResponse)
|
||||
const allResponses = await this.client.requestAll({
|
||||
command: 'ledger_data',
|
||||
})
|
||||
assert.equal(allResponses.length, 2)
|
||||
assert.equal(
|
||||
allResponses[1].result.state[0].index,
|
||||
'000B714B790C3C79FEE00D17C4DEB436B375466F29679447BA64F265FD63D731',
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects when there are no more pages', async function () {
|
||||
this.mockRippled.addResponse('ledger_data', rippled.ledger_data.last_page)
|
||||
const allResponses = await this.client.requestAll({
|
||||
command: 'ledger_data',
|
||||
})
|
||||
assert.equal(allResponses.length, 1)
|
||||
})
|
||||
})
|
||||
@@ -23,15 +23,36 @@ describe('Client', function () {
|
||||
|
||||
const allTestSuites = loadTestSuites()
|
||||
|
||||
const testExceptions = new Set([
|
||||
// instance variables on Client, not actual methods
|
||||
'feeCushion',
|
||||
'maxFeeXRP',
|
||||
'connection',
|
||||
'url',
|
||||
// tested in integration tests, can't be tested with mockRippled
|
||||
'submitAndWait',
|
||||
'fundWallet',
|
||||
// tested in setup and in client.ts and connection.ts
|
||||
'connect',
|
||||
'disconnect',
|
||||
// used in subscriptions, can't really test directly
|
||||
'on',
|
||||
// copy of autofill
|
||||
'prepareTransaction',
|
||||
// inherited from EventEmitter
|
||||
'domain',
|
||||
'_eventsCount',
|
||||
'_events',
|
||||
'_maxListeners',
|
||||
])
|
||||
|
||||
// Report any missing tests.
|
||||
const allTestedMethods = new Set(
|
||||
allTestSuites.map((testsuite) => testsuite.name),
|
||||
)
|
||||
for (const methodName of allPublicMethods) {
|
||||
if (!allTestedMethods.has(methodName)) {
|
||||
/** TODO: Remove the skip, rename methods. */
|
||||
// eslint-disable-next-line mocha/no-skipped-tests -- skip these tests for now.
|
||||
it.skip(`${methodName} - no test suite found`, function () {
|
||||
if (!allTestedMethods.has(methodName) && !testExceptions.has(methodName)) {
|
||||
it(`${methodName} - no test suite found`, function () {
|
||||
throw new XrplError(
|
||||
`Test file not found! Create file "test/client/${methodName}.ts".`,
|
||||
)
|
||||
@@ -46,8 +67,7 @@ function getAllPublicMethods(client: Client): string[] {
|
||||
...Object.getOwnPropertyNames(client),
|
||||
...Object.getOwnPropertyNames(Client.prototype),
|
||||
]),
|
||||
// removes private methods
|
||||
).filter((key) => !key.startsWith('_'))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -276,14 +276,14 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('signTransaction', function () {
|
||||
describe('sign', function () {
|
||||
let wallet: Wallet
|
||||
|
||||
beforeEach(function () {
|
||||
wallet = Wallet.fromSeed('ss1x3KLrSvfg7irFc1D929WXZ7z9H')
|
||||
})
|
||||
|
||||
it('signTransaction successfully', async function () {
|
||||
it('sign successfully', async function () {
|
||||
const result = wallet.sign(REQUEST_FIXTURES.normal as Transaction)
|
||||
assert.deepEqual(result, {
|
||||
tx_blob: RESPONSE_FIXTURES.normal.signedTransaction,
|
||||
@@ -291,7 +291,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with lowercase hex data in memo (hex should be case insensitive)', async function () {
|
||||
it('sign with lowercase hex data in memo (hex should be case insensitive)', async function () {
|
||||
const secret = 'shd2nxpFD6iBRKWsRss2P4tKMWyy9'
|
||||
const lowercaseMemoTx: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
@@ -323,7 +323,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with EscrowFinish', async function () {
|
||||
it('sign with EscrowFinish', async function () {
|
||||
const result = wallet.sign(REQUEST_FIXTURES.escrow as Transaction)
|
||||
assert.deepEqual(result, {
|
||||
tx_blob: RESPONSE_FIXTURES.escrow.signedTransaction,
|
||||
@@ -331,7 +331,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with multisignAddress', async function () {
|
||||
it('sign with multisignAddress', async function () {
|
||||
const signature = wallet.sign(
|
||||
REQUEST_FIXTURES.signAs as Transaction,
|
||||
true,
|
||||
@@ -342,7 +342,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with X Address and no given tag for multisignAddress', async function () {
|
||||
it('sign with X Address and no given tag for multisignAddress', async function () {
|
||||
const signature = wallet.sign(
|
||||
REQUEST_FIXTURES.signAs as Transaction,
|
||||
wallet.getXAddress(),
|
||||
@@ -353,7 +353,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with X Address and tag for multisignAddress', async function () {
|
||||
it('sign with X Address and tag for multisignAddress', async function () {
|
||||
const signature = wallet.sign(
|
||||
REQUEST_FIXTURES.signAs as Transaction,
|
||||
wallet.getXAddress(0),
|
||||
@@ -368,7 +368,7 @@ describe('Wallet', function () {
|
||||
assert.deepEqual(signature, expectedSignature)
|
||||
})
|
||||
|
||||
it('signTransaction throws when given a transaction that is already signed', async function () {
|
||||
it('sign throws when given a transaction that is already signed', async function () {
|
||||
const result = wallet.sign(REQUEST_FIXTURES.normal as Transaction)
|
||||
assert.throws(() => {
|
||||
const tx = decode(result.tx_blob) as unknown as Transaction
|
||||
@@ -376,7 +376,7 @@ describe('Wallet', function () {
|
||||
}, /txJSON must not contain "TxnSignature" or "Signers" properties/u)
|
||||
})
|
||||
|
||||
it('signTransaction with an EscrowExecution transaction', async function () {
|
||||
it('sign with an EscrowExecution transaction', async function () {
|
||||
const result = wallet.sign(REQUEST_FIXTURES.escrow as Transaction)
|
||||
assert.deepEqual(result, {
|
||||
tx_blob: RESPONSE_FIXTURES.escrow.signedTransaction,
|
||||
@@ -384,7 +384,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction succeeds when given a transaction with no flags', async function () {
|
||||
it('sign succeeds when given a transaction with no flags', async function () {
|
||||
const tx: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r45Rev1EXGxy2hAUmJPCne97KUE7qyrD3j',
|
||||
@@ -408,7 +408,7 @@ describe('Wallet', function () {
|
||||
assert.deepEqual(result, expectedResult)
|
||||
})
|
||||
|
||||
it('signTransaction succeeds with source.amount/destination.minAmount', async function () {
|
||||
it('sign succeeds with source.amount/destination.minAmount', async function () {
|
||||
// See also: 'preparePayment with source.amount/destination.minAmount'
|
||||
|
||||
const tx: Transaction = {
|
||||
@@ -451,7 +451,7 @@ describe('Wallet', function () {
|
||||
assert.deepEqual(result, expectedResult)
|
||||
})
|
||||
|
||||
it('signTransaction throws when encoded tx does not match decoded tx because of illegal small fee', async function () {
|
||||
it('sign throws when encoded tx does not match decoded tx because of illegal small fee', async function () {
|
||||
const tx: Transaction = {
|
||||
Flags: 2147483648,
|
||||
TransactionType: 'AccountSet',
|
||||
@@ -469,7 +469,7 @@ describe('Wallet', function () {
|
||||
}, /1\.2 is an illegal amount/u)
|
||||
})
|
||||
|
||||
it('signTransaction throws when encoded tx does not match decoded tx because of illegal higher fee', async function () {
|
||||
it('sign throws when encoded tx does not match decoded tx because of illegal higher fee', async function () {
|
||||
const tx: Transaction = {
|
||||
Flags: 2147483648,
|
||||
TransactionType: 'AccountSet',
|
||||
@@ -487,7 +487,7 @@ describe('Wallet', function () {
|
||||
}, /1123456\.7 is an illegal amount/u)
|
||||
})
|
||||
|
||||
it('signTransaction with a ticket transaction', async function () {
|
||||
it('sign with a ticket transaction', async function () {
|
||||
const result = wallet.sign(REQUEST_FIXTURES.ticket as Transaction)
|
||||
assert.deepEqual(result, {
|
||||
tx_blob: RESPONSE_FIXTURES.ticket.signedTransaction,
|
||||
@@ -495,7 +495,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with a Payment transaction with paths', async function () {
|
||||
it('sign with a Payment transaction with paths', async function () {
|
||||
const payment: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
@@ -528,7 +528,7 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('signTransaction with a prepared payment', async function () {
|
||||
it('sign with a prepared payment', async function () {
|
||||
const payment: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
@@ -549,7 +549,7 @@ describe('Wallet', function () {
|
||||
assert.deepEqual(result, expectedResult)
|
||||
})
|
||||
|
||||
it('signTransaction throws when an illegal amount is provided', async function () {
|
||||
it('sign throws when an illegal amount is provided', async function () {
|
||||
const payment: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { assert } from 'chai'
|
||||
import { decode, encode } from 'ripple-binary-codec/dist'
|
||||
import { JsonObject } from 'ripple-binary-codec/dist/types/serialized-type'
|
||||
|
||||
import { Transaction, ValidationError } from 'xrpl-local'
|
||||
import Wallet from 'xrpl-local/wallet'
|
||||
@@ -15,8 +14,6 @@ const publicKey =
|
||||
const privateKey =
|
||||
'00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F'
|
||||
const address = 'rhvh5SrgBL5V8oeV9EpDuVszeJSSCEkbPc'
|
||||
const seed = 'ss1x3KLrSvfg7irFc1D929WXZ7z9H'
|
||||
const wallet = Wallet.fromSeed(seed)
|
||||
const verifyWallet = new Wallet(publicKey, privateKey)
|
||||
|
||||
const tx: Transaction = {
|
||||
@@ -29,46 +26,6 @@ const tx: Transaction = {
|
||||
SigningPubKey: publicKey,
|
||||
}
|
||||
|
||||
const unsignedTx1: Transaction = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: 'rEuLyBCvcw4CFmzv8RepSiAoNgF8tTGJQC',
|
||||
Fee: '30000',
|
||||
Flags: 262144,
|
||||
LimitAmount: {
|
||||
currency: 'USD',
|
||||
issuer: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
||||
value: '100',
|
||||
},
|
||||
Sequence: 2,
|
||||
}
|
||||
|
||||
const unsignedSecret1 = 'spzGHmohX9bAM6gzF4m9FvJmJb1CR'
|
||||
|
||||
const multisignTx1: Transaction = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: 'rEuLyBCvcw4CFmzv8RepSiAoNgF8tTGJQC',
|
||||
Fee: '30000',
|
||||
Flags: 262144,
|
||||
LimitAmount: {
|
||||
currency: 'USD',
|
||||
issuer: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
||||
value: '100',
|
||||
},
|
||||
Sequence: 2,
|
||||
Signers: [
|
||||
{
|
||||
Signer: {
|
||||
Account: 'rJvuSQhQR37czfxRou4vNWaM97uEhT4ShE',
|
||||
SigningPubKey:
|
||||
'02B78EEA571B2633180834CC6E7B4ED84FBF6811D12ECB59410E0C92D13B7726F5',
|
||||
TxnSignature:
|
||||
'304502210098009CEFA61EE9843BB7FC29B78CFFAACF28352A4A7CF3AAE79EF12D79BA50910220684F116266E5E4519A7A33F7421631EB8494082BE51A8B03FECCB3E59F77154A',
|
||||
},
|
||||
},
|
||||
],
|
||||
SigningPubKey: '',
|
||||
}
|
||||
|
||||
describe('Signer', function () {
|
||||
let multisignTxToCombine1
|
||||
let multisignTxToCombine2
|
||||
@@ -161,36 +118,6 @@ describe('Signer', function () {
|
||||
}
|
||||
expectedMultisign = encode(multisignJSON)
|
||||
})
|
||||
it('sign', function () {
|
||||
// Test case data generated using this tutorial - https://xrpl.org/send-xrp.html#send-xrp
|
||||
const tx3: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'rHLEki8gPUMnF72JnuALvnAMRhRemzhRke',
|
||||
Amount: '22000000',
|
||||
Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe',
|
||||
Flags: 2147483648,
|
||||
LastLedgerSequence: 20582339,
|
||||
Fee: '12',
|
||||
Sequence: 20582260,
|
||||
}
|
||||
const signedTxResponse = {
|
||||
tx_blob:
|
||||
'120000228000000024013A0F74201B013A0FC36140000000014FB18068400000000000000C732102A8A44DB3D4C73EEEE11DFE54D2029103B776AA8A8D293A91D645977C9DF5F544744730450221009ECB5324717E14DD6970126271F05BC2626D2A8FA9F3797555D417F8257C1E6002206BDD74A0F30425F2BA9DB69C90F21B3E27735C190FB4F3A640F066ACBBF06AD98114B3263BD0A9BF9DFDBBBBD07F536355FF477BF0E98314F667B0CA50CC7709A220B0561B85E53A48461FA8',
|
||||
hash: 'F73E975C70497A3DA61ADB76A3B39CD971A2DE017419A690BFAD6733B5FD8B3B',
|
||||
}
|
||||
|
||||
const signedTx = wallet.sign(tx3)
|
||||
assert.deepEqual(signedTx, signedTxResponse)
|
||||
})
|
||||
|
||||
it('sign in multisign format', function () {
|
||||
const multisignWallet = Wallet.fromSeed(unsignedSecret1)
|
||||
|
||||
assert.deepEqual(
|
||||
decode(multisignWallet.sign(unsignedTx1, true).tx_blob),
|
||||
multisignTx1 as unknown as JsonObject,
|
||||
)
|
||||
})
|
||||
|
||||
it('multisign runs successfully with Transaction objects', function () {
|
||||
const transactions = [multisignTxToCombine1, multisignTxToCombine2]
|
||||
|
||||
Reference in New Issue
Block a user