mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Improvements to js tests and increment of the ripple-lib version
This commit is contained in:
@@ -28,181 +28,180 @@ buster.testCase("//Account_tx tests", {
|
||||
'setUp' : testutils.build_setup(),
|
||||
'tearDown' : testutils.build_teardown(),
|
||||
|
||||
"make a lot of transactions and query using account_tx" :
|
||||
function (done) {
|
||||
var self = this;
|
||||
var final_create;
|
||||
var transactionCounter = 0;
|
||||
var f = 0;
|
||||
var functionHolder;
|
||||
var createOfferFunction = function (callback) {
|
||||
self.remote.transaction()
|
||||
.offer_create("root", "500", "100/USD/root")
|
||||
.on('proposed', function (m) {
|
||||
transactionCounter++;
|
||||
if (VERBOSE) console.log('Submitted transaction', transactionCounter);
|
||||
"make a lot of transactions and query using account_tx" : function (done) {
|
||||
var self = this;
|
||||
var final_create;
|
||||
var transactionCounter = 0;
|
||||
var f = 0;
|
||||
var functionHolder;
|
||||
var createOfferFunction = function (callback) {
|
||||
self.remote.transaction()
|
||||
.offer_create("root", "500", "100/USD/root")
|
||||
.on('proposed', function (m) {
|
||||
transactionCounter++;
|
||||
if (VERBOSE) console.log('Submitted transaction', transactionCounter);
|
||||
|
||||
callback(m.result !== 'tesSUCCESS');
|
||||
})
|
||||
.on('final', function (m) {
|
||||
f++;
|
||||
if (VERBOSE) console.log("Finalized transaction", f);
|
||||
buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult);
|
||||
buster.assert(final_create);
|
||||
if ( f == transactionCounter ) {
|
||||
if (VERBOSE) console.log("All transactions have been finalized.");
|
||||
functionHolder();
|
||||
}
|
||||
})
|
||||
.submit();
|
||||
};
|
||||
|
||||
function lotsOfTransactions(number, whenDone) {
|
||||
var bunchOfOffers = [];
|
||||
for (var i=0; i<number; i++) {
|
||||
bunchOfOffers.push(createOfferFunction);
|
||||
}
|
||||
functionHolder = whenDone; //lolwut
|
||||
async.parallel(bunchOfOffers, function (error) {
|
||||
if (VERBOSE) console.log("Accepting ledger.");
|
||||
buster.refute(error);
|
||||
self.remote
|
||||
.once('ledger_closed', function (message) {
|
||||
final_create = message;
|
||||
})
|
||||
.ledger_accept();
|
||||
});
|
||||
}
|
||||
|
||||
function firstBatch() {
|
||||
lotsOfTransactions(FIRST_BATCH,
|
||||
function(){runTests(self, FIRST_BATCH, 0, undefined,
|
||||
function(){runTests(self, FIRST_BATCH, OFFSET, undefined,
|
||||
function(){runTests(self, FIRST_BATCH, 0, LIMIT, secondBatch)})}
|
||||
)});
|
||||
}
|
||||
|
||||
function secondBatch() {
|
||||
lotsOfTransactions(SECOND_BATCH,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, 0, undefined,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, undefined, thirdBatch)}
|
||||
)});
|
||||
}
|
||||
|
||||
function thirdBatch() {
|
||||
lotsOfTransactions(THIRD_BATCH,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, undefined,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, undefined, done)}
|
||||
)});
|
||||
}
|
||||
|
||||
firstBatch();
|
||||
|
||||
|
||||
function standardErrorHandler(callback) {
|
||||
return function(r) {
|
||||
if (VERBOSE) console.log("ERROR!");
|
||||
if (VERBOSE) console.log(r);
|
||||
callback(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function runTests(self, actualNumberOfTransactions, offset, limit, finalCallback) {
|
||||
if (VERBOSE) console.log("Testing batch with offset and limit:", offset, limit);
|
||||
async.series([
|
||||
function(callback) {
|
||||
if (VERBOSE) console.log('nonbinary');
|
||||
self.remote.request_account_tx({
|
||||
account:ACCOUNT,
|
||||
ledger_index_min:-1,
|
||||
ledger_index_max:-1,
|
||||
offset:offset,
|
||||
limit:limit
|
||||
}).on('success', function (r) {
|
||||
if (r.transactions) {
|
||||
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
|
||||
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
|
||||
//Check for proper ordering.
|
||||
for (var i=0; i<r.transactions.length-1; i++) {
|
||||
var t1 = r.transactions[i].tx;
|
||||
var t2 = r.transactions[i+1].tx;
|
||||
buster.assert(t1.inLedger<=t2.inLedger,
|
||||
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
|
||||
}
|
||||
} else {
|
||||
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
|
||||
}
|
||||
callback(m.result !== 'tesSUCCESS');
|
||||
})
|
||||
.on('final', function (m) {
|
||||
f++;
|
||||
if (VERBOSE) console.log("Finalized transaction", f);
|
||||
buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult);
|
||||
buster.assert(final_create);
|
||||
if ( f == transactionCounter ) {
|
||||
if (VERBOSE) console.log("All transactions have been finalized.");
|
||||
functionHolder();
|
||||
}
|
||||
})
|
||||
.submit();
|
||||
};
|
||||
|
||||
callback(false);
|
||||
})
|
||||
.on('error', standardErrorHandler(callback))
|
||||
.request();
|
||||
},
|
||||
|
||||
function(callback) {
|
||||
if (VERBOSE) console.log('binary');
|
||||
self.remote.request_account_tx({
|
||||
account:ACCOUNT,
|
||||
ledger_index_min:-1,
|
||||
ledger_index_max:-1,
|
||||
binary:true,
|
||||
offset:offset,
|
||||
limit:limit
|
||||
}).on('success', function (r) {
|
||||
if (r.transactions) {
|
||||
var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
|
||||
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
|
||||
} else {
|
||||
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
|
||||
}
|
||||
callback(false);
|
||||
})
|
||||
.on('error', standardErrorHandler(callback))
|
||||
.request();
|
||||
},
|
||||
function lotsOfTransactions(number, whenDone) {
|
||||
var bunchOfOffers = [];
|
||||
for (var i=0; i<number; i++) {
|
||||
bunchOfOffers.push(createOfferFunction);
|
||||
}
|
||||
functionHolder = whenDone; //lolwut
|
||||
async.parallel(bunchOfOffers, function (error) {
|
||||
if (VERBOSE) console.log("Accepting ledger.");
|
||||
buster.refute(error);
|
||||
self.remote
|
||||
.once('ledger_closed', function (message) {
|
||||
final_create = message;
|
||||
})
|
||||
.ledger_accept();
|
||||
});
|
||||
}
|
||||
|
||||
function(callback) {
|
||||
if (VERBOSE) console.log('nonbinary+offset');
|
||||
self.remote.request_account_tx({
|
||||
account:ACCOUNT,
|
||||
ledger_index_min:-1,
|
||||
ledger_index_max:-1,
|
||||
descending:true,
|
||||
offset:offset,
|
||||
limit:limit
|
||||
}).on('success', function (r) {
|
||||
if (r.transactions) {
|
||||
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset );
|
||||
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
|
||||
//Check for proper ordering.
|
||||
for (var i=0; i<r.transactions.length-1; i++) {
|
||||
var t1 = r.transactions[i].tx;
|
||||
var t2 = r.transactions[i+1].tx;
|
||||
//buster.assert(t1.inLedger>t2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ),
|
||||
// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
|
||||
buster.assert(t1.inLedger>=t2.inLedger,
|
||||
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
|
||||
}
|
||||
} else {
|
||||
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
|
||||
}
|
||||
|
||||
function firstBatch() {
|
||||
lotsOfTransactions(FIRST_BATCH,
|
||||
function(){runTests(self, FIRST_BATCH, 0, undefined,
|
||||
function(){runTests(self, FIRST_BATCH, OFFSET, undefined,
|
||||
function(){runTests(self, FIRST_BATCH, 0, LIMIT, secondBatch)})}
|
||||
)});
|
||||
}
|
||||
|
||||
callback(false);
|
||||
})
|
||||
.on('error', standardErrorHandler(callback))
|
||||
.request();
|
||||
},
|
||||
function secondBatch() {
|
||||
lotsOfTransactions(SECOND_BATCH,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, 0, undefined,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, undefined, thirdBatch)}
|
||||
)});
|
||||
}
|
||||
|
||||
function thirdBatch() {
|
||||
lotsOfTransactions(THIRD_BATCH,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, undefined,
|
||||
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, undefined, done)}
|
||||
)});
|
||||
}
|
||||
|
||||
firstBatch();
|
||||
|
||||
|
||||
], function (error) {
|
||||
buster.refute(error);
|
||||
finalCallback();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
function standardErrorHandler(callback) {
|
||||
return function(r) {
|
||||
if (VERBOSE) console.log("ERROR!");
|
||||
if (VERBOSE) console.log(r);
|
||||
callback(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function runTests(self, actualNumberOfTransactions, offset, limit, finalCallback) {
|
||||
if (VERBOSE) console.log("Testing batch with offset and limit:", offset, limit);
|
||||
async.series([
|
||||
function(callback) {
|
||||
if (VERBOSE) console.log('nonbinary');
|
||||
self.remote.request_account_tx({
|
||||
account:ACCOUNT,
|
||||
ledger_index_min:-1,
|
||||
ledger_index_max:-1,
|
||||
offset:offset,
|
||||
limit:limit
|
||||
}).on('success', function (r) {
|
||||
if (r.transactions) {
|
||||
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
|
||||
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
|
||||
//Check for proper ordering.
|
||||
for (var i=0; i<r.transactions.length-1; i++) {
|
||||
var t1 = r.transactions[i].tx;
|
||||
var t2 = r.transactions[i+1].tx;
|
||||
buster.assert(t1.inLedger<=t2.inLedger,
|
||||
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
|
||||
}
|
||||
} else {
|
||||
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
|
||||
}
|
||||
|
||||
callback(false);
|
||||
})
|
||||
.on('error', standardErrorHandler(callback))
|
||||
.request();
|
||||
},
|
||||
|
||||
function(callback) {
|
||||
if (VERBOSE) console.log('binary');
|
||||
self.remote.request_account_tx({
|
||||
account:ACCOUNT,
|
||||
ledger_index_min:-1,
|
||||
ledger_index_max:-1,
|
||||
binary:true,
|
||||
offset:offset,
|
||||
limit:limit
|
||||
}).on('success', function (r) {
|
||||
if (r.transactions) {
|
||||
var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
|
||||
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
|
||||
} else {
|
||||
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
|
||||
}
|
||||
callback(false);
|
||||
})
|
||||
.on('error', standardErrorHandler(callback))
|
||||
.request();
|
||||
},
|
||||
|
||||
function(callback) {
|
||||
if (VERBOSE) console.log('nonbinary+offset');
|
||||
self.remote.request_account_tx({
|
||||
account:ACCOUNT,
|
||||
ledger_index_min:-1,
|
||||
ledger_index_max:-1,
|
||||
descending:true,
|
||||
offset:offset,
|
||||
limit:limit
|
||||
}).on('success', function (r) {
|
||||
if (r.transactions) {
|
||||
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset );
|
||||
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
|
||||
//Check for proper ordering.
|
||||
for (var i=0; i<r.transactions.length-1; i++) {
|
||||
var t1 = r.transactions[i].tx;
|
||||
var t2 = r.transactions[i+1].tx;
|
||||
//buster.assert(t1.inLedger>t2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ),
|
||||
// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
|
||||
buster.assert(t1.inLedger>=t2.inLedger,
|
||||
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
|
||||
}
|
||||
} else {
|
||||
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
|
||||
}
|
||||
|
||||
|
||||
callback(false);
|
||||
})
|
||||
.on('error', standardErrorHandler(callback))
|
||||
.request();
|
||||
},
|
||||
|
||||
|
||||
], function (error) {
|
||||
buster.refute(error);
|
||||
finalCallback();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user