Wallet Model: Check that "m" and "n" arguments are numbers
This commit is contained in:
parent
65a6ce4e8a
commit
7530ee9d0e
|
@ -18,6 +18,9 @@ Wallet.create = function(opts) {
|
||||||
|
|
||||||
var x = new Wallet();
|
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.version = '1.0.0';
|
||||||
x.createdOn = Math.floor(Date.now() / 1000);
|
x.createdOn = Math.floor(Date.now() / 1000);
|
||||||
x.id = opts.id || Uuid.v4();
|
x.id = opts.id || Uuid.v4();
|
||||||
|
@ -44,6 +47,9 @@ Wallet.create = function(opts) {
|
||||||
Wallet.fromObj = function(obj) {
|
Wallet.fromObj = function(obj) {
|
||||||
var x = new Wallet();
|
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.version = obj.version;
|
||||||
x.createdOn = obj.createdOn;
|
x.createdOn = obj.createdOn;
|
||||||
x.id = obj.id;
|
x.id = obj.id;
|
||||||
|
|
|
@ -9,7 +9,26 @@ var Wallet = require('../../lib/model/wallet');
|
||||||
|
|
||||||
describe('Wallet', function() {
|
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() {
|
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() {
|
it('read a wallet', function() {
|
||||||
var w = Wallet.fromObj(testWallet);
|
var w = Wallet.fromObj(testWallet);
|
||||||
w.isComplete().should.be.true;
|
w.isComplete().should.be.true;
|
||||||
|
|
Loading…
Reference in New Issue