mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
UT: Test offer counts.
This commit is contained in:
@@ -622,7 +622,6 @@ Remote.prototype.request_ledger_entry = function (type) {
|
||||
|
||||
// console.log('request_ledger_entry: caught');
|
||||
|
||||
|
||||
if (self._ledger_hash) {
|
||||
// A specific ledger is requested.
|
||||
|
||||
@@ -913,6 +912,19 @@ Remote.prototype.request_account_balance = function (account, current) {
|
||||
});
|
||||
};
|
||||
|
||||
// Return a request to emit the owner count.
|
||||
Remote.prototype.request_owner_count = function (account, current) {
|
||||
var request = this.request_ledger_entry('account_root');
|
||||
|
||||
return request
|
||||
.account_root(account)
|
||||
.ledger_choose(current)
|
||||
.on('success', function (message) {
|
||||
// If the caller also waits for 'success', they might run before this.
|
||||
request.emit('owner_count', message.node.OwnerCount);
|
||||
});
|
||||
};
|
||||
|
||||
// Return the next account sequence if possible.
|
||||
// <-- undefined or Sequence
|
||||
Remote.prototype.account_seq = function (account, advance) {
|
||||
|
||||
@@ -15,6 +15,7 @@ buster.testRunner.timeout = 5000;
|
||||
|
||||
buster.testCase("Offer tests", {
|
||||
'setUp' : testutils.build_setup(),
|
||||
// 'setUp' : testutils.build_setup({ verbose: true }),
|
||||
'tearDown' : testutils.build_teardown(),
|
||||
|
||||
"offer create then cancel in one ledger" :
|
||||
@@ -344,6 +345,11 @@ buster.testCase("Offer tests", {
|
||||
|
||||
testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "mtgox"], callback);
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Owner count undefined.";
|
||||
|
||||
testutils.verify_owner_count(self.remote, "bob", undefined, callback);
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Set limits.";
|
||||
|
||||
@@ -354,6 +360,16 @@ buster.testCase("Offer tests", {
|
||||
},
|
||||
callback);
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Owner counts after trust.";
|
||||
|
||||
testutils.verify_owner_counts(self.remote,
|
||||
{
|
||||
"alice" : 1,
|
||||
"bob" : 1,
|
||||
},
|
||||
callback);
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Distribute funds.";
|
||||
|
||||
@@ -376,6 +392,16 @@ buster.testCase("Offer tests", {
|
||||
})
|
||||
.submit();
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Owner counts after offer create.";
|
||||
|
||||
testutils.verify_owner_counts(self.remote,
|
||||
{
|
||||
"alice" : 1,
|
||||
"bob" : 2,
|
||||
},
|
||||
callback);
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Verify offer balance.";
|
||||
|
||||
@@ -409,6 +435,16 @@ buster.testCase("Offer tests", {
|
||||
|
||||
testutils.verify_offer_not_found(self.remote, "bob", seq, callback);
|
||||
},
|
||||
function (callback) {
|
||||
self.what = "Owner counts after consumed.";
|
||||
|
||||
testutils.verify_owner_counts(self.remote,
|
||||
{
|
||||
"alice" : 1,
|
||||
"bob" : 1,
|
||||
},
|
||||
callback);
|
||||
},
|
||||
], function (error) {
|
||||
buster.refute(error, self.what);
|
||||
done();
|
||||
|
||||
@@ -138,6 +138,8 @@ var build_teardown = function (host) {
|
||||
var create_accounts = function (remote, src, amount, accounts, callback) {
|
||||
assert(5 === arguments.length);
|
||||
|
||||
remote.set_account_seq(src, 1);
|
||||
|
||||
async.forEach(accounts, function (account, callback) {
|
||||
// Cache the seq as 1.
|
||||
// Otherwise, when other operations attempt to opperate async against the account they may get confused.
|
||||
@@ -364,6 +366,36 @@ var verify_offer_not_found = function (remote, owner, seq, callback) {
|
||||
.request();
|
||||
};
|
||||
|
||||
var verify_owner_count = function (remote, account, value, callback) {
|
||||
assert(4 === arguments.length);
|
||||
|
||||
remote.request_owner_count(account, 'CURRENT')
|
||||
.once('owner_count', function (owner_count) {
|
||||
if (owner_count !== value)
|
||||
console.log("owner_count: %s/%d", owner_count, value);
|
||||
|
||||
callback(owner_count !== value);
|
||||
})
|
||||
.request();
|
||||
};
|
||||
|
||||
var verify_owner_counts = function (remote, counts, callback) {
|
||||
var tests = [];
|
||||
|
||||
for (var src in counts) {
|
||||
tests.push( { "source" : src, "count" : counts[src] } );
|
||||
}
|
||||
|
||||
async.every(tests,
|
||||
function (check, callback) {
|
||||
verify_owner_count(remote, check.source, check.count,
|
||||
function (mismatch) { callback(!mismatch); });
|
||||
},
|
||||
function (every) {
|
||||
callback(!every);
|
||||
});
|
||||
};
|
||||
|
||||
exports.account_dump = account_dump;
|
||||
|
||||
exports.build_setup = build_setup;
|
||||
@@ -378,5 +410,7 @@ exports.verify_balance = verify_balance;
|
||||
exports.verify_balances = verify_balances;
|
||||
exports.verify_offer = verify_offer;
|
||||
exports.verify_offer_not_found = verify_offer_not_found;
|
||||
exports.verify_owner_count = verify_owner_count;
|
||||
exports.verify_owner_counts = verify_owner_counts;
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
Reference in New Issue
Block a user