@@ -9,6 +9,8 @@ var fixtures = require('./fixtures/address.json')
99describe ( 'address' , function ( ) {
1010 describe ( 'fromBase58Check' , function ( ) {
1111 fixtures . standard . forEach ( function ( f ) {
12+ if ( ! f . base58check ) return
13+
1214 it ( 'decodes ' + f . base58check , function ( ) {
1315 var decode = baddress . fromBase58Check ( f . base58check )
1416
@@ -27,34 +29,34 @@ describe('address', function () {
2729 } )
2830
2931 describe ( 'fromBech32' , function ( ) {
30- fixtures . bech32 . forEach ( ( f ) => {
31- it ( 'encodes ' + f . address , function ( ) {
32- var actual = baddress . fromBech32 ( f . address )
32+ fixtures . standard . forEach ( ( f ) => {
33+ if ( ! f . bech32 ) return
34+
35+ it ( 'decodes ' + f . bech32 , function ( ) {
36+ var actual = baddress . fromBech32 ( f . bech32 )
3337
34- assert . strictEqual ( actual . prefix , f . prefix )
35- assert . strictEqual ( actual . program . toString ( 'hex' ) , f . program )
3638 assert . strictEqual ( actual . version , f . version )
39+ assert . strictEqual ( actual . prefix , networks [ f . network ] . bech32 )
40+ assert . strictEqual ( actual . data . toString ( 'hex' ) , f . data )
3741 } )
3842 } )
3943
4044 fixtures . invalid . bech32 . forEach ( ( f , i ) => {
41- if ( f . address === undefined ) return
42-
43- it ( 'decode fails for ' + f . address + '(' + f . exception + ')' , function ( ) {
45+ it ( 'decode fails for ' + f . bech32 + '(' + f . exception + ')' , function ( ) {
4446 assert . throws ( function ( ) {
45- baddress . fromBech32 ( f . address , f . prefix )
47+ baddress . fromBech32 ( f . address )
4648 } , new RegExp ( f . exception ) )
4749 } )
4850 } )
4951 } )
5052
5153 describe ( 'fromOutputScript' , function ( ) {
5254 fixtures . standard . forEach ( function ( f ) {
53- it ( 'parses ' + f . script . slice ( 0 , 30 ) + '... (' + f . network + ')' , function ( ) {
55+ it ( 'encodes ' + f . script . slice ( 0 , 30 ) + '... (' + f . network + ')' , function ( ) {
5456 var script = bscript . fromASM ( f . script )
5557 var address = baddress . fromOutputScript ( script , networks [ f . network ] )
5658
57- assert . strictEqual ( address , f . base58check )
59+ assert . strictEqual ( address , f . base58check || f . bech32 . toLowerCase ( ) )
5860 } )
5961 } )
6062
@@ -71,7 +73,9 @@ describe('address', function () {
7173
7274 describe ( 'toBase58Check' , function ( ) {
7375 fixtures . standard . forEach ( function ( f ) {
74- it ( 'formats ' + f . hash + ' (' + f . network + ')' , function ( ) {
76+ if ( ! f . base58check ) return
77+
78+ it ( 'encodes ' + f . hash + ' (' + f . network + ')' , function ( ) {
7579 var address = baddress . toBase58Check ( Buffer . from ( f . hash , 'hex' ) , f . version )
7680
7781 assert . strictEqual ( address , f . base58check )
@@ -81,32 +85,29 @@ describe('address', function () {
8185
8286 describe ( 'toBech32' , function ( ) {
8387 fixtures . bech32 . forEach ( ( f , i ) => {
84- // unlike the reference impl., we don't support mixed/uppercase
85- var string = f . address . toLowerCase ( )
86- var program = Buffer . from ( f . program , 'hex' )
88+ if ( ! f . bech32 ) return
89+ var data = Buffer . from ( f . data , 'hex' )
8790
88- it ( 'encode ' + string , function ( ) {
89- assert . deepEqual ( baddress . toBech32 ( f . prefix , f . version , program ) , string )
91+ it ( 'encode ' + f . address , function ( ) {
92+ assert . deepEqual ( baddress . toBech32 ( data , f . version , f . prefix ) , f . address )
9093 } )
9194 } )
9295
9396 fixtures . invalid . bech32 . forEach ( ( f , i ) => {
94- if ( ! f . prefix || f . version === undefined || f . program === undefined ) return
97+ if ( ! f . prefix || f . version === undefined || f . data === undefined ) return
9598
9699 it ( 'encode fails (' + f . exception , function ( ) {
97100 assert . throws ( function ( ) {
98- baddress . toBech32 ( f . prefix , f . version , Buffer . from ( f . program , 'hex' ) )
101+ baddress . toBech32 ( Buffer . from ( f . data , 'hex' ) , f . version , f . prefix )
99102 } , new RegExp ( f . exception ) )
100103 } )
101104 } )
102105 } )
103106
104107 describe ( 'toOutputScript' , function ( ) {
105108 fixtures . standard . forEach ( function ( f ) {
106- var network = networks [ f . network ]
107-
108- it ( 'exports ' + f . script . slice ( 0 , 30 ) + '... (' + f . network + ')' , function ( ) {
109- var script = baddress . toOutputScript ( f . base58check , network )
109+ it ( 'decodes ' + f . script . slice ( 0 , 30 ) + '... (' + f . network + ')' , function ( ) {
110+ var script = baddress . toOutputScript ( f . base58check || f . bech32 , networks [ f . network ] )
110111
111112 assert . strictEqual ( bscript . toASM ( script ) , f . script )
112113 } )
@@ -115,7 +116,7 @@ describe('address', function () {
115116 fixtures . invalid . toOutputScript . forEach ( function ( f ) {
116117 it ( 'throws when ' + f . exception , function ( ) {
117118 assert . throws ( function ( ) {
118- baddress . toOutputScript ( f . address )
119+ baddress . toOutputScript ( f . address , f . network )
119120 } , new RegExp ( f . address + ' ' + f . exception ) )
120121 } )
121122 } )
0 commit comments