Refactor JavaScript library.

- Separate classes in separate modules (files)
- Constants should be associated with a class
- Replace exports.config scheme with a config singleton
- Refactor base58 functions as a static class
This commit is contained in:
Stefan Thomas
2013-02-01 15:13:09 +01:00
parent daada2b298
commit 6f34cfa369
9 changed files with 486 additions and 442 deletions

View File

@@ -8,7 +8,8 @@ var amount = require("../src/js/amount.js");
var Amount = require("../src/js/amount.js").Amount;
var UInt160 = require("../src/js/amount.js").UInt160;
require("../src/js/amount.js").config = require("./config.js");
var extend = require('extend');
extend(require('../src/js/config'), require('./config'));
var config = require('./config.js');
@@ -20,16 +21,16 @@ buster.testCase("Amount", {
buster.assert.equals(nbi(), UInt160.from_generic("0")._value);
},
"Parse 0 export" : function () {
buster.assert.equals(amount.consts.address_xns, UInt160.from_generic("0").to_json());
buster.assert.equals(UInt160.ADDRESS_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(amount.consts.address_xns, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrrhoLvTp").to_json());
buster.assert.equals(UInt160.ADDRESS_ZERO, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrrhoLvTp").to_json());
},
"Parse rrrrrrrrrrrrrrrrrrrrBZbvji export" : function () {
buster.assert.equals(amount.consts.address_one, UInt160.from_json("rrrrrrrrrrrrrrrrrrrrBZbvji").to_json());
buster.assert.equals(UInt160.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());