Wallet Model: Check that "m" and "n" arguments are numbers

This commit is contained in:
Braydon Fuller 2016-02-01 11:21:49 -05:00
parent 65a6ce4e8a
commit 7530ee9d0e
2 changed files with 25 additions and 0 deletions

View File

@ -18,6 +18,9 @@ Wallet.create = function(opts) {
var x = new Wallet();
$.checkArgument(_.isNumber(opts.m), '"m" is expected to be a number');
$.checkArgument(_.isNumber(opts.n), '"n" is expected to be a number');
x.version = '1.0.0';
x.createdOn = Math.floor(Date.now() / 1000);
x.id = opts.id || Uuid.v4();
@ -44,6 +47,9 @@ Wallet.create = function(opts) {
Wallet.fromObj = function(obj) {
var x = new Wallet();
$.checkArgument(_.isNumber(obj.m), '"m" is expected to be a number');
$.checkArgument(_.isNumber(obj.n), '"n" is expected to be a number');
x.version = obj.version;
x.createdOn = obj.createdOn;
x.id = obj.id;

View File

@ -9,7 +9,26 @@ var Wallet = require('../../lib/model/wallet');
describe('Wallet', function() {
describe('#create', function() {
it('will throw with an invalid string argument for "m" or "n"', function() {
(function() {
Wallet.create({m: '2', n: 2});
}).should.throw('"m" is expected to be a number');
(function() {
Wallet.create({m: 2, n: '2'});
}).should.throw('"n" is expected to be a number');
});
});
describe('#fromObj', function() {
it('will throw with an invalid string argument for "m" or "n"', function() {
(function() {
Wallet.fromObj({m: '2', n: 2});
}).should.throw('"m" is expected to be a number');
(function() {
Wallet.fromObj({m: 2, n: '2'});
}).should.throw('"n" is expected to be a number');
});
it('read a wallet', function() {
var w = Wallet.fromObj(testWallet);
w.isComplete().should.be.true;