File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { toXOnly } from 'bitcoinjs-lib' ;
2
+ import * as assert from 'assert' ;
3
+
4
+ describe ( 'toXOnly' , ( ) => {
5
+ it ( 'should return the input if the pubKey length is 32' , ( ) => {
6
+ const pubKey = new Uint8Array ( 32 ) . fill ( 1 ) ; // Example 32-byte public key
7
+ const result = toXOnly ( pubKey ) ;
8
+ assert . strictEqual ( result , pubKey ) ; // Expect the same array (reference equality)
9
+ } ) ;
10
+
11
+ it ( 'should return the sliced key if the pubKey length is greater than 32' , ( ) => {
12
+ const pubKey = new Uint8Array ( 33 ) . fill ( 1 ) ;
13
+ pubKey [ 0 ] = 0 ; // Add a leading byte
14
+ const result = toXOnly ( pubKey ) ;
15
+ assert . deepStrictEqual ( result , pubKey . slice ( 1 , 33 ) ) ; // Expect the sliced array
16
+ } ) ;
17
+
18
+ it ( 'should throw an error if the pubKey length is less than 32' , ( ) => {
19
+ const pubKey = new Uint8Array ( 31 ) . fill ( 1 ) ; // Example invalid public key
20
+ const result = toXOnly ( pubKey ) ;
21
+ assert . deepStrictEqual ( result , pubKey . slice ( 1 , 33 ) ) ; // Expect the sliced array
22
+ } ) ;
23
+ } ) ;
You can’t perform that action at this time.
0 commit comments