@@ -2,15 +2,32 @@ import { hexToBytes } from "@noble/hashes/utils";
22import { describe , expect , test } from "bun:test" ;
33import { decodeEthAddress , encodeEthAddress } from "./eth.js" ;
44
5+ const prefixlessAddress = "314159265dD8dbb310642f98f50C066173C1259b" ;
6+ const hex = "314159265dd8dbb310642f98f50c066173c1259b" ;
7+
8+ test ( `eth address: encode 0x${ prefixlessAddress } ` , ( ) => {
9+ expect ( encodeEthAddress ( hexToBytes ( hex ) ) ) . toEqual ( `0x${ prefixlessAddress } ` ) ;
10+ } ) ;
11+ test ( "eth address: invalid checksum" , ( ) => {
12+ expect ( ( ) =>
13+ decodeEthAddress ( "0x314159265Dd8Dbb310642f98F50C066173C1259b" )
14+ ) . toThrow ( ) ;
15+ } ) ;
16+
517describe . each ( [
618 {
7- text : "0x314159265dD8dbb310642f98f50C066173C1259b" ,
8- hex : "314159265dd8dbb310642f98f50c066173c1259b" ,
19+ // checksummed address
20+ text : `0x ${ prefixlessAddress } ` ,
921 } ,
10- ] ) ( "eth address" , ( { text, hex } ) => {
11- test ( `encode: ${ text } ` , ( ) => {
12- expect ( encodeEthAddress ( hexToBytes ( hex ) ) ) . toEqual ( text ) ;
13- } ) ;
22+ {
23+ // all lowercased address
24+ text : `0x${ prefixlessAddress . toLowerCase ( ) } ` ,
25+ } ,
26+ {
27+ // all uppercased address
28+ text : `0x${ prefixlessAddress . toUpperCase ( ) } ` ,
29+ } ,
30+ ] ) ( "eth address" , ( { text } ) => {
1431 test ( `decode: ${ text } ` , ( ) => {
1532 expect ( decodeEthAddress ( text ) ) . toEqual ( hexToBytes ( hex ) ) ;
1633 } ) ;
0 commit comments