Merge branch 'main' into amm

This commit is contained in:
Omar Khan
2023-05-31 15:27:38 -04:00
20 changed files with 98 additions and 73 deletions

View File

@@ -31,13 +31,6 @@ Please check relevant options, delete irrelevant ones.
- [ ] Documentation Updates - [ ] Documentation Updates
- [ ] Release - [ ] Release
## Before / After
<!--
If just refactoring / back-end changes, this can be just an in-English description of the change at a technical level.
If a UI change, screenshots should be included.
-->
## Test Plan ## Test Plan
<!-- <!--
@@ -47,4 +40,4 @@ Please describe the tests that you ran to verify your changes and provide instru
<!-- <!--
## Future Tasks ## Future Tasks
For future tasks related to PR. For future tasks related to PR.
--> -->

View File

@@ -25,9 +25,9 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Setup npm version 7 - name: Setup npm version 9
run: | run: |
npm i -g npm@7 --registry=https://registry.npmjs.org npm i -g npm@9 --registry=https://registry.npmjs.org
- name: Cache node modules - name: Cache node modules
id: cache-nodemodules id: cache-nodemodules
@@ -66,9 +66,9 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Setup npm version 7 - name: Setup npm version 9
run: | run: |
npm i -g npm@7 --registry=https://registry.npmjs.org npm i -g npm@9 --registry=https://registry.npmjs.org
- name: Cache node modules - name: Cache node modules
id: cache-nodemodules id: cache-nodemodules
@@ -112,9 +112,9 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- name: Setup npm version 7 - name: Setup npm version 9
run: | run: |
npm i -g npm@7 --registry=https://registry.npmjs.org npm i -g npm@9 --registry=https://registry.npmjs.org
- name: Cache node modules - name: Cache node modules
id: cache-nodemodules id: cache-nodemodules
@@ -164,9 +164,9 @@ jobs:
run: | run: |
docker run --detach --rm --name rippled-service -p 6006:6006 --volume "${{ github.workspace }}/.ci-config/":"/config/" --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s --env "ENV_ARGS=-a --start" --env GITHUB_ACTIONS=true --env CI=true xrpllabsofficial/xrpld:latest docker run --detach --rm --name rippled-service -p 6006:6006 --volume "${{ github.workspace }}/.ci-config/":"/config/" --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s --env "ENV_ARGS=-a --start" --env GITHUB_ACTIONS=true --env CI=true xrpllabsofficial/xrpld:latest
- name: Setup npm version 7 - name: Setup npm version 9
run: | run: |
npm i -g npm@7 --registry=https://registry.npmjs.org npm i -g npm@9 --registry=https://registry.npmjs.org
- name: Cache node modules - name: Cache node modules
id: cache-nodemodules id: cache-nodemodules

2
package-lock.json generated
View File

@@ -69,7 +69,7 @@
}, },
"engines": { "engines": {
"node": ">=12.0.0", "node": ">=12.0.0",
"npm": ">=7.0.0 < 9.0.0" "npm": ">=7.0.0 < 10.0.0"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {

View File

@@ -76,6 +76,6 @@
], ],
"engines": { "engines": {
"node": ">=12.0.0", "node": ">=12.0.0",
"npm": ">=7.0.0 < 9.0.0" "npm": ">=7.0.0 < 10.0.0"
} }
} }

View File

@@ -3,6 +3,9 @@
## Unreleased ## Unreleased
## 4.2.5 (2023-03-08) ## 4.2.5 (2023-03-08)
### Added
* Adds support for npm v9
### Changed ### Changed
- All tests now use the Jest test runner and have been refactored for consistency across all packages - All tests now use the Jest test runner and have been refactored for consistency across all packages

View File

@@ -3,6 +3,7 @@
## Unreleased ## Unreleased
### Added ### Added
- Allow custom type definitions to be used for encoding/decoding transactions at runtime (e.g. for sidechains/new amendments) - Allow custom type definitions to be used for encoding/decoding transactions at runtime (e.g. for sidechains/new amendments)
* Adds support for npm v9
## 1.5.0 (2023-03-08) ## 1.5.0 (2023-03-08)
### Changed ### Changed

View File

@@ -2,6 +2,9 @@
## Unreleased ## Unreleased
### Added
* Adds support for npm v9
## 1.1.5 (2023-03-08) ## 1.1.5 (2023-03-08)
### Changed ### Changed
- All tests now use the Jest test runner and have been refactored for consistency across all packages - All tests now use the Jest test runner and have been refactored for consistency across all packages

View File

@@ -2,3 +2,5 @@ dist
node_modules node_modules
.github .github
.vscode .vscode
karma.config.js
karma-setup.js

View File

@@ -4,14 +4,15 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
## Unreleased ## Unreleased
### Added ### Added
* Guard check for signing algorithm used in `Wallet.generate()` * Adds support for npm v9
* Null and undefined values in transactions are now treated as though the field was not passed in.
### Fixed ### Fixed
* Fixed `ServerState.transitions` typing, it is now a string instead of a number. (Only used in return from `server_state` request) * Fixed `ServerState.transitions` typing, it is now a string instead of a number. (Only used in return from `server_state` request)
* Added `destination_amount` to `PathOption` which is returned as part of a `path_find` request * Added `destination_amount` to `PathOption` which is returned as part of a `path_find` request
* Removed the `decode(encode(tx)) == tx` check from the wallet signing process * Removed the `decode(encode(tx)) == tx` check from the wallet signing process
* Fixed the location of `signer_lists` in the `account_info` response so that it matches rippled * Fixed the location of `signer_lists` in the `account_info` response so that it matches rippled
* Guard check for signing algorithm used in `Wallet.generate()`
* Null and undefined values in transactions are now treated as though the field was not passed in.
### Removed ### Removed
* RPCs and utils related to the old sidechain design * RPCs and utils related to the old sidechain design

View File

@@ -4,5 +4,9 @@ const base = require('../../jest.config.base.js')
module.exports = { module.exports = {
...base, ...base,
roots: [...base.roots, '<rootDir>/test'], roots: [...base.roots, '<rootDir>/test'],
testMatch: [
'<rootDir>/test/integration/**/*.test.ts',
'<rootDir>/test/integration/*.test.ts',
],
displayName: 'xrpl.js', displayName: 'xrpl.js',
} }

View File

@@ -0,0 +1,13 @@
// Jest configuration for api
const base = require('../../jest.config.base.js')
module.exports = {
...base,
roots: [...base.roots, '<rootDir>/test'],
testMatch: ['<rootDir>/test/**/*.test.ts'],
testPathIgnorePatterns: [
'<rootDir>/test/integration',
'<rootDir>/test/fixtures',
],
displayName: 'xrpl.js',
}

View File

@@ -30,5 +30,15 @@ module.exports = function (config) {
}, },
browsers: ['ChromeHeadless'], browsers: ['ChromeHeadless'],
// runs only one browser at a time
concurrency: 1,
// CI mode
singleRun: true,
client: {
jasmine: {
// ensures that tests are run in order instead of a random order
random: false,
},
},
}) })
} }

View File

@@ -61,8 +61,8 @@
"clean": "rm -rf dist build coverage", "clean": "rm -rf dist build coverage",
"docgen": "tsc --build tsconfig.docs.json && typedoc && echo js.xrpl.org >> ../../docs/CNAME", "docgen": "tsc --build tsconfig.docs.json && typedoc && echo js.xrpl.org >> ../../docs/CNAME",
"prepublish": "npx run-s clean build", "prepublish": "npx run-s clean build",
"test": "jest --verbose false --silent=false ./test/**/*.test.ts --testPathIgnorePatterns=./test/integration --testPathIgnorePatterns=./test/fixtures", "test": "jest --config=jest.config.unit.js --verbose false --silent=false",
"test:integration": "TS_NODE_PROJECT=tsconfig.build.json jest --verbose false --silent=false --runInBand ./test/integration/**/*.test.ts", "test:integration": "TS_NODE_PROJECT=tsconfig.build.json jest --config=jest.config.integration.js --verbose false --silent=false --runInBand",
"test:browser": "npm run build && npm run build:browserTests && karma start ./karma.config.js --single-run", "test:browser": "npm run build && npm run build:browserTests && karma start ./karma.config.js --single-run",
"test:watch": "jest --watch --verbose false --silent=false --runInBand ./test/**/*.test.ts --testPathIgnorePatterns=./test/integration --testPathIgnorePatterns=./test/fixtures", "test:watch": "jest --watch --verbose false --silent=false --runInBand ./test/**/*.test.ts --testPathIgnorePatterns=./test/integration --testPathIgnorePatterns=./test/fixtures",
"format": "prettier --write '{src,test}/**/*.ts'", "format": "prettier --write '{src,test}/**/*.ts'",

View File

@@ -437,6 +437,7 @@ describe('Connection', function () {
try { try {
await clientContext.client.connect() await clientContext.client.connect()
} catch (error) { } catch (error) {
// @ts-expect-error -- error.message is expected to be defined
expect(error.message).toEqual( expect(error.message).toEqual(
"Error: connect() timed out after 5000 ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.", "Error: connect() timed out after 5000 ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.",
) )

View File

@@ -1,12 +1,16 @@
/* eslint-disable import/export -- Tells webpack which files exist. */ /* eslint-disable import/export -- Tells webpack which files exist. */
// These go first because they're affected by the `ledger_accept`s
export * from './transactions/escrowFinish.test'
export * from './transactions/escrowCancel.test'
// Transactions
export * from './transactions/accountSet.test' export * from './transactions/accountSet.test'
export * from './transactions/checkCancel.test' export * from './transactions/checkCancel.test'
export * from './transactions/checkCash.test' export * from './transactions/checkCash.test'
export * from './transactions/checkCreate.test' export * from './transactions/checkCreate.test'
export * from './transactions/depositPreauth.test' export * from './transactions/depositPreauth.test'
export * from './transactions/escrowCancel.test'
export * from './transactions/escrowCreate.test' export * from './transactions/escrowCreate.test'
export * from './transactions/escrowFinish.test'
export * from './transactions/offerCancel.test' export * from './transactions/offerCancel.test'
export * from './transactions/offerCreate.test' export * from './transactions/offerCreate.test'
export * from './transactions/payment.test' export * from './transactions/payment.test'
@@ -16,6 +20,7 @@ export * from './transactions/paymentChannelFund.test'
export * from './transactions/signerListSet.test' export * from './transactions/signerListSet.test'
export * from './transactions/trustSet.test' export * from './transactions/trustSet.test'
// Requests
export * from './requests/accountChannels.test' export * from './requests/accountChannels.test'
export * from './requests/accountCurrencies.test' export * from './requests/accountCurrencies.test'
export * from './requests/accountInfo.test' export * from './requests/accountInfo.test'
@@ -49,7 +54,6 @@ export * from './integration.test'
export * from './onConnect.test' export * from './onConnect.test'
export * from './regularKey.test' export * from './regularKey.test'
export * from './submitAndWait.test' export * from './submitAndWait.test'
export * from './wallet.test'
// Because this does 256 ledger accepts, we do it last // Because this does 256 ledger accepts, we do it last
export * from './transactions/accountDelete.test' export * from './transactions/accountDelete.test'

View File

@@ -8,21 +8,13 @@ import {
type XrplIntegrationTestContext, type XrplIntegrationTestContext,
} from '../setup' } from '../setup'
import { import {
// calculateWaitTimeForTransaction, calculateWaitTimeForTransaction,
generateFundedWallet, generateFundedWallet,
// getXRPBalance, getXRPBalance,
testTransaction, testTransaction,
submitTransaction, sendLedgerAccept,
} from '../utils' } from '../utils'
// TODO: Fix these tests
// NOTE: Because ledger accept is called among multiple tests, the actual ledger close time is not
// accurate. It can end up very far into the future. This means that the CancelAfter timer can potentially
// need to wait for several minutes to be able to properly complete. Since we are not testing the functionaity
// of rippled in this library, only that we are submitting commands properly, we can just test that the EscrowCancel
// command was successfully received. If in the future we isolate tests to run on their own rippled instance,
// we can uncomment the code in this file to test that the escrow was actually cancelled.
// how long before each test case times out // how long before each test case times out
const TIMEOUT = 50000 const TIMEOUT = 50000
@@ -48,7 +40,7 @@ describe('EscrowCancel', function () {
}) })
).result.ledger.close_time ).result.ledger.close_time
// const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME) const waitTimeInMs = calculateWaitTimeForTransaction(CLOSE_TIME)
const createTx: EscrowCreate = { const createTx: EscrowCreate = {
Account: testContext.wallet.classicAddress, Account: testContext.wallet.classicAddress,
@@ -61,10 +53,10 @@ describe('EscrowCancel', function () {
await testTransaction(testContext.client, createTx, testContext.wallet) await testTransaction(testContext.client, createTx, testContext.wallet)
// const initialBalanceWallet1 = await getXRPBalance( const initialBalanceWallet1 = await getXRPBalance(
// testContext.client, testContext.client,
// wallet1, wallet1,
// ) )
// check that the object was actually created // check that the object was actually created
const accountObjects = ( const accountObjects = (
@@ -96,29 +88,25 @@ describe('EscrowCancel', function () {
// We set the CancelAfter timer to be 3 seconds after the last ledger close_time. We need to wait this long // We set the CancelAfter timer to be 3 seconds after the last ledger close_time. We need to wait this long
// before we can cancel the escrow. // before we can cancel the escrow.
// const cancelAfterTimerPromise = new Promise((resolve) => { const cancelAfterTimerPromise = new Promise((resolve) => {
// setTimeout(resolve, waitTimeInMs) setTimeout(resolve, waitTimeInMs)
// }) })
// Make sure we wait long enough before canceling the escrow. // Make sure we wait long enough before canceling the escrow.
// await cancelAfterTimerPromise await cancelAfterTimerPromise
// await testTransaction(testContext.client, cancelTx, testContext.wallet, { // rippled uses the close time of the previous ledger
// count: 20, await sendLedgerAccept(testContext.client)
// delayMs: 2000, await testTransaction(testContext.client, cancelTx, testContext.wallet, {
// }) count: 20,
delayMs: 2000,
await submitTransaction({
client: testContext.client,
transaction: cancelTx,
wallet: testContext.wallet,
}) })
// Make sure the Destination wallet did not receive any XRP. // Make sure the Destination wallet did not receive any XRP.
// assert.equal( assert.equal(
// await getXRPBalance(testContext.client, wallet1), await getXRPBalance(testContext.client, wallet1),
// initialBalanceWallet1, initialBalanceWallet1,
// ) )
}, },
TIMEOUT, TIMEOUT,
) )

View File

@@ -11,6 +11,7 @@ import {
calculateWaitTimeForTransaction, calculateWaitTimeForTransaction,
generateFundedWallet, generateFundedWallet,
getXRPBalance, getXRPBalance,
sendLedgerAccept,
testTransaction, testTransaction,
} from '../utils' } from '../utils'
@@ -84,6 +85,8 @@ describe('EscrowFinish', function () {
await finishAfterPromise await finishAfterPromise
// rippled uses the close time of the previous ledger
await sendLedgerAccept(testContext.client)
await testTransaction(testContext.client, finishTx, testContext.wallet) await testTransaction(testContext.client, finishTx, testContext.wallet)
const expectedBalance = String(Number(initialBalance) + Number(AMOUNT)) const expectedBalance = String(Number(initialBalance) + Number(AMOUNT))

View File

@@ -1,4 +1,6 @@
import { TrustSet, percentToQuality } from '../../../src' import { assert } from 'chai'
import { TrustSet, percentToQuality, Wallet } from '../../../src'
import serverUrl from '../serverUrl' import serverUrl from '../serverUrl'
import { import {
setupClient, setupClient,
@@ -12,16 +14,21 @@ const TIMEOUT = 20000
describe('TrustSet', function () { describe('TrustSet', function () {
let testContext: XrplIntegrationTestContext let testContext: XrplIntegrationTestContext
let wallet2: Wallet | undefined
beforeEach(async () => { beforeEach(async () => {
testContext = await setupClient(serverUrl) testContext = await setupClient(serverUrl)
if (!wallet2) {
// eslint-disable-next-line require-atomic-updates -- race condition doesn't really matter
wallet2 = await generateFundedWallet(testContext.client)
}
}) })
afterEach(async () => teardownClient(testContext)) afterEach(async () => teardownClient(testContext))
it( it(
'base', 'base',
async () => { async () => {
const wallet2 = await generateFundedWallet(testContext.client) assert(wallet2 != null)
const tx: TrustSet = { const tx: TrustSet = {
TransactionType: 'TrustSet', TransactionType: 'TrustSet',
Account: testContext.wallet.classicAddress, Account: testContext.wallet.classicAddress,
@@ -40,14 +47,14 @@ describe('TrustSet', function () {
it( it(
'Quality < 1', 'Quality < 1',
async () => { async () => {
const wallet2 = await generateFundedWallet(testContext.client) assert(wallet2 != null)
const tx: TrustSet = { const tx: TrustSet = {
TransactionType: 'TrustSet', TransactionType: 'TrustSet',
Account: testContext.wallet.address, Account: testContext.wallet.address,
QualityIn: percentToQuality('99%'), QualityIn: percentToQuality('99%'),
QualityOut: percentToQuality('99%'), QualityOut: percentToQuality('99%'),
LimitAmount: { LimitAmount: {
currency: 'USD', currency: 'BTC',
issuer: wallet2.address, issuer: wallet2.address,
value: '100', value: '100',
}, },
@@ -61,14 +68,14 @@ describe('TrustSet', function () {
it( it(
'Quality > 1', 'Quality > 1',
async () => { async () => {
const wallet2 = await generateFundedWallet(testContext.client) assert(wallet2 != null)
const tx: TrustSet = { const tx: TrustSet = {
TransactionType: 'TrustSet', TransactionType: 'TrustSet',
QualityIn: percentToQuality('101%'), QualityIn: percentToQuality('101%'),
QualityOut: percentToQuality('101%'), QualityOut: percentToQuality('101%'),
Account: testContext.wallet.address, Account: testContext.wallet.address,
LimitAmount: { LimitAmount: {
currency: 'USD', currency: 'ETH',
issuer: wallet2.address, issuer: wallet2.address,
value: '100', value: '100',
}, },

View File

@@ -18,7 +18,7 @@ import { hashSignedTx } from '../../src/utils/hashes'
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh' const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb' const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
async function sendLedgerAccept(client: Client): Promise<unknown> { export async function sendLedgerAccept(client: Client): Promise<unknown> {
return client.connection.request({ command: 'ledger_accept' }) return client.connection.request({ command: 'ledger_accept' })
} }
@@ -253,7 +253,6 @@ export async function testTransaction(
}, },
): Promise<SubmitResponse> { ): Promise<SubmitResponse> {
// Accept any un-validated changes. // Accept any un-validated changes.
await ledgerAccept(client)
// sign/submit the transaction // sign/submit the transaction
const response = await submitTransaction({ const response = await submitTransaction({

View File

@@ -1,7 +0,0 @@
import { Wallet } from '../../src'
const walletSecret = 'shK6YXzwYfnFVn3YZSaMh5zuAddKx'
const wallet = Wallet.fromSeed(walletSecret)
export default wallet