Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/updated fee address tests #44

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "dlc-btc-lib",
"version": "2.4.19",
"version": "2.4.2",
"description": "This library provides a comprehensive set of interfaces and functions for minting dlcBTC tokens on supported blockchains.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/functions/bitcoin/bitcoin-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
import { TransactionInput } from '@scure/btc-signer/psbt';
import { BIP32Factory, BIP32Interface } from 'bip32';
import { Network, address } from 'bitcoinjs-lib';
import { Network, address, initEccLib } from 'bitcoinjs-lib';
import { bitcoin, regtest, testnet } from 'bitcoinjs-lib/src/networks.js';
import { Decimal } from 'decimal.js';
import * as ellipticCurveCryptography from 'tiny-secp256k1';
Expand All @@ -37,6 +37,7 @@ const TAPROOT_UNSPENDABLE_KEY_HEX =
const ECDSA_PUBLIC_KEY_LENGTH = 33;

const bip32 = BIP32Factory(ellipticCurveCryptography);
initEccLib(ellipticCurveCryptography);

export function getFeeAmount(bitcoinAmount: number, feeBasisPoints: number): number {
const feePercentage = new Decimal(feeBasisPoints).dividedBy(10000);
Expand Down
22 changes: 18 additions & 4 deletions tests/unit/bitcoin-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
getScriptMatchingOutputFromTransaction,
getUnspendableKeyCommittedToUUID,
} from '../../src/functions/bitcoin/bitcoin-functions';
import { shiftValue, unshiftValue } from '../../src/utilities';
import {
TEST_TESTNET_ATTESTOR_EXTENDED_GROUP_PUBLIC_KEY_1,
TEST_TESTNET_ATTESTOR_UNHARDENED_DERIVED_PUBLIC_KEY_1,
Expand Down Expand Up @@ -79,7 +78,12 @@ describe('Bitcoin Functions', () => {
});

it('accepts taproot (p2tr) address', () => {
const address = 'bc1qw02rsw9afgp4dsd5n87z5s6rqnf455yhhsnz9f';
const address = 'bc1pgj9ef0lhysgd2v042jta4mv8qmc70yappkv7vpl76dhfvrdfvusqqe4qj3';
expect(getFeeRecipientAddress(address, network)).toBe(address);
});

it('accepts nested segwit (p2sh) address', () => {
const address = '3KF9nXowQ4asSGxRRzeiTpDjMuwM2nypAN';
expect(getFeeRecipientAddress(address, network)).toBe(address);
});

Expand All @@ -99,7 +103,12 @@ describe('Bitcoin Functions', () => {
});

it('accepts taproot (p2tr) address', () => {
const address = 'tb1qqhy33peyp82mf82fktdtphfmnhtxyhtp6x9hrc';
const address = 'tb1pa8hxt6r2gkc8d5thzfrw7gyrqlv354rdy4k05ylkvf6nadnhg8xsygyusf';
expect(getFeeRecipientAddress(address, network)).toBe(address);
});

it('accepts nested segwit (p2sh) address', () => {
const address = '2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc';
expect(getFeeRecipientAddress(address, network)).toBe(address);
});

Expand All @@ -119,7 +128,12 @@ describe('Bitcoin Functions', () => {
});

it('accepts taproot (p2tr) address', () => {
const address = 'bcrt1qqhy33peyp82mf82fktdtphfmnhtxyhtpc0u653';
const address = 'bcrt1pa8hxt6r2gkc8d5thzfrw7gyrqlv354rdy4k05ylkvf6nadnhg8xsf3w69n';
expect(getFeeRecipientAddress(address, network)).toBe(address);
});

it('accepts nested segwit (p2sh) address', () => {
const address = '2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc';
expect(getFeeRecipientAddress(address, network)).toBe(address);
});

Expand Down
Loading