Merge pull request #458 from braydonf/precondition/m-and-n
Wallet Model: Check that "m" and "n" arguments are numbers
This commit is contained in:
commit
256dc35b86
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue