@@ -16,7 +16,7 @@ describe("bech32", () => {
1616 } ) ;
1717
1818 it ( "works for very long prefixes" , ( ) => {
19- expect ( ( ) => toBech32 ( "p" . repeat ( 70 ) , new Uint8Array ( 20 ) ) ) . toThrowError ( / e x c e e d s l e n g t h l i m i t / i) ;
19+ expect ( ( ) => toBech32 ( "p" . repeat ( 70 ) , new Uint8Array ( 20 ) ) ) . toThrowError ( / l e n g t h 1 0 9 e x c e e d s l i m i t 9 0 / i) ;
2020 } ) ;
2121
2222 // See https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#Bech32
@@ -26,7 +26,7 @@ describe("bech32", () => {
2626 } ) ;
2727
2828 it ( "throws if result exceeds 90 characters" , ( ) => {
29- expect ( ( ) => toBech32 ( "eth" , new Uint8Array ( 51 ) ) ) . toThrowError ( / e x c e e d s l e n g t h l i m i t / i) ;
29+ expect ( ( ) => toBech32 ( "eth" , new Uint8Array ( 51 ) ) ) . toThrowError ( / l e n g t h 9 2 e x c e e d s l i m i t 9 0 / i) ;
3030 } ) ;
3131
3232 it ( "works if a limit parameter is provided" , ( ) => {
@@ -40,7 +40,7 @@ describe("bech32", () => {
4040
4141 it ( "throws if result exceeds the provided limit parameter" , ( ) => {
4242 const limit = 10 ;
43- expect ( ( ) => toBech32 ( "eth" , ethAddressRaw , limit ) ) . toThrowError ( / e x c e e d s l e n g t h l i m i t / i) ;
43+ expect ( ( ) => toBech32 ( "eth" , ethAddressRaw , limit ) ) . toThrowError ( / l e n g t h 4 2 e x c e e d s l i m i t 1 0 / i) ;
4444 } ) ;
4545 } ) ;
4646
@@ -77,16 +77,33 @@ describe("bech32", () => {
7777 "cosmospub1ytql0csgqvfzd666axrjzqmn5q2ucztcyxw8hvlzen94ay05tegaerkug5pn3xn8wqdymt598ufzd666axrjzqsxllmwacap3f6xyc4x30jl8ecrcs2tze3zzgxkmthcsqxnqxhwwgfzd666axrjzqs2rlu3wz5gnslgpprszjr8r65n0d6y39q657th77eyvengtk3z0y6h2pnk" ,
7878 90 ,
7979 ) ,
80- ) . toThrowError ( / e x c e e d s l e n g t h l i m i t / i) ;
80+ ) . toThrowError ( / i n v a l i d s t r i n g l e n g t h / i) ;
81+ } ) ;
82+
83+ it ( "throws for missing separator" , ( ) => {
84+ expect ( ( ) => fromBech32 ( "nooneinhere" ) ) . toThrowError ( / N o b e c h 3 2 s e p a r a t o r f o u n d / i) ;
85+ } ) ;
86+
87+ it ( "throws for invalid checksum" , ( ) => {
88+ const corrupted = "eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0dxxxxxx" ;
89+ expect ( ( ) => fromBech32 ( corrupted ) ) . toThrowError ( / i n v a l i d c h e c k s u m / i) ;
8190 } ) ;
8291
8392 it ( "throws for mixed case addresses" , ( ) => {
8493 // "Decoders MUST NOT accept strings where some characters are uppercase and some are lowercase (such strings are referred to as mixed case strings)."
8594 // https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
86- expect ( ( ) => fromBech32 ( "Eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
87- expect ( ( ) => fromBech32 ( "eTh1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
88- expect ( ( ) => fromBech32 ( "ETH1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
89- expect ( ( ) => fromBech32 ( "eth1n48g2mjh9Ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
95+ expect ( ( ) => fromBech32 ( "Eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
96+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
97+ ) ;
98+ expect ( ( ) => fromBech32 ( "eTh1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
99+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
100+ ) ;
101+ expect ( ( ) => fromBech32 ( "ETH1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
102+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
103+ ) ;
104+ expect ( ( ) => fromBech32 ( "eth1n48g2mjh9Ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
105+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
106+ ) ;
90107 } ) ;
91108 } ) ;
92109
@@ -103,10 +120,18 @@ describe("bech32", () => {
103120 it ( "throws for mixed case addresses" , ( ) => {
104121 // "Decoders MUST NOT accept strings where some characters are uppercase and some are lowercase (such strings are referred to as mixed case strings)."
105122 // https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
106- expect ( ( ) => normalizeBech32 ( "Eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
107- expect ( ( ) => normalizeBech32 ( "eTh1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
108- expect ( ( ) => normalizeBech32 ( "ETH1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
109- expect ( ( ) => normalizeBech32 ( "eth1n48g2mjh9Ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError ( / M i x e d - c a s e / i) ;
123+ expect ( ( ) => normalizeBech32 ( "Eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
124+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
125+ ) ;
126+ expect ( ( ) => normalizeBech32 ( "eTh1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
127+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
128+ ) ;
129+ expect ( ( ) => normalizeBech32 ( "ETH1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
130+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
131+ ) ;
132+ expect ( ( ) => normalizeBech32 ( "eth1n48g2mjh9Ezz7zjtya37wtgg5r5emr0drkwlgw" ) ) . toThrowError (
133+ / m u s t b e l o w e r c a s e o r u p p e r c a s e / i,
134+ ) ;
110135 } ) ;
111136 } ) ;
112137} ) ;
0 commit comments