File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import { describe , it } from 'mocha' ;
2+ import assert from 'assert' ;
3+ import { opcodes as OPS } from 'bitcoinjs-lib' ;
4+
5+ describe ( 'OPS Enum Tests' , ( ) => {
6+ it ( 'should map OPS keys to correct numbers and reverse lookup' , ( ) => {
7+ Object . keys ( OPS )
8+ . filter ( key => isNaN ( Number ( key ) ) ) // Only test enum keys, not reverse-mapped numbers
9+ . forEach ( key => {
10+ const value = OPS [ key as keyof typeof OPS ] ;
11+
12+ // Assert the forward mapping
13+ assert . strictEqual (
14+ OPS [ key ] ,
15+ value ,
16+ `Failed for key: ${ key } , value: ${ value } ` ,
17+ ) ;
18+ } ) ;
19+ } ) ;
20+
21+ it ( 'should reverse map numbers to correct keys' , ( ) => {
22+ const valueToKeysMap = new Map < number , string [ ] > ( ) ;
23+
24+ Object . keys ( OPS )
25+ . filter ( key => isNaN ( Number ( key ) ) )
26+ . forEach ( key => {
27+ const value = OPS [ key as keyof typeof OPS ] ;
28+ if ( ! valueToKeysMap . has ( value ) ) {
29+ valueToKeysMap . set ( value , [ ] ) ;
30+ }
31+ valueToKeysMap . get ( value ) ! . push ( key ) ;
32+ } ) ;
33+
34+ Object . values ( OPS )
35+ . filter ( value => typeof value === 'number' )
36+ . forEach ( value => {
37+ const keys = valueToKeysMap . get ( value ) || [ ] ;
38+ keys . forEach ( key => {
39+ assert . strictEqual (
40+ OPS [ key ] ,
41+ value ,
42+ `Failed for value: ${ value } , key: ${ key } ` ,
43+ ) ;
44+ } ) ;
45+ } ) ;
46+ } ) ;
47+ } ) ;
You can’t perform that action at this time.
0 commit comments