Skip to content

Commit 4fe7522

Browse files
committed
test: add test for bip371
1 parent 72ac2f7 commit 4fe7522

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/bip371.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
});

0 commit comments

Comments
 (0)