From da9feffada11aa22b4ff21ebe8dcc61c56433d2f Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Wed, 25 Aug 2021 10:39:00 -0700 Subject: [PATCH] Remove deprecated functions from api.ts (aka client.ts) (#1534) * Removed deprecated functions from client.ts * Renamed files to be camelCase * Created top-level utils folder and tied all sub-references to it * Grouped tests for those utils into their own section Co-authored-by: Nathan Nichols --- src/client/broadcast.ts | 2 +- src/client/index.ts | 77 +----- src/common/index.ts | 9 - src/common/schema-validator.ts | 2 +- src/index.ts | 2 +- src/ledger/parse/account-delete.ts | 2 +- src/ledger/parse/account-order.ts | 2 +- src/ledger/parse/account-trustline.ts | 2 +- src/ledger/parse/amount.ts | 4 +- src/ledger/parse/check-cancel.ts | 2 +- src/ledger/parse/check-cash.ts | 2 +- src/ledger/parse/check-create.ts | 2 +- src/ledger/parse/deposit-preauth.ts | 2 +- src/ledger/parse/escrow-cancellation.ts | 2 +- src/ledger/parse/escrow-creation.ts | 2 +- src/ledger/parse/escrow-execution.ts | 2 +- src/ledger/parse/fee-update.ts | 2 +- src/ledger/parse/ledger.ts | 8 +- src/ledger/parse/order.ts | 3 +- src/ledger/parse/orderbook-order.ts | 2 +- src/ledger/parse/payment-channel-claim.ts | 3 +- src/ledger/parse/payment-channel-create.ts | 2 +- src/ledger/parse/payment-channel-fund.ts | 2 +- src/ledger/parse/payment-channel.ts | 2 +- src/ledger/parse/payment.ts | 5 +- src/ledger/parse/ticket-create.ts | 2 +- src/ledger/parse/transaction.ts | 2 +- src/ledger/parse/trustline.ts | 3 +- src/ledger/parse/utils.ts | 13 +- src/ledger/pathfind.ts | 6 +- src/ledger/utils.ts | 5 +- src/offline/utils.ts | 64 ----- src/transaction/check-cash.ts | 4 +- src/transaction/check-create.ts | 6 +- src/transaction/combine.ts | 2 +- src/transaction/escrow-creation.ts | 7 +- src/transaction/order.ts | 5 +- src/transaction/payment-channel-claim.ts | 3 +- src/transaction/payment-channel-create.ts | 5 +- src/transaction/payment-channel-fund.ts | 5 +- src/transaction/payment.ts | 2 +- src/transaction/sign.ts | 4 +- src/transaction/utils.ts | 12 +- src/{offline => utils}/derive.ts | 0 .../generateAddress.ts} | 5 +- src/{common => utils}/hashes/README.md | 0 .../hashes/hashPrefix.ts} | 0 src/{common => utils}/hashes/index.ts | 34 +-- .../hashes/ledgerSpaces.ts} | 0 src/{common => utils}/hashes/sha512Half.ts | 0 src/{common => utils}/hashes/shamap.ts | 2 +- src/{common/utils.ts => utils/index.ts} | 72 +++-- .../ledgerhash.ts => utils/ledgerHash.ts} | 21 +- .../signPaymentChannelClaim.ts} | 5 +- .../verifyPaymentChannelClaim.ts} | 3 +- src/wallet/wallet-generation.ts | 2 +- test/.mocharc.json | 2 +- test/broadcast-client-test.ts | 2 +- test/client/combine/index.ts | 2 +- test/client/constructor/index.ts | 2 +- test/client/deriveAddress/index.ts | 16 -- test/client/deriveKeypair/index.ts | 39 --- test/client/deriveXAddress/index.ts | 2 +- test/client/errors/index.ts | 2 +- test/client/formatBidsAndAsks/index.ts | 2 +- test/client/generateXAddress/index.ts | 252 ------------------ test/client/getBalances/index.ts | 2 +- test/client/getFee/index.ts | 2 +- test/client/getOrderbook/index.ts | 2 +- test/client/getPaths/index.ts | 2 +- test/client/getTrustlines/index.ts | 2 +- test/client/hasNextPage/index.ts | 2 +- test/client/isConnected/index.ts | 2 +- test/client/isValidAddress/index.ts | 2 +- test/client/isValidSecret/index.ts | 2 +- test/client/prepareCheckCancel/index.ts | 2 +- test/client/prepareCheckCash/index.ts | 2 +- test/client/prepareCheckCreate/index.ts | 2 +- .../client/prepareEscrowCancellation/index.ts | 2 +- test/client/prepareEscrowCreation/index.ts | 2 +- test/client/prepareEscrowExecution/index.ts | 2 +- test/client/prepareOrder/index.ts | 2 +- test/client/prepareOrderCancellation/index.ts | 2 +- test/client/preparePayment/index.ts | 2 +- .../preparePaymentChannelClaim/index.ts | 2 +- .../preparePaymentChannelCreate/index.ts | 2 +- .../client/preparePaymentChannelFund/index.ts | 2 +- test/client/prepareSettings/index.ts | 2 +- test/client/prepareTicket/index.ts | 2 +- test/client/prepareTransaction/index.ts | 23 +- test/client/prepareTrustline/index.ts | 2 +- test/client/request/index.ts | 2 +- test/client/requestNextPage/index.ts | 2 +- test/client/sign/index.ts | 2 +- test/client/signPaymentChannelClaim/index.ts | 25 -- .../client/verifyPaymentChannelClaim/index.ts | 34 --- test/connection-test.ts | 2 +- test/integration/integration-test.ts | 21 +- test/mock-rippled.ts | 2 +- test/ripple-client-test-private.ts | 5 +- test/ripple-client-test.ts | 2 +- test/setup-client.ts | 2 +- test/shamap-test.ts | 2 +- test/{utils.ts => testUtils.ts} | 2 +- .../index.ts => utils/computeLedgerHash.ts} | 83 +++--- .../index.ts => utils/dropsToXrp.ts} | 114 ++++---- .../index.ts => utils/generateAddress.ts} | 132 ++++----- test/{hashes-test.ts => utils/hashesTest.ts} | 37 ++- test/utils/signPaymentChannelClaim.ts | 26 ++ test/utils/verifyPaymentChannelClaim.ts | 30 +++ .../index.ts => utils/xrpToDrops.ts} | 108 ++++---- test/wallet/fromEntropy/index.ts | 2 +- test/wallet/fromMnemonic/index.ts | 2 +- test/wallet/fromSeed/index.ts | 2 +- test/wallet/signTransaction/index.ts | 2 +- test/wallet/verifyTransaction/index.ts | 2 +- 116 files changed, 525 insertions(+), 949 deletions(-) delete mode 100644 src/offline/utils.ts rename src/{offline => utils}/derive.ts (100%) rename src/{offline/generate-address.ts => utils/generateAddress.ts} (89%) rename src/{common => utils}/hashes/README.md (100%) rename src/{common/hashes/hash-prefix.ts => utils/hashes/hashPrefix.ts} (100%) rename src/{common => utils}/hashes/index.ts (85%) rename src/{common/hashes/ledgerspaces.ts => utils/hashes/ledgerSpaces.ts} (100%) rename src/{common => utils}/hashes/sha512Half.ts (100%) rename src/{common => utils}/hashes/shamap.ts (99%) rename src/{common/utils.ts => utils/index.ts} (73%) rename src/{offline/ledgerhash.ts => utils/ledgerHash.ts} (87%) rename src/{offline/sign-payment-channel-claim.ts => utils/signPaymentChannelClaim.ts} (85%) rename src/{offline/verify-payment-channel-claim.ts => utils/verifyPaymentChannelClaim.ts} (88%) delete mode 100644 test/client/deriveAddress/index.ts delete mode 100644 test/client/deriveKeypair/index.ts delete mode 100644 test/client/generateXAddress/index.ts delete mode 100644 test/client/signPaymentChannelClaim/index.ts delete mode 100644 test/client/verifyPaymentChannelClaim/index.ts rename test/{utils.ts => testUtils.ts} (99%) rename test/{client/computeLedgerHash/index.ts => utils/computeLedgerHash.ts} (57%) rename test/{client/dropsToXrp/index.ts => utils/dropsToXrp.ts} (52%) rename test/{client/generateAddress/index.ts => utils/generateAddress.ts} (63%) rename test/{hashes-test.ts => utils/hashesTest.ts} (81%) create mode 100644 test/utils/signPaymentChannelClaim.ts create mode 100644 test/utils/verifyPaymentChannelClaim.ts rename test/{client/xrpToDrops/index.ts => utils/xrpToDrops.ts} (51%) diff --git a/src/client/broadcast.ts b/src/client/broadcast.ts index d2ab8b8d..9a63adef 100644 --- a/src/client/broadcast.ts +++ b/src/client/broadcast.ts @@ -33,7 +33,7 @@ class BroadcastClient extends Client { // synchronous methods are all passed directly to the first client instance const defaultClient = clients[0] - const syncMethods = ['sign', 'generateAddress', 'computeLedgerHash'] + const syncMethods = ['sign'] syncMethods.forEach((name) => { this[name] = defaultClient[name].bind(defaultClient) }) diff --git a/src/client/index.ts b/src/client/index.ts index 50a9b549..bc6afcb8 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -3,11 +3,7 @@ import { constants, errors, validate, - xrpToDrops, - dropsToXrp, - rippleTimeToISO8601, - iso8601ToRippleTime, - txFlags + txFlags, } from '../common' import { Connection, ConnectionUserOptions } from './connection' import getTrustlines from '../ledger/trustlines' @@ -31,11 +27,7 @@ import prepareSettings from '../transaction/settings' import prepareTicketCreate from '../transaction/ticket' import {sign} from '../transaction/sign' import combine from '../transaction/combine' -import { generateAddress, generateXAddress } from '../offline/utils' -import {deriveKeypair, deriveAddress, deriveXAddress} from '../offline/derive' -import computeLedgerHash from '../offline/ledgerhash' -import signPaymentChannelClaim from '../offline/sign-payment-channel-claim' -import verifyPaymentChannelClaim from '../offline/verify-payment-channel-claim' +import {deriveAddress, deriveXAddress} from '../utils/derive' import { Request, Response, @@ -130,19 +122,6 @@ import { encodeXAddress, decodeXAddress } from 'ripple-address-codec' -import { - computeBinaryTransactionHash, - computeTransactionHash, - computeBinaryTransactionSigningHash, - computeAccountLedgerObjectID, - computeSignerListLedgerObjectID, - computeOrderID, - computeTrustlineHash, - computeTransactionTreeHash, - computeStateTreeHash, - computeEscrowHash, - computePaymentChannelHash -} from '../common/hashes' import generateFaucetWallet from '../wallet/wallet-generation' import { ValidationError } from '../common/errors' @@ -389,10 +368,6 @@ class Client extends EventEmitter { return results } - // @deprecated Use X-addresses instead & Invoke from top-level package instead - generateAddress = generateAddress - generateXAddress = generateXAddress // @deprecated Invoke from top-level package instead - isConnected(): boolean { return this.connection.isConnected() } @@ -432,12 +407,6 @@ class Client extends EventEmitter { sign = sign combine = combine - deriveKeypair = deriveKeypair // @deprecated Invoke from top-level package instead - deriveAddress = deriveAddress // @deprecated Invoke from top-level package instead - computeLedgerHash = computeLedgerHash // @deprecated Invoke from top-level package instead - signPaymentChannelClaim = signPaymentChannelClaim // @deprecated Invoke from top-level package instead - verifyPaymentChannelClaim = verifyPaymentChannelClaim // @deprecated Invoke from top-level package instead - generateFaucetWallet = generateFaucetWallet errors = errors @@ -467,48 +436,6 @@ class Client extends EventEmitter { static encodeXAddress = encodeXAddress static decodeXAddress = decodeXAddress - /** - * Static methods that replace functionality from the now-deprecated ripple-hashes library - */ - // Compute the hash of a binary transaction blob. - // @deprecated Invoke from top-level package instead - static computeBinaryTransactionHash = computeBinaryTransactionHash // (txBlobHex: string): string - // Compute the hash of a transaction in txJSON format. - // @deprecated Invoke from top-level package instead - static computeTransactionHash = computeTransactionHash // (txJSON: any): string - // @deprecated Invoke from top-level package instead - static computeBinaryTransactionSigningHash = - computeBinaryTransactionSigningHash // (txBlobHex: string): string - // Compute the hash of an account, given the account's classic address (starting with `r`). - // @deprecated Invoke from top-level package instead - static computeAccountLedgerObjectID = computeAccountLedgerObjectID // (address: string): string - // Compute the hash (ID) of an account's SignerList. - // @deprecated Invoke from top-level package instead - static computeSignerListLedgerObjectID = computeSignerListLedgerObjectID // (address: string): string - // Compute the hash of an order, given the owner's classic address (starting with `r`) and the account sequence number of the `OfferCreate` order transaction. - // @deprecated Invoke from top-level package instead - static computeOrderID = computeOrderID // (address: string, sequence: number): string - // Compute the hash of a trustline, given the two parties' classic addresses (starting with `r`) and the currency code. - // @deprecated Invoke from top-level package instead - static computeTrustlineHash = computeTrustlineHash // (address1: string, address2: string, currency: string): string - // @deprecated Invoke from top-level package instead - static computeTransactionTreeHash = computeTransactionTreeHash // (transactions: any[]): string - // @deprecated Invoke from top-level package instead - static computeStateTreeHash = computeStateTreeHash // (entries: any[]): string - // Compute the hash of a ledger. - // @deprecated Invoke from top-level package instead - static computeLedgerHash = computeLedgerHash // (ledgerHeader): string - // Compute the hash of an escrow, given the owner's classic address (starting with `r`) and the account sequence number of the `EscrowCreate` escrow transaction. - // @deprecated Invoke from top-level package instead - static computeEscrowHash = computeEscrowHash // (address, sequence): string - // Compute the hash of a payment channel, given the owner's classic address (starting with `r`), the classic address of the destination, and the account sequence number of the `PaymentChannelCreate` payment channel transaction. - // @deprecated Invoke from top-level package instead - static computePaymentChannelHash = computePaymentChannelHash // (address, dstAddress, sequence): string - - xrpToDrops = xrpToDrops // @deprecated Invoke from top-level package instead - dropsToXrp = dropsToXrp // @deprecated Invoke from top-level package instead - rippleTimeToISO8601 = rippleTimeToISO8601 // @deprecated Invoke from top-level package instead - iso8601ToRippleTime = iso8601ToRippleTime // @deprecated Invoke from top-level package instead txFlags = txFlags static txFlags = txFlags accountSetFlags = constants.AccountSetFlags diff --git a/src/common/index.ts b/src/common/index.ts index 6c1b4cf5..439b585a 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -24,13 +24,4 @@ export function ensureClassicAddress(account: string): string { } export {constants, errors, validate} -export { - dropsToXrp, - xrpToDrops, - toRippledAmount, - removeUndefined, - convertKeysFromSnakeCaseToCamelCase, - iso8601ToRippleTime, - rippleTimeToISO8601 -} from './utils' export {txFlags} from './txflags' diff --git a/src/common/schema-validator.ts b/src/common/schema-validator.ts index 6c87fb5c..2c6f8211 100644 --- a/src/common/schema-validator.ts +++ b/src/common/schema-validator.ts @@ -3,7 +3,7 @@ import * as assert from 'assert' const {Validator} = require('jsonschema') import {ValidationError} from './errors' import {isValidClassicAddress, isValidXAddress} from 'ripple-address-codec' -import {isValidSecret} from './utils' +import {isValidSecret} from '../utils' function loadSchemas() { // listed explicitly for webpack (instead of scanning schemas directory) diff --git a/src/index.ts b/src/index.ts index eec2303a..6c030ef3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export * from './common/types/objects/ledger' export * from './models/methods' -export * from './offline/utils' +export * from './utils' // Broadcast client is experimental export {BroadcastClient} from './client/broadcast' diff --git a/src/ledger/parse/account-delete.ts b/src/ledger/parse/account-delete.ts index 2e8f82c0..9020f815 100644 --- a/src/ledger/parse/account-delete.ts +++ b/src/ledger/parse/account-delete.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import {classicAddressToXAddress} from 'ripple-address-codec' import {parseMemos} from './utils' diff --git a/src/ledger/parse/account-order.ts b/src/ledger/parse/account-order.ts index 354deeb2..d347c041 100644 --- a/src/ledger/parse/account-order.ts +++ b/src/ledger/parse/account-order.ts @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js' import parseAmount from './amount' import {parseTimestamp, adjustQualityForXRP} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import {orderFlags} from './flags' import {FormattedOrderSpecification} from '../../common/types/objects' diff --git a/src/ledger/parse/account-trustline.ts b/src/ledger/parse/account-trustline.ts index b85a8b3a..179d68bb 100644 --- a/src/ledger/parse/account-trustline.ts +++ b/src/ledger/parse/account-trustline.ts @@ -1,5 +1,5 @@ import {parseQuality} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import { Trustline, FormattedTrustline diff --git a/src/ledger/parse/amount.ts b/src/ledger/parse/amount.ts index 578bbb73..f8d696b9 100644 --- a/src/ledger/parse/amount.ts +++ b/src/ledger/parse/amount.ts @@ -1,11 +1,11 @@ -import * as common from '../../common' import {Amount, RippledAmount} from '../../common/types/objects' +import {dropsToXrp} from '../../utils' function parseAmount(amount: RippledAmount): Amount { if (typeof amount === 'string') { return { currency: 'XRP', - value: common.dropsToXrp(amount) + value: dropsToXrp(amount) } } return { diff --git a/src/ledger/parse/check-cancel.ts b/src/ledger/parse/check-cancel.ts index aa523f6d..81c18a22 100644 --- a/src/ledger/parse/check-cancel.ts +++ b/src/ledger/parse/check-cancel.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import {parseMemos} from './utils' export type FormattedCheckCancel = { diff --git a/src/ledger/parse/check-cash.ts b/src/ledger/parse/check-cash.ts index 53c9542f..0bf83c7e 100644 --- a/src/ledger/parse/check-cash.ts +++ b/src/ledger/parse/check-cash.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import parseAmount from './amount' import {Amount} from '../../common/types/objects' import {parseMemos} from './utils' diff --git a/src/ledger/parse/check-create.ts b/src/ledger/parse/check-create.ts index 79ad6a8b..afecf78a 100644 --- a/src/ledger/parse/check-create.ts +++ b/src/ledger/parse/check-create.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' import {parseTimestamp} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import parseAmount from './amount' import {Amount} from '../../common/types/objects' import {parseMemos} from './utils' diff --git a/src/ledger/parse/deposit-preauth.ts b/src/ledger/parse/deposit-preauth.ts index 71094245..890033f5 100644 --- a/src/ledger/parse/deposit-preauth.ts +++ b/src/ledger/parse/deposit-preauth.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import {parseMemos} from './utils' export type FormattedDepositPreauth = { diff --git a/src/ledger/parse/escrow-cancellation.ts b/src/ledger/parse/escrow-cancellation.ts index 7d1bcddf..1db6d589 100644 --- a/src/ledger/parse/escrow-cancellation.ts +++ b/src/ledger/parse/escrow-cancellation.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' import {parseMemos} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' function parseEscrowCancellation(tx: any): object { assert.ok(tx.TransactionType === 'EscrowCancel') diff --git a/src/ledger/parse/escrow-creation.ts b/src/ledger/parse/escrow-creation.ts index cc601bd2..b14a6894 100644 --- a/src/ledger/parse/escrow-creation.ts +++ b/src/ledger/parse/escrow-creation.ts @@ -1,7 +1,7 @@ import * as assert from 'assert' import parseAmount from './amount' import {parseTimestamp, parseMemos} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' function parseEscrowCreation(tx: any): object { assert.ok(tx.TransactionType === 'EscrowCreate') diff --git a/src/ledger/parse/escrow-execution.ts b/src/ledger/parse/escrow-execution.ts index c4adc707..2c2bf737 100644 --- a/src/ledger/parse/escrow-execution.ts +++ b/src/ledger/parse/escrow-execution.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' import {parseMemos} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' function parseEscrowExecution(tx: any): object { assert.ok(tx.TransactionType === 'EscrowFinish') diff --git a/src/ledger/parse/fee-update.ts b/src/ledger/parse/fee-update.ts index fdba6168..7bf9e8a8 100644 --- a/src/ledger/parse/fee-update.ts +++ b/src/ledger/parse/fee-update.ts @@ -1,5 +1,5 @@ import BigNumber from 'bignumber.js' -import {dropsToXrp} from '../../common' +import {dropsToXrp} from '../../utils' import {parseMemos} from './utils' function parseFeeUpdate(tx: any) { diff --git a/src/ledger/parse/ledger.ts b/src/ledger/parse/ledger.ts index 8e52b54e..c667c264 100644 --- a/src/ledger/parse/ledger.ts +++ b/src/ledger/parse/ledger.ts @@ -1,5 +1,5 @@ import * as _ from 'lodash' -import {removeUndefined, rippleTimeToISO8601} from '../../common' +import {removeUndefined, rippleTimeToISOTime} from '../../utils' import parseTransaction from './transaction' import { TransactionAndMetadata } from '../../models/transactions' @@ -62,7 +62,7 @@ function parseState(state) { /** * @param {Ledger} ledger must be a *closed* ledger with valid `close_time` and `parent_close_time` * @returns {FormattedLedger} formatted ledger - * @throws RangeError: Invalid time value (rippleTimeToISO8601) + * @throws RangeError: Invalid time value (rippleTimeToISOTime) */ export function parseLedger(ledger): FormattedLedger { const ledgerVersion = parseInt(ledger.ledger_index, 10) @@ -70,13 +70,13 @@ export function parseLedger(ledger): FormattedLedger { Object.assign( { stateHash: ledger.account_hash, - closeTime: rippleTimeToISO8601(ledger.close_time), + closeTime: rippleTimeToISOTime(ledger.close_time), closeTimeResolution: ledger.close_time_resolution, closeFlags: ledger.close_flags, ledgerHash: ledger.ledger_hash, ledgerVersion: ledgerVersion, parentLedgerHash: ledger.parent_hash, - parentCloseTime: rippleTimeToISO8601(ledger.parent_close_time), + parentCloseTime: rippleTimeToISOTime(ledger.parent_close_time), totalDrops: ledger.total_coins, transactionHash: ledger.transaction_hash }, diff --git a/src/ledger/parse/order.ts b/src/ledger/parse/order.ts index 1d77c9b8..82ffd985 100644 --- a/src/ledger/parse/order.ts +++ b/src/ledger/parse/order.ts @@ -2,7 +2,8 @@ import * as assert from 'assert' import {parseTimestamp} from './utils' import {parseMemos} from './utils' import parseAmount from './amount' -import {removeUndefined, txFlags} from '../../common' +import {removeUndefined} from '../../utils' +import {txFlags} from '../../common' import { FormattedOrderSpecification, OfferCreateTransaction diff --git a/src/ledger/parse/orderbook-order.ts b/src/ledger/parse/orderbook-order.ts index 3eac581c..7b5b4f42 100644 --- a/src/ledger/parse/orderbook-order.ts +++ b/src/ledger/parse/orderbook-order.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash' import {parseTimestamp, adjustQualityForXRP} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import {orderFlags} from './flags' import parseAmount from './amount' diff --git a/src/ledger/parse/payment-channel-claim.ts b/src/ledger/parse/payment-channel-claim.ts index aa15042d..22175f9f 100644 --- a/src/ledger/parse/payment-channel-claim.ts +++ b/src/ledger/parse/payment-channel-claim.ts @@ -1,5 +1,6 @@ import * as assert from 'assert' -import {removeUndefined, txFlags} from '../../common' +import {removeUndefined} from '../../utils' +import {txFlags} from '../../common' import parseAmount from './amount' import {parseMemos} from './utils' const claimFlags = txFlags.PaymentChannelClaim diff --git a/src/ledger/parse/payment-channel-create.ts b/src/ledger/parse/payment-channel-create.ts index 1ca7892f..08caf67f 100644 --- a/src/ledger/parse/payment-channel-create.ts +++ b/src/ledger/parse/payment-channel-create.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' import {parseTimestamp,parseMemos} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import parseAmount from './amount' function parsePaymentChannelCreate(tx: any): object { diff --git a/src/ledger/parse/payment-channel-fund.ts b/src/ledger/parse/payment-channel-fund.ts index 0028e329..ef371bb5 100644 --- a/src/ledger/parse/payment-channel-fund.ts +++ b/src/ledger/parse/payment-channel-fund.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' import {parseTimestamp,parseMemos} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import parseAmount from './amount' function parsePaymentChannelFund(tx: any): object { diff --git a/src/ledger/parse/payment-channel.ts b/src/ledger/parse/payment-channel.ts index 7a7896e2..92b79d5e 100644 --- a/src/ledger/parse/payment-channel.ts +++ b/src/ledger/parse/payment-channel.ts @@ -1,5 +1,5 @@ import {parseTimestamp, parseMemos} from './utils' -import {removeUndefined, dropsToXrp} from '../../common' +import {removeUndefined, dropsToXrp} from '../../utils' import { PayChannel } from '../../models/ledger' export type FormattedPaymentChannel = { diff --git a/src/ledger/parse/payment.ts b/src/ledger/parse/payment.ts index 749d2480..015c7f7a 100644 --- a/src/ledger/parse/payment.ts +++ b/src/ledger/parse/payment.ts @@ -1,7 +1,8 @@ -import * as _ from 'lodash' +import _ from 'lodash' import * as assert from 'assert' import * as utils from './utils' -import {txFlags, removeUndefined} from '../../common' +import {txFlags} from '../../common' +import {removeUndefined} from '../../utils' import parseAmount from './amount' function isNoDirectRipple(tx) { diff --git a/src/ledger/parse/ticket-create.ts b/src/ledger/parse/ticket-create.ts index 388acb9d..c949ab45 100644 --- a/src/ledger/parse/ticket-create.ts +++ b/src/ledger/parse/ticket-create.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import {parseMemos} from './utils' function parseTicketCreate(tx: any): object { diff --git a/src/ledger/parse/transaction.ts b/src/ledger/parse/transaction.ts index d38c45f0..557ac136 100644 --- a/src/ledger/parse/transaction.ts +++ b/src/ledger/parse/transaction.ts @@ -1,5 +1,5 @@ import {parseOutcome} from './utils' -import {removeUndefined} from '../../common' +import {removeUndefined} from '../../utils' import parseSettings from './settings' import parseAccountDelete from './account-delete' diff --git a/src/ledger/parse/trustline.ts b/src/ledger/parse/trustline.ts index f284e9cd..513d30d5 100644 --- a/src/ledger/parse/trustline.ts +++ b/src/ledger/parse/trustline.ts @@ -1,6 +1,7 @@ import * as assert from 'assert' import {parseQuality, parseMemos} from './utils' -import {txFlags, removeUndefined} from '../../common' +import {txFlags} from '../../common' +import {removeUndefined} from '../../utils' const flags = txFlags.TrustSet function parseFlag(flagsValue, trueValue, falseValue) { diff --git a/src/ledger/parse/utils.ts b/src/ledger/parse/utils.ts index 03adfca2..98f62e4b 100644 --- a/src/ledger/parse/utils.ts +++ b/src/ledger/parse/utils.ts @@ -1,9 +1,10 @@ import transactionParser from 'ripple-lib-transactionparser' import BigNumber from 'bignumber.js' -import * as common from '../../common' import parseAmount from './amount' import {Amount, Memo} from '../../common/types/objects' +import {txFlags} from '../../common' +import {removeUndefined, dropsToXrp, rippleTimeToISOTime} from '../../utils' type OfferDescription = { direction: string, @@ -54,7 +55,7 @@ function parseTimestamp(rippleTime?: number | null): string | undefined { if (typeof rippleTime !== 'number') { return undefined } - return common.rippleTimeToISO8601(rippleTime) + return rippleTimeToISOTime(rippleTime) } function removeEmptyCounterparty(amount) { @@ -78,7 +79,7 @@ function removeEmptyCounterpartyInOrderbookChanges(orderbookChanges: Orderbook) } function isPartialPayment(tx: any) { - return (tx.Flags & common.txFlags.Payment.PartialPayment) !== 0 + return (tx.Flags & txFlags.Payment.PartialPayment) !== 0 } function parseDeliveredAmount(tx: any): Amount | void { @@ -133,10 +134,10 @@ function parseOutcome(tx: any): any | undefined { removeEmptyCounterpartyInBalanceChanges(balanceChanges) removeEmptyCounterpartyInOrderbookChanges(orderbookChanges) - return common.removeUndefined({ + return removeUndefined({ result: tx.meta.TransactionResult, timestamp: parseTimestamp(tx.date), - fee: common.dropsToXrp(tx.Fee), + fee: dropsToXrp(tx.Fee), balanceChanges: balanceChanges, orderbookChanges: orderbookChanges, channelChanges: channelChanges, @@ -155,7 +156,7 @@ function parseMemos(tx: any): Array | undefined { return undefined } return tx.Memos.map((m) => { - return common.removeUndefined({ + return removeUndefined({ type: m.Memo.parsed_memo_type || hexToString(m.Memo.MemoType), format: m.Memo.parsed_memo_format || hexToString(m.Memo.MemoFormat), data: m.Memo.parsed_memo_data || hexToString(m.Memo.MemoData) diff --git a/src/ledger/pathfind.ts b/src/ledger/pathfind.ts index cafc2443..4a9084ce 100644 --- a/src/ledger/pathfind.ts +++ b/src/ledger/pathfind.ts @@ -3,11 +3,9 @@ import BigNumber from 'bignumber.js' import {getXRPBalance, renameCounterpartyToIssuer} from './utils' import { validate, - toRippledAmount, - errors, - xrpToDrops, - dropsToXrp + errors } from '../common' +import {toRippledAmount, xrpToDrops, dropsToXrp} from '../utils' import {Connection} from '../client' import parsePathfind from './parse/pathfind' import {RippledAmount, Amount} from '../common/types/objects' diff --git a/src/ledger/utils.ts b/src/ledger/utils.ts index ffb1becb..49d872c9 100644 --- a/src/ledger/utils.ts +++ b/src/ledger/utils.ts @@ -5,7 +5,8 @@ import {Connection} from '../client' import {FormattedTransactionType} from '../transaction/types' import {Issue} from '../common/types/objects' import {Client} from '..' -import { AccountInfoRequest } from '../models/methods' +import {AccountInfoRequest} from '../models/methods' +import {dropsToXrp} from '..' export type RecursiveData = { marker: string @@ -31,7 +32,7 @@ async function getXRPBalance( } const data = await client .request(request) - return common.dropsToXrp(data.result.account_data.Balance) + return dropsToXrp(data.result.account_data.Balance) } // If the marker is omitted from a response, you have reached the end diff --git a/src/offline/utils.ts b/src/offline/utils.ts deleted file mode 100644 index 21f77650..00000000 --- a/src/offline/utils.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { deriveKeypair, deriveAddress, deriveXAddress } from './derive' -import computeLedgerHeaderHash from './ledgerhash' -import signPaymentChannelClaim from './sign-payment-channel-claim' -import verifyPaymentChannelClaim from './verify-payment-channel-claim' -import { dropsToXrp, - xrpToDrops, - toRippledAmount, - convertKeysFromSnakeCaseToCamelCase, - removeUndefined, - rippleTimeToISO8601, - iso8601ToRippleTime, - isValidSecret, -} from '../common/utils' -import { - computeBinaryTransactionHash, - computeTransactionHash, - computeBinaryTransactionSigningHash, - computeAccountLedgerObjectID, - computeSignerListLedgerObjectID, - computeOrderID, - computeTrustlineHash, - computeTransactionTreeHash, - computeStateTreeHash, - computeLedgerHash, - computeEscrowHash, - computePaymentChannelHash, -} from '../common/hashes' -import { generateAddressAPI, GenerateAddressOptions, GeneratedAddress } from '../offline/generate-address' - -// @deprecated Use X-addresses instead -const generateAddress = (options: GenerateAddressOptions = {}): GeneratedAddress => ( - generateAddressAPI({...options, includeClassicAddress: true}) -) - -export { - computeLedgerHeaderHash, - dropsToXrp, - xrpToDrops, - toRippledAmount, - convertKeysFromSnakeCaseToCamelCase, - removeUndefined, - rippleTimeToISO8601, - iso8601ToRippleTime, - isValidSecret, - computeBinaryTransactionHash, - computeTransactionHash, - computeBinaryTransactionSigningHash, - computeAccountLedgerObjectID, - computeSignerListLedgerObjectID, - computeOrderID, - computeTrustlineHash, - computeTransactionTreeHash, - computeStateTreeHash, - computeLedgerHash, - computeEscrowHash, - computePaymentChannelHash, - generateAddress, - generateAddressAPI as generateXAddress, - deriveKeypair, - deriveAddress, - deriveXAddress, - signPaymentChannelClaim, - verifyPaymentChannelClaim, -} diff --git a/src/transaction/check-cash.ts b/src/transaction/check-cash.ts index 49b131e7..239d877c 100644 --- a/src/transaction/check-cash.ts +++ b/src/transaction/check-cash.ts @@ -1,10 +1,10 @@ import * as utils from './utils' -const ValidationError = utils.common.errors.ValidationError -const toRippledAmount = utils.common.toRippledAmount import {validate} from '../common' import {Instructions, Prepare, TransactionJSON} from './types' import {Amount} from '../common/types/objects' import {Client} from '..' +import {toRippledAmount} from '../utils' +import {ValidationError} from '../common/errors' export type CheckCashParameters = { checkID: string diff --git a/src/transaction/check-create.ts b/src/transaction/check-create.ts index 1a53f843..d024dd8c 100644 --- a/src/transaction/check-create.ts +++ b/src/transaction/check-create.ts @@ -1,6 +1,6 @@ import * as utils from './utils' -const toRippledAmount = utils.common.toRippledAmount -import {validate, iso8601ToRippleTime} from '../common' +import {validate} from '../common' +import {ISOTimeToRippleTime, toRippledAmount} from '../utils' import {Instructions, Prepare, TransactionJSON} from './types' import {Amount} from '../common/types/objects' import {Client} from '..' @@ -29,7 +29,7 @@ function createCheckCreateTransaction( } if (check.expiration != null) { - txJSON.Expiration = iso8601ToRippleTime(check.expiration) + txJSON.Expiration = ISOTimeToRippleTime(check.expiration) } if (check.invoiceID != null) { diff --git a/src/transaction/combine.ts b/src/transaction/combine.ts index 20fb8d36..bb19fe68 100644 --- a/src/transaction/combine.ts +++ b/src/transaction/combine.ts @@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js' import {ValidationError} from '../common/errors' import {decodeAccountID} from 'ripple-address-codec' import {validate} from '../common' -import {computeBinaryTransactionHash} from '../common/hashes' +import {computeBinaryTransactionHash} from '../utils/hashes' import {JsonObject} from 'ripple-binary-codec/dist/types/serialized-type' /** diff --git a/src/transaction/escrow-creation.ts b/src/transaction/escrow-creation.ts index a214b981..35be8df7 100644 --- a/src/transaction/escrow-creation.ts +++ b/src/transaction/escrow-creation.ts @@ -1,5 +1,6 @@ import * as utils from './utils' -import {validate, iso8601ToRippleTime, xrpToDrops} from '../common' +import {validate} from '../common' +import {ISOTimeToRippleTime, xrpToDrops} from '../utils' const ValidationError = utils.common.errors.ValidationError import {Instructions, Prepare, TransactionJSON} from './types' import {Memo} from '../common/types/objects' @@ -31,10 +32,10 @@ function createEscrowCreationTransaction( txJSON.Condition = payment.condition } if (payment.allowCancelAfter != null) { - txJSON.CancelAfter = iso8601ToRippleTime(payment.allowCancelAfter) + txJSON.CancelAfter = ISOTimeToRippleTime(payment.allowCancelAfter) } if (payment.allowExecuteAfter != null) { - txJSON.FinishAfter = iso8601ToRippleTime(payment.allowExecuteAfter) + txJSON.FinishAfter = ISOTimeToRippleTime(payment.allowExecuteAfter) } if (payment.sourceTag != null) { txJSON.SourceTag = payment.sourceTag diff --git a/src/transaction/order.ts b/src/transaction/order.ts index e6967574..dcbff55b 100644 --- a/src/transaction/order.ts +++ b/src/transaction/order.ts @@ -1,6 +1,7 @@ import * as utils from './utils' const offerFlags = utils.common.txFlags.OfferCreate -import {validate, iso8601ToRippleTime, toRippledAmount} from '../common' +import {validate} from '../common' +import {ISOTimeToRippleTime, toRippledAmount} from '../utils' import {Instructions, Prepare, OfferCreateTransaction} from './types' import {FormattedOrderSpecification} from '../common/types/objects/index' import {Client} from '..' @@ -36,7 +37,7 @@ function createOrderTransaction( txJSON.Flags |= offerFlags.FillOrKill } if (order.expirationTime != null) { - txJSON.Expiration = iso8601ToRippleTime(order.expirationTime) + txJSON.Expiration = ISOTimeToRippleTime(order.expirationTime) } if (order.orderToReplace != null) { txJSON.OfferSequence = order.orderToReplace diff --git a/src/transaction/payment-channel-claim.ts b/src/transaction/payment-channel-claim.ts index 8afed802..676d3fb8 100644 --- a/src/transaction/payment-channel-claim.ts +++ b/src/transaction/payment-channel-claim.ts @@ -1,7 +1,8 @@ import * as utils from './utils' const ValidationError = utils.common.errors.ValidationError const claimFlags = utils.common.txFlags.PaymentChannelClaim -import {validate, xrpToDrops} from '../common' +import {validate} from '../common' +import {xrpToDrops} from '../utils' import {Instructions, Prepare, TransactionJSON} from './types' import {Client} from '..' diff --git a/src/transaction/payment-channel-create.ts b/src/transaction/payment-channel-create.ts index 7165e941..591572dd 100644 --- a/src/transaction/payment-channel-create.ts +++ b/src/transaction/payment-channel-create.ts @@ -1,5 +1,6 @@ import * as utils from './utils' -import {validate, iso8601ToRippleTime, xrpToDrops} from '../common' +import {validate} from '../common' +import {ISOTimeToRippleTime, xrpToDrops} from '../utils' import {Instructions, Prepare, TransactionJSON} from './types' import {Client} from '..' @@ -27,7 +28,7 @@ function createPaymentChannelCreateTransaction( } if (paymentChannel.cancelAfter != null) { - txJSON.CancelAfter = iso8601ToRippleTime(paymentChannel.cancelAfter) + txJSON.CancelAfter = ISOTimeToRippleTime(paymentChannel.cancelAfter) } if (paymentChannel.sourceTag != null) { txJSON.SourceTag = paymentChannel.sourceTag diff --git a/src/transaction/payment-channel-fund.ts b/src/transaction/payment-channel-fund.ts index f6d941c4..6192be54 100644 --- a/src/transaction/payment-channel-fund.ts +++ b/src/transaction/payment-channel-fund.ts @@ -1,5 +1,6 @@ import * as utils from './utils' -import {validate, iso8601ToRippleTime, xrpToDrops} from '../common' +import {validate} from '../common' +import {ISOTimeToRippleTime, xrpToDrops} from '../utils' import {Instructions, Prepare, TransactionJSON} from './types' import {Client} from '..' @@ -21,7 +22,7 @@ function createPaymentChannelFundTransaction( } if (fund.expiration != null) { - txJSON.Expiration = iso8601ToRippleTime(fund.expiration) + txJSON.Expiration = ISOTimeToRippleTime(fund.expiration) } return txJSON diff --git a/src/transaction/payment.ts b/src/transaction/payment.ts index c29e3972..cd8aca6a 100644 --- a/src/transaction/payment.ts +++ b/src/transaction/payment.ts @@ -11,7 +11,7 @@ import { MinAdjustment, Memo } from '../common/types/objects' -import {toRippledAmount, xrpToDrops} from '../common' +import {toRippledAmount, xrpToDrops} from '../utils' import {Client} from '..' import {getClassicAccountAndTag, ClassicAccountAndTag} from './utils' diff --git a/src/transaction/sign.ts b/src/transaction/sign.ts index a9b28230..5f6336ad 100644 --- a/src/transaction/sign.ts +++ b/src/transaction/sign.ts @@ -2,10 +2,10 @@ import _ from 'lodash' import * as utils from './utils' import keypairs from 'ripple-keypairs' import binaryCodec from 'ripple-binary-codec' -import {computeBinaryTransactionHash} from '../common/hashes' +import {computeBinaryTransactionHash} from '../utils/hashes' import {SignOptions, KeyPair, TransactionJSON} from './types' import BigNumber from 'bignumber.js' -import {xrpToDrops} from '../common' +import {xrpToDrops} from '../utils' import {Client} from '..' import Wallet from '../Wallet' import {SignedTransaction} from '../common/types/objects' diff --git a/src/transaction/utils.ts b/src/transaction/utils.ts index 2cd1a15c..ce4079b7 100644 --- a/src/transaction/utils.ts +++ b/src/transaction/utils.ts @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js' import * as common from '../common' import {Memo} from '../common/types/objects' import {Instructions, Prepare, TransactionJSON} from './types' -import {toRippledAmount} from '../common' +import {toRippledAmount, dropsToXrp, removeUndefined, xrpToDrops} from '../utils' import {Client} from '..' import {ValidationError} from '../common/errors' import {xAddressToClassicAddress, isValidXAddress} from 'ripple-address-codec' @@ -23,7 +23,7 @@ export type ApiMemo = { function formatPrepareResponse(txJSON: any): Prepare { const instructions = { - fee: common.dropsToXrp(txJSON.Fee), + fee: dropsToXrp(txJSON.Fee), maxLedgerVersion: txJSON.LastLedgerSequence == null ? null : txJSON.LastLedgerSequence } @@ -310,7 +310,7 @@ function prepareTransaction( ) } newTxJSON.Fee = scaleValue( - common.xrpToDrops(instructions.fee), + xrpToDrops(instructions.fee), multiplier ) return Promise.resolve() @@ -331,11 +331,11 @@ function prepareTransaction( Math.floor( Buffer.from(newTxJSON.Fulfillment, 'hex').length / 16 )) - const feeDrops = common.xrpToDrops(fee) + const feeDrops = xrpToDrops(fee) const maxFeeXRP = instructions.maxFee ? BigNumber.min(client._maxFeeXRP, instructions.maxFee) : client._maxFeeXRP - const maxFeeDrops = common.xrpToDrops(maxFeeXRP) + const maxFeeDrops = xrpToDrops(maxFeeXRP) const normalFee = scaleValue(feeDrops, multiplier, extraFee) newTxJSON.Fee = BigNumber.min(normalFee, maxFeeDrops).toString(10) @@ -398,7 +398,7 @@ function convertStringToHex(string: string): string { function convertMemo(memo: Memo): {Memo: ApiMemo} { return { - Memo: common.removeUndefined({ + Memo: removeUndefined({ MemoData: memo.data ? convertStringToHex(memo.data) : undefined, MemoType: memo.type ? convertStringToHex(memo.type) : undefined, MemoFormat: memo.format ? convertStringToHex(memo.format) : undefined diff --git a/src/offline/derive.ts b/src/utils/derive.ts similarity index 100% rename from src/offline/derive.ts rename to src/utils/derive.ts diff --git a/src/offline/generate-address.ts b/src/utils/generateAddress.ts similarity index 89% rename from src/offline/generate-address.ts rename to src/utils/generateAddress.ts index e4ef3f0c..215ac769 100644 --- a/src/offline/generate-address.ts +++ b/src/utils/generateAddress.ts @@ -26,7 +26,8 @@ export interface GenerateAddressOptions { includeClassicAddress?: boolean } -function generateAddressAPI(options: GenerateAddressOptions = {}): GeneratedAddress { +// TODO: move this function to be a static function of the Wallet class (Along with its helper data types) +function generateXAddress(options: GenerateAddressOptions = {}): GeneratedAddress { validate.generateAddress({options}) try { const generateSeedOptions: { @@ -59,4 +60,4 @@ function generateAddressAPI(options: GenerateAddressOptions = {}): GeneratedAddr } } -export {generateAddressAPI} +export {generateXAddress} diff --git a/src/common/hashes/README.md b/src/utils/hashes/README.md similarity index 100% rename from src/common/hashes/README.md rename to src/utils/hashes/README.md diff --git a/src/common/hashes/hash-prefix.ts b/src/utils/hashes/hashPrefix.ts similarity index 100% rename from src/common/hashes/hash-prefix.ts rename to src/utils/hashes/hashPrefix.ts diff --git a/src/common/hashes/index.ts b/src/utils/hashes/index.ts similarity index 85% rename from src/common/hashes/index.ts rename to src/utils/hashes/index.ts index b035f6c9..06048eea 100644 --- a/src/common/hashes/index.ts +++ b/src/utils/hashes/index.ts @@ -1,10 +1,10 @@ import BigNumber from 'bignumber.js' import {decodeAccountID} from 'ripple-address-codec' import sha512Half from './sha512Half' -import HashPrefix from './hash-prefix' +import HashPrefix from './hashPrefix' import {SHAMap, NodeType} from './shamap' import {encode} from 'ripple-binary-codec' -import ledgerspaces from './ledgerspaces' +import ledgerSpaces from './ledgerSpaces' const padLeftZero = (string: string, length: number): string => { return Array(length - string.length + 1).join('0') + string @@ -27,7 +27,7 @@ const bigintToHex = ( } const ledgerSpaceHex = (name: string): string => { - return intToHex(ledgerspaces[name].charCodeAt(0), 2) + return intToHex(ledgerSpaces[name].charCodeAt(0), 2) } const addressToHex = (address: string): string => { @@ -84,36 +84,36 @@ export const computeBinaryTransactionSigningHash = ( } /** - * Compute Account Ledger Object ID + * Compute Account Root Index * - * All objects in a ledger's state tree have a unique ID. - * The Account Ledger Object ID is derived by hashing the + * All objects in a ledger's state tree have a unique index. + * The Account Root index is derived by hashing the * address with a namespace identifier. This ensures every - * ID is unique. + * index is unique. * * See [Ledger Object IDs](https://xrpl.org/ledger-object-ids.html) * * @param address The classic account address - * @returns {string} The Ledger Object ID for the account + * @returns {string} The Ledger Object Index for the account */ -export const computeAccountLedgerObjectID = (address: string): string => { +export const computeAccountRootIndex = (address: string): string => { return sha512Half(ledgerSpaceHex('account') + addressToHex(address)) } /** * [SignerList ID Format](https://xrpl.org/signerlist.html#signerlist-id-format) * - * The ID of a SignerList object is the SHA-512Half of the following values, concatenated in order: + * The index of a SignerList object is the SHA-512Half of the following values, concatenated in order: * * The RippleState space key (0x0053) * * The AccountID of the owner of the SignerList * * The SignerListID (currently always 0) * - * This method computes a SignerList Ledger Object ID. + * This method computes a SignerList index. * * @param address The classic account address of the SignerList owner (starting with r) * @return {string} The ID of the account's SignerList object */ -export const computeSignerListLedgerObjectID = (address: string): string => { +export const computeSignerListIndex = (address: string): string => { return sha512Half( ledgerSpaceHex('signerList') + addressToHex(address) + '00000000' ) // uint32(0) signer list index @@ -122,18 +122,18 @@ export const computeSignerListLedgerObjectID = (address: string): string => { /** * [Offer ID Format](https://xrpl.org/offer.html#offer-id-format) * - * The ID of a Offer object is the SHA-512Half of the following values, concatenated in order: + * The index of a Offer object is the SHA-512Half of the following values, concatenated in order: * * The Offer space key (0x006F) * * The AccountID of the account placing the offer * * The Sequence number of the OfferCreate transaction that created the offer * - * This method computes an Offer ID (aka Order ID). + * This method computes an Offer Index (aka Order Index). * * @param address The classic account address of the SignerList owner (starting with r) - * @returns {string} The ID of the account's Offer object + * @returns {string} The index of the account's Offer object */ -export const computeOrderID = (address: string, sequence: number): string => { - const prefix = '00' + intToHex(ledgerspaces.offer.charCodeAt(0), 1) +export const computeOfferIndex = (address: string, sequence: number): string => { + const prefix = '00' + intToHex(ledgerSpaces.offer.charCodeAt(0), 1) return sha512Half(prefix + addressToHex(address) + intToHex(sequence, 4)) } diff --git a/src/common/hashes/ledgerspaces.ts b/src/utils/hashes/ledgerSpaces.ts similarity index 100% rename from src/common/hashes/ledgerspaces.ts rename to src/utils/hashes/ledgerSpaces.ts diff --git a/src/common/hashes/sha512Half.ts b/src/utils/hashes/sha512Half.ts similarity index 100% rename from src/common/hashes/sha512Half.ts rename to src/utils/hashes/sha512Half.ts diff --git a/src/common/hashes/shamap.ts b/src/utils/hashes/shamap.ts similarity index 99% rename from src/common/hashes/shamap.ts rename to src/utils/hashes/shamap.ts index 5c5b36eb..9f8b621e 100644 --- a/src/common/hashes/shamap.ts +++ b/src/utils/hashes/shamap.ts @@ -1,4 +1,4 @@ -import hashPrefix from './hash-prefix' +import hashPrefix from './hashPrefix' import sha512Half from './sha512Half' const HEX_ZERO = '0000000000000000000000000000000000000000000000000000000000000000' diff --git a/src/common/utils.ts b/src/utils/index.ts similarity index 73% rename from src/common/utils.ts rename to src/utils/index.ts index 46f1b846..7dc3dd2a 100644 --- a/src/common/utils.ts +++ b/src/utils/index.ts @@ -1,8 +1,27 @@ -import * as _ from 'lodash' +import { deriveKeypair, deriveAddress, deriveXAddress } from './derive' +import computeLedgerHeaderHash from './ledgerHash' +import signPaymentChannelClaim from './signPaymentChannelClaim' +import verifyPaymentChannelClaim from './verifyPaymentChannelClaim' +import { + computeBinaryTransactionHash, + computeTransactionHash, + computeBinaryTransactionSigningHash, + computeAccountRootIndex, + computeSignerListIndex, + computeOfferIndex, + computeTrustlineHash, + computeTransactionTreeHash, + computeStateTreeHash, + computeLedgerHash, + computeEscrowHash, + computePaymentChannelHash, +} from './hashes' +import { generateXAddress } from './generateAddress' + +import _ from 'lodash' import BigNumber from 'bignumber.js' -import {deriveKeypair} from 'ripple-keypairs' -import {RippledAmount} from './types/objects' -import {ValidationError} from './errors' +import {RippledAmount} from '../common/types/objects' +import {ValidationError} from '../common/errors' import {xAddressToClassicAddress} from 'ripple-address-codec' function isValidSecret(secret: string): boolean { @@ -170,13 +189,17 @@ function rippleToUnixTimestamp(rpepoch: number): number { /** * @param {Number|Date} timestamp (ms since unix epoch) - * @return {Number} seconds since ripple epoch (1/1/2000 GMT) + * @return {Number} seconds since Ripple Epoch (1/1/2000 GMT) */ function unixToRippleTimestamp(timestamp: number): number { return Math.round(timestamp / 1000) - 0x386d4380 } -function rippleTimeToISO8601(rippleTime: number): string { +/** + * @param {number} rippleTime is the number of seconds since Ripple Epoch (1/1/2000 GMT) + * @return {string} iso8601 international standard date format + */ +function rippleTimeToISOTime(rippleTime: number): string { return new Date(rippleToUnixTimestamp(rippleTime)).toISOString() } @@ -184,17 +207,36 @@ function rippleTimeToISO8601(rippleTime: number): string { * @param {string} iso8601 international standard date format * @return {number} seconds since ripple epoch (1/1/2000 GMT) */ -function iso8601ToRippleTime(iso8601: string): number { +function ISOTimeToRippleTime(iso8601: string): number { return unixToRippleTimestamp(Date.parse(iso8601)) } export { - dropsToXrp, - xrpToDrops, - toRippledAmount, - convertKeysFromSnakeCaseToCamelCase, - removeUndefined, - rippleTimeToISO8601, - iso8601ToRippleTime, - isValidSecret + computeLedgerHeaderHash, + dropsToXrp, + xrpToDrops, + toRippledAmount, + convertKeysFromSnakeCaseToCamelCase, + removeUndefined, + rippleTimeToISOTime, + ISOTimeToRippleTime, + isValidSecret, + computeBinaryTransactionHash, + computeTransactionHash, + computeBinaryTransactionSigningHash, + computeAccountRootIndex, + computeSignerListIndex, + computeOfferIndex, + computeTrustlineHash, + computeTransactionTreeHash, + computeStateTreeHash, + computeLedgerHash, + computeEscrowHash, + computePaymentChannelHash, + generateXAddress, + deriveKeypair, + deriveAddress, + deriveXAddress, + signPaymentChannelClaim, + verifyPaymentChannelClaim, } diff --git a/src/offline/ledgerhash.ts b/src/utils/ledgerHash.ts similarity index 87% rename from src/offline/ledgerhash.ts rename to src/utils/ledgerHash.ts index f44ec2d7..cd92535c 100644 --- a/src/offline/ledgerhash.ts +++ b/src/utils/ledgerHash.ts @@ -1,22 +1,23 @@ -import * as _ from 'lodash' +import _ from 'lodash' +import { ISOTimeToRippleTime } from '.' +import { ValidationError } from '../common/errors' import { computeLedgerHash, computeTransactionTreeHash, computeStateTreeHash -} from '../common/hashes' -import * as common from '../common' +} from '../utils/hashes' function convertLedgerHeader(header): any { return { account_hash: header.stateHash, - close_time: common.iso8601ToRippleTime(header.closeTime), + close_time: ISOTimeToRippleTime(header.closeTime), close_time_resolution: header.closeTimeResolution, close_flags: header.closeFlags, hash: header.ledgerHash, ledger_hash: header.ledgerHash, ledger_index: header.ledgerVersion.toString(), parent_hash: header.parentLedgerHash, - parent_close_time: common.iso8601ToRippleTime(header.parentCloseTime), + parent_close_time: ISOTimeToRippleTime(header.parentCloseTime), total_coins: header.totalDrops, transaction_hash: header.transactionHash } @@ -45,14 +46,14 @@ function computeTransactionHash( 'SyntaxError: Unexpected' + ' token u in JSON at position 0' ) { // one or more of the `tx.rawTransaction`s is undefined - throw new common.errors.ValidationError( + throw new ValidationError( 'ledger' + ' is missing raw transactions' ) } } } else { if (options.computeTreeHashes) { - throw new common.errors.ValidationError( + throw new ValidationError( 'transactions' + ' property is missing from the ledger' ) } @@ -73,7 +74,7 @@ function computeTransactionHash( ledger.transactionHash != null && ledger.transactionHash !== transactionHash ) { - throw new common.errors.ValidationError( + throw new ValidationError( 'transactionHash in header' + ' does not match computed hash of transactions', { @@ -88,7 +89,7 @@ function computeTransactionHash( function computeStateHash(ledger, options: ComputeLedgerHeaderHashOptions) { if (ledger.rawState == null) { if (options.computeTreeHashes) { - throw new common.errors.ValidationError( + throw new ValidationError( 'rawState' + ' property is missing from the ledger' ) } @@ -97,7 +98,7 @@ function computeStateHash(ledger, options: ComputeLedgerHeaderHashOptions) { const state = JSON.parse(ledger.rawState) const stateHash = computeStateTreeHash(state) if (ledger.stateHash != null && ledger.stateHash !== stateHash) { - throw new common.errors.ValidationError( + throw new ValidationError( 'stateHash in header' + ' does not match computed hash of state' ) } diff --git a/src/offline/sign-payment-channel-claim.ts b/src/utils/signPaymentChannelClaim.ts similarity index 85% rename from src/offline/sign-payment-channel-claim.ts rename to src/utils/signPaymentChannelClaim.ts index 3a323a67..5c604e4f 100644 --- a/src/offline/sign-payment-channel-claim.ts +++ b/src/utils/signPaymentChannelClaim.ts @@ -1,7 +1,7 @@ -import * as common from '../common' import keypairs from 'ripple-keypairs' import binary from 'ripple-binary-codec' -const {validate, xrpToDrops} = common +import { validate } from '../common' +import { xrpToDrops } from '.' function signPaymentChannelClaim( channel: string, @@ -9,7 +9,6 @@ function signPaymentChannelClaim( privateKey: string ): string { validate.signPaymentChannelClaim({channel, amount, privateKey}) - const signingData = binary.encodeForSigningClaim({ channel: channel, amount: xrpToDrops(amount) diff --git a/src/offline/verify-payment-channel-claim.ts b/src/utils/verifyPaymentChannelClaim.ts similarity index 88% rename from src/offline/verify-payment-channel-claim.ts rename to src/utils/verifyPaymentChannelClaim.ts index e4eb76b7..b9d9c6f9 100644 --- a/src/offline/verify-payment-channel-claim.ts +++ b/src/utils/verifyPaymentChannelClaim.ts @@ -1,6 +1,7 @@ import keypairs from 'ripple-keypairs' import binary from 'ripple-binary-codec' -import {validate, xrpToDrops} from '../common' +import {validate} from '../common' +import {xrpToDrops} from '.' function verifyPaymentChannelClaim( channel: string, diff --git a/src/wallet/wallet-generation.ts b/src/wallet/wallet-generation.ts index f436f1f7..fbae8083 100644 --- a/src/wallet/wallet-generation.ts +++ b/src/wallet/wallet-generation.ts @@ -2,7 +2,7 @@ import https = require('https') import {Client} from '..' import {errors} from '../common' -import {GeneratedAddress} from '../offline/generate-address' +import {GeneratedAddress} from '../utils/generateAddress' import {isValidAddress} from '../common/schema-validator' import {RippledError} from '../common/errors' diff --git a/test/.mocharc.json b/test/.mocharc.json index bc7c5e2d..1f2ff0ed 100644 --- a/test/.mocharc.json +++ b/test/.mocharc.json @@ -1,6 +1,6 @@ { "diff": true, - "spec": ["./test/*.ts", "./test/models/**/*.ts"], + "spec": ["./test/*.ts", "./test/models/**/*.ts", "./test/utils/**/*.ts"], "extension": ["ts"], "package": "../package.json", "require": "ts-node/register", diff --git a/test/broadcast-client-test.ts b/test/broadcast-client-test.ts index 4b5549a7..dae89864 100644 --- a/test/broadcast-client-test.ts +++ b/test/broadcast-client-test.ts @@ -3,7 +3,7 @@ import assert from 'assert-diff' import setupClient from './setup-client' import responses from './fixtures/responses' import rippled from './fixtures/rippled' -import {ignoreWebSocketDisconnect} from './utils' +import {ignoreWebSocketDisconnect} from './testUtils' const TIMEOUT = 20000 diff --git a/test/client/combine/index.ts b/test/client/combine/index.ts index 4c93a46e..464beaa8 100644 --- a/test/client/combine/index.ts +++ b/test/client/combine/index.ts @@ -2,7 +2,7 @@ import assert from 'assert-diff' import binary from 'ripple-binary-codec' import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const {combine: REQUEST_FIXTURES} = requests const {combine: RESPONSE_FIXTURES} = responses diff --git a/test/client/constructor/index.ts b/test/client/constructor/index.ts index ac30cebb..f660a58e 100644 --- a/test/client/constructor/index.ts +++ b/test/client/constructor/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import {Client} from 'xrpl-local' /** diff --git a/test/client/deriveAddress/index.ts b/test/client/deriveAddress/index.ts deleted file mode 100644 index 64225527..00000000 --- a/test/client/deriveAddress/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -import assert from 'assert-diff' -import {TestSuite} from '../../utils' - -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'returns address for public key': async (client, address) => { - var address = client.deriveAddress( - '035332FBA71D705BD5D97014A833BE2BBB25BEFCD3506198E14AFEA241B98C2D06' - ) - assert.equal(address, 'rLczgQHxPhWtjkaQqn3Q6UM8AbRbbRvs5K') - } -} diff --git a/test/client/deriveKeypair/index.ts b/test/client/deriveKeypair/index.ts deleted file mode 100644 index c5aa8e64..00000000 --- a/test/client/deriveKeypair/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -import assert from 'assert-diff' -import {TestSuite} from '../../utils' - -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'returns keypair for secret': async (client, address) => { - var keypair = client.deriveKeypair('snsakdSrZSLkYpCXxfRkS4Sh96PMK') - assert.equal( - keypair.privateKey, - '008850736302221AFD59FF9CA1A29D4975F491D726249302EE48A3078A8934D335' - ) - assert.equal( - keypair.publicKey, - '035332FBA71D705BD5D97014A833BE2BBB25BEFCD3506198E14AFEA241B98C2D06' - ) - }, - - 'returns keypair for ed25519 secret': async (client, address) => { - var keypair = client.deriveKeypair('sEdV9eHWbibBnTj7b1H5kHfPfv7gudx') - assert.equal( - keypair.privateKey, - 'ED5C2EF6C2E3200DFA6B72F47935C7F64D35453646EA34919192538F458C7BC30F' - ) - assert.equal( - keypair.publicKey, - 'ED0805EC4E728DB87C0CA6C420751F296C57A5F42D02E9E6150CE60694A44593E5' - ) - }, - - 'throws with an invalid secret': async (client, address) => { - assert.throws(() => { - client.deriveKeypair('...') - }, /^Error: Non-base58 character$/) - } -} diff --git a/test/client/deriveXAddress/index.ts b/test/client/deriveXAddress/index.ts index 4f28e7f6..699c2936 100644 --- a/test/client/deriveXAddress/index.ts +++ b/test/client/deriveXAddress/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import {Client} from '../../../src' /** diff --git a/test/client/errors/index.ts b/test/client/errors/index.ts index 18774cd3..be899bb2 100644 --- a/test/client/errors/index.ts +++ b/test/client/errors/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/formatBidsAndAsks/index.ts b/test/client/formatBidsAndAsks/index.ts index 33bbaca3..e8ec5c4d 100644 --- a/test/client/formatBidsAndAsks/index.ts +++ b/test/client/formatBidsAndAsks/index.ts @@ -3,7 +3,7 @@ // import {Client} from 'xrpl-local' // import requests from '../../fixtures/requests' // import responses from '../../fixtures/responses' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' // function checkSortingOfOrders(orders) { // let previousRate = '0' diff --git a/test/client/generateXAddress/index.ts b/test/client/generateXAddress/index.ts deleted file mode 100644 index ca952782..00000000 --- a/test/client/generateXAddress/index.ts +++ /dev/null @@ -1,252 +0,0 @@ -import assert from 'assert-diff' -import responses from '../../fixtures/responses' -import {TestSuite} from '../../utils' -import ECDSA from '../../../src/common/ecdsa' -import {GenerateAddressOptions} from '../../../src/offline/generate-address' - -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'generateXAddress': async (client) => { - // GIVEN entropy of all zeros - function random() { - return new Array(16).fill(0) - } - - assert.deepEqual( - // WHEN generating an X-address - client.generateXAddress({entropy: random()}), - - // THEN we get the expected return value - responses.generateXAddress - ) - }, - - 'generateXAddress invalid entropy': async (client) => { - assert.throws(() => { - // GIVEN entropy of 1 byte - function random() { - return new Array(1).fill(0) - } - - // WHEN generating an X-address - client.generateXAddress({entropy: random()}) - - // THEN an UnexpectedError is thrown - // because 16 bytes of entropy are required - }, client.errors.UnexpectedError) - }, - - 'generateXAddress with no options object': async (client) => { - // GIVEN no options - - // WHEN generating an X-address - const account = client.generateXAddress() - - // THEN we get an object with an xAddress starting with 'X' and a secret starting with 's' - assert( - account.xAddress.startsWith('X'), - 'By default X-addresses start with X' - ) - assert(account.secret.startsWith('s'), 'Secrets start with s') - }, - - 'generateXAddress with empty options object': async (client) => { - // GIVEN an empty options object - const options = {} - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get an object with an xAddress starting with 'X' and a secret starting with 's' - assert( - account.xAddress.startsWith('X'), - 'By default X-addresses start with X' - ) - assert(account.secret.startsWith('s'), 'Secrets start with s') - }, - - 'generateXAddress with algorithm `ecdsa-secp256k1`': async (client) => { - // GIVEN we want to use 'ecdsa-secp256k1' - const options: GenerateAddressOptions = {algorithm: ECDSA.secp256k1} - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get an object with an xAddress starting with 'X' and a secret starting with 's' - assert( - account.xAddress.startsWith('X'), - 'By default X-addresses start with X' - ) - assert.deepEqual( - account.secret.slice(0, 1), - 's', - `Secret ${account.secret} must start with 's'` - ) - assert.notStrictEqual( - account.secret.slice(0, 3), - 'sEd', - `secp256k1 secret ${account.secret} must not start with 'sEd'` - ) - }, - - 'generateXAddress with algorithm `ed25519`': async (client) => { - // GIVEN we want to use 'ed25519' - const options: GenerateAddressOptions = {algorithm: ECDSA.ed25519} - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get an object with an xAddress starting with 'X' and a secret starting with 'sEd' - assert( - account.xAddress.startsWith('X'), - 'By default X-addresses start with X' - ) - assert.deepEqual( - account.secret.slice(0, 3), - 'sEd', - `Ed25519 secret ${account.secret} must start with 'sEd'` - ) - }, - - 'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy': async ( - client - ) => { - // GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero - const options: GenerateAddressOptions = { - algorithm: ECDSA.secp256k1, - entropy: new Array(16).fill(0) - } - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get the expected return value - assert.deepEqual(account, responses.generateXAddress) - }, - - 'generateXAddress with algorithm `ed25519` and given entropy': async ( - client - ) => { - // GIVEN we want to use 'ed25519' with entropy of zero - const options: GenerateAddressOptions = { - algorithm: ECDSA.ed25519, - entropy: new Array(16).fill(0) - } - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get the expected return value - assert.deepEqual(account, { - xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB', - secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE' - }) - }, - - 'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async ( - client - ) => { - // GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero - const options: GenerateAddressOptions = { - algorithm: ECDSA.secp256k1, - entropy: new Array(16).fill(0), - includeClassicAddress: true - } - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get the expected return value - assert.deepEqual(account, responses.generateAddress) - }, - - 'generateXAddress with algorithm `ed25519` and given entropy; include classic address': async ( - client - ) => { - // GIVEN we want to use 'ed25519' with entropy of zero - const options: GenerateAddressOptions = { - algorithm: ECDSA.ed25519, - entropy: new Array(16).fill(0), - includeClassicAddress: true - } - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get the expected return value - assert.deepEqual(account, { - xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB', - secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE', - classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7', - address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7' - }) - }, - - 'generateXAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async ( - client - ) => { - // GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero - const options: GenerateAddressOptions = { - algorithm: ECDSA.secp256k1, - entropy: new Array(16).fill(0), - includeClassicAddress: true, - test: true - } - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get the expected return value - const response = Object.assign({}, responses.generateAddress, { - xAddress: 'TVG3TcCD58BD6MZqsNuTihdrhZwR8SzvYS8U87zvHsAcNw4' - }) - assert.deepEqual(account, response) - }, - - 'generateXAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async ( - client - ) => { - // GIVEN we want to use 'ed25519' with entropy of zero - const options: GenerateAddressOptions = { - algorithm: ECDSA.ed25519, - entropy: new Array(16).fill(0), - includeClassicAddress: true, - test: true - } - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get the expected return value - assert.deepEqual(account, { - xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo', - secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE', - classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7', - address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7' - }) - }, - - 'generateXAddress for test network use': async (client) => { - // GIVEN we want an X-address for test network use - const options: GenerateAddressOptions = {test: true} - - // WHEN generating an X-address - const account = client.generateXAddress(options) - - // THEN we get an object with xAddress starting with 'T' and a secret starting with 's' - assert.deepEqual( - account.xAddress.slice(0, 1), - 'T', - 'Test X-addresses start with T' - ) - assert.deepEqual( - account.secret.slice(0, 1), - 's', - `Secret ${account.secret} must start with 's'` - ) - } -} diff --git a/test/client/getBalances/index.ts b/test/client/getBalances/index.ts index e56d9575..6f48a190 100644 --- a/test/client/getBalances/index.ts +++ b/test/client/getBalances/index.ts @@ -1,5 +1,5 @@ import responses from '../../fixtures/responses' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/getFee/index.ts b/test/client/getFee/index.ts index 699ba855..c50d31ed 100644 --- a/test/client/getFee/index.ts +++ b/test/client/getFee/index.ts @@ -1,6 +1,6 @@ import assert from 'assert-diff' import rippled from '../../fixtures/rippled' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../../test/testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/getOrderbook/index.ts b/test/client/getOrderbook/index.ts index ed11a351..65f220a4 100644 --- a/test/client/getOrderbook/index.ts +++ b/test/client/getOrderbook/index.ts @@ -1,7 +1,7 @@ import assert from 'assert-diff' import responses from '../../fixtures/responses' import requests from '../../fixtures/requests' -import {TestSuite, assertResultMatch, assertRejects} from '../../utils' +import {TestSuite, assertResultMatch, assertRejects} from '../../testUtils' // import BigNumber from 'bignumber.js' // function checkSortingOfOrders(orders) { diff --git a/test/client/getPaths/index.ts b/test/client/getPaths/index.ts index 5d6b8ea2..0c27ffb6 100644 --- a/test/client/getPaths/index.ts +++ b/test/client/getPaths/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import { assertRejects, TestSuite } from '../../utils' +import { assertRejects, TestSuite } from '../../testUtils' import requests from '../../fixtures/requests' // import responses from '../../fixtures/responses' import addresses from '../../fixtures/addresses.json' diff --git a/test/client/getTrustlines/index.ts b/test/client/getTrustlines/index.ts index d7630623..a9a8a689 100644 --- a/test/client/getTrustlines/index.ts +++ b/test/client/getTrustlines/index.ts @@ -1,6 +1,6 @@ import addresses from '../../fixtures/addresses.json' import responses from '../../fixtures/responses' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const {getTrustlines: RESPONSE_FIXTURES} = responses /** diff --git a/test/client/hasNextPage/index.ts b/test/client/hasNextPage/index.ts index 2472ea1b..b5bed742 100644 --- a/test/client/hasNextPage/index.ts +++ b/test/client/hasNextPage/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/isConnected/index.ts b/test/client/isConnected/index.ts index 5bdf91d5..51ff97ce 100644 --- a/test/client/isConnected/index.ts +++ b/test/client/isConnected/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/isValidAddress/index.ts b/test/client/isValidAddress/index.ts index f3e6ccd8..744d9edf 100644 --- a/test/client/isValidAddress/index.ts +++ b/test/client/isValidAddress/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import addresses from '../../fixtures/addresses.json' export default { diff --git a/test/client/isValidSecret/index.ts b/test/client/isValidSecret/index.ts index b5d393d1..a016d438 100644 --- a/test/client/isValidSecret/index.ts +++ b/test/client/isValidSecret/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' export default { 'returns true for valid secret': async (client, address) => { diff --git a/test/client/prepareCheckCancel/index.ts b/test/client/prepareCheckCancel/index.ts index 80884bee..f65b3f18 100644 --- a/test/client/prepareCheckCancel/index.ts +++ b/test/client/prepareCheckCancel/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareCheckCash/index.ts b/test/client/prepareCheckCash/index.ts index ea1a24e7..36b191b2 100644 --- a/test/client/prepareCheckCash/index.ts +++ b/test/client/prepareCheckCash/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareCheckCreate/index.ts b/test/client/prepareCheckCreate/index.ts index 57233381..a9337060 100644 --- a/test/client/prepareCheckCreate/index.ts +++ b/test/client/prepareCheckCreate/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareEscrowCancellation/index.ts b/test/client/prepareEscrowCancellation/index.ts index ce205fd8..b56c67cc 100644 --- a/test/client/prepareEscrowCancellation/index.ts +++ b/test/client/prepareEscrowCancellation/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareEscrowCreation/index.ts b/test/client/prepareEscrowCreation/index.ts index fd9c1782..b1554825 100644 --- a/test/client/prepareEscrowCreation/index.ts +++ b/test/client/prepareEscrowCreation/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertRejects, assertResultMatch, TestSuite} from '../../utils' +import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} export const config = { diff --git a/test/client/prepareEscrowExecution/index.ts b/test/client/prepareEscrowExecution/index.ts index c3c4bdf3..4a68de19 100644 --- a/test/client/prepareEscrowExecution/index.ts +++ b/test/client/prepareEscrowExecution/index.ts @@ -1,4 +1,4 @@ -import {TestSuite, assertRejects, assertResultMatch} from '../../utils' +import {TestSuite, assertRejects, assertResultMatch} from '../../testUtils' import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' diff --git a/test/client/prepareOrder/index.ts b/test/client/prepareOrder/index.ts index 47d73c8f..6a403f7a 100644 --- a/test/client/prepareOrder/index.ts +++ b/test/client/prepareOrder/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertRejects, assertResultMatch, TestSuite} from '../../utils' +import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareOrderCancellation/index.ts b/test/client/prepareOrderCancellation/index.ts index 16012473..10fca979 100644 --- a/test/client/prepareOrderCancellation/index.ts +++ b/test/client/prepareOrderCancellation/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertRejects, assertResultMatch, TestSuite} from '../../utils' +import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/preparePayment/index.ts b/test/client/preparePayment/index.ts index c682dddb..e22639e8 100644 --- a/test/client/preparePayment/index.ts +++ b/test/client/preparePayment/index.ts @@ -1,4 +1,4 @@ -import {assertResultMatch, TestSuite, assertRejects} from '../../utils' +import {assertResultMatch, TestSuite, assertRejects} from '../../testUtils' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' import requests from '../../fixtures/requests' diff --git a/test/client/preparePaymentChannelClaim/index.ts b/test/client/preparePaymentChannelClaim/index.ts index ba194952..b446e61f 100644 --- a/test/client/preparePaymentChannelClaim/index.ts +++ b/test/client/preparePaymentChannelClaim/index.ts @@ -2,7 +2,7 @@ import assert from 'assert-diff' import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} const {preparePaymentChannelClaim: REQUEST_FIXTURES} = requests const {preparePaymentChannelClaim: RESPONSE_FIXTURES} = responses diff --git a/test/client/preparePaymentChannelCreate/index.ts b/test/client/preparePaymentChannelCreate/index.ts index 0530637b..4841b872 100644 --- a/test/client/preparePaymentChannelCreate/index.ts +++ b/test/client/preparePaymentChannelCreate/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} export const config = { diff --git a/test/client/preparePaymentChannelFund/index.ts b/test/client/preparePaymentChannelFund/index.ts index 51df4536..0b489724 100644 --- a/test/client/preparePaymentChannelFund/index.ts +++ b/test/client/preparePaymentChannelFund/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareSettings/index.ts b/test/client/prepareSettings/index.ts index 43d0f420..c67584fc 100644 --- a/test/client/prepareSettings/index.ts +++ b/test/client/prepareSettings/index.ts @@ -2,7 +2,7 @@ import assert from 'assert-diff' import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/prepareTicket/index.ts b/test/client/prepareTicket/index.ts index c7037895..4a6d2dca 100644 --- a/test/client/prepareTicket/index.ts +++ b/test/client/prepareTicket/index.ts @@ -1,4 +1,4 @@ -import {assertResultMatch, TestSuite} from '../../utils' +import {assertResultMatch, TestSuite} from '../../testUtils' // import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' // import requests from '../../fixtures/requests' diff --git a/test/client/prepareTransaction/index.ts b/test/client/prepareTransaction/index.ts index c2c22214..ece5181c 100644 --- a/test/client/prepareTransaction/index.ts +++ b/test/client/prepareTransaction/index.ts @@ -1,8 +1,9 @@ import {ValidationError} from 'xrpl-local/common/errors' // import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' +import {xrpToDrops, ISOTimeToRippleTime} from '../../../src/utils' import rippled from '../../fixtures/rippled' -import {assertRejects, assertResultMatch, TestSuite} from '../../utils' +import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} export const config = { @@ -1188,7 +1189,7 @@ export default { PublicKey: '32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A' // If cancelAfter is used, you must use RippleTime. - // You can use `iso8601ToRippleTime()` to convert to RippleTime. + // You can use `ISOTimeToRippleTime()` to convert to RippleTime. // Other fields are available (but not used in this test), // including `sourceTag` and `destinationTag`. @@ -1207,12 +1208,12 @@ export default { const txJSON = { Account: address, TransactionType: 'PaymentChannelCreate', - Amount: client.xrpToDrops('1'), // or '1000000' + Amount: xrpToDrops('1'), // or '1000000' Destination: 'rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW', SettleDelay: 86400, // Ensure this is in upper case if it is not already PublicKey: '32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A'.toUpperCase(), - CancelAfter: client.iso8601ToRippleTime('2017-02-17T15:04:57Z'), + CancelAfter: ISOTimeToRippleTime('2017-02-17T15:04:57Z'), SourceTag: 11747, DestinationTag: 23480 } @@ -1236,7 +1237,7 @@ export default { TransactionType: 'PaymentChannelFund', Channel: 'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198', - Amount: client.xrpToDrops('1') // or '1000000' + Amount: xrpToDrops('1') // or '1000000' } const response = await client.prepareTransaction(txJSON, localInstructions) assertResultMatch( @@ -1253,8 +1254,8 @@ export default { TransactionType: 'PaymentChannelFund', Channel: 'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198', - Amount: client.xrpToDrops('1'), // or '1000000' - Expiration: client.iso8601ToRippleTime('2017-02-17T15:04:57Z') + Amount: xrpToDrops('1'), // or '1000000' + Expiration: ISOTimeToRippleTime('2017-02-17T15:04:57Z') } const response = await client.prepareTransaction(txJSON) @@ -1300,8 +1301,8 @@ export default { TransactionType: 'PaymentChannelClaim', Channel: 'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198', - Balance: client.xrpToDrops('1'), // or '1000000' - Amount: client.xrpToDrops('1'), // or '1000000' + Balance: xrpToDrops('1'), // or '1000000' + Amount: xrpToDrops('1'), // or '1000000' Signature: '30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA3CD7B9B', PublicKey: @@ -1330,8 +1331,8 @@ export default { TransactionType: 'PaymentChannelClaim', Channel: 'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198', - Balance: client.xrpToDrops('1'), // or 1000000 - Amount: client.xrpToDrops('1'), // or 1000000 + Balance: xrpToDrops('1'), // or 1000000 + Amount: xrpToDrops('1'), // or 1000000 Signature: '30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA3CD7B9B', PublicKey: diff --git a/test/client/prepareTrustline/index.ts b/test/client/prepareTrustline/index.ts index d6d66c31..c4c4ef00 100644 --- a/test/client/prepareTrustline/index.ts +++ b/test/client/prepareTrustline/index.ts @@ -1,7 +1,7 @@ import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {assertRejects, assertResultMatch, TestSuite} from '../../utils' +import {assertRejects, assertResultMatch, TestSuite} from '../../testUtils' const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100} /** diff --git a/test/client/request/index.ts b/test/client/request/index.ts index 8350d2bf..1bb2087f 100644 --- a/test/client/request/index.ts +++ b/test/client/request/index.ts @@ -1,6 +1,6 @@ import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {TestSuite, assertResultMatch} from '../../utils' +import {TestSuite, assertResultMatch} from '../../testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/requestNextPage/index.ts b/test/client/requestNextPage/index.ts index f245286c..c11c91ef 100644 --- a/test/client/requestNextPage/index.ts +++ b/test/client/requestNextPage/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {assertRejects, TestSuite} from '../../utils' +import {assertRejects, TestSuite} from '../../testUtils' /** * Every test suite exports their tests in the default object. diff --git a/test/client/sign/index.ts b/test/client/sign/index.ts index 4d68d80b..6f32be13 100644 --- a/test/client/sign/index.ts +++ b/test/client/sign/index.ts @@ -4,7 +4,7 @@ import binary from 'ripple-binary-codec' import requests from '../../fixtures/requests' import responses from '../../fixtures/responses' import rippled from '../../fixtures/rippled' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' const {schemaValidator} = Client._PRIVATE const {sign: REQUEST_FIXTURES} = requests diff --git a/test/client/signPaymentChannelClaim/index.ts b/test/client/signPaymentChannelClaim/index.ts deleted file mode 100644 index b33d2168..00000000 --- a/test/client/signPaymentChannelClaim/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {TestSuite, assertResultMatch} from '../../utils' -import requests from '../../fixtures/requests' -import responses from '../../fixtures/responses' - -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - signPaymentChannelClaim: async (client, address) => { - const privateKey = - 'ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A' - const result = client.signPaymentChannelClaim( - requests.signPaymentChannelClaim.channel, - requests.signPaymentChannelClaim.amount, - privateKey - ) - assertResultMatch( - result, - responses.signPaymentChannelClaim, - 'signPaymentChannelClaim' - ) - } -} diff --git a/test/client/verifyPaymentChannelClaim/index.ts b/test/client/verifyPaymentChannelClaim/index.ts deleted file mode 100644 index bad29cdf..00000000 --- a/test/client/verifyPaymentChannelClaim/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import requests from '../../fixtures/requests' -import responses from '../../fixtures/responses' -import {assertResultMatch, TestSuite} from '../../utils' - -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'verifyPaymentChannelClaim': async (client, address) => { - const publicKey = - '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8' - const result = client.verifyPaymentChannelClaim( - requests.signPaymentChannelClaim.channel, - requests.signPaymentChannelClaim.amount, - responses.signPaymentChannelClaim, - publicKey - ) - assertResultMatch(result, true, 'verifyPaymentChannelClaim') - }, - - 'verifyPaymentChannelClaim - invalid': async (client, address) => { - const publicKey = - '03A6523FE4281DA48A6FD77FAF3CB77F5C7001ABA0B32BCEDE0369AC009758D7D9' - const result = client.verifyPaymentChannelClaim( - requests.signPaymentChannelClaim.channel, - requests.signPaymentChannelClaim.amount, - responses.signPaymentChannelClaim, - publicKey - ) - assertResultMatch(result, false, 'verifyPaymentChannelClaim') - } -} diff --git a/test/connection-test.ts b/test/connection-test.ts index f03bb7dc..2ab23d2f 100644 --- a/test/connection-test.ts +++ b/test/connection-test.ts @@ -3,7 +3,7 @@ import net from 'net' import assert from 'assert-diff' import setupClient from './setup-client' import {Client} from 'xrpl-local' -import {ignoreWebSocketDisconnect} from './utils' +import {ignoreWebSocketDisconnect} from './testUtils' const utils = Client._PRIVATE.ledgerUtils const TIMEOUT = 200000 // how long before each test case times out diff --git a/test/integration/integration-test.ts b/test/integration/integration-test.ts index 9a3781ff..ab5659ff 100644 --- a/test/integration/integration-test.ts +++ b/test/integration/integration-test.ts @@ -3,10 +3,11 @@ import assert from 'assert' import wallet from './wallet' import requests from '../fixtures/requests' import {Client} from 'xrpl-local' -import {isValidClassicAddress} from 'ripple-address-codec' import {payTo, ledgerAccept} from './utils' import {errors} from 'xrpl-local/common' -import {isValidSecret} from 'xrpl-local/common/utils' +import {isValidSecret} from 'xrpl-local/utils' +import { generateXAddress } from '../../src/utils/generateAddress' +import { isValidXAddress } from 'ripple-address-codec' // how long before each test case times out const TIMEOUT = 20000 @@ -160,7 +161,7 @@ function setupAccounts(testcase) { const promise = payTo(client, 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM') .then(() => payTo(client, wallet.getAddress())) - .then(() => payTo(client, testcase.newWallet.address)) + .then(() => payTo(client, testcase.newWallet.xAddress)) .then(() => payTo(client, 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc')) .then(() => payTo(client, 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q')) .then(() => { @@ -176,7 +177,7 @@ function setupAccounts(testcase) { .then(() => makeTrustLine( testcase, - testcase.newWallet.address, + testcase.newWallet.xAddress, testcase.newWallet.secret ) ) @@ -197,7 +198,7 @@ function setupAccounts(testcase) { } return makeOrder( testcase.client, - testcase.newWallet.address, + testcase.newWallet.xAddress, orderSpecification, testcase.newWallet.secret ) @@ -236,7 +237,7 @@ function suiteSetup(this: any) { setup .bind(this)(serverUrl) .then(() => ledgerAccept(this.client)) - .then(() => (this.newWallet = this.client.generateAddress())) + .then(() => (this.newWallet = generateXAddress())) // two times to give time to server to send `ledgerClosed` event // so getLedgerVersion will return right value .then(() => ledgerAccept(this.client)) @@ -501,9 +502,9 @@ describe('integration tests', function () { // }) it('generateWallet', function () { - const newWallet = this.client.generateAddress() - assert(newWallet && newWallet.address && newWallet.secret) - assert(isValidClassicAddress(newWallet.address)) + const newWallet = generateXAddress() + assert(newWallet && newWallet.xAddress && newWallet.secret) + assert(isValidXAddress(newWallet.xAddress)) assert(isValidSecret(newWallet.secret)) }) }) @@ -596,4 +597,4 @@ describe('integration tests - standalone rippled', function () { }) }) }) -}) +}) \ No newline at end of file diff --git a/test/mock-rippled.ts b/test/mock-rippled.ts index d98771d6..332cf5a7 100644 --- a/test/mock-rippled.ts +++ b/test/mock-rippled.ts @@ -9,7 +9,7 @@ import hashes from './fixtures/hashes.json' import transactionsResponse from './fixtures/rippled/account-tx' import accountLinesResponse from './fixtures/rippled/account-lines' import fullLedger from './fixtures/rippled/ledger-full-38129.json' -import {getFreePort} from './utils' +import {getFreePort} from './testUtils' import { Request } from '../src' function isUSD(json) { diff --git a/test/ripple-client-test-private.ts b/test/ripple-client-test-private.ts index d3a7259f..0bc17cc1 100644 --- a/test/ripple-client-test-private.ts +++ b/test/ripple-client-test-private.ts @@ -2,9 +2,10 @@ import assert from 'assert-diff' import _ from 'lodash' import {Client} from 'xrpl-local' import {RecursiveData} from 'xrpl-local/ledger/utils' -import {assertRejects} from './utils' +import {assertRejects} from './testUtils' import addresses from './fixtures/addresses.json' import setupClient from './setup-client' +import {toRippledAmount} from '../src' const {validate, schemaValidator, ledgerUtils} = Client._PRIVATE const address = addresses.ACCOUNT @@ -123,7 +124,7 @@ describe('Client', function () { it('common utils - toRippledAmount', async () => { const amount = {issuer: 'is', currency: 'c', value: 'v'} - assert.deepEqual(ledgerUtils.common.toRippledAmount(amount), { + assert.deepEqual(toRippledAmount(amount), { issuer: 'is', currency: 'c', value: 'v' diff --git a/test/ripple-client-test.ts b/test/ripple-client-test.ts index dae6e6fa..a64c8c7f 100644 --- a/test/ripple-client-test.ts +++ b/test/ripple-client-test.ts @@ -1,7 +1,7 @@ import setupClient from './setup-client' import {Client} from 'xrpl-local' import addresses from './fixtures/addresses.json' -import {getAllPublicMethods, loadTestSuites} from './utils' +import {getAllPublicMethods, loadTestSuites} from './testUtils' /** * Client Test Runner diff --git a/test/setup-client.ts b/test/setup-client.ts index 7fda03ab..a4d77e85 100644 --- a/test/setup-client.ts +++ b/test/setup-client.ts @@ -1,6 +1,6 @@ import {Client, BroadcastClient} from 'xrpl-local' import {createMockRippled} from './mock-rippled' -import {getFreePort} from './utils' +import {getFreePort} from './testUtils' function setupMockRippledConnection(testcase, port) { return new Promise((resolve, reject) => { diff --git a/test/shamap-test.ts b/test/shamap-test.ts index e1d125ef..1e4eb989 100644 --- a/test/shamap-test.ts +++ b/test/shamap-test.ts @@ -1,5 +1,5 @@ import assert from 'assert' -import {SHAMap, NodeType} from '../src/common/hashes/shamap' +import {SHAMap, NodeType} from '../src/utils/hashes/shamap' const TYPE_TRANSACTION_NO_METADATA = NodeType.TRANSACTION_NO_METADATA var HEX_ZERO = diff --git a/test/utils.ts b/test/testUtils.ts similarity index 99% rename from test/utils.ts rename to test/testUtils.ts index 6f8db88c..42b8ee90 100644 --- a/test/utils.ts +++ b/test/testUtils.ts @@ -147,4 +147,4 @@ export function ignoreWebSocketDisconnect(error: Error): void { return } throw error -} +} \ No newline at end of file diff --git a/test/client/computeLedgerHash/index.ts b/test/utils/computeLedgerHash.ts similarity index 57% rename from test/client/computeLedgerHash/index.ts rename to test/utils/computeLedgerHash.ts index 28b1d766..75055cd8 100644 --- a/test/client/computeLedgerHash/index.ts +++ b/test/utils/computeLedgerHash.ts @@ -1,35 +1,27 @@ import assert from 'assert-diff' -import requests from '../../fixtures/requests' -import responses from '../../fixtures/responses' -import {assertResultMatch, TestSuite} from '../../utils' +import {computeLedgerHeaderHash} from '../../src/utils' +import {ValidationError} from '../../src/common/errors' +import requests from '../fixtures/requests' +import responses from '../fixtures/responses' +import {assertResultMatch} from '../testUtils' const {computeLedgerHash: REQUEST_FIXTURES} = requests function getNewLedger() { return JSON.parse(JSON.stringify(responses.getLedger.full)) } -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'given corrupt data - should fail': async (client, address) => { +describe('Compute Ledger Hash', function () { + it('given corrupt data - should fail', () => { const ledger = getNewLedger() - // assert.strictEqual( - // // @ts-ignore - // ledger.transactions[0].rawTransaction, - // '{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Amount":"10000000000","Destination":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Fee":"10","Flags":0,"Sequence":62,"SigningPubKey":"034AADB09CFF4A4804073701EC53C3510CDC95917C2BB0150FB742D0C66E6CEE9E","TransactionType":"Payment","TxnSignature":"3045022022EB32AECEF7C644C891C19F87966DF9C62B1F34BABA6BE774325E4BB8E2DD62022100A51437898C28C2B297112DF8131F2BB39EA5FE613487DDD611525F1796264639","hash":"3B1A4E1C9BB6A7208EB146BCDB86ECEA6068ED01466D933528CA2B4C64F753EF","meta":{"AffectedNodes":[{"CreatedNode":{"LedgerEntryType":"AccountRoot","LedgerIndex":"4C6ACBD635B0F07101F7FA25871B0925F8836155462152172755845CE691C49E","NewFields":{"Account":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Balance":"10000000000","Sequence":1}}},{"ModifiedNode":{"FinalFields":{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Balance":"981481999380","Flags":0,"OwnerCount":0,"Sequence":63},"LedgerEntryType":"AccountRoot","LedgerIndex":"B33FDD5CF3445E1A7F2BE9B06336BEBD73A5E3EE885D3EF93F7E3E2992E46F1A","PreviousFields":{"Balance":"991481999390","Sequence":62},"PreviousTxnID":"2485FDC606352F1B0785DA5DE96FB9DBAF43EB60ECBB01B7F6FA970F512CDA5F","PreviousTxnLgrSeq":31317}}],"TransactionIndex":0,"TransactionResult":"tesSUCCESS"},"ledger_index":38129}' - // ) // @ts-ignore - Change Amount to 12000000000 ledger.transactions[0].rawTransaction = '{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Amount":"12000000000","Destination":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Fee":"10","Flags":0,"Sequence":62,"SigningPubKey":"034AADB09CFF4A4804073701EC53C3510CDC95917C2BB0150FB742D0C66E6CEE9E","TransactionType":"Payment","TxnSignature":"3045022022EB32AECEF7C644C891C19F87966DF9C62B1F34BABA6BE774325E4BB8E2DD62022100A51437898C28C2B297112DF8131F2BB39EA5FE613487DDD611525F1796264639","hash":"3B1A4E1C9BB6A7208EB146BCDB86ECEA6068ED01466D933528CA2B4C64F753EF","meta":{"AffectedNodes":[{"CreatedNode":{"LedgerEntryType":"AccountRoot","LedgerIndex":"4C6ACBD635B0F07101F7FA25871B0925F8836155462152172755845CE691C49E","NewFields":{"Account":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Balance":"10000000000","Sequence":1}}},{"ModifiedNode":{"FinalFields":{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Balance":"981481999380","Flags":0,"OwnerCount":0,"Sequence":63},"LedgerEntryType":"AccountRoot","LedgerIndex":"B33FDD5CF3445E1A7F2BE9B06336BEBD73A5E3EE885D3EF93F7E3E2992E46F1A","PreviousFields":{"Balance":"991481999390","Sequence":62},"PreviousTxnID":"2485FDC606352F1B0785DA5DE96FB9DBAF43EB60ECBB01B7F6FA970F512CDA5F","PreviousTxnLgrSeq":31317}}],"TransactionIndex":0,"TransactionResult":"tesSUCCESS"},"ledger_index":38129}' ledger.parentCloseTime = ledger.closeTime let hash try { - hash = client.computeLedgerHash(ledger, {computeTreeHashes: true}) + hash = computeLedgerHeaderHash(ledger, {computeTreeHashes: true}) } catch (error) { - assert(error instanceof client.errors.ValidationError) + assert(error instanceof ValidationError) assert.strictEqual( error.message, 'transactionHash in header does not match computed hash of transactions' @@ -46,27 +38,18 @@ export default { false, 'Should throw ValidationError instead of producing hash: ' + hash ) - }, + }) - 'given ledger without raw transactions - should throw': async ( - client, - address - ) => { + it('given ledger without raw transactions - should throw', () => { const ledger = getNewLedger() - // assert.strictEqual( - // // @ts-ignore - // ledger.transactions[0].rawTransaction, - // '{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Amount":"10000000000","Destination":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Fee":"10","Flags":0,"Sequence":62,"SigningPubKey":"034AADB09CFF4A4804073701EC53C3510CDC95917C2BB0150FB742D0C66E6CEE9E","TransactionType":"Payment","TxnSignature":"3045022022EB32AECEF7C644C891C19F87966DF9C62B1F34BABA6BE774325E4BB8E2DD62022100A51437898C28C2B297112DF8131F2BB39EA5FE613487DDD611525F1796264639","hash":"3B1A4E1C9BB6A7208EB146BCDB86ECEA6068ED01466D933528CA2B4C64F753EF","meta":{"AffectedNodes":[{"CreatedNode":{"LedgerEntryType":"AccountRoot","LedgerIndex":"4C6ACBD635B0F07101F7FA25871B0925F8836155462152172755845CE691C49E","NewFields":{"Account":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Balance":"10000000000","Sequence":1}}},{"ModifiedNode":{"FinalFields":{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Balance":"981481999380","Flags":0,"OwnerCount":0,"Sequence":63},"LedgerEntryType":"AccountRoot","LedgerIndex":"B33FDD5CF3445E1A7F2BE9B06336BEBD73A5E3EE885D3EF93F7E3E2992E46F1A","PreviousFields":{"Balance":"991481999390","Sequence":62},"PreviousTxnID":"2485FDC606352F1B0785DA5DE96FB9DBAF43EB60ECBB01B7F6FA970F512CDA5F","PreviousTxnLgrSeq":31317}}],"TransactionIndex":0,"TransactionResult":"tesSUCCESS"},"ledger_index":38129}' - // ) - // Delete rawTransaction // @ts-ignore - Delete rawTransaction delete ledger.transactions[0].rawTransaction ledger.parentCloseTime = ledger.closeTime let hash try { - hash = client.computeLedgerHash(ledger, {computeTreeHashes: true}) + hash = computeLedgerHeaderHash(ledger, {computeTreeHashes: true}) } catch (error) { - assert(error instanceof client.errors.ValidationError) + assert(error instanceof ValidationError) assert.strictEqual( error.message, 'ledger' + ' is missing raw transactions' @@ -77,12 +60,9 @@ export default { false, 'Should throw ValidationError instead of producing hash: ' + hash ) - }, + }) - 'given ledger without state or transactions - only compute ledger hash': async ( - client, - address - ) => { + it('given ledger without state or transactions - only compute ledger hash', () => { const ledger = getNewLedger() assert.strictEqual( // @ts-ignore @@ -90,8 +70,7 @@ export default { '{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Amount":"10000000000","Destination":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Fee":"10","Flags":0,"Sequence":62,"SigningPubKey":"034AADB09CFF4A4804073701EC53C3510CDC95917C2BB0150FB742D0C66E6CEE9E","TransactionType":"Payment","TxnSignature":"3045022022EB32AECEF7C644C891C19F87966DF9C62B1F34BABA6BE774325E4BB8E2DD62022100A51437898C28C2B297112DF8131F2BB39EA5FE613487DDD611525F1796264639","hash":"3B1A4E1C9BB6A7208EB146BCDB86ECEA6068ED01466D933528CA2B4C64F753EF","meta":{"AffectedNodes":[{"CreatedNode":{"LedgerEntryType":"AccountRoot","LedgerIndex":"4C6ACBD635B0F07101F7FA25871B0925F8836155462152172755845CE691C49E","NewFields":{"Account":"rLQBHVhFnaC5gLEkgr6HgBJJ3bgeZHg9cj","Balance":"10000000000","Sequence":1}}},{"ModifiedNode":{"FinalFields":{"Account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","Balance":"981481999380","Flags":0,"OwnerCount":0,"Sequence":63},"LedgerEntryType":"AccountRoot","LedgerIndex":"B33FDD5CF3445E1A7F2BE9B06336BEBD73A5E3EE885D3EF93F7E3E2992E46F1A","PreviousFields":{"Balance":"991481999390","Sequence":62},"PreviousTxnID":"2485FDC606352F1B0785DA5DE96FB9DBAF43EB60ECBB01B7F6FA970F512CDA5F","PreviousTxnLgrSeq":31317}}],"TransactionIndex":0,"TransactionResult":"tesSUCCESS"},"ledger_index":38129}' ) ledger.parentCloseTime = ledger.closeTime - const computeLedgerHash = client.computeLedgerHash - const ValidationError = client.errors.ValidationError + const computeLedgerHash = computeLedgerHeaderHash function testCompute(ledger, expectedError) { let hash = computeLedgerHash(ledger) assert.strictEqual( @@ -119,11 +98,11 @@ export default { testCompute(ledger, 'transactions property is missing from the ledger') ledger.transactions = transactions testCompute(ledger, 'rawState property is missing from the ledger') - }, + }) - 'wrong hash': async (client, address) => { + it('wrong hash', () => { const ledger = getNewLedger() - assertResultMatch(ledger, getNewLedger(), 'getLedger') + assertResultMatch(ledger, responses.getLedger.full, 'getLedger') const newLedger = { ...ledger, parentCloseTime: ledger.closeTime, @@ -131,38 +110,38 @@ export default { 'D9ABF622DA26EEEE48203085D4BC23B0F77DC6F8724AC33D975DA3CA492D2E44' } assert.throws(() => { - client.computeLedgerHash(newLedger) + computeLedgerHeaderHash(newLedger) }, /does not match computed hash of state/) - }, + }) - 'computeLedgerHash': async (client, address) => { + it('computeLedgerHash', () => { const header = REQUEST_FIXTURES.header - const ledgerHash = client.computeLedgerHash(header) + const ledgerHash = computeLedgerHeaderHash(header) assert.strictEqual( ledgerHash, 'F4D865D83EB88C1A1911B9E90641919A1314F36E1B099F8E95FE3B7C77BE3349' ) - }, + }) - 'computeLedgerHash - with transactions': async (client, address) => { + it('computeLedgerHash - with transactions', () => { const header = { ...REQUEST_FIXTURES.header, transactionHash: undefined, rawTransactions: JSON.stringify(REQUEST_FIXTURES.transactions) } - const ledgerHash = client.computeLedgerHash(header) + const ledgerHash = computeLedgerHeaderHash(header) assert.strictEqual( ledgerHash, 'F4D865D83EB88C1A1911B9E90641919A1314F36E1B099F8E95FE3B7C77BE3349' ) - }, + }) - 'computeLedgerHash - incorrent transaction_hash': async (client, address) => { + it('computeLedgerHash - incorrent transaction_hash', () => { const header = Object.assign({}, REQUEST_FIXTURES.header, { transactionHash: '325EACC5271322539EEEC2D6A5292471EF1B3E72AE7180533EFC3B8F0AD435C9' }) header.rawTransactions = JSON.stringify(REQUEST_FIXTURES.transactions) - assert.throws(() => client.computeLedgerHash(header)) - } -} + assert.throws(() => computeLedgerHeaderHash(header)) + }) +}) diff --git a/test/client/dropsToXrp/index.ts b/test/utils/dropsToXrp.ts similarity index 52% rename from test/client/dropsToXrp/index.ts rename to test/utils/dropsToXrp.ts index 62027cea..ed55e655 100644 --- a/test/client/dropsToXrp/index.ts +++ b/test/utils/dropsToXrp.ts @@ -1,119 +1,123 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' import BigNumber from 'bignumber.js' +import {dropsToXrp} from '../../src/utils' -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'works with a typical amount': async (client) => { - const xrp = client.dropsToXrp('2000000') +describe('Drops To XRP', function () { + it('works with a typical amount', () => { + const xrp = dropsToXrp('2000000') assert.strictEqual(xrp, '2', '2 million drops equals 2 XRP') - }, - 'works with fractions': async (client) => { - let xrp = client.dropsToXrp('3456789') + }) + + it('works with fractions', () => { + let xrp = dropsToXrp('3456789') assert.strictEqual(xrp, '3.456789', '3,456,789 drops equals 3.456789 XRP') - xrp = client.dropsToXrp('3400000') + xrp = dropsToXrp('3400000') assert.strictEqual(xrp, '3.4', '3,400,000 drops equals 3.4 XRP') - xrp = client.dropsToXrp('1') + xrp = dropsToXrp('1') assert.strictEqual(xrp, '0.000001', '1 drop equals 0.000001 XRP') - xrp = client.dropsToXrp('1.0') + xrp = dropsToXrp('1.0') assert.strictEqual(xrp, '0.000001', '1.0 drops equals 0.000001 XRP') - xrp = client.dropsToXrp('1.00') + xrp = dropsToXrp('1.00') assert.strictEqual(xrp, '0.000001', '1.00 drops equals 0.000001 XRP') - }, - 'works with zero': async (client) => { - let xrp = client.dropsToXrp('0') + }) + + it('works with zero', () => { + let xrp = dropsToXrp('0') assert.strictEqual(xrp, '0', '0 drops equals 0 XRP') // negative zero is equivalent to zero - xrp = client.dropsToXrp('-0') + xrp = dropsToXrp('-0') assert.strictEqual(xrp, '0', '-0 drops equals 0 XRP') - xrp = client.dropsToXrp('0.00') + xrp = dropsToXrp('0.00') assert.strictEqual(xrp, '0', '0.00 drops equals 0 XRP') - xrp = client.dropsToXrp('000000000') + xrp = dropsToXrp('000000000') assert.strictEqual(xrp, '0', '000000000 drops equals 0 XRP') - }, - 'works with a negative value': async (client) => { - const xrp = client.dropsToXrp('-2000000') + }) + + it('works with a negative value', () => { + const xrp = dropsToXrp('-2000000') assert.strictEqual(xrp, '-2', '-2 million drops equals -2 XRP') - }, - 'works with a value ending with a decimal point': async (client) => { - let xrp = client.dropsToXrp('2000000.') + }) + + it('works with a value ending with a decimal point', () => { + let xrp = dropsToXrp('2000000.') assert.strictEqual(xrp, '2', '2000000. drops equals 2 XRP') - xrp = client.dropsToXrp('-2000000.') + xrp = dropsToXrp('-2000000.') assert.strictEqual(xrp, '-2', '-2000000. drops equals -2 XRP') - }, - 'works with BigNumber objects': async (client) => { - let xrp = client.dropsToXrp(new BigNumber(2000000)) + }) + + it('works with BigNumber objects', () => { + let xrp = dropsToXrp(new BigNumber(2000000)) assert.strictEqual(xrp, '2', '(BigNumber) 2 million drops equals 2 XRP') - xrp = client.dropsToXrp(new BigNumber(-2000000)) + xrp = dropsToXrp(new BigNumber(-2000000)) assert.strictEqual(xrp, '-2', '(BigNumber) -2 million drops equals -2 XRP') - xrp = client.dropsToXrp(new BigNumber(2345678)) + xrp = dropsToXrp(new BigNumber(2345678)) assert.strictEqual( xrp, '2.345678', '(BigNumber) 2,345,678 drops equals 2.345678 XRP' ) - xrp = client.dropsToXrp(new BigNumber(-2345678)) + xrp = dropsToXrp(new BigNumber(-2345678)) assert.strictEqual( xrp, '-2.345678', '(BigNumber) -2,345,678 drops equals -2.345678 XRP' ) - }, - 'works with a number': async (client) => { + }) + + it('works with a number', () => { // This is not recommended. Use strings or BigNumber objects to avoid precision errors. - let xrp = client.dropsToXrp(2000000) + let xrp = dropsToXrp(2000000) assert.strictEqual(xrp, '2', '(number) 2 million drops equals 2 XRP') - xrp = client.dropsToXrp(-2000000) + xrp = dropsToXrp(-2000000) assert.strictEqual(xrp, '-2', '(number) -2 million drops equals -2 XRP') - }, - 'throws with an amount with too many decimal places': async (client) => { + }) + + it('throws with an amount with too many decimal places', () => { assert.throws(() => { - client.dropsToXrp('1.2') + dropsToXrp('1.2') }, /has too many decimal places/) assert.throws(() => { - client.dropsToXrp('0.10') + dropsToXrp('0.10') }, /has too many decimal places/) - }, - 'throws with an invalid value': async (client) => { + }) + + it('throws with an invalid value', () => { assert.throws(() => { - client.dropsToXrp('FOO') + dropsToXrp('FOO') }, /invalid value/) assert.throws(() => { - client.dropsToXrp('1e-7') + dropsToXrp('1e-7') }, /invalid value/) assert.throws(() => { - client.dropsToXrp('2,0') + dropsToXrp('2,0') }, /invalid value/) assert.throws(() => { - client.dropsToXrp('.') + dropsToXrp('.') }, /dropsToXrp: invalid value '\.', should be a BigNumber or string-encoded number\./) - }, - 'throws with an amount more than one decimal point': async (client) => { + }) + + it('throws with an amount more than one decimal point', () => { assert.throws(() => { - client.dropsToXrp('1.0.0') + dropsToXrp('1.0.0') }, /dropsToXrp: invalid value '1\.0\.0'/) assert.throws(() => { - client.dropsToXrp('...') + dropsToXrp('...') }, /dropsToXrp: invalid value '\.\.\.'/) - } -} + }) +}) diff --git a/test/client/generateAddress/index.ts b/test/utils/generateAddress.ts similarity index 63% rename from test/client/generateAddress/index.ts rename to test/utils/generateAddress.ts index d2ef2b91..329bb3a8 100644 --- a/test/client/generateAddress/index.ts +++ b/test/utils/generateAddress.ts @@ -1,17 +1,11 @@ import assert from 'assert-diff' -import responses from '../../fixtures/responses' -import {TestSuite} from '../../utils' -import {GenerateAddressOptions} from '../../../src/offline/generate-address' -import ECDSA from '../../../src/common/ecdsa' -const {generateAddress: RESPONSE_FIXTURES} = responses +import responses from '../fixtures/responses' +import {generateXAddress, GenerateAddressOptions} from '../../src/utils/generateAddress' +import ECDSA from '../../src/common/ecdsa' +import {UnexpectedError} from '../../src/common/errors' -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'generateAddress': async (client) => { +describe('Generate Address', function () { + it('generateAddress', () => { // GIVEN entropy of all zeros function random() { return new Array(16).fill(0) @@ -19,14 +13,14 @@ export default { assert.deepEqual( // WHEN generating an address - client.generateAddress({entropy: random()}), + generateXAddress({entropy: random()}), // THEN we get the expected return value - RESPONSE_FIXTURES + responses.generateXAddress ) - }, + }) - 'generateAddress invalid entropy': async (client) => { + it('generateAddress invalid entropy', () => { assert.throws(() => { // GIVEN entropy of 1 byte function random() { @@ -34,45 +28,45 @@ export default { } // WHEN generating an address - client.generateAddress({entropy: random()}) + generateXAddress({entropy: random()}) // THEN an UnexpectedError is thrown // because 16 bytes of entropy are required - }, client.errors.UnexpectedError) - }, + }, UnexpectedError) + }) - 'generateAddress with no options object': async (client) => { + it('generateAddress with no options object', () => { // GIVEN no options // WHEN generating an address - const account = client.generateAddress() + const account = generateXAddress() - // THEN we get an object with an address starting with 'r' and a secret starting with 's' - assert(account.address.startsWith('r'), 'Address must start with `r`') + // THEN we get an object with an xAddress starting with 'x' and a secret starting with 's' + assert(account.xAddress.startsWith('X'), 'Address must start with `X`') assert(account.secret.startsWith('s'), 'Secret must start with `s`') - }, + }) - 'generateAddress with empty options object': async (client) => { + it('generateAddress with empty options object', () => { // GIVEN an empty options object const options = {} // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) - // THEN we get an object with an address starting with 'r' and a secret starting with 's' - assert(account.address.startsWith('r'), 'Address must start with `r`') + // THEN we get an object with an xAddress starting with 'x' and a secret starting with 's' + assert(account.xAddress.startsWith('X'), 'Address must start with `X`') assert(account.secret.startsWith('s'), 'Secret must start with `s`') - }, + }) - 'generateAddress with algorithm `ecdsa-secp256k1`': async (client) => { + it('generateAddress with algorithm `ecdsa-secp256k1`', () => { // GIVEN we want to use 'ecdsa-secp256k1' - const options: GenerateAddressOptions = {algorithm: ECDSA.secp256k1} + const options: GenerateAddressOptions = {algorithm: ECDSA.secp256k1, includeClassicAddress: true} // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get an object with an address starting with 'r' and a secret starting with 's' (not 'sEd') - assert(account.address.startsWith('r'), 'Address must start with `r`') + assert(account.classicAddress.startsWith('r'), 'Address must start with `r`') assert.deepEqual( account.secret.slice(0, 1), 's', @@ -83,27 +77,25 @@ export default { 'sEd', `secp256k1 secret ${account.secret} must not start with 'sEd'` ) - }, + }) - 'generateAddress with algorithm `ed25519`': async (client) => { + it('generateAddress with algorithm `ed25519`', () => { // GIVEN we want to use 'ed25519' - const options: GenerateAddressOptions = {algorithm: ECDSA.ed25519} + const options: GenerateAddressOptions = {algorithm: ECDSA.ed25519, includeClassicAddress: true} // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get an object with an address starting with 'r' and a secret starting with 'sEd' - assert(account.address.startsWith('r'), 'Address must start with `r`') + assert(account.classicAddress.startsWith('r'), 'Address must start with `r`') assert.deepEqual( account.secret.slice(0, 3), 'sEd', `Ed25519 secret ${account.secret} must start with 'sEd'` ) - }, + }) - 'generateAddress with algorithm `ecdsa-secp256k1` and given entropy': async ( - client - ) => { + it('generateAddress with algorithm `ecdsa-secp256k1` and given entropy', () => { // GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero const options: GenerateAddressOptions = { algorithm: ECDSA.secp256k1, @@ -111,13 +103,13 @@ export default { } // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get the expected return value - assert.deepEqual(account, responses.generateAddress) - }, + assert.deepEqual(account, responses.generateXAddress) + }) - 'generateAddress with algorithm `ed25519` and given entropy': async (client) => { + it('generateAddress with algorithm `ed25519` and given entropy', () => { // GIVEN we want to use 'ed25519' with entropy of zero const options: GenerateAddressOptions = { algorithm: ECDSA.ed25519, @@ -125,22 +117,17 @@ export default { } // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get the expected return value assert.deepEqual(account, { // generateAddress return value always includes xAddress to encourage X-address adoption xAddress: 'X7xq1YJ4xmLSGGLhuakFQB9CebWYthQkgsvFC4LGFH871HB', - - classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7', - address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7', secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE' }) - }, + }) - 'generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address': async ( - client - ) => { + it('generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address', () => { // GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero const options: GenerateAddressOptions = { algorithm: ECDSA.secp256k1, @@ -149,15 +136,13 @@ export default { } // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get the expected return value assert.deepEqual(account, responses.generateAddress) - }, + }) - 'generateAddress with algorithm `ed25519` and given entropy; include classic address': async ( - client - ) => { + it('generateAddress with algorithm `ed25519` and given entropy; include classic address', () => { // GIVEN we want to use 'ed25519' with entropy of zero const options: GenerateAddressOptions = { algorithm: ECDSA.ed25519, @@ -166,7 +151,7 @@ export default { } // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get the expected return value assert.deepEqual(account, { @@ -177,11 +162,9 @@ export default { classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7', address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7' }) - }, + }) - 'generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use': async ( - client - ) => { + it('generateAddress with algorithm `ecdsa-secp256k1` and given entropy; include classic address; for test network use', () => { // GIVEN we want to use 'ecdsa-secp256k1' with entropy of zero const options: GenerateAddressOptions = { algorithm: ECDSA.secp256k1, @@ -191,7 +174,7 @@ export default { } // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get the expected return value const response = Object.assign({}, responses.generateAddress, { @@ -199,11 +182,9 @@ export default { xAddress: 'TVG3TcCD58BD6MZqsNuTihdrhZwR8SzvYS8U87zvHsAcNw4' }) assert.deepEqual(account, response) - }, + }) - 'generateAddress with algorithm `ed25519` and given entropy; include classic address; for test network use': async ( - client - ) => { + it('generateAddress with algorithm `ed25519` and given entropy; include classic address; for test network use', () => { // GIVEN we want to use 'ed25519' with entropy of zero const options: GenerateAddressOptions = { algorithm: ECDSA.ed25519, @@ -213,25 +194,24 @@ export default { } // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get the expected return value assert.deepEqual(account, { // generateAddress return value always includes xAddress to encourage X-address adoption xAddress: 'T7t4HeTMF5tT68agwuVbJwu23ssMPeh8dDtGysZoQiij1oo', - secret: 'sEdSJHS4oiAdz7w2X2ni1gFiqtbJHqE', classicAddress: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7', address: 'r9zRhGr7b6xPekLvT6wP4qNdWMryaumZS7' }) - }, + }) - 'generateAddress for test network use': async (client) => { + it('generateAddress for test network use', () => { // GIVEN we want an address for test network use const options: GenerateAddressOptions = {test: true} // WHEN generating an address - const account = client.generateAddress(options) + const account = generateXAddress(options) // THEN we get an object with xAddress starting with 'T' and a secret starting with 's' @@ -247,5 +227,5 @@ export default { 's', `Secret ${account.secret} must start with 's'` ) - } -} + }) +}) \ No newline at end of file diff --git a/test/hashes-test.ts b/test/utils/hashesTest.ts similarity index 81% rename from test/hashes-test.ts rename to test/utils/hashesTest.ts index 3e99376c..2e9e56b0 100644 --- a/test/hashes-test.ts +++ b/test/utils/hashesTest.ts @@ -1,6 +1,15 @@ import assert from 'assert' import fs from 'fs' -import * as hashes from '../src/common/hashes' +import { + computeStateTreeHash, + computeTransactionTreeHash, + computeAccountRootIndex, + computeTrustlineHash, + computeOfferIndex, + computeSignerListIndex, + computeEscrowHash, + computePaymentChannelHash +} from '../../src/utils/hashes' /** * Expects a corresponding ledger dump in $repo/test/fixtures/rippled folder @@ -8,7 +17,7 @@ import * as hashes from '../src/common/hashes' function createLedgerTest(ledgerIndex: number) { describe(String(ledgerIndex), function () { var path = - __dirname + '/fixtures/rippled/ledger-full-' + ledgerIndex + '.json' + __dirname + '/../fixtures/rippled/ledger-full-' + ledgerIndex + '.json' var ledgerRaw = fs.readFileSync(path, {encoding: 'utf8'}) var ledgerJSON = JSON.parse(ledgerRaw) @@ -21,14 +30,14 @@ function createLedgerTest(ledgerIndex: number) { it('has account_hash of ' + ledgerJSON.account_hash, function () { assert.equal( ledgerJSON.account_hash, - hashes.computeStateTreeHash(ledgerJSON.accountState) + computeStateTreeHash(ledgerJSON.accountState) ) }) } it('has transaction_hash of ' + ledgerJSON.transaction_hash, function () { assert.equal( ledgerJSON.transaction_hash, - hashes.computeTransactionTreeHash(ledgerJSON.transactions) + computeTransactionTreeHash(ledgerJSON.transactions) ) }) }) @@ -47,7 +56,7 @@ describe('Ledger', function () { var account = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh' var expectedEntryHash = '2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8' - var actualEntryHash = hashes.computeAccountLedgerObjectID(account) + var actualEntryHash = computeAccountRootIndex(account) assert.equal(actualEntryHash, expectedEntryHash) }) @@ -61,12 +70,12 @@ describe('Ledger', function () { var expectedEntryHash = 'C683B5BB928F025F1E860D9D69D6C554C2202DE0D45877ADB3077DA4CB9E125C' - var actualEntryHash1 = hashes.computeTrustlineHash( + var actualEntryHash1 = computeTrustlineHash( account1, account2, currency ) - var actualEntryHash2 = hashes.computeTrustlineHash( + var actualEntryHash2 = computeTrustlineHash( account2, account1, currency @@ -83,12 +92,12 @@ describe('Ledger', function () { var expectedEntryHash = 'AE9ADDC584358E5847ADFC971834E471436FC3E9DE6EA1773DF49F419DC0F65E' - var actualEntryHash1 = hashes.computeTrustlineHash( + var actualEntryHash1 = computeTrustlineHash( account1, account2, currency ) - var actualEntryHash2 = hashes.computeTrustlineHash( + var actualEntryHash2 = computeTrustlineHash( account2, account1, currency @@ -105,18 +114,18 @@ describe('Ledger', function () { var sequence = 137 var expectedEntryHash = '03F0AED09DEEE74CEF85CD57A0429D6113507CF759C597BABB4ADB752F734CE3' - var actualEntryHash = hashes.computeOrderID(account, sequence) + var actualEntryHash = computeOfferIndex(account, sequence) assert.equal(actualEntryHash, expectedEntryHash) }) }) - describe('computeSignerListLedgerObjectID', function () { + describe('computeSignerListIndex', function () { it('will calculate the SignerList index for r32UufnaCGL82HubijgJGDmdE5hac7ZvLw', function () { var account = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh' var expectedEntryHash = '778365D5180F5DF3016817D1F318527AD7410D83F8636CF48C43E8AF72AB49BF' - var actualEntryHash = hashes.computeSignerListLedgerObjectID(account) + var actualEntryHash = computeSignerListIndex(account) assert.equal(actualEntryHash, expectedEntryHash) }) }) @@ -127,7 +136,7 @@ describe('Ledger', function () { var sequence = 84 var expectedEntryHash = '61E8E8ED53FA2CEBE192B23897071E9A75217BF5A410E9CB5B45AAB7AECA567A' - var actualEntryHash = hashes.computeEscrowHash(account, sequence) + var actualEntryHash = computeEscrowHash(account, sequence) assert.equal(actualEntryHash, expectedEntryHash) }) @@ -140,7 +149,7 @@ describe('Ledger', function () { var sequence = 82 var expectedEntryHash = 'E35708503B3C3143FB522D749AAFCC296E8060F0FB371A9A56FAE0B1ED127366' - var actualEntryHash = hashes.computePaymentChannelHash( + var actualEntryHash = computePaymentChannelHash( account, dstAccount, sequence diff --git a/test/utils/signPaymentChannelClaim.ts b/test/utils/signPaymentChannelClaim.ts new file mode 100644 index 00000000..f2e0d4cb --- /dev/null +++ b/test/utils/signPaymentChannelClaim.ts @@ -0,0 +1,26 @@ +import {assertResultMatch} from '../testUtils' +import responses from '../fixtures/responses' +import signPaymentChannelClaim from '../../src/utils/signPaymentChannelClaim' + + + +describe('signPaymentChannelClaim', function () { + it('basic signature matches', () => { + + const channel = "3E18C05AD40319B809520F1A136370C4075321B285217323396D6FD9EE1E9037" + const amount = ".00001" + const privateKey = 'ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A' + + const result = signPaymentChannelClaim( + channel, + amount, + privateKey + ) + + assertResultMatch( + result, + responses.signPaymentChannelClaim, + 'signPaymentChannelClaim' + ) + }) +}) diff --git a/test/utils/verifyPaymentChannelClaim.ts b/test/utils/verifyPaymentChannelClaim.ts new file mode 100644 index 00000000..534c228b --- /dev/null +++ b/test/utils/verifyPaymentChannelClaim.ts @@ -0,0 +1,30 @@ +import {verifyPaymentChannelClaim} from '../../src' +import requests from '../fixtures/requests' +import responses from '../fixtures/responses' +import {assertResultMatch} from '../testUtils' + +describe('Verify Payment Channel Claim', function () { + it('basic verification works', () => { + const publicKey = + '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8' + const result = verifyPaymentChannelClaim( + requests.signPaymentChannelClaim.channel, + requests.signPaymentChannelClaim.amount, + responses.signPaymentChannelClaim, + publicKey + ) + assertResultMatch(result, true, 'verifyPaymentChannelClaim') + }) + + it('invalid payment channel claim fails', () => { + const publicKey = + '03A6523FE4281DA48A6FD77FAF3CB77F5C7001ABA0B32BCEDE0369AC009758D7D9' + const result = verifyPaymentChannelClaim( + requests.signPaymentChannelClaim.channel, + requests.signPaymentChannelClaim.amount, + responses.signPaymentChannelClaim, + publicKey + ) + assertResultMatch(result, false, 'verifyPaymentChannelClaim') + }) +}) diff --git a/test/client/xrpToDrops/index.ts b/test/utils/xrpToDrops.ts similarity index 51% rename from test/client/xrpToDrops/index.ts rename to test/utils/xrpToDrops.ts index 65dfa1e6..a72086ea 100644 --- a/test/client/xrpToDrops/index.ts +++ b/test/utils/xrpToDrops.ts @@ -1,104 +1,108 @@ import assert from 'assert-diff' import BigNumber from 'bignumber.js' -import {TestSuite} from '../../utils' +import {xrpToDrops} from '../../src/utils' -/** - * Every test suite exports their tests in the default object. - * - Check out the "TestSuite" type for documentation on the interface. - * - Check out "test/client/index.ts" for more information about the test runner. - */ -export default { - 'works with a typical amount': function (client) { - const drops = client.xrpToDrops('2') +describe('XRP To Drops', function () { + it('works with a typical amount', () => { + const drops = xrpToDrops('2') assert.strictEqual(drops, '2000000', '2 XRP equals 2 million drops') - }, - 'works with fractions': function (client) { - let drops = client.xrpToDrops('3.456789') + }) + + it('works with fractions', () => { + let drops = xrpToDrops('3.456789') assert.strictEqual(drops, '3456789', '3.456789 XRP equals 3,456,789 drops') - drops = client.xrpToDrops('3.400000') + drops = xrpToDrops('3.400000') assert.strictEqual(drops, '3400000', '3.400000 XRP equals 3,400,000 drops') - drops = client.xrpToDrops('0.000001') + drops = xrpToDrops('0.000001') assert.strictEqual(drops, '1', '0.000001 XRP equals 1 drop') - drops = client.xrpToDrops('0.0000010') + drops = xrpToDrops('0.0000010') assert.strictEqual(drops, '1', '0.0000010 XRP equals 1 drop') - }, - 'works with zero': function (client) { - let drops = client.xrpToDrops('0') + }) + + it('works with zero', () => { + let drops = xrpToDrops('0') assert.strictEqual(drops, '0', '0 XRP equals 0 drops') - drops = client.xrpToDrops('-0') // negative zero is equivalent to zero + drops = xrpToDrops('-0') // negative zero is equivalent to zero assert.strictEqual(drops, '0', '-0 XRP equals 0 drops') - drops = client.xrpToDrops('0.000000') + drops = xrpToDrops('0.000000') assert.strictEqual(drops, '0', '0.000000 XRP equals 0 drops') - drops = client.xrpToDrops('0.0000000') + drops = xrpToDrops('0.0000000') assert.strictEqual(drops, '0', '0.0000000 XRP equals 0 drops') - }, - 'works with a negative value': function (client) { - const drops = client.xrpToDrops('-2') + }) + + it('works with a negative value', () => { + const drops = xrpToDrops('-2') assert.strictEqual(drops, '-2000000', '-2 XRP equals -2 million drops') - }, - 'works with a value ending with a decimal point': function (client) { - let drops = client.xrpToDrops('2.') + }) + + it('works with a value ending with a decimal point', () => { + let drops = xrpToDrops('2.') assert.strictEqual(drops, '2000000', '2. XRP equals 2000000 drops') - drops = client.xrpToDrops('-2.') + drops = xrpToDrops('-2.') assert.strictEqual(drops, '-2000000', '-2. XRP equals -2000000 drops') - }, - 'works with BigNumber objects': function (client) { - let drops = client.xrpToDrops(new BigNumber(2)) + }) + + it('works with BigNumber objects', () => { + let drops = xrpToDrops(new BigNumber(2)) assert.strictEqual( drops, '2000000', '(BigNumber) 2 XRP equals 2 million drops' ) - drops = client.xrpToDrops(new BigNumber(-2)) + drops = xrpToDrops(new BigNumber(-2)) assert.strictEqual( drops, '-2000000', '(BigNumber) -2 XRP equals -2 million drops' ) - }, - 'works with a number': function (client) { + }) + + it('works with a number', () => { // This is not recommended. Use strings or BigNumber objects to avoid precision errors. - let drops = client.xrpToDrops(2) + let drops = xrpToDrops(2) assert.strictEqual( drops, '2000000', '(number) 2 XRP equals 2 million drops' ) - drops = client.xrpToDrops(-2) + drops = xrpToDrops(-2) assert.strictEqual( drops, '-2000000', '(number) -2 XRP equals -2 million drops' ) - }, - 'throws with an amount with too many decimal places': function (client) { + }) + + it('throws with an amount with too many decimal places', () => { assert.throws(() => { - client.xrpToDrops('1.1234567') + xrpToDrops('1.1234567') }, /has too many decimal places/) assert.throws(() => { - client.xrpToDrops('0.0000001') + xrpToDrops('0.0000001') }, /has too many decimal places/) - }, - 'throws with an invalid value': function (client) { + }) + + it('throws with an invalid value', () => { assert.throws(() => { - client.xrpToDrops('FOO') + xrpToDrops('FOO') }, /invalid value/) assert.throws(() => { - client.xrpToDrops('1e-7') + xrpToDrops('1e-7') }, /invalid value/) assert.throws(() => { - client.xrpToDrops('2,0') + xrpToDrops('2,0') }, /invalid value/) assert.throws(() => { - client.xrpToDrops('.') + xrpToDrops('.') }, /xrpToDrops: invalid value '\.', should be a BigNumber or string-encoded number\./) - }, - 'throws with an amount more than one decimal point': function (client) { + }) + + it('throws with an amount more than one decimal point', () => { assert.throws(() => { - client.xrpToDrops('1.0.0') + xrpToDrops('1.0.0') }, /xrpToDrops: invalid value '1\.0\.0'/) assert.throws(() => { - client.xrpToDrops('...') + xrpToDrops('...') }, /xrpToDrops: invalid value '\.\.\.'/) - } -} + }) +}) diff --git a/test/wallet/fromEntropy/index.ts b/test/wallet/fromEntropy/index.ts index ad09f7e4..4e211a1f 100644 --- a/test/wallet/fromEntropy/index.ts +++ b/test/wallet/fromEntropy/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import ECDSA from '../../../src/common/ecdsa' import Wallet from '../../../src/Wallet' diff --git a/test/wallet/fromMnemonic/index.ts b/test/wallet/fromMnemonic/index.ts index 1f4ff1e9..ecad32d1 100644 --- a/test/wallet/fromMnemonic/index.ts +++ b/test/wallet/fromMnemonic/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import Wallet from '../../../src/Wallet' const mnemonic = diff --git a/test/wallet/fromSeed/index.ts b/test/wallet/fromSeed/index.ts index 3dc56139..53b2455a 100644 --- a/test/wallet/fromSeed/index.ts +++ b/test/wallet/fromSeed/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import ECDSA from '../../../src/common/ecdsa' import Wallet from '../../../src/Wallet' diff --git a/test/wallet/signTransaction/index.ts b/test/wallet/signTransaction/index.ts index c8fcc0aa..26c7003a 100644 --- a/test/wallet/signTransaction/index.ts +++ b/test/wallet/signTransaction/index.ts @@ -1,5 +1,5 @@ import {Client} from 'xrpl-local' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import Wallet from '../../../src/Wallet' const {schemaValidator} = Client._PRIVATE diff --git a/test/wallet/verifyTransaction/index.ts b/test/wallet/verifyTransaction/index.ts index 59e886fd..1d657b21 100644 --- a/test/wallet/verifyTransaction/index.ts +++ b/test/wallet/verifyTransaction/index.ts @@ -1,5 +1,5 @@ import assert from 'assert-diff' -import {TestSuite} from '../../utils' +import {TestSuite} from '../../testUtils' import Wallet from 'xrpl-local/Wallet' const publicKey =