Skip to content

Commit

Permalink
Fix transaction sequencing
Browse files Browse the repository at this point in the history
  • Loading branch information
wltsmrz committed Jul 28, 2015
1 parent 4568b39 commit fae22b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/core/transactionmanager.js
Expand Up @@ -728,8 +728,7 @@ TransactionManager.prototype.submit = function(tx) {

if (typeof tx.tx_json.Sequence !== 'number') {
// Honor manually-set sequences
this._nextSequence += 1;
tx.tx_json.Sequence = this._nextSequence;
tx.tx_json.Sequence = this._nextSequence++;
}

tx.once('cleanup', function() {
Expand Down
26 changes: 20 additions & 6 deletions test/transaction-manager-test.js
Expand Up @@ -425,6 +425,8 @@ describe('TransactionManager', function() {
rippled.once('request_submit', function(m, req) {
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(new SerializedObject(m.tx_blob).to_json().Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
assert.strictEqual(transactionManager.getPending().length(), 1);
req.sendResponse(SUBMIT_RESPONSE, {id: m.id});
setImmediate(function() {
Expand Down Expand Up @@ -463,6 +465,8 @@ describe('TransactionManager', function() {
rippled.once('request_submit', function(m, req) {
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(new SerializedObject(m.tx_blob).to_json().Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
assert.strictEqual(transactionManager.getPending().length(), 1);
req.sendResponse(SUBMIT_TEC_RESPONSE, {id: m.id});
setImmediate(function() {
Expand Down Expand Up @@ -506,13 +510,15 @@ describe('TransactionManager', function() {

switch (deserialized.TransactionType) {
case 'Payment':
assert.strictEqual(transactionManager.getPending().length(), 1);
assert.deepEqual(deserialized, transaction.tx_json);
assert.strictEqual(transactionManager.getPending().length(), 1);
req.sendResponse(SUBMIT_TER_RESPONSE, {id: m.id});
break;
case 'AccountSet':
assert.strictEqual(deserialized.Account, ACCOUNT.address);
assert.strictEqual(deserialized.Flags, 2147483648);
assert.strictEqual(deserialized.Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
req.sendResponse(SUBMIT_RESPONSE, {id: m.id});
req.closeLedger();
break;
Expand Down Expand Up @@ -568,9 +574,9 @@ describe('TransactionManager', function() {
});

rippled.on('request_submit', function(m, req) {
assert.strictEqual(transactionManager.getPending().length(), 1);
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(transactionManager.getPending().length(), 1);
req.sendResponse(SUBMIT_TEF_RESPONSE, {id: m.id});
});

Expand Down Expand Up @@ -626,9 +632,11 @@ describe('TransactionManager', function() {
});

rippled.on('request_submit', function(m, req) {
assert.strictEqual(transactionManager.getPending().length(), 1);
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(new SerializedObject(m.tx_blob).to_json().Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
assert.strictEqual(transactionManager.getPending().length(), 1);
req.sendResponse(SUBMIT_TEL_RESPONSE, {id: m.id});
});

Expand Down Expand Up @@ -729,9 +737,11 @@ describe('TransactionManager', function() {
});

rippled.on('request_submit', function(m, req) {
assert.strictEqual(transactionManager.getPending().length(), 1);
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(new SerializedObject(m.tx_blob).to_json().Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
assert.strictEqual(transactionManager.getPending().length(), 1);

/* eslint-disable max-len */

Expand Down Expand Up @@ -787,9 +797,11 @@ describe('TransactionManager', function() {
});

rippled.on('request_submit', function(m, req) {
assert.strictEqual(transactionManager.getPending().length(), 1);
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(new SerializedObject(m.tx_blob).to_json().Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
assert.strictEqual(transactionManager.getPending().length(), 1);
req.sendResponse(SUBMIT_TEL_RESPONSE, {id: m.id});
});

Expand Down Expand Up @@ -852,9 +864,11 @@ describe('TransactionManager', function() {
});

rippled.on('request_submit', function(m, req) {
assert.strictEqual(transactionManager.getPending().length(), 1);
assert.strictEqual(m.tx_blob, SerializedObject.from_json(
transaction.tx_json).to_hex());
assert.strictEqual(new SerializedObject(m.tx_blob).to_json().Sequence,
ACCOUNT_INFO_RESPONSE.result.account_data.Sequence);
assert.strictEqual(transactionManager.getPending().length(), 1);

req.sendResponse(SUBMIT_TOO_BUSY_ERROR, {id: m.id});
});
Expand Down

0 comments on commit fae22b7

Please sign in to comment.