mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-16 18:35:50 +00:00
Update ripple-lib tests to use mocha
This commit is contained in:
@@ -1,373 +1,358 @@
|
||||
var buster = require("buster");
|
||||
var assert = require('assert');
|
||||
|
||||
var jsbn = require('../src/js/ripple/jsbn');
|
||||
var BigInteger = jsbn.BigInteger;
|
||||
var nbi = jsbn.nbi;
|
||||
var _ = require('underscore');
|
||||
|
||||
var Amount = require("../src/js/ripple/amount").Amount;
|
||||
var UInt160 = require("../src/js/ripple/uint160").UInt160;
|
||||
var Amount = require('../src/js/ripple/amount').Amount;
|
||||
var UInt160 = require('../src/js/ripple/uint160').UInt160;
|
||||
|
||||
try {
|
||||
var conf = require('./config');
|
||||
} catch(exception) {
|
||||
var conf = require('./config-example');
|
||||
}
|
||||
var config = require('./testutils').get_config();
|
||||
|
||||
var config = require('../src/js/ripple/config').load(conf);
|
||||
|
||||
// XXX Add test cases that push XRP vs non-XRP behavior.
|
||||
|
||||
buster.testCase("Amount", {
|
||||
"negatives" : {
|
||||
"Number 1" : function () {
|
||||
buster.assert.equals("-1", Amount.from_human('0').add(Amount.from_human('-1')).to_human());
|
||||
},
|
||||
},
|
||||
|
||||
"from_number" : {
|
||||
"Number 1" : function () {
|
||||
buster.assert.equals("1/1/rrrrrrrrrrrrrrrrrrrrBZbvji", Amount.from_number(1).to_text_full());
|
||||
},
|
||||
},
|
||||
|
||||
"UInt160" : {
|
||||
"Parse 0" : function () {
|
||||
buster.assert.equals(nbi(), UInt160.from_generic("0")._value);
|
||||
},
|
||||
"Parse 0 export" : function () {
|
||||
buster.assert.equals(UInt160.ACCOUNT_ZERO, UInt160.from_generic("0").to_json());
|
||||
},
|
||||
"Parse 1" : function () {
|
||||
buster.assert.equals(new BigInteger([1]), UInt160.from_generic("1")._value);
|
||||
},
|
||||
"Parse rrrrrrrrrrrrrrrrrrrrrhoLvTp export" : function () {
|
||||
buster.assert.equals(UInt160.ACCOUNT_ZERO, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrrhoLvTp").to_json());
|
||||
},
|
||||
"Parse rrrrrrrrrrrrrrrrrrrrBZbvji export" : function () {
|
||||
buster.assert.equals(UInt160.ACCOUNT_ONE, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrBZbvji").to_json());
|
||||
},
|
||||
"Parse mtgox export" : function () {
|
||||
buster.assert.equals(config.accounts["mtgox"].account, UInt160.from_json("mtgox").to_json());
|
||||
},
|
||||
|
||||
"is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvTp')" : function () {
|
||||
buster.assert(UInt160.is_valid("rrrrrrrrrrrrrrrrrrrrrhoLvTp"));
|
||||
},
|
||||
|
||||
"!is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvT')" : function () {
|
||||
buster.refute(UInt160.is_valid("rrrrrrrrrrrrrrrrrrrrrhoLvT"));
|
||||
},
|
||||
},
|
||||
|
||||
"Amount parsing" : {
|
||||
"Parse 800/USD/mtgox" : function () {
|
||||
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/XRP", Amount.from_json("0").to_text_full());
|
||||
},
|
||||
"Parse native 0.0" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("0.0").to_text_full());
|
||||
},
|
||||
"Parse native -0" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("-0").to_text_full());
|
||||
},
|
||||
"Parse native -0.0" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("-0.0").to_text_full());
|
||||
},
|
||||
"Parse native 1000" : function () {
|
||||
buster.assert.equals("0.001/XRP", Amount.from_json("1000").to_text_full());
|
||||
},
|
||||
"Parse native 12.3" : function () {
|
||||
buster.assert.equals("12.3/XRP", Amount.from_json("12.3").to_text_full());
|
||||
},
|
||||
"Parse native -12.3" : function () {
|
||||
buster.assert.equals("-12.3/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());
|
||||
},
|
||||
"Parse 12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
buster.assert.equals("12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").to_text_full());
|
||||
},
|
||||
"Parse 12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
buster.assert.equals("12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").to_text_full());
|
||||
},
|
||||
"Parse 1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
buster.assert.equals("1.23/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").to_text_full());
|
||||
},
|
||||
"Parse -0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
buster.assert.equals("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").to_text_full());
|
||||
},
|
||||
"Parse -0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
buster.assert.equals("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").to_text_full());
|
||||
},
|
||||
},
|
||||
"Amount operations" : {
|
||||
"Negate native 123" : function () {
|
||||
buster.assert.equals("-0.000123/XRP", Amount.from_json("123").negate().to_text_full());
|
||||
},
|
||||
"Negate native -123" : function () {
|
||||
buster.assert.equals("0.000123/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());
|
||||
},
|
||||
"Negate non-native -123" : function () {
|
||||
buster.assert.equals("123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").negate().to_text_full());
|
||||
},
|
||||
"Clone non-native -123" : function () {
|
||||
buster.assert.equals("-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").clone().to_text_full());
|
||||
},
|
||||
"Add XRP to XRP" : function () {
|
||||
buster.assert.equals("0.0002/XRP", Amount.from_json("150").add(Amount.from_json("50")).to_text_full());
|
||||
},
|
||||
"Add USD to USD" : function () {
|
||||
buster.assert.equals("200.52/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("150.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").add(Amount.from_json("50.5/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply 0 XRP with 0 XRP" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("0").multiply(Amount.from_json("0")).to_text_full());
|
||||
},
|
||||
"Multiply 0 USD with 0 XRP" : function () {
|
||||
buster.assert.equals("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("0")).to_text_full());
|
||||
},
|
||||
"Multiply 0 XRP with 0 USD" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("0").multiply(Amount.from_json("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply 1 XRP with 0 XRP" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("1").multiply(Amount.from_json("0")).to_text_full());
|
||||
},
|
||||
"Multiply 1 USD with 0 XRP" : function () {
|
||||
buster.assert.equals("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("0")).to_text_full());
|
||||
},
|
||||
"Multiply 1 XRP with 0 USD" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("1").multiply(Amount.from_json("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply 0 XRP with 1 XRP" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("0").multiply(Amount.from_json("1")).to_text_full());
|
||||
},
|
||||
"Multiply 0 USD with 1 XRP" : function () {
|
||||
buster.assert.equals("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("1")).to_text_full());
|
||||
},
|
||||
"Multiply 0 XRP with 1 USD" : function () {
|
||||
buster.assert.equals("0/XRP", Amount.from_json("0").multiply(Amount.from_json("1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply XRP with USD" : function () {
|
||||
buster.assert.equals("2000/XRP", Amount.from_json("200").multiply(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply XRP with USD" : function () {
|
||||
buster.assert.equals("0.2/XRP", Amount.from_json("20000").multiply(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply XRP with USD" : function () {
|
||||
buster.assert.equals("20/XRP", Amount.from_json("2000000").multiply(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply XRP with USD, neg" : function () {
|
||||
buster.assert.equals("-0.002/XRP", Amount.from_json("200").multiply(Amount.from_json("-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply XRP with USD, neg, frac" : function () {
|
||||
buster.assert.equals("-0.222/XRP", Amount.from_json("-6000").multiply(Amount.from_json("37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply USD with USD" : function () {
|
||||
buster.assert.equals("0.020000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply USD with USD" : function () {
|
||||
buster.assert.equals("200000000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply EUR with USD, result < 1" : function () {
|
||||
buster.assert.equals("100000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply EUR with USD, neg" : function () {
|
||||
buster.assert.equals("-48000000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply EUR with USD, neg, <1" : function () {
|
||||
buster.assert.equals("-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Multiply EUR with XRP, factor < 1" : function () {
|
||||
buster.assert.equals("100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("2000")).to_text_full());
|
||||
},
|
||||
"Multiply EUR with XRP, neg" : function () {
|
||||
buster.assert.equals("-500/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("5")).to_text_full());
|
||||
},
|
||||
"Multiply EUR with XRP, neg, <1" : function () {
|
||||
buster.assert.equals("-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").multiply(Amount.from_json("2000")).to_text_full());
|
||||
},
|
||||
"Multiply XRP with XRP" : function () {
|
||||
buster.assert.equals("0.0001/XRP", Amount.from_json("10").multiply(Amount.from_json("10")).to_text_full());
|
||||
},
|
||||
"Divide XRP by USD" : function () {
|
||||
buster.assert.equals("0.00002/XRP", Amount.from_json("200").divide(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide XRP by USD" : function () {
|
||||
buster.assert.equals("0.002/XRP", Amount.from_json("20000").divide(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide XRP by USD" : function () {
|
||||
buster.assert.equals("0.2/XRP", Amount.from_json("2000000").divide(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide XRP by USD, neg" : function () {
|
||||
buster.assert.equals("-0.00002/XRP", Amount.from_json("200").divide(Amount.from_json("-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide XRP by USD, neg, frac" : function () {
|
||||
buster.assert.equals("-0.000162/XRP", Amount.from_json("-6000").divide(Amount.from_json("37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide USD by USD" : function () {
|
||||
buster.assert.equals("200/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide USD by USD, fractional" : function () {
|
||||
buster.assert.equals("57142.85714285714/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("35/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide USD by USD" : function () {
|
||||
buster.assert.equals("20/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide EUR by USD, factor < 1" : function () {
|
||||
buster.assert.equals("0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide EUR by USD, neg" : function () {
|
||||
buster.assert.equals("-12/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide EUR by USD, neg, <1" : function () {
|
||||
buster.assert.equals("-0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")).to_text_full());
|
||||
},
|
||||
"Divide EUR by XRP, result < 1" : function () {
|
||||
buster.assert.equals("0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("2000")).to_text_full());
|
||||
},
|
||||
"Divide EUR by XRP, neg" : function () {
|
||||
buster.assert.equals("-20/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("5")).to_text_full());
|
||||
},
|
||||
"Divide EUR by XRP, neg, <1" : function () {
|
||||
buster.assert.equals("-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", Amount.from_json("-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").divide(Amount.from_json("2000")).to_text_full());
|
||||
}
|
||||
},
|
||||
"Amount comparisons" : {
|
||||
"0 USD == 0 USD" : function () {
|
||||
var a = Amount.from_json("0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"0 USD == -0 USD" : function () {
|
||||
var a = Amount.from_json("0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("-0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"0 XRP == 0 XRP" : function () {
|
||||
var a = Amount.from_json("0");
|
||||
var b = Amount.from_json("0.0");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"0 XRP == -0 XRP" : function () {
|
||||
var a = Amount.from_json("0");
|
||||
var b = Amount.from_json("-0");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"10 USD == 10 USD" : function () {
|
||||
var a = Amount.from_json("10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"123.4567 USD == 123.4567 USD" : function () {
|
||||
var a = Amount.from_json("123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"10 XRP == 10 XRP" : function () {
|
||||
var a = Amount.from_json("10");
|
||||
var b = Amount.from_json("10");
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"1.1 XRP == 1.1 XRP" : function () {
|
||||
var a = Amount.from_json("1.1");
|
||||
var b = Amount.from_json("11.0").ratio_human(10);
|
||||
buster.assert(a.equals(b));
|
||||
buster.refute(a.not_equals_why(b));
|
||||
},
|
||||
"0 USD == 0 USD (ignore issuer)" : function () {
|
||||
var a = Amount.from_json("0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("0/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP");
|
||||
buster.assert(a.equals(b, true));
|
||||
buster.refute(a.not_equals_why(b, true));
|
||||
},
|
||||
"1.1 USD == 1.10 USD (ignore issuer)" : function () {
|
||||
var a = Amount.from_json("1.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("1.10/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP");
|
||||
buster.assert(a.equals(b, true));
|
||||
buster.refute(a.not_equals_why(b, true));
|
||||
},
|
||||
// Exponent mismatch
|
||||
"10 USD != 100 USD" : function () {
|
||||
var a = Amount.from_json("10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("100/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Non-XRP value differs.");
|
||||
},
|
||||
"10 XRP != 100 XRP" : function () {
|
||||
var a = Amount.from_json("10");
|
||||
var b = Amount.from_json("100");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "XRP value differs.");
|
||||
},
|
||||
// Mantissa mismatch
|
||||
"1 USD != 2 USD" : function () {
|
||||
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Non-XRP value differs.");
|
||||
},
|
||||
"1 XRP != 2 XRP" : function () {
|
||||
var a = Amount.from_json("1");
|
||||
var b = Amount.from_json("2");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "XRP value differs.");
|
||||
},
|
||||
"0.1 USD != 0.2 USD" : function () {
|
||||
var a = Amount.from_json("0.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("0.2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Non-XRP value differs.");
|
||||
},
|
||||
// Sign mismatch
|
||||
"1 USD != -1 USD" : function () {
|
||||
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("-1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Non-XRP sign differs.");
|
||||
},
|
||||
"1 XRP != -1 XRP" : function () {
|
||||
var a = Amount.from_json("1");
|
||||
var b = Amount.from_json("-1");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "XRP sign differs.");
|
||||
},
|
||||
"1 USD != 1 USD (issuer mismatch)" : function () {
|
||||
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("1/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Non-XRP issuer differs: rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
},
|
||||
"1 USD != 1 EUR" : function () {
|
||||
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("1/EUR/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Non-XRP currency differs.");
|
||||
},
|
||||
"1 USD != 1 XRP" : function () {
|
||||
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
var b = Amount.from_json("1");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Native mismatch.");
|
||||
},
|
||||
"1 XRP != 1 USD" : function () {
|
||||
var a = Amount.from_json("1");
|
||||
var b = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
|
||||
buster.refute(a.equals(b));
|
||||
buster.assert.equals(a.not_equals_why(b), "Native mismatch.");
|
||||
}
|
||||
}
|
||||
describe('Amount', function() {
|
||||
describe('Negatives', function() {
|
||||
it('Number 1', function () {
|
||||
assert.strictEqual(Amount.from_human('0').add(Amount.from_human('-1')).to_human(), '-1');
|
||||
});
|
||||
});
|
||||
describe('from_number', function() {
|
||||
it('Number 1', function() {
|
||||
assert.strictEqual(Amount.from_number(1).to_text_full(), '1/1/rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
});
|
||||
});
|
||||
describe('UInt160', function() {
|
||||
it('Parse 0', function () {
|
||||
assert(_.isEqual(jsbn.nbi(), UInt160.from_generic('0')._value));
|
||||
});
|
||||
it('Parse 0 export', function () {
|
||||
assert.strictEqual(UInt160.ACCOUNT_ZERO, UInt160.from_generic('0').to_json());
|
||||
});
|
||||
it('Parse 1', function () {
|
||||
assert(_.isEqual(new BigInteger([1]), UInt160.from_generic('1')._value));
|
||||
});
|
||||
it('Parse rrrrrrrrrrrrrrrrrrrrrhoLvTp export', function () {
|
||||
assert.strictEqual(UInt160.ACCOUNT_ZERO, UInt160.from_json('rrrrrrrrrrrrrrrrrrrrrhoLvTp').to_json());
|
||||
});
|
||||
it('Parse rrrrrrrrrrrrrrrrrrrrBZbvji export', function () {
|
||||
assert.strictEqual(UInt160.ACCOUNT_ONE, UInt160.from_json('rrrrrrrrrrrrrrrrrrrrBZbvji').to_json());
|
||||
});
|
||||
it('Parse mtgox export', function () {
|
||||
assert.strictEqual(config.accounts['mtgox'].account, UInt160.from_json('mtgox').to_json());
|
||||
});
|
||||
it('is_valid rrrrrrrrrrrrrrrrrrrrrhoLvTp', function () {
|
||||
assert(UInt160.is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvTp'));
|
||||
});
|
||||
it('!is_valid rrrrrrrrrrrrrrrrrrrrrhoLvT', function () {
|
||||
assert(!UInt160.is_valid('rrrrrrrrrrrrrrrrrrrrrhoLvT'));
|
||||
});
|
||||
});
|
||||
describe('Amount parsing', function() {
|
||||
it('Parse 800/USD/mtgox', function () {
|
||||
assert.strictEqual('800/USD/'+config.accounts['mtgox'].account, Amount.from_json('800/USD/mtgox').to_text_full());
|
||||
});
|
||||
it('Parse native 0', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').to_text_full());
|
||||
});
|
||||
it('Parse native 0.0', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0.0').to_text_full());
|
||||
});
|
||||
it('Parse native -0', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('-0').to_text_full());
|
||||
});
|
||||
it('Parse native -0.0', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('-0.0').to_text_full());
|
||||
});
|
||||
it('Parse native 1000', function () {
|
||||
assert.strictEqual('0.001/XRP', Amount.from_json('1000').to_text_full());
|
||||
});
|
||||
it('Parse native 12.3', function () {
|
||||
assert.strictEqual('12.3/XRP', Amount.from_json('12.3').to_text_full());
|
||||
});
|
||||
it('Parse native -12.3', function () {
|
||||
assert.strictEqual('-12.3/XRP', Amount.from_json('-12.3').to_text_full());
|
||||
});
|
||||
it('Parse 123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('123./USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse 12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('12300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse 12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('12.3/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse 1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('1.23/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1.2300/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse -0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
it('Parse -0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0.0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').to_text_full());
|
||||
});
|
||||
});
|
||||
describe('Amount operations', function() {
|
||||
it('Negate native 123', function () {
|
||||
assert.strictEqual('-0.000123/XRP', Amount.from_json('123').negate().to_text_full());
|
||||
});
|
||||
it('Negate native -123', function () {
|
||||
assert.strictEqual('0.000123/XRP', Amount.from_json('-123').negate().to_text_full());
|
||||
});
|
||||
it('Negate non-native 123', function () {
|
||||
assert.strictEqual('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').negate().to_text_full());
|
||||
});
|
||||
it('Negate non-native -123', function () {
|
||||
assert.strictEqual('123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').negate().to_text_full());
|
||||
});
|
||||
it('Clone non-native -123', function () {
|
||||
assert.strictEqual('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-123/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').clone().to_text_full());
|
||||
});
|
||||
it('Add XRP to XRP', function () {
|
||||
assert.strictEqual('0.0002/XRP', Amount.from_json('150').add(Amount.from_json('50')).to_text_full());
|
||||
});
|
||||
it('Add USD to USD', function () {
|
||||
assert.strictEqual('200.52/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('150.02/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').add(Amount.from_json('50.5/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 0 XRP', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('0')).to_text_full());
|
||||
});
|
||||
it('Multiply 0 USD with 0 XRP', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('0')).to_text_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 0 USD', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply 1 XRP with 0 XRP', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('1').multiply(Amount.from_json('0')).to_text_full());
|
||||
});
|
||||
it('Multiply 1 USD with 0 XRP', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('0')).to_text_full());
|
||||
});
|
||||
it('Multiply 1 XRP with 0 USD', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('1').multiply(Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 1 XRP', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('1')).to_text_full());
|
||||
});
|
||||
it('Multiply 0 USD with 1 XRP', function () {
|
||||
assert.strictEqual('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('1')).to_text_full());
|
||||
});
|
||||
it('Multiply 0 XRP with 1 USD', function () {
|
||||
assert.strictEqual('0/XRP', Amount.from_json('0').multiply(Amount.from_json('1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply XRP with USD', function () {
|
||||
assert.equal('0.002/XRP', Amount.from_json('200').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply XRP with USD', function () {
|
||||
assert.strictEqual('0.2/XRP', Amount.from_json('20000').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply XRP with USD', function () {
|
||||
assert.strictEqual('20/XRP', Amount.from_json('2000000').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply XRP with USD, neg', function () {
|
||||
assert.strictEqual('-0.002/XRP', Amount.from_json('200').multiply(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply XRP with USD, neg, frac', function () {
|
||||
assert.strictEqual('-0.222/XRP', Amount.from_json('-6000').multiply(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply USD with USD', function () {
|
||||
assert.strictEqual('20000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply USD with USD', function () {
|
||||
assert.strictEqual('200000000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply EUR with USD, result < 1', function () {
|
||||
assert.strictEqual('100000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply EUR with USD, neg', function () {
|
||||
assert.strictEqual('-48000000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply EUR with USD, neg, <1', function () {
|
||||
assert.strictEqual('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Multiply EUR with XRP, factor < 1', function () {
|
||||
assert.strictEqual('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000')).to_text_full());
|
||||
});
|
||||
it('Multiply EUR with XRP, neg', function () {
|
||||
assert.strictEqual('-500/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('5')).to_text_full());
|
||||
});
|
||||
it('Multiply EUR with XRP, neg, <1', function () {
|
||||
assert.strictEqual('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').multiply(Amount.from_json('2000')).to_text_full());
|
||||
});
|
||||
it('Multiply XRP with XRP', function () {
|
||||
assert.strictEqual('0.0001/XRP', Amount.from_json('10').multiply(Amount.from_json('10')).to_text_full());
|
||||
});
|
||||
it('Divide XRP by USD', function () {
|
||||
assert.strictEqual('0.00002/XRP', Amount.from_json('200').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide XRP by USD', function () {
|
||||
assert.strictEqual('0.002/XRP', Amount.from_json('20000').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide XRP by USD', function () {
|
||||
assert.strictEqual('0.2/XRP', Amount.from_json('2000000').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide XRP by USD, neg', function () {
|
||||
assert.strictEqual('-0.00002/XRP', Amount.from_json('200').divide(Amount.from_json('-10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide XRP by USD, neg, frac', function () {
|
||||
assert.strictEqual('-0.000162/XRP', Amount.from_json('-6000').divide(Amount.from_json('37/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide USD by USD', function () {
|
||||
assert.strictEqual('200/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('10/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide USD by USD, fractional', function () {
|
||||
assert.strictEqual('57142.85714285714/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('35/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide USD by USD', function () {
|
||||
assert.strictEqual('20/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('2000000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('100000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide EUR by USD, factor < 1', function () {
|
||||
assert.strictEqual('0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide EUR by USD, neg', function () {
|
||||
assert.strictEqual('-12/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-24000/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide EUR by USD, neg, <1', function () {
|
||||
assert.strictEqual('-0.1/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('-1000/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')).to_text_full());
|
||||
});
|
||||
it('Divide EUR by XRP, result < 1', function () {
|
||||
assert.strictEqual('0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_text_full());
|
||||
});
|
||||
it('Divide EUR by XRP, neg', function () {
|
||||
assert.strictEqual('-20/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('5')).to_text_full());
|
||||
});
|
||||
it('Divide EUR by XRP, neg, <1', function () {
|
||||
assert.strictEqual('-0.05/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', Amount.from_json('-100/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh').divide(Amount.from_json('2000')).to_text_full());
|
||||
});
|
||||
});
|
||||
describe('Amount comparisons', function() {
|
||||
it('0 USD == 0 USD', function () {
|
||||
var a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('0 USD == -0 USD', function () {
|
||||
var a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('-0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('0 XRP == 0 XRP', function () {
|
||||
var a = Amount.from_json('0');
|
||||
var b = Amount.from_json('0.0');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('0 XRP == -0 XRP', function () {
|
||||
var a = Amount.from_json('0');
|
||||
var b = Amount.from_json('-0');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('10 USD == 10 USD', function () {
|
||||
var a = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('123.4567 USD == 123.4567 USD', function () {
|
||||
var a = Amount.from_json('123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('123.4567/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('10 XRP == 10 XRP', function () {
|
||||
var a = Amount.from_json('10');
|
||||
var b = Amount.from_json('10');
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('1.1 XRP == 1.1 XRP', function () {
|
||||
var a = Amount.from_json('1.1');
|
||||
var b = Amount.from_json('11.0').ratio_human(10);
|
||||
assert(a.equals(b));
|
||||
assert(!a.not_equals_why(b));
|
||||
});
|
||||
it('0 USD == 0 USD (ignore issuer)', function () {
|
||||
var a = Amount.from_json('0/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('0/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
|
||||
assert(a.equals(b, true));
|
||||
assert(!a.not_equals_why(b, true));
|
||||
});
|
||||
it('1.1 USD == 1.10 USD (ignore issuer)', function () {
|
||||
var a = Amount.from_json('1.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('1.10/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
|
||||
assert(a.equals(b, true));
|
||||
assert(!a.not_equals_why(b, true));
|
||||
});
|
||||
// Exponent mismatch
|
||||
it('10 USD != 100 USD', function () {
|
||||
var a = Amount.from_json('10/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('100/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Non-XRP value differs.');
|
||||
});
|
||||
it('10 XRP != 100 XRP', function () {
|
||||
var a = Amount.from_json('10');
|
||||
var b = Amount.from_json('100');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'XRP value differs.');
|
||||
});
|
||||
// Mantissa mismatch
|
||||
it('1 USD != 2 USD', function () {
|
||||
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Non-XRP value differs.');
|
||||
});
|
||||
it('1 XRP != 2 XRP', function () {
|
||||
var a = Amount.from_json('1');
|
||||
var b = Amount.from_json('2');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'XRP value differs.');
|
||||
});
|
||||
it('0.1 USD != 0.2 USD', function () {
|
||||
var a = Amount.from_json('0.1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('0.2/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Non-XRP value differs.');
|
||||
});
|
||||
// Sign mismatch
|
||||
it('1 USD != -1 USD', function () {
|
||||
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('-1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Non-XRP sign differs.');
|
||||
});
|
||||
it('1 XRP != -1 XRP', function () {
|
||||
var a = Amount.from_json('1');
|
||||
var b = Amount.from_json('-1');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'XRP sign differs.');
|
||||
});
|
||||
it('1 USD != 1 USD (issuer mismatch)', function () {
|
||||
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('1/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Non-XRP issuer differs: rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
});
|
||||
it('1 USD != 1 EUR', function () {
|
||||
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('1/EUR/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Non-XRP currency differs.');
|
||||
});
|
||||
it('1 USD != 1 XRP', function () {
|
||||
var a = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
var b = Amount.from_json('1');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Native mismatch.');
|
||||
});
|
||||
it('1 XRP != 1 USD', function () {
|
||||
var a = Amount.from_json('1');
|
||||
var b = Amount.from_json('1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL');
|
||||
assert(!a.equals(b));
|
||||
assert.strictEqual(a.not_equals_why(b), 'Native mismatch.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
var buster = require("buster");
|
||||
var assert = require('assert');
|
||||
|
||||
var Seed = require("../src/js/ripple/seed").Seed;
|
||||
var Seed = require('../src/js/ripple/seed').Seed;
|
||||
|
||||
try {
|
||||
var conf = require('./config');
|
||||
} catch(exception) {
|
||||
var conf = require('./config-example');
|
||||
}
|
||||
var config = require('./testutils').get_config();
|
||||
|
||||
var config = require('../src/js/ripple/config').load(conf);
|
||||
|
||||
buster.testCase("Base58", {
|
||||
"Seed" : {
|
||||
"saESc82Vun7Ta5EJRzGJbrXb5HNYk" : function () {
|
||||
var seed = Seed.from_json("saESc82Vun7Ta5EJRzGJbrXb5HNYk");
|
||||
buster.assert.equals(seed.to_hex(), "FF1CF838D02B2CF7B45BAC27F5F24F4F");
|
||||
},
|
||||
"sp6iDHnmiPN7tQFHm5sCW59ax3hfE" : function () {
|
||||
var seed = Seed.from_json("sp6iDHnmiPN7tQFHm5sCW59ax3hfE");
|
||||
buster.assert.equals(seed.to_hex(), "00AD8DA764C3C8AF5F9B8D51C94B9E49");
|
||||
}
|
||||
}
|
||||
describe('Base58', function() {
|
||||
describe('Seed', function() {
|
||||
it('saESc82Vun7Ta5EJRzGJbrXb5HNYk', function () {
|
||||
var seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
|
||||
assert.strictEqual(seed.to_hex(), 'FF1CF838D02B2CF7B45BAC27F5F24F4F');
|
||||
});
|
||||
it('sp6iDHnmiPN7tQFHm5sCW59ax3hfE', function () {
|
||||
var seed = Seed.from_json('sp6iDHnmiPN7tQFHm5sCW59ax3hfE');
|
||||
assert.strictEqual(seed.to_hex(), '00AD8DA764C3C8AF5F9B8D51C94B9E49');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
@@ -1,47 +1,40 @@
|
||||
var buster = require("buster");
|
||||
var assert = require('assert');
|
||||
var _ = require('underscore');
|
||||
var SerializedObject = require('../src/js/ripple/serializedobject').SerializedObject;
|
||||
|
||||
var SerializedObject = require("../src/js/ripple/serializedobject").SerializedObject;
|
||||
//var types = require("../src/js/ripple/serializedtypes");
|
||||
|
||||
var jsbn = require('../src/js/ripple/jsbn');
|
||||
var BigInteger = jsbn.BigInteger;
|
||||
|
||||
try {
|
||||
var conf = require('./config');
|
||||
} catch(exception) {
|
||||
var conf = require('./config-example');
|
||||
}
|
||||
|
||||
var config = require('../src/js/ripple/config').load(conf);
|
||||
|
||||
buster.testCase("Serialized objects", {
|
||||
"SerializedObject" : {
|
||||
"From json and back" : function () {
|
||||
describe('Serialied object', function() {
|
||||
describe('Serialized object', function() {
|
||||
it('From json and back', function() {
|
||||
var input_json = {
|
||||
"Account":"r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS",
|
||||
"Amount":"274579388",
|
||||
"Destination":"r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS",
|
||||
"Fee":"15",
|
||||
"Flags":0,
|
||||
"Paths":[[{"account":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV","currency":"USD","issuer":"r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV"},{"currency":"XRP"}]],
|
||||
"SendMax":{"currency":"USD","issuer":"r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS","value":"2.74579388"},
|
||||
"Sequence":351,
|
||||
"SigningPubKey":"02854B06CE8F3E65323F89260E9E19B33DA3E01B30EA4CA172612DE77973FAC58A",
|
||||
"TransactionType":"Payment",
|
||||
"TxnSignature":"30450221009DA3A42DD25E3B22EC45AD8BA8FC7A954264264A816D300B2DF69F814D7D4DD2022072C9627F97EEC6DA13DE841E06E2CD985EF06A0FBB15DDBF0800D0730C8986BF"
|
||||
Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
Amount: '274579388',
|
||||
Destination: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
Fee: '15',
|
||||
Flags: 0,
|
||||
Paths: [[
|
||||
{
|
||||
account: 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV',
|
||||
currency: 'USD',
|
||||
issuer: 'r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV'
|
||||
},
|
||||
{
|
||||
currency:'XRP'
|
||||
}
|
||||
so = SerializedObject.from_json(input_json);
|
||||
var output_json = so.to_json();
|
||||
//console.log(input_json);
|
||||
assert.equals(input_json,output_json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
]],
|
||||
SendMax: {
|
||||
currency: 'USD',
|
||||
issuer: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS',
|
||||
value: '2.74579388'
|
||||
},
|
||||
Sequence: 351,
|
||||
SigningPubKey: '02854B06CE8F3E65323F89260E9E19B33DA3E01B30EA4CA172612DE77973FAC58A',
|
||||
TransactionType: 'Payment',
|
||||
TxnSignature: '30450221009DA3A42DD25E3B22EC45AD8BA8FC7A954264264A816D300B2DF69F814D7D4DD2022072C9627F97EEC6DA13DE841E06E2CD985EF06A0FBB15DDBF0800D0730C8986BF'
|
||||
};
|
||||
var output_json = SerializedObject.from_json(input_json).to_json();
|
||||
assert(_.isEqual(input_json, output_json));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
@@ -1,487 +1,482 @@
|
||||
var buster = require("buster");
|
||||
var buster = require('buster');
|
||||
|
||||
var SerializedObject = require("../src/js/ripple/serializedobject").SerializedObject;
|
||||
var types = require("../src/js/ripple/serializedtypes");
|
||||
var SerializedObject = require('../src/js/ripple/serializedobject').SerializedObject;
|
||||
var types = require('../src/js/ripple/serializedtypes');
|
||||
|
||||
var jsbn = require('../src/js/ripple/jsbn');
|
||||
var BigInteger = jsbn.BigInteger;
|
||||
|
||||
try {
|
||||
var conf = require('./config');
|
||||
} catch(exception) {
|
||||
var conf = require('./config-example');
|
||||
}
|
||||
var config = require('./testutils').get_config();
|
||||
|
||||
var config = require('../src/js/ripple/config').load(conf);
|
||||
|
||||
buster.testCase("Serialized types", {
|
||||
"Int8" : {
|
||||
"Serialize 0" : function () {
|
||||
describe('Serialized types', function() {
|
||||
describe('Int8', function() {
|
||||
it('Serialize 0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int8.serialize(so, 0);
|
||||
assert.equals(so.to_hex(), "00");
|
||||
},
|
||||
"Serialize 123" : function () {
|
||||
assert.equals(so.to_hex(), '00');
|
||||
});
|
||||
it('Serialize 123', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int8.serialize(so, 123);
|
||||
assert.equals(so.to_hex(), "7B");
|
||||
},
|
||||
"Serialize 255" : function () {
|
||||
assert.equals(so.to_hex(), '7B');
|
||||
});
|
||||
it('Serialize 255', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int8.serialize(so, 255);
|
||||
assert.equals(so.to_hex(), "FF");
|
||||
},
|
||||
"Fail to serialize 256" : function () {
|
||||
assert.equals(so.to_hex(), 'FF');
|
||||
});
|
||||
it('Fail to serialize 256', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, 256);
|
||||
});
|
||||
},
|
||||
"Fail to serialize -1" : function () {
|
||||
});
|
||||
it('Fail to serialize -1', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, -1);
|
||||
});
|
||||
},
|
||||
"Serialize 5.5 (should floor)" : function () {
|
||||
});
|
||||
it('Serialize 5.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int8.serialize(so, 5.5);
|
||||
assert.equals(so.to_hex(), "05");
|
||||
},
|
||||
"Serialize 255.9 (should floor)" : function () {
|
||||
assert.equals(so.to_hex(), '05');
|
||||
});
|
||||
it('Serialize 255.9 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int8.serialize(so, 255.9);
|
||||
assert.equals(so.to_hex(), "FF");
|
||||
},
|
||||
"Fail to serialize null" : function () {
|
||||
assert.equals(so.to_hex(), 'FF');
|
||||
});
|
||||
it('Fail to serialize null', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, null);
|
||||
});
|
||||
},
|
||||
"Fail to serialize 'bla'" : function () {
|
||||
});
|
||||
it('Fail to serialize "bla"', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, 'bla');
|
||||
});
|
||||
},
|
||||
"Fail to serialize {}" : function () {
|
||||
});
|
||||
it('Fail to serialize {}', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, {});
|
||||
});
|
||||
}
|
||||
},
|
||||
"Int16" : {
|
||||
"Serialize 0" : function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Int16', function() {
|
||||
it('Serialize 0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 0);
|
||||
assert.equals(so.to_hex(), "0000");
|
||||
},
|
||||
"Serialize 123" : function () {
|
||||
assert.equals(so.to_hex(), '0000');
|
||||
});
|
||||
it('Serialize 123', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 123);
|
||||
assert.equals(so.to_hex(), "007B");
|
||||
},
|
||||
"Serialize 255" : function () {
|
||||
assert.equals(so.to_hex(), '007B');
|
||||
});
|
||||
it('Serialize 255', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 255);
|
||||
assert.equals(so.to_hex(), "00FF");
|
||||
},
|
||||
"Serialize 256" : function () {
|
||||
assert.equals(so.to_hex(), '00FF');
|
||||
});
|
||||
it('Serialize 256', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 256);
|
||||
assert.equals(so.to_hex(), "0100");
|
||||
},
|
||||
"Serialize 65535" : function () {
|
||||
assert.equals(so.to_hex(), '0100');
|
||||
});
|
||||
it('Serialize 65535', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 65535);
|
||||
assert.equals(so.to_hex(), "FFFF");
|
||||
},
|
||||
"Fail to serialize 65536" : function () {
|
||||
assert.equals(so.to_hex(), 'FFFF');
|
||||
});
|
||||
it('Fail to serialize 65536', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, 65536);
|
||||
});
|
||||
},
|
||||
"Fail to serialize -1" : function () {
|
||||
});
|
||||
it('Fail to serialize -1', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int16.serialize(so, -1);
|
||||
});
|
||||
},
|
||||
"Serialize 123.5 (should floor)" : function () {
|
||||
});
|
||||
it('Serialize 123.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 123.5);
|
||||
assert.equals(so.to_hex(), "007B");
|
||||
},
|
||||
"Serialize 65535.5 (should floor)" : function () {
|
||||
assert.equals(so.to_hex(), '007B');
|
||||
});
|
||||
it('Serialize 65535.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int16.serialize(so, 65535.5);
|
||||
assert.equals(so.to_hex(), "FFFF");
|
||||
},
|
||||
"Fail to serialize null" : function () {
|
||||
assert.equals(so.to_hex(), 'FFFF');
|
||||
});
|
||||
it('Fail to serialize null', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int16.serialize(so, null);
|
||||
});
|
||||
},
|
||||
"Fail to serialize 'bla'" : function () {
|
||||
});
|
||||
it('Fail to serialize "bla"', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int16.serialize(so, 'bla');
|
||||
});
|
||||
},
|
||||
"Fail to serialize {}" : function () {
|
||||
});
|
||||
it('Fail to serialize {}', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int16.serialize(so, {});
|
||||
});
|
||||
}
|
||||
},
|
||||
"Int32" : {
|
||||
"Serialize 0" : function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Int32', function() {
|
||||
it('Serialize 0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 0);
|
||||
assert.equals(so.to_hex(), "00000000");
|
||||
},
|
||||
"Serialize 123" : function () {
|
||||
assert.equals(so.to_hex(), '00000000');
|
||||
});
|
||||
it('Serialize 123', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 123);
|
||||
assert.equals(so.to_hex(), "0000007B");
|
||||
},
|
||||
"Serialize 255" : function () {
|
||||
assert.equals(so.to_hex(), '0000007B');
|
||||
});
|
||||
it('Serialize 255', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 255);
|
||||
assert.equals(so.to_hex(), "000000FF");
|
||||
},
|
||||
"Serialize 256" : function () {
|
||||
assert.equals(so.to_hex(), '000000FF');
|
||||
});
|
||||
it('Serialize 256', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 256);
|
||||
assert.equals(so.to_hex(), "00000100");
|
||||
},
|
||||
"Serialize 0xF0F0F0F0" : function () {
|
||||
assert.equals(so.to_hex(), '00000100');
|
||||
});
|
||||
it('Serialize 0xF0F0F0F0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 0xF0F0F0F0);
|
||||
assert.equals(so.to_hex(), "F0F0F0F0");
|
||||
},
|
||||
"Serialize 0xFFFFFFFF" : function () {
|
||||
assert.equals(so.to_hex(), 'F0F0F0F0');
|
||||
});
|
||||
it('Serialize 0xFFFFFFFF', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 0xFFFFFFFF);
|
||||
assert.equals(so.to_hex(), "FFFFFFFF");
|
||||
},
|
||||
"Fail to serialize 0x100000000" : function () {
|
||||
assert.equals(so.to_hex(), 'FFFFFFFF');
|
||||
});
|
||||
it('Fail to serialize 0x100000000', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, 0x100000000);
|
||||
});
|
||||
},
|
||||
"Fail to serialize -1" : function () {
|
||||
});
|
||||
it('Fail to serialize -1', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int32.serialize(so, -1);
|
||||
});
|
||||
},
|
||||
"Serialize 123.5 (should floor)" : function () {
|
||||
});
|
||||
it('Serialize 123.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 123.5);
|
||||
assert.equals(so.to_hex(), "0000007B");
|
||||
},
|
||||
"Serialize 4294967295.5 (should floor)" : function () {
|
||||
assert.equals(so.to_hex(), '0000007B');
|
||||
});
|
||||
it('Serialize 4294967295.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int32.serialize(so, 4294967295.5);
|
||||
assert.equals(so.to_hex(), "FFFFFFFF");
|
||||
},
|
||||
"Fail to serialize null" : function () {
|
||||
assert.equals(so.to_hex(), 'FFFFFFFF');
|
||||
});
|
||||
it('Fail to serialize null', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int32.serialize(so, null);
|
||||
});
|
||||
},
|
||||
"Fail to serialize 'bla'" : function () {
|
||||
});
|
||||
it('Fail to serialize "bla"', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int32.serialize(so, 'bla');
|
||||
});
|
||||
},
|
||||
"Fail to serialize {}" : function () {
|
||||
});
|
||||
it('Fail to serialize {}', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int32.serialize(so, {});
|
||||
});
|
||||
}
|
||||
},
|
||||
"Int64" : {
|
||||
"Serialize 0" : function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Int64', function() {
|
||||
it('Serialize 0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 0);
|
||||
assert.equals(so.to_hex(), "0000000000000000");
|
||||
},
|
||||
"Serialize 123" : function () {
|
||||
assert.equals(so.to_hex(), '0000000000000000');
|
||||
});
|
||||
it('Serialize 123', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 123);
|
||||
assert.equals(so.to_hex(), "000000000000007B");
|
||||
},
|
||||
"Serialize 255" : function () {
|
||||
assert.equals(so.to_hex(), '000000000000007B');
|
||||
});
|
||||
it('Serialize 255', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 255);
|
||||
assert.equals(so.to_hex(), "00000000000000FF");
|
||||
},
|
||||
"Serialize 256" : function () {
|
||||
assert.equals(so.to_hex(), '00000000000000FF');
|
||||
});
|
||||
it('Serialize 256', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 256);
|
||||
assert.equals(so.to_hex(), "0000000000000100");
|
||||
},
|
||||
"Serialize 0xF0F0F0F0" : function () {
|
||||
assert.equals(so.to_hex(), '0000000000000100');
|
||||
});
|
||||
it('Serialize 0xF0F0F0F0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 0xF0F0F0F0);
|
||||
assert.equals(so.to_hex(), "00000000F0F0F0F0");
|
||||
},
|
||||
"Serialize 0xFFFFFFFF" : function () {
|
||||
assert.equals(so.to_hex(), '00000000F0F0F0F0');
|
||||
});
|
||||
it('Serialize 0xFFFFFFFF', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 0xFFFFFFFF);
|
||||
assert.equals(so.to_hex(), "00000000FFFFFFFF");
|
||||
},
|
||||
"Serialize 0x100000000" : function () {
|
||||
assert.equals(so.to_hex(), '00000000FFFFFFFF');
|
||||
});
|
||||
it('Serialize 0x100000000', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 0x100000000);
|
||||
assert.equals(so.to_hex(), "0000000100000000");
|
||||
},
|
||||
"Fail to serialize 0x100000000" : function () {
|
||||
assert.equals(so.to_hex(), '0000000100000000');
|
||||
});
|
||||
it('Fail to serialize 0x100000000', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int8.serialize(so, 0x100000000);
|
||||
});
|
||||
},
|
||||
"Fail to serialize -1" : function () {
|
||||
});
|
||||
it('Fail to serialize -1', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, -1);
|
||||
});
|
||||
},
|
||||
"Serialize 123.5 (should floor)" : function () {
|
||||
});
|
||||
it('Serialize 123.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 123.5);
|
||||
assert.equals(so.to_hex(), "000000000000007B");
|
||||
},
|
||||
"Serialize 4294967295.5 (should floor)" : function () {
|
||||
assert.equals(so.to_hex(), '000000000000007B');
|
||||
});
|
||||
it('Serialize 4294967295.5 (should floor)', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, 4294967295.5);
|
||||
assert.equals(so.to_hex(), "00000000FFFFFFFF");
|
||||
},
|
||||
"Serialize '0123456789ABCDEF'" : function () {
|
||||
assert.equals(so.to_hex(), '00000000FFFFFFFF');
|
||||
});
|
||||
it('Serialize "0123456789ABCDEF"', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, "0123456789ABCDEF");
|
||||
assert.equals(so.to_hex(), "0123456789ABCDEF");
|
||||
},
|
||||
"Serialize 'F0E1D2C3B4A59687'" : function () {
|
||||
types.Int64.serialize(so, '0123456789ABCDEF');
|
||||
assert.equals(so.to_hex(), '0123456789ABCDEF');
|
||||
});
|
||||
it('Serialize "F0E1D2C3B4A59687"', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, "F0E1D2C3B4A59687");
|
||||
assert.equals(so.to_hex(), "F0E1D2C3B4A59687");
|
||||
},
|
||||
"Serialize BigInteger('FFEEDDCCBBAA9988')" : function () {
|
||||
types.Int64.serialize(so, 'F0E1D2C3B4A59687');
|
||||
assert.equals(so.to_hex(), 'F0E1D2C3B4A59687');
|
||||
});
|
||||
it('Serialize BigInteger("FFEEDDCCBBAA9988")', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Int64.serialize(so, new BigInteger("FFEEDDCCBBAA9988", 16));
|
||||
assert.equals(so.to_hex(), "FFEEDDCCBBAA9988");
|
||||
},
|
||||
"Fail to serialize BigInteger('-1')" : function () {
|
||||
types.Int64.serialize(so, new BigInteger('FFEEDDCCBBAA9988', 16));
|
||||
assert.equals(so.to_hex(), 'FFEEDDCCBBAA9988');
|
||||
});
|
||||
it('Fail to serialize BigInteger("-1")', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, new BigInteger("-1", 10));
|
||||
types.Int64.serialize(so, new BigInteger('-1', 10));
|
||||
});
|
||||
},
|
||||
"Fail to serialize '10000000000000000'" : function () {
|
||||
});
|
||||
it('Fail to serialize "10000000000000000"', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, "10000000000000000");
|
||||
types.Int64.serialize(so, '10000000000000000');
|
||||
});
|
||||
},
|
||||
"Fail to serialize '110000000000000000'" : function () {
|
||||
});
|
||||
it('Fail to serialize "110000000000000000"', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, "110000000000000000");
|
||||
types.Int64.serialize(so, '110000000000000000');
|
||||
});
|
||||
},
|
||||
"Fail to serialize null" : function () {
|
||||
});
|
||||
it('Fail to serialize null', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, null);
|
||||
});
|
||||
},
|
||||
"Fail to serialize 'bla'" : function () {
|
||||
});
|
||||
it('Fail to serialize "bla"', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, 'bla');
|
||||
});
|
||||
},
|
||||
"Fail to serialize {}" : function () {
|
||||
});
|
||||
it('Fail to serialize {}', function () {
|
||||
var so = new SerializedObject();
|
||||
assert.exception(function () {
|
||||
types.Int64.serialize(so, {});
|
||||
});
|
||||
}
|
||||
},
|
||||
"Hash128" : {
|
||||
"Serialize 0" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash128.serialize(so, "00000000000000000000000000000000");
|
||||
assert.equals(so.to_hex(), "00000000000000000000000000000000");
|
||||
},
|
||||
"Serialize 102030405060708090A0B0C0D0E0F000" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash128.serialize(so, "102030405060708090A0B0C0D0E0F000");
|
||||
assert.equals(so.to_hex(), "102030405060708090A0B0C0D0E0F000");
|
||||
},
|
||||
"Serialize FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash128.serialize(so, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
assert.equals(so.to_hex(), "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
},
|
||||
},
|
||||
"Hash160" : {
|
||||
"Serialize 0" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash160.serialize(so, "rrrrrrrrrrrrrrrrrrrrrhoLvTp");
|
||||
assert.equals(so.to_hex(), "0000000000000000000000000000000000000000");
|
||||
},
|
||||
"Serialize 1" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash160.serialize(so, "rrrrrrrrrrrrrrrrrrrrBZbvji");
|
||||
assert.equals(so.to_hex(), "0000000000000000000000000000000000000001");
|
||||
},
|
||||
"Serialize FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash160.serialize(so, "rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi");
|
||||
assert.equals(so.to_hex(), "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
},
|
||||
},
|
||||
"Amount" : {
|
||||
"Serialize 0 XRP" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "0");
|
||||
assert.equals(so.to_hex(), "4000000000000000");
|
||||
},
|
||||
"Serialize 1 XRP" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "1");
|
||||
assert.equals(so.to_hex(), "4000000000000001");
|
||||
},
|
||||
"Serialize -1 XRP" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "-1");
|
||||
assert.equals(so.to_hex(), "0000000000000001");
|
||||
},
|
||||
"Serialize 213 XRP" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "213");
|
||||
assert.equals(so.to_hex(), "40000000000000D5");
|
||||
},
|
||||
"Serialize 270544960 XRP" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "270544960");
|
||||
assert.equals(so.to_hex(), "4000000010203040");
|
||||
},
|
||||
"Serialize 1161981756646125568 XRP" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "1161981756646125696");
|
||||
assert.equals(so.to_hex(), "5020304050607080");
|
||||
},
|
||||
"Serialize 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
assert.equals(so.to_hex(), "D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8");
|
||||
},
|
||||
"Serialize 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
assert.equals(so.to_hex(), "D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8");
|
||||
},
|
||||
"Serialize -1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, "-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
assert.equals(so.to_hex(), "94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8");
|
||||
},
|
||||
"Parse 1 XRP" : function () {
|
||||
var so = new SerializedObject("4000000000000001");
|
||||
assert.equals(types.Amount.parse(so).to_json(), "1");
|
||||
},
|
||||
"Parse -1 XRP" : function () {
|
||||
var so = new SerializedObject("0000000000000001");
|
||||
assert.equals(types.Amount.parse(so).to_json(), "-1");
|
||||
},
|
||||
"Parse 213 XRP" : function () {
|
||||
var so = new SerializedObject("40000000000000D5");
|
||||
assert.equals(types.Amount.parse(so).to_json(), "213");
|
||||
},
|
||||
"Parse 270544960 XRP" : function () {
|
||||
var so = new SerializedObject("4000000010203040");
|
||||
assert.equals(types.Amount.parse(so).to_json(), "270544960");
|
||||
},
|
||||
"Parse 1161981756646125568 XRP" : function () {
|
||||
var so = new SerializedObject("5020304050607080");
|
||||
assert.equals(types.Amount.parse(so).to_json(), "1161981756646125696");
|
||||
},
|
||||
"Parse 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
var so = new SerializedObject("D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8");
|
||||
assert.equals(types.Amount.parse(so).to_text_full(), "1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
},
|
||||
"Parse 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
var so = new SerializedObject("D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8");
|
||||
assert.equals(types.Amount.parse(so).to_text_full(), "87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
},
|
||||
"Parse -1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" : function () {
|
||||
var so = new SerializedObject("94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8");
|
||||
assert.equals(types.Amount.parse(so).to_text_full(), "-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe('Hash128', function() {
|
||||
it('Serialize 0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash128.serialize(so, '00000000000000000000000000000000');
|
||||
assert.equals(so.to_hex(), '00000000000000000000000000000000');
|
||||
});
|
||||
it('Serialize 102030405060708090A0B0C0D0E0F000', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash128.serialize(so, '102030405060708090A0B0C0D0E0F000');
|
||||
assert.equals(so.to_hex(), '102030405060708090A0B0C0D0E0F000');
|
||||
});
|
||||
it('Serialize FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash128.serialize(so, 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
|
||||
assert.equals(so.to_hex(), 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
|
||||
});
|
||||
});
|
||||
|
||||
"PathSet" : {
|
||||
"Serialize single empty path [[]]" : function () {
|
||||
describe('Hash160', function() {
|
||||
it('Serialize 0', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash160.serialize(so, 'rrrrrrrrrrrrrrrrrrrrrhoLvTp');
|
||||
assert.equals(so.to_hex(), '0000000000000000000000000000000000000000');
|
||||
});
|
||||
it('Serialize 1', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash160.serialize(so, 'rrrrrrrrrrrrrrrrrrrrBZbvji');
|
||||
assert.equals(so.to_hex(), '0000000000000000000000000000000000000001');
|
||||
});
|
||||
it('Serialize FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Hash160.serialize(so, 'rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi');
|
||||
assert.equals(so.to_hex(), 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Amount', function() {
|
||||
it('Serialize 0 XRP', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '0');
|
||||
assert.equals(so.to_hex(), '4000000000000000');
|
||||
});
|
||||
it('Serialize 1 XRP', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '1');
|
||||
assert.equals(so.to_hex(), '4000000000000001');
|
||||
});
|
||||
it('Serialize -1 XRP', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '-1');
|
||||
assert.equals(so.to_hex(), '0000000000000001');
|
||||
});
|
||||
it('Serialize 213 XRP', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '213');
|
||||
assert.equals(so.to_hex(), '40000000000000D5');
|
||||
});
|
||||
it('Serialize 270544960 XRP', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '270544960');
|
||||
assert.equals(so.to_hex(), '4000000010203040');
|
||||
});
|
||||
it('Serialize 1161981756646125568 XRP', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '1161981756646125696');
|
||||
assert.equals(so.to_hex(), '5020304050607080');
|
||||
});
|
||||
it('Serialize 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.equals(so.to_hex(), 'D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
});
|
||||
it('Serialize 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.equals(so.to_hex(), 'D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
});
|
||||
it('Serialize -1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Amount.serialize(so, '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.equals(so.to_hex(), '94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
});
|
||||
it('Parse 1 XRP', function () {
|
||||
var so = new SerializedObject('4000000000000001');
|
||||
assert.equals(types.Amount.parse(so).to_json(), '1');
|
||||
});
|
||||
it('Parse -1 XRP', function () {
|
||||
var so = new SerializedObject('0000000000000001');
|
||||
assert.equals(types.Amount.parse(so).to_json(), '-1');
|
||||
});
|
||||
it('Parse 213 XRP', function () {
|
||||
var so = new SerializedObject('40000000000000D5');
|
||||
assert.equals(types.Amount.parse(so).to_json(), '213');
|
||||
});
|
||||
it('Parse 270544960 XRP', function () {
|
||||
var so = new SerializedObject('4000000010203040');
|
||||
assert.equals(types.Amount.parse(so).to_json(), '270544960');
|
||||
});
|
||||
it('Parse 1161981756646125568 XRP', function () {
|
||||
var so = new SerializedObject('5020304050607080');
|
||||
assert.equals(types.Amount.parse(so).to_json(), '1161981756646125696');
|
||||
});
|
||||
it('Parse 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject('D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
assert.equals(types.Amount.parse(so).to_text_full(), '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Parse 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject('D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
assert.equals(types.Amount.parse(so).to_text_full(), '87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
it('Parse -1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function () {
|
||||
var so = new SerializedObject('94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8');
|
||||
assert.equals(types.Amount.parse(so).to_text_full(), '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PathSet', function() {
|
||||
it('Serialize single empty path [[]]', function () {
|
||||
var so = new SerializedObject();
|
||||
types.PathSet.serialize(so, [[]]);
|
||||
assert.equals(so.to_hex(), "00");
|
||||
},
|
||||
|
||||
"Serialize [[e],[e,e]]" : function () {
|
||||
assert.equals(so.to_hex(), '00');
|
||||
});
|
||||
it('Serialize [[e],[e,e]]', function () {
|
||||
var so = new SerializedObject();
|
||||
types.PathSet.serialize(so, [[{account:123, currency:"USD", issuer:789}],[{account:123, currency:"BTC", issuer:789},{account:987, currency:"EUR", issuer:321}]]);
|
||||
assert.equals(so.to_hex(), "31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100"); //TODO: Check this independently
|
||||
},
|
||||
|
||||
"Parse single empty path [[]]" : function () {
|
||||
var so = new SerializedObject("00");
|
||||
types.PathSet.serialize(so, [[{account:123, currency:'USD', issuer:789}],[{account:123, currency:'BTC', issuer:789}, {account:987, currency:'EUR', issuer:321}]]);
|
||||
assert.equals(so.to_hex(), '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); //TODO: Check this independently
|
||||
});
|
||||
it('Parse single empty path [[]]', function () {
|
||||
var so = new SerializedObject('00');
|
||||
var parsed_path=types.PathSet.parse(so)
|
||||
assert.equals(parsed_path,[[]]);
|
||||
},
|
||||
|
||||
"Parse [[e],[e,e]]" : function () {
|
||||
var so = new SerializedObject("31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100");
|
||||
});
|
||||
it('Parse [[e],[e,e]]', function () {
|
||||
var so = new SerializedObject('31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100');
|
||||
parsed_path=types.PathSet.parse(so);
|
||||
assert.equals(parsed_path,[[{account:{_value:123}, currency:{_value:"USD"}, issuer:{_value:789}}],[{account:{_value:123}, currency:{_value:"BTC"}, issuer:{_value:789}},{account:{_value:987}, currency:{_value:"EUR"}, issuer:{_value:321}}]]);
|
||||
}
|
||||
assert.equals(parsed_path,[[{account:{_value:123}, currency:{_value:'USD'}, issuer:{_value:789}}],[{account:{_value:123}, currency:{_value:'BTC'}, issuer:{_value:789}},{account:{_value:987}, currency:{_value:'EUR'}, issuer:{_value:321}}]]);
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
"Object" : {
|
||||
"Serialize empty object {}" : function () {
|
||||
describe('Object', function() {
|
||||
it('Serialize empty object {}', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Object.serialize(so, {});
|
||||
assert.equals(so.to_hex(), "E1");
|
||||
},
|
||||
"Parse empty object {}" : function () {
|
||||
var so = new SerializedObject("E1");
|
||||
assert.equals(so.to_hex(), 'E1');
|
||||
});
|
||||
it('Parse empty object {}', function () {
|
||||
var so = new SerializedObject('E1');
|
||||
var parsed_object=types.Object.parse(so)
|
||||
assert.equals(parsed_object,{});
|
||||
},
|
||||
'Serialize simple object {"TakerPays":"87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", "TakerGets":"213", "Fee":789}' : function () {
|
||||
});
|
||||
it('Serialize simple object {TakerPays:"87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", TakerGets:213, Fee:"789"}', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Object.serialize(so, {"TakerPays":"87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", "TakerGets":"213", "Fee":789});
|
||||
assert.equals(so.to_hex(), "64D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E86540000000000000D5684000000000000315E1");
|
||||
types.Object.serialize(so, {'TakerPays':'87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', 'TakerGets':'213', 'Fee':789});
|
||||
assert.equals(so.to_hex(), '64D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E86540000000000000D5684000000000000315E1');
|
||||
//TODO: Check independently.
|
||||
},
|
||||
"Parse same object" : function () {
|
||||
var so = new SerializedObject("64D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E86540000000000000D5684000000000000315E1");
|
||||
});
|
||||
it('Parse same object', function () {
|
||||
var so = new SerializedObject('64D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E86540000000000000D5684000000000000315E1');
|
||||
var parsed_object=types.Object.parse(so);
|
||||
assert.equals(parsed_object,
|
||||
{ TakerPays:
|
||||
@@ -507,64 +502,61 @@ buster.testCase("Serialized types", {
|
||||
_issuer: { _value: NaN } } }
|
||||
);
|
||||
//TODO: Check independently.
|
||||
},
|
||||
});
|
||||
|
||||
'Serialize simple object {"DestinationTag":123, "QualityIn":456, "QualityOut":789}' : function () {
|
||||
it('Serialize simple object {DestinationTag:123, QualityIn:456, QualityOut:789}', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Object.serialize(so, {"DestinationTag":123, "QualityIn":456, "QualityOut":789});
|
||||
//console.log("DOES THE JSON METHOD WORK?", so.to_json());
|
||||
assert.equals(so.to_hex(), "2E0000007B2014000001C8201500000315E1");
|
||||
types.Object.serialize(so, {DestinationTag:123, QualityIn:456, QualityOut:789});
|
||||
//console.log('DOES THE JSON METHOD WORK?', so.to_json());
|
||||
assert.equals(so.to_hex(), '2E0000007B2014000001C8201500000315E1');
|
||||
//TODO: Check independently.
|
||||
},
|
||||
'Parse simple object {"DestinationTag":123, "QualityIn":456, "QualityOut":789}' : function () { //2E0000007B22000001C82400000315E1 2E0000007B2002000001C8200200000315E1
|
||||
var so = new SerializedObject("2E0000007B2014000001C8201500000315E1");
|
||||
});
|
||||
it('Parse simple object {DestinationTag:123, QualityIn:456, QualityOut:789}', function () { //2E0000007B22000001C82400000315E1 2E0000007B2002000001C8200200000315E1
|
||||
var so = new SerializedObject('2E0000007B2014000001C8201500000315E1');
|
||||
var parsed_object=types.Object.parse(so);
|
||||
assert.equals(parsed_object,{"DestinationTag":123, "QualityIn":456, "QualityOut":789});
|
||||
assert.equals(parsed_object,{DestinationTag:123, QualityIn:456, QualityOut:789});
|
||||
//TODO: Check independently.
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
"Array" : {
|
||||
"Serialize empty array []" : function () {
|
||||
describe('Array', function() {
|
||||
it('Serialize empty array []', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Array.serialize(so, []);
|
||||
assert.equals(so.to_hex(), "F1");
|
||||
},
|
||||
"Parse empty array []" : function () {
|
||||
var so = new SerializedObject("F1");
|
||||
assert.equals(so.to_hex(), 'F1');
|
||||
});
|
||||
it('Parse empty array []', function () {
|
||||
var so = new SerializedObject('F1');
|
||||
var parsed_object=types.Array.parse(so);
|
||||
assert.equals(parsed_object,[]);
|
||||
},
|
||||
'Serialize 3-length array [{"TakerPays":123}, {"TakerGets":456}, {"Fee":789}]' : function () {
|
||||
});
|
||||
it('Serialize 3-length array [{TakerPays:123}); {TakerGets:456}, {Fee:789}]', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Array.serialize(so, [{"TakerPays":123}, {"TakerGets":456}, {"Fee":789}]);
|
||||
types.Array.serialize(so, [{TakerPays:123}, {TakerGets:456}, {Fee:789}]);
|
||||
//TODO: Check this manually
|
||||
|
||||
assert.equals(so.to_hex(), "64400000000000007B6540000000000001C8684000000000000315F1");
|
||||
},
|
||||
"Parse the same array" : function () {
|
||||
var so = new SerializedObject("64400000000000007B6540000000000001C8684000000000000315F1");
|
||||
assert.equals(so.to_hex(), '64400000000000007B6540000000000001C8684000000000000315F1');
|
||||
});
|
||||
it('Parse the same array', function () {
|
||||
var so = new SerializedObject('64400000000000007B6540000000000001C8684000000000000315F1');
|
||||
var parsed_object=types.Array.parse(so);
|
||||
//console.log("WE GOT:", parsed_object[0].TakerPays._value, parsed_object[1].TakerGets._value, parsed_object[2].Fee._value);
|
||||
//console.log('WE GOT:', parsed_object[0].TakerPays._value, parsed_object[1].TakerGets._value, parsed_object[2].Fee._value);
|
||||
assert.equals([123,456,789],[parsed_object[0].TakerPays._value, parsed_object[1].TakerGets._value, parsed_object[2].Fee._value]);
|
||||
},
|
||||
'Serialize 3-length array [{"DestinationTag":123}, {"QualityIn":456}, {"Fee":789}]' : function () {
|
||||
});
|
||||
it('Serialize 3-length array [{DestinationTag:123}); {QualityIn:456}, {Fee:789}]', function () {
|
||||
var so = new SerializedObject();
|
||||
types.Array.serialize(so, [{"DestinationTag":123}, {"QualityIn":456}, {"Fee":789}]);
|
||||
types.Array.serialize(so, [{DestinationTag:123}, {QualityIn:456}, {Fee:789}]);
|
||||
//TODO: Check this manually
|
||||
//console.log("DOES THE JSON METHOD WORK2?", so.to_json());
|
||||
assert.equals(so.to_hex(), "2E0000007B2014000001C8684000000000000315F1");
|
||||
},
|
||||
"Parse the same array 2" : function () {
|
||||
var so = new SerializedObject("2E0000007B2014000001C8684000000000000315F1");
|
||||
//console.log('DOES THE JSON METHOD WORK2?', so.to_json());
|
||||
assert.equals(so.to_hex(), '2E0000007B2014000001C8684000000000000315F1');
|
||||
});
|
||||
it('Parse the same array 2', function () {
|
||||
var so = new SerializedObject('2E0000007B2014000001C8684000000000000315F1');
|
||||
var parsed_object=types.Array.parse(so);
|
||||
//TODO: Is this correct? Return some things as integers, and others as objects?
|
||||
assert.equals([123,456,789],[parsed_object[0].DestinationTag, parsed_object[1].QualityIn, parsed_object[2].Fee._value]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
var buster = require("buster");
|
||||
var assert = require('assert');
|
||||
var Seed = require('../src/js/ripple/seed').Seed;
|
||||
|
||||
var Seed = require("../src/js/ripple/seed").Seed;
|
||||
|
||||
try {
|
||||
var conf = require('./config');
|
||||
} catch(exception) {
|
||||
var conf = require('./config-example');
|
||||
}
|
||||
|
||||
var config = require('../src/js/ripple/config').load(conf);
|
||||
|
||||
buster.testCase("Signing", {
|
||||
"Keys" : {
|
||||
"SigningPubKey 1 (ripple-client issue #245)" : function () {
|
||||
var seed = Seed.from_json("saESc82Vun7Ta5EJRzGJbrXb5HNYk");
|
||||
var key = seed.get_key("rBZ4j6MsoctipM6GEyHSjQKzXG3yambDnZ");
|
||||
describe('Signing', function() {
|
||||
describe('Keys', function() {
|
||||
it('SigningPubKey 1 (ripple-client issue #245)', function () {
|
||||
var seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
|
||||
var key = seed.get_key('rBZ4j6MsoctipM6GEyHSjQKzXG3yambDnZ');
|
||||
var pub = key.to_hex_pub();
|
||||
buster.assert.equals(pub, "0396941B22791A448E5877A44CE98434DB217D6FB97D63F0DAD23BE49ED45173C9");
|
||||
},
|
||||
"SigningPubKey 2 (master seed)" : function () {
|
||||
var seed = Seed.from_json("snoPBrXtMeMyMHUVTgbuqAfg1SUTb");
|
||||
var key = seed.get_key("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
assert.strictEqual(pub, '0396941B22791A448E5877A44CE98434DB217D6FB97D63F0DAD23BE49ED45173C9');
|
||||
});
|
||||
it('SigningPubKey 2 (master seed)', function () {
|
||||
var seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
|
||||
var key = seed.get_key('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
var pub = key.to_hex_pub();
|
||||
buster.assert.equals(pub, "0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020");
|
||||
}
|
||||
}
|
||||
assert.strictEqual(pub, '0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
18
test/testutils.js
Normal file
18
test/testutils.js
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
exports.get_config = get_config;
|
||||
|
||||
function get_config() {
|
||||
var config = { };
|
||||
try {
|
||||
config = require('./config');
|
||||
} catch(exception) {
|
||||
config = require('./config-example');
|
||||
}
|
||||
return load_config(config);
|
||||
}
|
||||
|
||||
exports.load_config = load_config;
|
||||
|
||||
function load_config(config) {
|
||||
return( require('../src/js/ripple/config')).load(config);
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
var fs = require("fs");
|
||||
var buster = require("buster");
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var utils = require('../src/js/ripple/utils.js');
|
||||
|
||||
var utils = require("../src/js/ripple/utils.js");
|
||||
|
||||
buster.testCase("Utils", {
|
||||
"hexToString and stringToHex" : {
|
||||
"Even: 123456" : function () {
|
||||
buster.assert.equals("123456", utils.stringToHex(utils.hexToString("123456")));
|
||||
},
|
||||
"Odd: 12345" : function () {
|
||||
buster.assert.equals("012345", utils.stringToHex(utils.hexToString("12345")));
|
||||
},
|
||||
"Under 10: 0" : function () {
|
||||
buster.assert.equals("00", utils.stringToHex(utils.hexToString("0")));
|
||||
},
|
||||
"Under 10: 1" : function () {
|
||||
buster.assert.equals("01", utils.stringToHex(utils.hexToString("1")));
|
||||
},
|
||||
"Empty" : function () {
|
||||
buster.assert.equals("", utils.stringToHex(utils.hexToString("")));
|
||||
}
|
||||
}
|
||||
describe('Utils', function() {
|
||||
describe('hexToString and stringToHex', function() {
|
||||
it('Even: 123456', function () {
|
||||
assert.strictEqual('123456', utils.stringToHex(utils.hexToString('123456')));
|
||||
});
|
||||
it('Odd: 12345', function () {
|
||||
assert.strictEqual('012345', utils.stringToHex(utils.hexToString('12345')));
|
||||
});
|
||||
it('Under 10: 0', function () {
|
||||
assert.strictEqual('00', utils.stringToHex(utils.hexToString('0')));
|
||||
});
|
||||
it('Under 10: 1', function () {
|
||||
assert.strictEqual('01', utils.stringToHex(utils.hexToString('1')));
|
||||
});
|
||||
it('Empty', function () {
|
||||
assert.strictEqual('', utils.stringToHex(utils.hexToString('')));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
Reference in New Issue
Block a user