Skip to content

Commit 240be2f

Browse files
committed
fix: tests for nodev18
1 parent fc415aa commit 240be2f

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/addresses.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ import * as ecc from 'tiny-secp256k1';
44
import { describe, it } from 'mocha';
55
import * as bitcoin from 'bitcoinjs-lib';
66
import { regtestUtils } from './_regtest.js';
7+
import { randomBytes } from 'crypto';
78

89
const ECPair = ECPairFactory(ecc);
910
const dhttp = regtestUtils.dhttp;
1011
const TESTNET = bitcoin.networks.testnet;
1112

13+
const rng = (size: number) => randomBytes(size);
14+
1215
describe('bitcoinjs-lib (addresses)', () => {
1316
it(
1417
'can generate a random address [and support the retrieval of ' +
1518
'transactions for that address (via 3PBP)]',
1619
async () => {
17-
const keyPair = ECPair.makeRandom();
20+
const keyPair = ECPair.makeRandom({ rng });
1821
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
1922

2023
// bitcoin P2PKH addresses start with a '1'
@@ -107,7 +110,7 @@ describe('bitcoinjs-lib (addresses)', () => {
107110

108111
// examples using other network information
109112
it('can generate a Testnet address', () => {
110-
const keyPair = ECPair.makeRandom({ network: TESTNET });
113+
const keyPair = ECPair.makeRandom({ network: TESTNET, rng });
111114
const { address } = bitcoin.payments.p2pkh({
112115
pubkey: keyPair.publicKey,
113116
network: TESTNET,
@@ -134,7 +137,7 @@ describe('bitcoinjs-lib (addresses)', () => {
134137
wif: 0xb0,
135138
};
136139

137-
const keyPair = ECPair.makeRandom({ network: LITECOIN });
140+
const keyPair = ECPair.makeRandom({ network: LITECOIN, rng });
138141
const { address } = bitcoin.payments.p2pkh({
139142
pubkey: keyPair.publicKey,
140143
network: LITECOIN,

test/integration/payments.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import * as ecc from 'tiny-secp256k1';
33
import { describe, it } from 'mocha';
44
import * as bitcoin from 'bitcoinjs-lib';
55
import { regtestUtils } from './_regtest.js';
6+
import { randomBytes } from 'crypto';
67

78
import p2msFixtures from '../fixtures/p2ms.json';
89
import p2pkFixtures from '../fixtures/p2pk.json';
910
import p2pkhFixtures from '../fixtures/p2pkh.json';
1011
import p2wpkhFixtures from '../fixtures/p2wpkh.json';
1112

13+
const rng = (size: number) => randomBytes(size);
14+
1215
const testSuite = [
1316
{
1417
paymentName: 'p2ms',
@@ -31,8 +34,8 @@ const testSuite = [
3134
const ECPair = ECPairFactory(ecc);
3235
const NETWORK = regtestUtils.network;
3336
const keyPairs = [
34-
ECPair.makeRandom({ network: NETWORK }),
35-
ECPair.makeRandom({ network: NETWORK }),
37+
ECPair.makeRandom({ network: NETWORK, rng }),
38+
ECPair.makeRandom({ network: NETWORK, rng }),
3639
];
3740

3841
async function buildAndSign(

test/integration/transactions.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
543543
'can create (and broadcast via 3PBP) a Transaction, w/ a ' +
544544
'P2SH(P2MS(2 of 2)) input with nonWitnessUtxo',
545545
async () => {
546-
const myKey = ECPair.makeRandom({ network: regtest });
546+
const myKey = ECPair.makeRandom({ network: regtest, rng });
547547
const myKeys = [
548548
myKey,
549549
ECPair.fromPrivateKey(myKey.privateKey!, { network: regtest }),
@@ -647,11 +647,11 @@ function createPayment(_type: string, myKeys?: any[], network?: any): any {
647647
throw new Error('Need n keys for multisig');
648648
}
649649
while (!myKeys && n > 1) {
650-
keys.push(ECPair.makeRandom({ network }));
650+
keys.push(ECPair.makeRandom({ network, rng }));
651651
n--;
652652
}
653653
}
654-
if (!myKeys) keys.push(ECPair.makeRandom({ network }));
654+
if (!myKeys) keys.push(ECPair.makeRandom({ network, rng }));
655655

656656
let payment: any;
657657
splitType.forEach(type => {

test/psbt.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type { Taptree } from 'bitcoinjs-lib/src/types';
1212
import { initEccLib } from 'bitcoinjs-lib';
1313
import * as tools from 'uint8array-tools';
1414

15+
const rng = (size: number) => crypto.randomBytes(size);
16+
1517
const bip32 = BIP32Factory.BIP32Factory(ecc);
1618
const ECPair = ECPairFactory(ecc);
1719

@@ -134,7 +136,7 @@ describe(`Psbt`, () => {
134136
});
135137

136138
fixtures.bip174.failSignChecks.forEach(f => {
137-
const keyPair = ECPair.makeRandom();
139+
const keyPair = ECPair.makeRandom({ rng });
138140
it(`Fails Signer checks: ${f.description}`, () => {
139141
const psbt = Psbt.fromBase64(f.psbt);
140142
assert.throws(() => {
@@ -720,7 +722,7 @@ describe(`Psbt`, () => {
720722
});
721723

722724
describe('getInputType', () => {
723-
const key = ECPair.makeRandom();
725+
const key = ECPair.makeRandom({ rng });
724726
const { publicKey } = key;
725727
const p2wpkhPub = (pubkey: Uint8Array): Uint8Array =>
726728
payments.p2wpkh({

0 commit comments

Comments
 (0)