This repository was archived by the owner on Apr 3, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -36,15 +36,17 @@ var Script = function Script(from) {
3636 return Script . fromAddress ( from ) ;
3737 } else if ( from instanceof Script ) {
3838 return Script . fromBuffer ( from . toBuffer ( ) ) ;
39- } else if ( typeof from === 'string' ) {
39+ } else if ( _ . isString ( from ) ) {
4040 return Script . fromString ( from ) ;
41- } else if ( typeof from !== 'undefined' ) {
41+ } else if ( _ . isObject ( from ) && _ . isArray ( from . chunks ) ) {
4242 this . set ( from ) ;
4343 }
4444} ;
4545
4646Script . prototype . set = function ( obj ) {
47- this . chunks = obj . chunks || this . chunks ;
47+ $ . checkArgument ( _ . isObject ( obj ) ) ;
48+ $ . checkArgument ( _ . isArray ( obj . chunks ) ) ;
49+ this . chunks = obj . chunks ;
4850 return this ;
4951} ;
5052
Original file line number Diff line number Diff line change @@ -15,7 +15,35 @@ describe('Script', function() {
1515
1616 it ( 'should make a new script' , function ( ) {
1717 var script = new Script ( ) ;
18- should . exist ( script ) ;
18+ expect ( script ) . to . be . instanceof ( Script ) ;
19+ expect ( script . chunks ) . to . deep . equal ( [ ] ) ;
20+ } ) ;
21+
22+ it ( 'should make a new script when from is null' , function ( ) {
23+ var script = new Script ( null ) ;
24+ expect ( script ) . to . be . instanceof ( Script ) ;
25+ expect ( script . chunks ) . to . deep . equal ( [ ] ) ;
26+ } ) ;
27+
28+ describe ( '#set' , function ( ) {
29+ var script = new Script ( ) ;
30+
31+ it ( 'should be object' , function ( ) {
32+ expect ( function ( ) {
33+ script . set ( null ) ;
34+ } ) . to . throw ( / ^ I n v a l i d A r g u m e n t $ / )
35+ } ) ;
36+
37+ it ( 'chunks should be array' , function ( ) {
38+ expect ( function ( ) {
39+ script . set ( { chunks : 1 } ) ;
40+ } ) . to . throw ( / ^ I n v a l i d A r g u m e n t $ / ) ;
41+ } ) ;
42+
43+ it ( 'set chunks' , function ( ) {
44+ script . set ( { chunks : [ 1 ] } ) ;
45+ expect ( script . chunks ) . to . deep . equal ( [ 1 ] ) ;
46+ } ) ;
1947 } ) ;
2048
2149 describe ( '#fromBuffer' , function ( ) {
You can’t perform that action at this time.
0 commit comments