JS: Fix UInt160 comparison.

This commit is contained in:
Arthur Britto
2012-10-22 16:56:00 -07:00
committed by Stefan Thomas
parent c0eec780de
commit 45c54b6484
2 changed files with 10 additions and 2 deletions

View File

@@ -152,7 +152,7 @@ UInt160.prototype.copyTo = function(d) {
}; };
UInt160.prototype.equals = function(d) { UInt160.prototype.equals = function(d) {
return this.value === d.value; return isNaN(this.value) || isNaN(d.value) ? false : this.value.equals(d.value);
}; };
// value = NaN on error. // value = NaN on error.

View File

@@ -6,7 +6,9 @@ var nbi = jsbn.nbi;
var amount = require("../js/amount.js"); var amount = require("../js/amount.js");
var Amount = require("../js/amount.js").Amount; var Amount = require("../js/amount.js").Amount;
var UInt160 = require("../js/amount.js").UInt160; var UInt160 = require("../js/amount.js").UInt160;
var config = require('./config.js');
buster.testCase("Amount", { buster.testCase("Amount", {
"UInt160" : { "UInt160" : {
@@ -25,8 +27,14 @@ buster.testCase("Amount", {
"Parse rrrrrrrrrrrrrrrrrrrrBZbvji export" : function () { "Parse rrrrrrrrrrrrrrrrrrrrBZbvji export" : function () {
buster.assert.equals(amount.consts.address_one, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrBZbvji").to_json()); buster.assert.equals(amount.consts.address_one, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrBZbvji").to_json());
}, },
"Parse mtgox export" : function () {
buster.assert.equals(config.accounts["mtgox"].account, UInt160.from_json("mtgox").to_json());
},
}, },
"Amount parsing" : { "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 () { "Parse native 0" : function () {
buster.assert.equals("0/XNS", Amount.from_json("0").to_text_full()); buster.assert.equals("0/XNS", Amount.from_json("0").to_text_full());
}, },