mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-05 05:15:48 +00:00
test: run snippets in CI (#2345)
* run snippets in CI * add name, try to avoid building * better printing * refactors * fix getTransaction test
This commit is contained in:
42
.github/workflows/nodejs.yml
vendored
42
.github/workflows/nodejs.yml
vendored
@@ -195,3 +195,45 @@ jobs:
|
||||
- name: Stop docker container
|
||||
if: always()
|
||||
run: docker stop rippled-service
|
||||
|
||||
snippets:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x, 16.x, 18.x, 20.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Setup npm version 9
|
||||
run: |
|
||||
npm i -g npm@9 --registry=https://registry.npmjs.org
|
||||
|
||||
- name: Cache node modules
|
||||
id: cache-nodemodules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# caching node_modules
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-deps-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-deps-${{ matrix.node-version }}-
|
||||
${{ runner.os }}-deps-
|
||||
|
||||
- name: Install Dependencies
|
||||
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
|
||||
run: npm ci
|
||||
|
||||
- run: npm run build
|
||||
- name: Run Snippets
|
||||
run: (for i in packages/xrpl/snippets/src/*.ts; do echo "Running $i" && npx ts-node $i || exit 1; done)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Client, LedgerResponse, TxResponse } from '../../src'
|
||||
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
const client = new Client('wss://s2.ripple.com:51233')
|
||||
|
||||
async function getTransaction(): Promise<void> {
|
||||
await client.connect()
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
AccountSet,
|
||||
convertStringToHex,
|
||||
SignerListSet,
|
||||
Wallet,
|
||||
} from '../../src'
|
||||
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
@@ -15,12 +16,8 @@ async function multisigning(): Promise<void> {
|
||||
* In practice, users generally will not have all keys in one spot,
|
||||
* hence, users need to implement a way to get signatures.
|
||||
*/
|
||||
const { wallet: wallet1 } = await client.fundWallet(null, {
|
||||
usageContext: 'code snippets',
|
||||
})
|
||||
const { wallet: wallet2 } = await client.fundWallet(null, {
|
||||
usageContext: 'code snippets',
|
||||
})
|
||||
const wallet1 = Wallet.generate()
|
||||
const wallet2 = Wallet.generate()
|
||||
const { wallet: walletMaster } = await client.fundWallet(null, {
|
||||
usageContext: 'code snippets',
|
||||
})
|
||||
|
||||
@@ -32,9 +32,13 @@ function multisign(transactions: Array<Transaction | string>): string {
|
||||
throw new ValidationError('There were 0 transactions to multisign')
|
||||
}
|
||||
|
||||
transactions.forEach((txOrBlob) => {
|
||||
const tx: Transaction = getDecodedTransaction(txOrBlob)
|
||||
const decodedTransactions: Transaction[] = transactions.map(
|
||||
(txOrBlob: string | Transaction) => {
|
||||
return getDecodedTransaction(txOrBlob)
|
||||
},
|
||||
)
|
||||
|
||||
decodedTransactions.forEach((tx) => {
|
||||
/*
|
||||
* This will throw a more clear error for JS users if any of the supplied transactions has incorrect formatting
|
||||
*/
|
||||
@@ -53,12 +57,6 @@ function multisign(transactions: Array<Transaction | string>): string {
|
||||
}
|
||||
})
|
||||
|
||||
const decodedTransactions: Transaction[] = transactions.map(
|
||||
(txOrBlob: string | Transaction) => {
|
||||
return getDecodedTransaction(txOrBlob)
|
||||
},
|
||||
)
|
||||
|
||||
validateTransactionEquivalence(decodedTransactions)
|
||||
|
||||
return encode(getTransactionWithAllSigners(decodedTransactions))
|
||||
@@ -154,10 +152,11 @@ function compareSigners(left: Signer, right: Signer): number {
|
||||
)
|
||||
}
|
||||
|
||||
const NUM_BITS_IN_HEX = 16
|
||||
|
||||
function addressToBigNumber(address: string): BigNumber {
|
||||
const hex = Buffer.from(decodeAccountID(address)).toString('hex')
|
||||
const numberOfBitsInHex = 16
|
||||
return new BigNumber(hex, numberOfBitsInHex)
|
||||
return new BigNumber(hex, NUM_BITS_IN_HEX)
|
||||
}
|
||||
|
||||
function getDecodedTransaction(txOrBlob: Transaction | string): Transaction {
|
||||
|
||||
Reference in New Issue
Block a user