From 19ec41e7bd178e8c8a04b6c98ed133aa87af983f Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Fri, 9 Nov 2012 15:05:32 -0800 Subject: [PATCH] JS and UT: XNS -> XRP --- src/js/amount.js | 26 +++++++++++++------------- test/amount-test.js | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/js/amount.js b/src/js/amount.js index 3fd7c357..bd62ab55 100644 --- a/src/js/amount.js +++ b/src/js/amount.js @@ -218,11 +218,11 @@ UInt160.prototype.to_json = function () { }; var Currency = function () { - // Internal form: 0 = XNS. 3 letter-code. + // Internal form: 0 = XRP. 3 letter-code. // XXX Internal should be 0 or hex with three letter annotation when valid. // Json form: - // '', 'XNS', '0': 0 + // '', 'XRP', '0': 0 // 3-letter code: ... // XXX Should support hex, C++ doesn't currently allow it. @@ -253,7 +253,7 @@ Currency.prototype.copyTo = function(d) { // this._value = NaN on error. Currency.prototype.parse_json = function(j) { - if ("" === j || "0" === j || "XNS" === j) { + if ("" === j || "0" === j || "XRP" === j) { this._value = 0; } else if ('string' != typeof j || 3 !== j.length) { @@ -267,22 +267,22 @@ Currency.prototype.parse_json = function(j) { }; Currency.prototype.to_json = function () { - return this._value ? this._value : "XNS"; + return this._value ? this._value : "XRP"; }; Currency.prototype.to_human = function() { - return this._value ? this._value : "XNS"; + return this._value ? this._value : "XRP"; }; var Amount = function () { // Json format: - // integer : XNS + // integer : XRP // { 'value' : ..., 'currency' : ..., 'issuer' : ...} - this._value = new BigInteger(); // NaN for bad value. Always positive for non-XNS. - this._offset = undefined; // For non-XNS. - this._is_native = true; // Default to XNS. Only valid if value is not NaN. - this._is_negative = undefined; // Undefined for XNS. + this._value = new BigInteger(); // NaN for bad value. Always positive for non-XRP. + this._offset = undefined; // For non-XRP. + this._is_native = true; // Default to XRP. Only valid if value is not NaN. + this._is_negative = undefined; // Undefined for XRP. this.currency = new Currency(); this.issuer = new UInt160(); @@ -432,11 +432,11 @@ Amount.prototype.to_text_full = function() { return isNaN(this._value) ? NaN : this._is_native - ? this.to_text() + "/XNS" + ? this.to_text() + "/XRP" : this.to_text() + "/" + this.currency.to_json() + "/" + this.issuer.to_json(); }; -// Parse a XNS value from untrusted input. +// Parse a XRP value from untrusted input. // - integer = raw units // - float = with precision 6 // XXX Improvements: disallow leading zeros. @@ -566,7 +566,7 @@ Amount.prototype.parse_json = function(j) { // Parse the passed value to sanitize and copy it. this.parse_value(j.value); - this.currency.parse_json(j.currency); // Never XNS. + this.currency.parse_json(j.currency); // Never XRP. this.issuer.parse_json(j.issuer); } else { diff --git a/test/amount-test.js b/test/amount-test.js index 841b0789..c5bb91c4 100644 --- a/test/amount-test.js +++ b/test/amount-test.js @@ -12,6 +12,8 @@ require("../src/js/amount.js").config = require("./config.js"); var config = require('./config.js'); +// XXX Add test cases that push XRP vs non-XRP behavior. + buster.testCase("Amount", { "UInt160" : { "Parse 0" : function () { @@ -38,25 +40,25 @@ buster.testCase("Amount", { buster.assert.equals("800/USD/"+config.accounts["mtgox"].account, Amount.from_json("800/USD/mtgox").to_text_full()); }, "Parse native 0" : function () { - buster.assert.equals("0/XNS", Amount.from_json("0").to_text_full()); + buster.assert.equals("0/XRP", Amount.from_json("0").to_text_full()); }, "Parse native 0.0" : function () { - buster.assert.equals("0/XNS", Amount.from_json("0.0").to_text_full()); + buster.assert.equals("0/XRP", Amount.from_json("0.0").to_text_full()); }, "Parse native -0" : function () { - buster.assert.equals("0/XNS", Amount.from_json("-0").to_text_full()); + buster.assert.equals("0/XRP", Amount.from_json("-0").to_text_full()); }, "Parse native -0.0" : function () { - buster.assert.equals("0/XNS", Amount.from_json("-0.0").to_text_full()); + buster.assert.equals("0/XRP", Amount.from_json("-0.0").to_text_full()); }, "Parse native 1000" : function () { - buster.assert.equals("1000/XNS", Amount.from_json("1000").to_text_full()); + buster.assert.equals("1000/XRP", Amount.from_json("1000").to_text_full()); }, "Parse native 12.3" : function () { - buster.assert.equals("12300000/XNS", Amount.from_json("12.3").to_text_full()); + buster.assert.equals("12300000/XRP", Amount.from_json("12.3").to_text_full()); }, "Parse native -12.3" : function () { - buster.assert.equals("-12300000/XNS", Amount.from_json("-12.3").to_text_full()); + buster.assert.equals("-12300000/XRP", Amount.from_json("-12.3").to_text_full()); }, "Parse 123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () { buster.assert.equals("123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").to_text_full()); @@ -79,10 +81,10 @@ buster.testCase("Amount", { }, "Amount operations" : { "Negate native 123" : function () { - buster.assert.equals("-123/XNS", Amount.from_json("123").negate().to_text_full()); + buster.assert.equals("-123/XRP", Amount.from_json("123").negate().to_text_full()); }, "Negate native -123" : function () { - buster.assert.equals("123/XNS", Amount.from_json("-123").negate().to_text_full()); + buster.assert.equals("123/XRP", Amount.from_json("-123").negate().to_text_full()); }, "Negate non-native 123" : function () { buster.assert.equals("-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").negate().to_text_full());