Improved inventory precondition checks to handle objects.
This commit is contained in:
parent
3921c46507
commit
101796f7e9
@ -7,12 +7,12 @@ var _ = bitcore.deps._;
|
|||||||
var utils;
|
var utils;
|
||||||
|
|
||||||
module.exports = utils = {
|
module.exports = utils = {
|
||||||
checkInventory: function(inventory) {
|
checkInventory: function(arg) {
|
||||||
$.checkArgument(
|
$.checkArgument(
|
||||||
_.isUndefined(inventory) ||
|
_.isUndefined(arg) ||
|
||||||
inventory.length === 0 ||
|
(Array.isArray(arg) && arg.length === 0) ||
|
||||||
(!_.isUndefined(inventory[0].type) && !_.isUndefined(inventory[0].hash)),
|
(Array.isArray(arg) && !_.isUndefined(arg[0].type) && !_.isUndefined(arg[0].hash)),
|
||||||
'Inventory must be an array of inventory objects'
|
'Argument is expected to be an array of inventory objects'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
checkFinished: function checkFinished(parser) {
|
checkFinished: function checkFinished(parser) {
|
||||||
|
|||||||
@ -70,6 +70,22 @@ describe('Command Messages', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Inventory', function() {
|
||||||
|
it('should error if arg is not an array', function() {
|
||||||
|
(function() {
|
||||||
|
var message = messages.Inventory({});
|
||||||
|
}).should.throw('Argument is expected to be an array of inventory objects');
|
||||||
|
});
|
||||||
|
it('should not error if arg is an empty array', function() {
|
||||||
|
var message = messages.Inventory([]);
|
||||||
|
});
|
||||||
|
it('should error if arg is not an array of inventory objects', function() {
|
||||||
|
(function() {
|
||||||
|
var message = messages.Inventory([Number(0)]);
|
||||||
|
}).should.throw('Argument is expected to be an array of inventory objects');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Transaction', function() {
|
describe('Transaction', function() {
|
||||||
|
|
||||||
it('should be able to pass a custom Transaction', function(done) {
|
it('should be able to pass a custom Transaction', function(done) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user