mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
JS: Add a way for the test suite to change Amount#equals, so it ignores issuers.
This commit is contained in:
@@ -283,7 +283,7 @@ Amount.prototype.currency = function () {
|
||||
return this._currency;
|
||||
};
|
||||
|
||||
Amount.prototype.equals = function (d) {
|
||||
Amount.prototype.equals = function (d, ignore_issuer) {
|
||||
if ("string" === typeof d) {
|
||||
return this.equals(Amount.from_json(d));
|
||||
}
|
||||
@@ -302,7 +302,7 @@ Amount.prototype.equals = function (d) {
|
||||
|
||||
if (!this._is_native) {
|
||||
if (!this._currency.equals(d._currency)) return false;
|
||||
if (!this._issuer.equals(d._issuer)) return false;
|
||||
if (!ignore_issuer && !this._issuer.equals(d._issuer)) return false;
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
@@ -917,7 +917,7 @@ Amount.prototype.to_text_full = function (opts) {
|
||||
};
|
||||
|
||||
// For debugging.
|
||||
Amount.prototype.not_equals_why = function (d) {
|
||||
Amount.prototype.not_equals_why = function (d, ignore_issuer) {
|
||||
if ("string" === typeof d) {
|
||||
return this.not_equals_why(Amount.from_json(d));
|
||||
}
|
||||
@@ -938,7 +938,9 @@ Amount.prototype.not_equals_why = function (d) {
|
||||
|
||||
if (!this._is_native) {
|
||||
if (!this._currency.equals(d._currency)) return "Non-XRP currency differs.";
|
||||
if (!this._issuer.equals(d._issuer)) return "Non-XRP issuer differs.";
|
||||
if (!ignore_issuer && !this._issuer.equals(d._issuer)) {
|
||||
return "Non-XRP issuer differs.";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else return "Wrong constructor.";
|
||||
|
||||
@@ -285,12 +285,13 @@ var verify_balance = function (remote, src, amount_json, callback) {
|
||||
if (amount_req.is_native()) {
|
||||
remote.request_account_balance(src, 'CURRENT')
|
||||
.once('account_balance', function (amount_act) {
|
||||
if (!amount_act.equals(amount_req))
|
||||
if (!amount_act.equals(amount_req, true)) {
|
||||
console.log("verify_balance: failed: %s / %s",
|
||||
amount_act.to_text_full(),
|
||||
amount_req.to_text_full());
|
||||
}
|
||||
|
||||
callback(!amount_act.equals(amount_req));
|
||||
callback(!amount_act.equals(amount_req, true));
|
||||
})
|
||||
.request();
|
||||
}
|
||||
@@ -305,11 +306,15 @@ var verify_balance = function (remote, src, amount_json, callback) {
|
||||
|
||||
var account_balance = Amount.from_json(m.account_balance);
|
||||
|
||||
if (!account_balance.equals(amount_req)) {
|
||||
console.log("verify_balance: failed: %s vs %s / %s: %s", src, account_balance.to_text_full(), amount_req.to_text_full(), account_balance.not_equals_why(amount_req));
|
||||
if (!account_balance.equals(amount_req, true)) {
|
||||
console.log("verify_balance: failed: %s vs %s / %s: %s",
|
||||
src,
|
||||
account_balance.to_text_full(),
|
||||
amount_req.to_text_full(),
|
||||
account_balance.not_equals_why(amount_req, true));
|
||||
}
|
||||
|
||||
callback(!account_balance.equals(amount_req));
|
||||
callback(!account_balance.equals(amount_req, true));
|
||||
})
|
||||
.request();
|
||||
}
|
||||
@@ -347,8 +352,8 @@ var verify_offer = function (remote, owner, seq, taker_pays, taker_gets, callbac
|
||||
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)));
|
||||
var wrong = !Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets), true)
|
||||
|| !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays), true);
|
||||
|
||||
if (wrong)
|
||||
console.log("verify_offer: failed: %s", JSON.stringify(m));
|
||||
|
||||
Reference in New Issue
Block a user