JS and UT: XNS -> XRP

This commit is contained in:
Arthur Britto
2012-11-09 15:05:32 -08:00
parent 5fbe7b2015
commit 9174886dbc
3 changed files with 26 additions and 24 deletions

View File

@@ -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 {

View File

@@ -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());

View File

@@ -19,7 +19,7 @@ buster.testCase("Sending", {
'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(),
"send XNS to non-existant account without create." :
"send XRP to non-existant account without create." :
function (done) {
var self = this;
var ledgers = 20;
@@ -713,6 +713,6 @@ buster.testCase("Indirect ripple", {
});
},
// Direct ripple without no liqudity.
// Test with XRC at start and end.
// Test with XRP at start and end.
});
// vim:sw=2:sts=2:ts=8