Skip to content

Commit

Permalink
run integration tests using standalone server
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Dec 19, 2015
1 parent ed79a04 commit 3dd21a7
Show file tree
Hide file tree
Showing 15 changed files with 1,248 additions and 214 deletions.
9 changes: 9 additions & 0 deletions circle.yml
@@ -1,7 +1,16 @@
machine:
node:
version: 0.12.0
dependencies:
pre:
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30.1-b11-1.deb
- sudo dpkg -i rippled_0.30.1-b11-1.deb
test:
pre:
- 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
post:
- killall /usr/bin/rippled
1 change: 1 addition & 0 deletions docs/index.md
Expand Up @@ -291,6 +291,7 @@ maxFee | [value](#value) | *Optional* The maximum fee to pay for the transaction
maxLedgerVersion | integer,null | *Optional* The highest ledger version that the transaction can be included in. If this option and `maxLedgerVersionOffset` are both omitted, the `maxLedgerVersion` option will default to 3 greater than the current validated ledger version (equivalent to `maxLedgerVersionOffset=3`). Use `null` to not set a maximum ledger version.
maxLedgerVersionOffset | integer | *Optional* Offset from current validated legder version to highest ledger version that the transaction can be included in.
sequence | [sequence](#account-sequence-number) | *Optional* The initiating account's sequence number for this transaction.
signersCount | integer | *Optional* Number of signers that will be signing this transaction.

We recommended that you specify a `maxLedgerVersion` so that you can quickly determine that a failed transaction will never succeeed in the future. It is impossible for a transaction to succeed after the network ledger version exceeds the transaction's `maxLedgerVersion`. If you omit `maxLedgerVersion`, the "prepare*" method automatically supplies a `maxLedgerVersion` equal to the current ledger plus 3, which it includes in the return value from the "prepare*" method.

Expand Down
5 changes: 5 additions & 0 deletions src/common/schemas/objects/instructions.json
Expand Up @@ -28,6 +28,11 @@
"description": "Offset from current validated legder version to highest ledger version that the transaction can be included in.",
"type": "integer",
"minimum": 0
},
"signersCount": {
"description": "Number of signers that will be signing this transaction.",
"type": "integer",
"minimum": 1
}
},
"additionalProperties": false,
Expand Down
3 changes: 2 additions & 1 deletion src/transaction/types.js
Expand Up @@ -6,7 +6,8 @@ export type Instructions = {
fee?: string,
maxFee?: string,
maxLedgerVersion?: number,
maxLedgerVersionOffset?: number
maxLedgerVersionOffset?: number,
signersCount?: number
}

export type Prepare = {
Expand Down
3 changes: 2 additions & 1 deletion src/transaction/utils.js
Expand Up @@ -55,7 +55,8 @@ function prepareTransaction(txJSON: Object, api: Object,
}

function prepareFee(): Promise<Object> {
const multiplier = (txJSON.Signers || []).length + 1;
const multiplier = instructions.signersCount === undefined ? 1 :
instructions.signersCount + 1;
if (instructions.fee !== undefined) {
txJSON.Fee = scaleValue(common.xrpToDrops(instructions.fee), multiplier);
return Promise.resolve(txJSON);
Expand Down
10 changes: 10 additions & 0 deletions test/api-test.js
Expand Up @@ -251,6 +251,16 @@ describe('RippleAPI', function() {
'prepare'));
});

it('prepareSettings - fee for multisign', function() {
const localInstructions = _.defaults({
signersCount: 4
}, instructions);
return this.api.prepareSettings(
address, requests.prepareSettings.domain, localInstructions).then(
_.partial(checkResult, responses.prepareSettings.flagsMultisign,
'prepare'));
});

it('prepareSuspendedPaymentCreation', function() {
const localInstructions = _.defaults({
maxFee: '0.000012'
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/responses/index.js
Expand Up @@ -81,6 +81,7 @@ module.exports = {
regularKey: require('./prepare-settings-regular-key.json'),
removeRegularKey: require('./prepare-settings-remove-regular-key.json'),
flags: require('./prepare-settings.json'),
flagsMultisign: require('./prepare-settings-multisign.json'),
flagSet: require('./prepare-settings-flag-set.json'),
flagClear: require('./prepare-settings-flag-clear.json'),
setTransferRate: require('./prepare-settings-set-transfer-rate.json'),
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/responses/prepare-settings-multisign.json
@@ -0,0 +1,8 @@
{
"txJSON": "{\"TransactionType\":\"AccountSet\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"Domain\":\"726970706C652E636F6D\",\"Flags\":2147483648,\"LastLedgerSequence\":8820051,\"Fee\":\"60\",\"Sequence\":23}",
"instructions": {
"fee": "0.00006",
"sequence": 23,
"maxLedgerVersion": 8820051
}
}
74 changes: 0 additions & 74 deletions test/integration/fixtures/get-transaction.json

This file was deleted.

72 changes: 0 additions & 72 deletions test/integration/fixtures/get-transactions.json

This file was deleted.

6 changes: 0 additions & 6 deletions test/integration/fixtures/index.js

This file was deleted.

74 changes: 55 additions & 19 deletions test/integration/http-integration-test.js
Expand Up @@ -4,18 +4,19 @@ const assert = require('assert-diff');
const _ = require('lodash');
const jayson = require('jayson');

const RippleAPI = require('../../src').RippleAPI;
const createHTTPServer = require('../../src/index').createHTTPServer;
const {payTo, ledgerAccept} = require('./utils');

const apiFixtures = require('../fixtures');
const apiRequests = apiFixtures.requests;
const apiResponses = apiFixtures.responses;

const fixtures = require('./fixtures');

const TIMEOUT = 20000; // how long before each test case times out

const serverUri = 'ws://127.0.0.1:6006';
const apiOptions = {
server: 'wss://s1.ripple.com'
server: serverUri
};

const httpPort = 3000;
Expand All @@ -38,11 +39,14 @@ function random() {
return _.fill(Array(16), 0);
}


describe('http server integration tests', function() {
this.timeout(TIMEOUT);

let server = null;
let client = null;
let paymentId = null;
let newWallet = null;

function createTestInternal(testName, methodName, params, testFunc, id) {
it(testName, function() {
Expand All @@ -60,6 +64,21 @@ describe('http server integration tests', function() {
makeNamedParams(params), testFunc, id);
}

before(() => {
this.api = new RippleAPI({server: serverUri});
console.log('CONNECTING...');
return this.api.connect().then(() => {
console.log('CONNECTED...');
})
.then(() => ledgerAccept(this.api))
.then(() => newWallet = this.api.generateAddress())
.then(() => ledgerAccept(this.api))
.then(() => payTo(this.api, newWallet.address))
.then(paymentId_ => {
paymentId = paymentId_;
});
});

beforeEach(function() {
server = createHTTPServer(apiOptions, httpPort);
return server.start().then(() => {
Expand All @@ -85,26 +104,43 @@ describe('http server integration tests', function() {
result => assert(_.isNumber(result.result.validatedLedger.ledgerVersion))
);

createTest(
'getTransaction',
[{id: '4EB6B76237DEEE99F1EA16FAACED2D1E69C5F9CB54F727A4ECA51A08AD3AF466'}],
result => assert.deepEqual(result, fixtures.getTransaction),
'2'
);
it('getTransaction', function() {
const params = [{id: paymentId}];
return new Promise((resolve, reject) => {
client.request('getTransaction', makePositionalParams(params),
(err, result) => {
if (err) {
reject(err);
}
assert.strictEqual(result.result.id, paymentId);
const outcome = result.result.outcome;
assert.strictEqual(outcome.result, 'tesSUCCESS');
assert.strictEqual(outcome.balanceChanges
.rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh[0].value, '-4003218.000012');
resolve(result);
});
});
});

createTest(
'getTransactions',
[{address: 'rpP2JgiMyTF5jR5hLG3xHCPi1knBb1v9cM'}, {
it('getTransactions', function() {
const params = [{address: newWallet.address}, {
options: {
binary: true,
limit: 1,
start:
'FBAAC31D6BAEEFA9E501266FD62DA7A7982662BC19BC42F49BB41405C2F820DB'
limit: 1
}
}],
result => assert.deepEqual(result, fixtures.getTransactions),
'3'
);
}];
return new Promise((resolve, reject) => {
client.request('getTransactions', makeNamedParams(params),
(err, result) => {
if (err) {
reject(err);
}
assert.strictEqual(result.result.length, 1);
assert.strictEqual(result.result[0].id, paymentId);
resolve(result);
});
});
});

createTest(
'prepareSettings',
Expand Down

0 comments on commit 3dd21a7

Please sign in to comment.