Skip to content

Commit e5a4741

Browse files
refactor(utxo-core): extract BIP322 test fixtures into utility file
Create a shared utility file for BIP322 test fixtures to improve code maintainability and reduce duplication across test files. Co-authored-by: llm-git <[email protected]> BTC-2361 TICKET: BTC-2361
1 parent 76a9583 commit e5a4741

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { payments, ECPair } from '@bitgo/utxo-lib';
2+
3+
export const BIP322_WIF_FIXTURE = 'L3VFeEujGtevx9w18HD1fhRbCH67Az2dpCymeRE1SoPK6XQtaN2k';
4+
export const BIP322_PRV_FIXTURE = ECPair.fromWIF(BIP322_WIF_FIXTURE);
5+
export const BIP322_PAYMENT_P2WPKH_FIXTURE = payments.p2wpkh({
6+
address: 'bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l',
7+
});

modules/utxo-core/test/bip322/toSign.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import assert from 'assert';
22

3-
import { payments, ECPair, Transaction } from '@bitgo/utxo-lib';
3+
import { Transaction } from '@bitgo/utxo-lib';
44

55
import * as bip322 from '../../src/bip322';
66

7+
import { BIP322_PAYMENT_P2WPKH_FIXTURE, BIP322_PRV_FIXTURE as prv } from './bip322.utils';
78
describe('BIP322 toSign', function () {
89
describe('buildToSignPsbt', function () {
9-
const WIF = 'L3VFeEujGtevx9w18HD1fhRbCH67Az2dpCymeRE1SoPK6XQtaN2k';
10-
const prv = ECPair.fromWIF(WIF);
11-
const scriptPubKey = payments.p2wpkh({
12-
address: 'bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l',
13-
}).output as Buffer;
14-
10+
const scriptPubKey = BIP322_PAYMENT_P2WPKH_FIXTURE.output as Buffer;
1511
// Source: https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki#transaction-hashes
1612
const fixtures = [
1713
{

modules/utxo-core/test/bip322/toSpend.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import assert from 'assert';
22

3-
import { payments } from '@bitgo/utxo-lib';
4-
53
import { buildToSpendTransaction, hashMessageWithTag } from '../../src/bip322';
64

5+
import { BIP322_PAYMENT_P2WPKH_FIXTURE } from './bip322.utils';
6+
77
describe('to_spend', function () {
88
describe('Message hashing', function () {
99
// Test vectors from BIP322
@@ -31,9 +31,7 @@ describe('to_spend', function () {
3131
});
3232

3333
describe('build to_spend transaction', function () {
34-
const scriptPubKey = payments.p2wpkh({
35-
address: 'bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l',
36-
}).output as Buffer;
34+
const scriptPubKey = BIP322_PAYMENT_P2WPKH_FIXTURE.output as Buffer;
3735

3836
// Source: https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki#transaction-hashes
3937
const fixtures = [

0 commit comments

Comments
 (0)