Skip to content

Commit

Permalink
run integration test using standalone server
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Dec 15, 2015
1 parent c23c6e4 commit 63fd50e
Show file tree
Hide file tree
Showing 5 changed files with 1,418 additions and 18 deletions.
7 changes: 7 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
machine:
node:
version: 0.12.0
dependencies:
pre:
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30-1.deb
- sudo dpkg -i rippled_0.30-1.deb
test:
pre:
- sudo rippled -a --start --conf "$HOME/$CIRCLE_PROJECT_REPONAME/test/integration/rippled.cfg":
background: true
override:
- scripts/ci.sh "$CIRCLE_NODE_INDEX" "$CIRCLE_NODE_TOTAL":
parallel: true
1 change: 1 addition & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ unittest() {

integrationtest() {
mocha test/integration/integration-test.js
# mocha test/integration/integration-strange-1-test.js
mocha test/integration/http-integration-test.js
}

Expand Down
286 changes: 286 additions & 0 deletions test/integration/integration-strange-1-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
/* eslint-disable */

/* eslint-disable max-nested-callbacks */
/* eslint-disable max-params */
'use strict';
const _ = require('lodash');
const assert = require('assert');
const errors = require('../../src/common/errors');
const wallet = require('./wallet');
const requests = require('../fixtures/requests');
const RippleAPI = require('../../src').RippleAPI;
const {isValidAddress} = require('ripple-address-codec');
const {isValidSecret} = require('../../src/common');


const TIMEOUT = 30000; // how long before each test case times out
const INTERVAL = 1000; // how long to wait between checks for validated ledger


function verifyTransaction(testcase, hash, type, options, txData) {
console.log('VERIFY...');
return testcase.api.getTransaction(hash, options).then(data => {
assert(data && data.outcome);
assert.strictEqual(data.type, type);
assert.strictEqual(data.address, wallet.getAddress());
assert.strictEqual(data.outcome.result, 'tesSUCCESS');
testcase.transactions.push(hash);
return {txJSON: JSON.stringify(txData), id: hash, tx: data};
}).catch(error => {
if (error instanceof errors.PendingLedgerVersionError) {
console.log('NOT VALIDATED YET...');
return new Promise((resolve, reject) => {
setTimeout(() => verifyTransaction(testcase, hash, type,
options, txData).then(resolve, reject), INTERVAL);
});
}
assert(false, 'Transaction not successful: ' + error.message);
});
}

function ledgerAccept(api) {
const request = {command: 'ledger_accept'};
return api.connection.request(request);
}

function testTransaction(testcase, type, lastClosedLedgerVersion, prepared) {
const txJSON = prepared.txJSON;
assert(txJSON, 'missing txJSON');
const txData = JSON.parse(txJSON);
assert.strictEqual(txData.Account, wallet.getAddress());
const signedData = testcase.api.sign(txJSON, wallet.getSecret());
console.log('PREPARED...');
return testcase.api.submit(signedData.signedTransaction).then(data => {
console.log('SUBMITTED...');
assert.strictEqual(data.resultCode, 'tesSUCCESS');
const options = {
minLedgerVersion: lastClosedLedgerVersion,
maxLedgerVersion: txData.LastLedgerSequence
};
ledgerAccept(testcase.api);
return new Promise((resolve, reject) => {
setTimeout(() => verifyTransaction(testcase, signedData.id, type,
options, txData).then(resolve, reject), INTERVAL);
});
});
}

function setup() {
this.api = new RippleAPI({server: 'ws://127.0.0.1:6006'});
this.api.on('error', (error, info) => {
console.log('!!!+++ got error:', error, info);
})
console.log('CONNECTING...');
return this.api.connect().then(() => {
console.log('CONNECTED...');
});
}

function pay(api, from, to, amount, secret, currency = 'XRP', counterparty) {
console.log('=== = pay of ' + amount + ' to ' + to);
const paymentSpecification = {
source: {
address: from,
maxAmount: {
value: amount,
currency: currency
}
},
destination: {
address: to,
amount: {
value: amount,
currency: currency
}
}
};

if (counterparty !== undefined) {
paymentSpecification.source.maxAmount.counterparty = counterparty;
paymentSpecification.destination.amount.counterparty = counterparty;
}

return api.preparePayment(from, paymentSpecification, {})
.then(data => api.sign(data.txJSON, secret))
.then(signed => api.submit(signed.signedTransaction))
.then(subres => {
console.log('---- submitted payment of ' + amount + ' to ' + to);
console.log(JSON.stringify(subres, null, 2));
})
.catch((error) => {
if (error) {
console.log('~~~~~ error');
console.log(error);
}
})
.then(() => ledgerAccept(api));
}

const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';

function payTo(api, to, amount = '4003218', currency = 'XRP', counterparty) {
const promise = pay(api, masterAccount, to, amount, masterSecret, currency,
counterparty);
return promise;
}

function makeTrustLine(api, address, secret) {
const specification = {
currency: 'USD',
counterparty: masterAccount,
limit: '1341.1'
};
console.log('>>>>>>>>>>>>> ' + address);
const trust = api.prepareTrustline(address, specification, {})
.then(data => api.sign(data.txJSON, secret))
.then(signed => api.submit(signed.signedTransaction));
return trust;
}

function makeOrder(api, address, specification, secret) {
return api.prepareOrder(address, specification)
.then(data => api.sign(data.txJSON, secret))
.then(signed => api.submit(signed.signedTransaction))
.then(() => ledgerAccept(api));
}

function setupAccounts(testcase) {
const promise = payTo(testcase.api, 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM')
.then(() => payTo(testcase.api, wallet.getAddress()))
.then(() => payTo(testcase.api, testcase.newWallet.address))
.then(() => makeTrustLine(testcase.api, wallet.getAddress(), wallet.getSecret()))
.then(() => makeTrustLine(testcase.api, testcase.newWallet.address, testcase.newWallet.secret))
.then(() => payTo(testcase.api, wallet.getAddress(), '123', 'USD', masterAccount))
.then(() => ledgerAccept(testcase.api));
return promise;
}

function teardown() {
return this.api.disconnect();
}

function suiteSetup() {
this.transactions = [];

return setup.bind(this)()
.then(() => ledgerAccept(this.api))
.then(() => this.newWallet = this.api.generateAddress())
// two times to give time to server to send `ledgerClosed` event
// so getLedgerVersion will return right value
.then(() => ledgerAccept(this.api))
.then(() => this.api.getLedgerVersion())
.then(ledgerVersion => {
this.startLedgerVersion = ledgerVersion;
console.log('--------- startLedgerVersion:', this.startLedgerVersion);
})
.then(() => setupAccounts(this))
.then(() => teardown.bind(this)())
.catch(err => {
console.log('++++ error:', err);
});
}

describe('integration tests', function() {
const address = wallet.getAddress();
const instructions = {maxLedgerVersionOffset: 10};
this.timeout(TIMEOUT);

before(suiteSetup);
beforeEach(setup);
afterEach(teardown);


it('can\'t make payment', function() {
const paymentSpecification = {
source: {
address: address,
maxAmount: {
currency: 'USD',
value: '11.5',
counterparty: address
}
},
destination: {
address: this.newWallet.address,
amount: {
currency: 'USD',
value: '.4',
counterparty: masterAccount
}
}
// paths: "[[{\"currency\":\"USD\",\"issuer\":\"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\"}]]"
};
return this.api.preparePayment(address, paymentSpecification)
.then(data => {
console.log(JSON.stringify(data, null, 2));
return data;
})
.then(data => this.api.sign(data.txJSON, wallet.getSecret()))
.then(signed => this.api.submit(signed.signedTransaction))
.then(data => {
console.log(JSON.stringify(data, null, 2));
return data;
})
// console.log(JSON.stringify(data, null, 2));
});

it('can\'t make payment with paths', function() {
const paymentSpecification = {
source: {
address: address,
maxAmount: {
currency: 'USD',
value: '11.5',
counterparty: address
}
},
destination: {
address: this.newWallet.address,
amount: {
currency: 'USD',
value: '.4',
counterparty: masterAccount
}
},
paths: "[[{\"currency\":\"USD\",\"issuer\":\"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\"}]]"
};
return this.api.preparePayment(address, paymentSpecification)
.then(data => {
console.log(JSON.stringify(data, null, 2));
return data;
})
.then(data => this.api.sign(data.txJSON, wallet.getSecret()))
.then(signed => this.api.submit(signed.signedTransaction))
.then(data => {
console.log(JSON.stringify(data, null, 2));
return data;
})
// console.log(JSON.stringify(data, null, 2));
});


it('not finding paths', function() {
const pathfind = {
source: {
address: address,
// amount: {
// value: '1',
// currency: 'USD'
// }
},
destination: {
address: this.newWallet.address,
amount: {
value: '1',
currency: 'USD',
counterparty: masterAccount
}
}
};
return this.api.getPaths(pathfind).then(data => {
console.log(JSON.stringify(data, null, 2));
});
});

});
Loading

0 comments on commit 63fd50e

Please sign in to comment.