Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ var Script = function Script(from) {
return Script.fromAddress(from);
} else if (from instanceof Script) {
return Script.fromBuffer(from.toBuffer());
} else if (typeof from === 'string') {
} else if (_.isString(from)) {
return Script.fromString(from);
} else if (typeof from !== 'undefined') {
} else if (_.isObject(from) && _.isArray(from.chunks)) {
this.set(from);
}
};

Script.prototype.set = function(obj) {
this.chunks = obj.chunks || this.chunks;
$.checkArgument(_.isObject(obj));
$.checkArgument(_.isArray(obj.chunks));
this.chunks = obj.chunks;
return this;
};

Expand Down
30 changes: 29 additions & 1 deletion test/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,35 @@ describe('Script', function() {

it('should make a new script', function() {
var script = new Script();
should.exist(script);
expect(script).to.be.instanceof(Script);
expect(script.chunks).to.deep.equal([]);
});

it('should make a new script when from is null', function() {
var script = new Script(null);
expect(script).to.be.instanceof(Script);
expect(script.chunks).to.deep.equal([]);
});

describe('#set', function() {
var script = new Script();

it('should be object', function() {
expect(function() {
script.set(null);
}).to.throw(/^Invalid Argument$/)
});

it('chunks should be array', function() {
expect(function() {
script.set({chunks: 1});
}).to.throw(/^Invalid Argument$/);
});

it('set chunks', function() {
script.set({chunks: [1]});
expect(script.chunks).to.deep.equal([1]);
});
});

describe('#fromBuffer', function() {
Expand Down