mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
UT: Add support for verifying offers & fix amount checking.
This commit is contained in:
@@ -97,6 +97,25 @@ Request.prototype.index = function (hash) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Provide the information id an offer.
|
||||||
|
// --> account
|
||||||
|
// --> seq : sequence number of transaction creating offer (integer)
|
||||||
|
Request.prototype.offer_id = function (account, seq) {
|
||||||
|
this.message.offer = {
|
||||||
|
'account' : UInt160.json_rewrite(account),
|
||||||
|
'seq' : seq
|
||||||
|
};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
// --> index : ledger entry index.
|
||||||
|
Request.prototype.offer_index = function (index) {
|
||||||
|
this.message.offer = index;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
Request.prototype.secret = function (s) {
|
Request.prototype.secret = function (s) {
|
||||||
if (s)
|
if (s)
|
||||||
this.message.secret = s;
|
this.message.secret = s;
|
||||||
@@ -403,6 +422,7 @@ Remote.prototype._connect_message = function (ws, json) {
|
|||||||
else {
|
else {
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case 'response':
|
case 'response':
|
||||||
|
// A response to a request.
|
||||||
{
|
{
|
||||||
request = ws.response[message.id];
|
request = ws.response[message.id];
|
||||||
|
|
||||||
@@ -510,8 +530,10 @@ Remote.prototype.request_ledger_current = function () {
|
|||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --> ledger : optional
|
// --> type : the type of ledger entry.
|
||||||
// --> ledger_index : optional
|
// .ledger()
|
||||||
|
// .ledger_index()
|
||||||
|
// .offer_id()
|
||||||
Remote.prototype.request_ledger_entry = function (type) {
|
Remote.prototype.request_ledger_entry = function (type) {
|
||||||
assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
|
assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
|
||||||
|
|
||||||
@@ -684,7 +706,7 @@ Remote.prototype._server_subscribe = function () {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ask the remote to accept the current ledger.
|
// For unit testing: ask the remote to accept the current ledger.
|
||||||
// - To be notified when the ledger is accepted, server_subscribe() then listen to 'ledger_hash' events.
|
// - To be notified when the ledger is accepted, server_subscribe() then listen to 'ledger_hash' events.
|
||||||
// A good way to be notified of the result of this is:
|
// A good way to be notified of the result of this is:
|
||||||
// remote.once('ledger_closed', function (ledger_closed, ledger_index) { ... } );
|
// remote.once('ledger_closed', function (ledger_closed, ledger_index) { ... } );
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_create("root", "500", "100/USD/root")
|
.offer_create("root", "500", "100/USD/root")
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS', m);
|
callback(m.result !== 'tesSUCCESS', m);
|
||||||
})
|
})
|
||||||
.on('final', function (m) {
|
.on('final', function (m) {
|
||||||
// console.log("FINAL: offer_create: %s", JSON.stringify(m));
|
// console.log("FINAL: offer_create: %s", JSON.stringify(m));
|
||||||
@@ -44,7 +44,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_cancel("root", m.tx_json.Sequence)
|
.offer_cancel("root", m.tx_json.Sequence)
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS', m);
|
callback(m.result !== 'tesSUCCESS', m);
|
||||||
})
|
})
|
||||||
.on('final', function (m) {
|
.on('final', function (m) {
|
||||||
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
|
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
|
||||||
@@ -85,7 +85,7 @@ buster.testCase("Offer tests", {
|
|||||||
|
|
||||||
offer_seq = m.tx_json.Sequence;
|
offer_seq = m.tx_json.Sequence;
|
||||||
|
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.on('final', function (m) {
|
.on('final', function (m) {
|
||||||
// console.log("FINAL: offer_create: %s", JSON.stringify(m));
|
// console.log("FINAL: offer_create: %s", JSON.stringify(m));
|
||||||
@@ -118,7 +118,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_cancel("root", offer_seq)
|
.offer_cancel("root", offer_seq)
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.on('final', function (m) {
|
.on('final', function (m) {
|
||||||
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
|
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
|
||||||
@@ -182,7 +182,7 @@ buster.testCase("Offer tests", {
|
|||||||
|
|
||||||
offer_seq = m.tx_json.Sequence;
|
offer_seq = m.tx_json.Sequence;
|
||||||
|
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.on('final', function (m) {
|
.on('final', function (m) {
|
||||||
// console.log("FINAL: offer_create: %s", JSON.stringify(m));
|
// console.log("FINAL: offer_create: %s", JSON.stringify(m));
|
||||||
@@ -215,7 +215,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_cancel("alice", offer_seq)
|
.offer_cancel("alice", offer_seq)
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.on('final', function (m) {
|
.on('final', function (m) {
|
||||||
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
|
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
|
||||||
@@ -263,7 +263,7 @@ buster.testCase("Offer tests", {
|
|||||||
.set_flags('CreateAccount')
|
.set_flags('CreateAccount')
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m));
|
// console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS', m);
|
callback(m.result !== 'tesSUCCESS', m);
|
||||||
})
|
})
|
||||||
.on('error', function(m) {
|
.on('error', function(m) {
|
||||||
// console.log("error: %s", m);
|
// console.log("error: %s", m);
|
||||||
@@ -279,7 +279,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_cancel("root", m.tx_json.Sequence)
|
.offer_cancel("root", m.tx_json.Sequence)
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS', m);
|
callback(m.result !== 'tesSUCCESS', m);
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -289,7 +289,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_cancel("root", m.tx_json.Sequence+1)
|
.offer_cancel("root", m.tx_json.Sequence+1)
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'temBAD_SEQUENCE', m);
|
callback(m.result !== 'temBAD_SEQUENCE', m);
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -302,7 +302,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_cancel("root", m.tx_json.Sequence+2)
|
.offer_cancel("root", m.tx_json.Sequence+2)
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("ERROR: offer_cancel future: %s", JSON.stringify(m));
|
// console.log("ERROR: offer_cancel future: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'temBAD_SEQUENCE');
|
callback(m.result !== 'temBAD_SEQUENCE');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -370,7 +370,7 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_create("bob", "100/USD/mtgox", "500")
|
.offer_create("bob", "100/USD/mtgox", "500")
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -383,7 +383,7 @@ buster.testCase("Offer tests", {
|
|||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -270,10 +270,10 @@ buster.testCase("Sending future", {
|
|||||||
.payment('alice', 'bob', "24/USD/alice")
|
.payment('alice', 'bob', "24/USD/alice")
|
||||||
.once('proposed', function (m) {
|
.once('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.once('final', function (m) {
|
.once('final', function (m) {
|
||||||
buster.assert(m.result != 'tesSUCCESS');
|
buster.assert(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -296,10 +296,10 @@ buster.testCase("Sending future", {
|
|||||||
.payment('alice', 'bob', "33/USD/bob")
|
.payment('alice', 'bob', "33/USD/bob")
|
||||||
.once('proposed', function (m) {
|
.once('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.once('final', function (m) {
|
.once('final', function (m) {
|
||||||
buster.assert(m.result != 'tesSUCCESS');
|
buster.assert(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -322,10 +322,10 @@ buster.testCase("Sending future", {
|
|||||||
.payment('bob', 'alice', "90/USD/bob")
|
.payment('bob', 'alice', "90/USD/bob")
|
||||||
.once('proposed', function (m) {
|
.once('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.once('final', function (m) {
|
.once('final', function (m) {
|
||||||
buster.assert(m.result != 'tesSUCCESS');
|
buster.assert(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -347,10 +347,10 @@ buster.testCase("Sending future", {
|
|||||||
.payment('alice', 'bob', "733/USD/bob")
|
.payment('alice', 'bob', "733/USD/bob")
|
||||||
.once('proposed', function (m) {
|
.once('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.once('final', function (m) {
|
.once('final', function (m) {
|
||||||
buster.assert(m.result != 'tesSUCCESS');
|
buster.assert(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -372,10 +372,10 @@ buster.testCase("Sending future", {
|
|||||||
.payment('bob', 'alice', "1300/USD/bob")
|
.payment('bob', 'alice', "1300/USD/bob")
|
||||||
.once('proposed', function (m) {
|
.once('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.once('final', function (m) {
|
.once('final', function (m) {
|
||||||
buster.assert(m.result != 'tesSUCCESS');
|
buster.assert(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -398,7 +398,7 @@ buster.testCase("Sending future", {
|
|||||||
.payment('bob', 'alice', "1/USD/bob")
|
.payment('bob', 'alice', "1/USD/bob")
|
||||||
.once('proposed', function (m) {
|
.once('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
callback(m.result != 'tepPATH_DRY');
|
callback(m.result !== 'tepPATH_DRY');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -503,7 +503,7 @@ buster.testCase("Indirect ripple", {
|
|||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
callback(m.result != 'tepPATH_PARTIAL');
|
callback(m.result !== 'tepPATH_PARTIAL');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -515,7 +515,7 @@ buster.testCase("Indirect ripple", {
|
|||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
callback(m.result != 'tepPATH_PARTIAL');
|
callback(m.result !== 'tepPATH_PARTIAL');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -563,7 +563,7 @@ buster.testCase("Indirect ripple", {
|
|||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -623,7 +623,7 @@ buster.testCase("Indirect ripple", {
|
|||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
@@ -691,7 +691,7 @@ buster.testCase("Indirect ripple", {
|
|||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("proposed: %s", JSON.stringify(m));
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
callback(m.result != 'tesSUCCESS');
|
callback(m.result !== 'tesSUCCESS');
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ var verify_balance = function (remote, src, amount_json, callback) {
|
|||||||
|
|
||||||
if (amount.is_native()) {
|
if (amount.is_native()) {
|
||||||
// XXX Not implemented.
|
// XXX Not implemented.
|
||||||
callback(false);
|
callback();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
remote.request_ripple_balance(src, amount.issuer.to_json(), amount.currency.to_json(), 'CURRENT')
|
remote.request_ripple_balance(src, amount.issuer.to_json(), amount.currency.to_json(), 'CURRENT')
|
||||||
@@ -237,11 +237,13 @@ var verify_balance = function (remote, src, amount_json, callback) {
|
|||||||
// console.log("issuer_balance: %s", m.issuer_balance.to_text_full());
|
// console.log("issuer_balance: %s", m.issuer_balance.to_text_full());
|
||||||
// console.log("issuer_limit: %s", m.issuer_limit.to_text_full());
|
// console.log("issuer_limit: %s", m.issuer_limit.to_text_full());
|
||||||
|
|
||||||
if (!m.account_balance.equals(amount)) {
|
var account_balance = Amount.from_json(m.account_balance);
|
||||||
|
|
||||||
|
if (!account_balance.equals(amount)) {
|
||||||
console.log("verify_balance: failed: %s vs %s is %s", src, amount_json, amount.to_text_full());
|
console.log("verify_balance: failed: %s vs %s is %s", src, amount_json, amount.to_text_full());
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(!m.account_balance.equals(amount));
|
callback(!account_balance.equals(amount));
|
||||||
})
|
})
|
||||||
.request();
|
.request();
|
||||||
}
|
}
|
||||||
@@ -269,6 +271,46 @@ var verify_balances = function (remote, balances, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --> owner: account
|
||||||
|
// --> seq: sequence number of creating transaction.
|
||||||
|
// --> taker_gets: json amount
|
||||||
|
// --> taker_pays: json amount
|
||||||
|
var verify_offer = function (remote, owner, seq, taker_gets, taker_pays, callback) {
|
||||||
|
assert(6 === arguments.length);
|
||||||
|
|
||||||
|
remote.request_ledger_entry('offer')
|
||||||
|
.offer_id(owner, seq)
|
||||||
|
.on('success', function (m) {
|
||||||
|
var wrong = (!Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets))
|
||||||
|
|| !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays)));
|
||||||
|
|
||||||
|
if (wrong)
|
||||||
|
console.log("verify_offer: failed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(wrong);
|
||||||
|
})
|
||||||
|
.request();
|
||||||
|
};
|
||||||
|
|
||||||
|
var verify_offer_not_found = function (remote, owner, seq, callback) {
|
||||||
|
assert(4 === arguments.length);
|
||||||
|
|
||||||
|
remote.request_ledger_entry('offer')
|
||||||
|
.offer_id(owner, seq)
|
||||||
|
.on('success', function (m) {
|
||||||
|
console.log("verify_no_offer: found offer: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback('entryFound');
|
||||||
|
})
|
||||||
|
.on('error', function (m) {
|
||||||
|
console.log("verify_no_offer: success: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback('remoteError' !== m.error
|
||||||
|
|| 'entryNotFound' !== m.remote.error);
|
||||||
|
})
|
||||||
|
.request();
|
||||||
|
};
|
||||||
|
|
||||||
exports.build_setup = build_setup;
|
exports.build_setup = build_setup;
|
||||||
exports.create_accounts = create_accounts;
|
exports.create_accounts = create_accounts;
|
||||||
exports.credit_limit = credit_limit;
|
exports.credit_limit = credit_limit;
|
||||||
@@ -279,5 +321,7 @@ exports.build_teardown = build_teardown;
|
|||||||
exports.transfer_rate = transfer_rate;
|
exports.transfer_rate = transfer_rate;
|
||||||
exports.verify_balance = verify_balance;
|
exports.verify_balance = verify_balance;
|
||||||
exports.verify_balances = verify_balances;
|
exports.verify_balances = verify_balances;
|
||||||
|
exports.verify_offer = verify_offer;
|
||||||
|
exports.verify_offer_not_found = verify_offer_not_found;
|
||||||
|
|
||||||
// vim:sw=2:sts=2:ts=8
|
// vim:sw=2:sts=2:ts=8
|
||||||
|
|||||||
Reference in New Issue
Block a user