mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-07 14:25:49 +00:00
GitHub Actions Integration Tests (#1466)
* ci: Add Github Actions integration testing against standalone rippled
This commit is contained in:
31
.github/workflows/nodejs.yml
vendored
31
.github/workflows/nodejs.yml
vendored
@@ -10,13 +10,13 @@ on:
|
||||
branches: [ develop ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
unit:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x, 13.x, 14.x, 16.x]
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -28,3 +28,30 @@ jobs:
|
||||
- run: yarn test
|
||||
- run: yarn lint
|
||||
- run: yarn build
|
||||
|
||||
integration:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
|
||||
services:
|
||||
rippled:
|
||||
image: natenichols/rippled-standalone:latest
|
||||
ports:
|
||||
- 6006:6006
|
||||
options:
|
||||
--health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: yarn install
|
||||
- run: yarn test:integration
|
||||
env:
|
||||
HOST: localhost
|
||||
PORT: ${{ job.services.rippled.ports['6006'] }}
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
"docgen": "node --harmony scripts/build_docs.js",
|
||||
"prepublish": "yarn clean && yarn build",
|
||||
"test": "TS_NODE_PROJECT=src/tsconfig.json nyc mocha --config=test/.mocharc.json --exit",
|
||||
"test:integration": "TS_NODE_PROJECT=src/tsconfig.json nyc mocha ./test/integration/*.ts",
|
||||
"test:watch": "TS_NODE_PROJECT=src/tsconfig.json mocha --watch --reporter dot",
|
||||
"format": "prettier --write '{src,test}/**/*.ts'",
|
||||
"lint": "eslint 'src/**/*.ts' 'test/*-test.{ts,js}'",
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import {RippleAPIBroadcast} from '../../src'
|
||||
|
||||
function main() {
|
||||
const servers = ['wss://s1.ripple.com', 'wss://s2.ripple.com']
|
||||
const api = new RippleAPIBroadcast(servers)
|
||||
api.connect().then(() => {
|
||||
api.getServerInfo().then((info) => {
|
||||
console.log(JSON.stringify(info, null, 2))
|
||||
})
|
||||
api.on('ledger', (ledger) => {
|
||||
console.log(JSON.stringify(ledger, null, 2))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -1,56 +0,0 @@
|
||||
import {Connection} from '../../src/common/connection'
|
||||
|
||||
const request1 = {
|
||||
command: 'server_info'
|
||||
}
|
||||
|
||||
const request2 = {
|
||||
command: 'account_info',
|
||||
account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'
|
||||
}
|
||||
|
||||
const request3 = {
|
||||
command: 'account_info'
|
||||
}
|
||||
|
||||
const request4 = {
|
||||
command: 'account_info',
|
||||
account: 'invalid'
|
||||
}
|
||||
|
||||
function makeRequest(connection, request) {
|
||||
return connection
|
||||
.request(request)
|
||||
.then((response) => {
|
||||
console.log(request)
|
||||
console.log(JSON.stringify(response, null, 2))
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(request)
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
|
||||
function main() {
|
||||
const connection = new Connection('wss://s1.ripple.com')
|
||||
connection.connect().then(() => {
|
||||
console.log('Connected')
|
||||
Promise.all([
|
||||
makeRequest(connection, request1),
|
||||
makeRequest(connection, request2),
|
||||
makeRequest(connection, request3),
|
||||
makeRequest(connection, request4)
|
||||
]).then(() => {
|
||||
console.log('Done')
|
||||
})
|
||||
connection.getLedgerVersion().then(console.log)
|
||||
connection.on('ledgerClosed', (ledger) => {
|
||||
console.log(ledger)
|
||||
connection.getLedgerVersion().then(console.log)
|
||||
})
|
||||
connection.hasLedgerVersions(1, 100).then(console.log)
|
||||
connection.hasLedgerVersions(16631039, 16631040).then(console.log)
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -3,7 +3,7 @@ import assert from 'assert'
|
||||
import wallet from './wallet'
|
||||
import requests from '../fixtures/requests'
|
||||
import {RippleAPI} from 'ripple-api'
|
||||
import {isValidAddress} from 'ripple-address-codec'
|
||||
import {isValidClassicAddress} from 'ripple-address-codec'
|
||||
import {payTo, ledgerAccept} from './utils'
|
||||
import {errors} from 'ripple-api/common'
|
||||
import {isValidSecret} from 'ripple-api/common/utils'
|
||||
@@ -12,7 +12,9 @@ import {isValidSecret} from 'ripple-api/common/utils'
|
||||
const TIMEOUT = 20000
|
||||
const INTERVAL = 1000 // how long to wait between checks for validated ledger
|
||||
|
||||
const serverUrl = 'ws://127.0.0.1:6006'
|
||||
const HOST = process.env.HOST ?? "127.0.0.1"
|
||||
const PORT = process.env.PORT ?? "6006"
|
||||
const serverUrl = `ws://${HOST}:${PORT}`
|
||||
|
||||
function acceptLedger(api) {
|
||||
return api.connection.request({command: 'ledger_accept'})
|
||||
@@ -101,7 +103,7 @@ function testTransaction(
|
||||
})
|
||||
}
|
||||
|
||||
function setup(this: any, server = 'wss://s1.ripple.com') {
|
||||
function setup(this: any, server = serverUrl) {
|
||||
this.api = new RippleAPI({server})
|
||||
console.log('CONNECTING...')
|
||||
return this.api.connect().then(
|
||||
@@ -348,16 +350,6 @@ describe('integration tests', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('ticket', function () {
|
||||
return this.api.getLedgerVersion().then((ledgerVersion) => {
|
||||
return this.api
|
||||
.prepareTicketCreate(address, 1, instructions)
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'ticket', ledgerVersion, prepared)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('isConnected', function () {
|
||||
assert(this.api.isConnected())
|
||||
})
|
||||
@@ -513,7 +505,7 @@ describe('integration tests', function () {
|
||||
it('generateWallet', function () {
|
||||
const newWallet = this.api.generateAddress()
|
||||
assert(newWallet && newWallet.address && newWallet.secret)
|
||||
assert(isValidAddress(newWallet.address))
|
||||
assert(isValidClassicAddress(newWallet.address))
|
||||
assert(isValidSecret(newWallet.secret))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
function getAddress() {
|
||||
return 'rQDhz2ZNXmhxzCYwxU6qAbdxsHA4HV45Y2';
|
||||
}
|
||||
|
||||
function getSecret() {
|
||||
return 'shK6YXzwYfnFVn3YZSaMh5zuAddKx';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAddress,
|
||||
getSecret
|
||||
};
|
||||
@@ -1,44 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function getUserHomePath() {
|
||||
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
|
||||
function getAddress() {
|
||||
return 'rQDhz2ZNXmhxzCYwxU6qAbdxsHA4HV45Y2';
|
||||
}
|
||||
|
||||
function loadWallet() {
|
||||
const secretPath = path.join(getUserHomePath(), '.ripple_wallet');
|
||||
try {
|
||||
const walletRaw = fs.readFileSync(secretPath, {encoding: 'utf8'}).trim();
|
||||
return JSON.parse(walletRaw);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const WALLET = loadWallet();
|
||||
|
||||
function getTestKey(key) {
|
||||
if (process.env.TEST_ADDRESS && process.env.TEST_SECRET) {
|
||||
if (key === 'address') {
|
||||
return process.env.TEST_ADDRESS;
|
||||
}
|
||||
if (key === 'secret') {
|
||||
return process.env.TEST_SECRET;
|
||||
}
|
||||
}
|
||||
if (WALLET === null) {
|
||||
throw new Error('Could not find .ripple_wallet file in home directory');
|
||||
}
|
||||
if (WALLET.test === undefined) {
|
||||
throw new Error('Wallet does not contain a "test" account');
|
||||
}
|
||||
return WALLET.test[key];
|
||||
function getSecret() {
|
||||
return 'shK6YXzwYfnFVn3YZSaMh5zuAddKx';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAddress: _.partial(getTestKey, 'address'),
|
||||
getSecret: _.partial(getTestKey, 'secret')
|
||||
getAddress,
|
||||
getSecret
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user