Skip to content

Commit 41bf2cd

Browse files
authored
Merge pull request #1476 from bitcoinjs/removeTxb
Tests cleanup
2 parents 603b0eb + e104a73 commit 41bf2cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1309
-1581
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ matrix:
1919
env: TEST_SUITE=gitdiff:ci
2020
- node_js: "lts/*"
2121
env: TEST_SUITE=lint
22+
- node_js: "lts/*"
23+
env: TEST_SUITE=lint:tests
2224
- node_js: "lts/*"
2325
env: TEST_SUITE=coverage
2426
env:

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ The below examples are implemented as integration tests, they should be very eas
8585
Otherwise, pull requests are appreciated.
8686
Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP).
8787

88-
### Warning: Currently the tests use TransactionBuilder, which will be removed in the future (v6.x.x or higher)
89-
We will move towards replacing all instances of TransactionBuilder in the tests with the new Psbt.
90-
91-
Currently we have a few examples on how to use the newer Psbt class at the following link:
92-
- [Psbt examples](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions-psbt.spec.ts)
93-
94-
The rest of the examples are below (using TransactionBuilder for Transaction creation)
95-
9688
- [Generate a random address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
9789
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
9890
- [Generate a 2-of-3 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
@@ -104,15 +96,14 @@ The rest of the examples are below (using TransactionBuilder for Transaction cre
10496
- [Generate a Testnet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
10597
- [Generate a Litecoin address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
10698
- [Create a 1-to-1 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
107-
- [Create a 2-to-2 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
10899
- [Create (and broadcast via 3PBP) a typical Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
109100
- [Create (and broadcast via 3PBP) a Transaction with an OP\_RETURN output](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
110101
- [Create (and broadcast via 3PBP) a Transaction with a 2-of-4 P2SH(multisig) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
111102
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2SH(P2WPKH) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
112103
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2WPKH input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
113104
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2PK input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
114105
- [Create (and broadcast via 3PBP) a Transaction with a SegWit 3-of-4 P2SH(P2WSH(multisig)) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
115-
- [Verify a Transaction signature](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
106+
- [Create (and broadcast via 3PBP) a Transaction and sign with an HDSigner interface (bip32)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
116107
- [Import a BIP32 testnet xpriv and export to WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
117108
- [Export a BIP32 xpriv, then import it](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
118109
- [Export a BIP32 xpub](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"gitdiff:ci": "npm run build && git diff --exit-code",
2929
"integration": "npm run build && npm run nobuild:integration",
3030
"lint": "tslint -p tsconfig.json -c tslint.json",
31+
"lint:tests": "tslint -p test/tsconfig.json -c tslint.json",
3132
"mocha:ts": "mocha --recursive --require test/ts-node-register",
3233
"nobuild:coverage-report": "nyc report --reporter=lcov",
3334
"nobuild:coverage-html": "nyc report --reporter=html",
@@ -48,7 +49,7 @@
4849
"types"
4950
],
5051
"dependencies": {
51-
"@types/node": "10.12.18",
52+
"@types/node": "12.7.5",
5253
"bech32": "^1.1.2",
5354
"bip174": "^1.0.1",
5455
"bip32": "^2.0.4",

test/bitcoin.core.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import * as base58KeysInvalid from './fixtures/core/base58_keys_invalid.json';
77
import * as base58KeysValid from './fixtures/core/base58_keys_valid.json';
88
import * as blocksValid from './fixtures/core/blocks.json';
99
import * as sigCanonical from './fixtures/core/sig_canonical.json';
10-
import * as sigHash from './fixtures/core/sighash.json';
1110
import * as sigNoncanonical from './fixtures/core/sig_noncanonical.json';
11+
import * as sigHash from './fixtures/core/sighash.json';
1212
import * as txValid from './fixtures/core/tx_valid.json';
1313

1414
describe('Bitcoin-core', () => {
@@ -72,11 +72,11 @@ describe('Bitcoin-core', () => {
7272
];
7373

7474
base58KeysInvalid.forEach(f => {
75-
const string = f[0];
75+
const strng = f[0];
7676

77-
it('throws on ' + string, () => {
77+
it('throws on ' + strng, () => {
7878
assert.throws(() => {
79-
const address = bitcoin.address.fromBase58Check(string);
79+
const address = bitcoin.address.fromBase58Check(strng);
8080

8181
assert.notStrictEqual(
8282
allowedNetworks.indexOf(address.version),
@@ -121,11 +121,11 @@ describe('Bitcoin-core', () => {
121121
];
122122

123123
base58KeysInvalid.forEach(f => {
124-
const string = f[0];
124+
const strng = f[0];
125125

126-
it('throws on ' + string, () => {
126+
it('throws on ' + strng, () => {
127127
assert.throws(() => {
128-
bitcoin.ECPair.fromWIF(string, allowedNetworks);
128+
bitcoin.ECPair.fromWIF(strng, allowedNetworks);
129129
}, /(Invalid|Unknown) (checksum|compression flag|network version|WIF length)/);
130130
});
131131
});
@@ -242,9 +242,14 @@ describe('Bitcoin-core', () => {
242242
const buffer = Buffer.from(hex, 'hex');
243243

244244
it('throws on ' + description, () => {
245+
const reg = new RegExp(
246+
'Expected DER (integer|sequence)|(R|S) value (excessively ' +
247+
'padded|is negative)|(R|S|DER sequence) length is (zero|too ' +
248+
'short|too long|invalid)|Invalid hashType',
249+
);
245250
assert.throws(() => {
246251
bitcoin.script.signature.decode(buffer);
247-
}, /Expected DER (integer|sequence)|(R|S) value (excessively padded|is negative)|(R|S|DER sequence) length is (zero|too short|too long|invalid)|Invalid hashType/);
252+
}, reg);
248253
});
249254
});
250255
});

test/block.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ describe('Block', () => {
88
describe('version', () => {
99
it('should be interpreted as an int32le', () => {
1010
const blockHex =
11-
'ffffffff0000000000000000000000000000000000000000000000000000000000000000414141414141414141414141414141414141414141414141414141414141414101000000020000000300000000';
11+
'ffffffff000000000000000000000000000000000000000000000000000000000000' +
12+
'00004141414141414141414141414141414141414141414141414141414141414141' +
13+
'01000000020000000300000000';
1214
const block = Block.fromHex(blockHex);
1315
assert.strictEqual(-1, block.version);
1416
assert.strictEqual(1, block.timestamp);

test/bufferutils.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ describe('bufferutils', () => {
99
fixtures.valid.forEach(f => {
1010
it('decodes ' + f.hex, () => {
1111
const buffer = Buffer.from(f.hex, 'hex');
12-
const number = bufferutils.readUInt64LE(buffer, 0);
12+
const num = bufferutils.readUInt64LE(buffer, 0);
1313

14-
assert.strictEqual(number, f.dec);
14+
assert.strictEqual(num, f.dec);
1515
});
1616
});
1717

test/classify.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from 'assert';
22
import { describe, it } from 'mocha';
3-
import * as bscript from '../src/script';
43
import * as classify from '../src/classify';
4+
import * as bscript from '../src/script';
55

66
import * as fixtures from './fixtures/templates.json';
77

@@ -10,9 +10,9 @@ import * as nullData from '../src/templates/nulldata';
1010
import * as pubKey from '../src/templates/pubkey';
1111
import * as pubKeyHash from '../src/templates/pubkeyhash';
1212
import * as scriptHash from '../src/templates/scripthash';
13+
import * as witnessCommitment from '../src/templates/witnesscommitment';
1314
import * as witnessPubKeyHash from '../src/templates/witnesspubkeyhash';
1415
import * as witnessScriptHash from '../src/templates/witnessscripthash';
15-
import * as witnessCommitment from '../src/templates/witnesscommitment';
1616

1717
const tmap = {
1818
pubKey,

test/integration/addresses.spec.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ const dhttp = regtestUtils.dhttp;
66
const TESTNET = bitcoin.networks.testnet;
77

88
describe('bitcoinjs-lib (addresses)', () => {
9-
it('can generate a random address [and support the retrieval of transactions for that address (via 3PBP)', async () => {
10-
const keyPair = bitcoin.ECPair.makeRandom();
11-
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
12-
13-
// bitcoin P2PKH addresses start with a '1'
14-
assert.strictEqual(address!.startsWith('1'), true);
15-
16-
const result = await dhttp({
17-
method: 'GET',
18-
url: 'https://blockchain.info/rawaddr/' + address,
19-
});
20-
21-
// random private keys [probably!] have no transactions
22-
assert.strictEqual((result as any).n_tx, 0);
23-
assert.strictEqual((result as any).total_received, 0);
24-
assert.strictEqual((result as any).total_sent, 0);
25-
});
9+
it(
10+
'can generate a random address [and support the retrieval of ' +
11+
'transactions for that address (via 3PBP)]',
12+
async () => {
13+
const keyPair = bitcoin.ECPair.makeRandom();
14+
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
15+
16+
// bitcoin P2PKH addresses start with a '1'
17+
assert.strictEqual(address!.startsWith('1'), true);
18+
19+
const result = await dhttp({
20+
method: 'GET',
21+
url: 'https://blockchain.info/rawaddr/' + address,
22+
});
23+
24+
// random private keys [probably!] have no transactions
25+
assert.strictEqual((result as any).n_tx, 0);
26+
assert.strictEqual((result as any).total_received, 0);
27+
assert.strictEqual((result as any).total_sent, 0);
28+
},
29+
);
2630

2731
it('can import an address via WIF', () => {
2832
const keyPair = bitcoin.ECPair.fromWIF(

test/integration/bip32.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from 'assert';
2-
import { describe, it } from 'mocha';
32
import * as bip32 from 'bip32';
43
import * as bip39 from 'bip39';
4+
import { describe, it } from 'mocha';
55
import * as bitcoin from '../..';
66

77
function getAddress(node: any, network?: any): string {
@@ -25,8 +25,8 @@ describe('bitcoinjs-lib (BIP32)', () => {
2525
'praise you muffin lion enable neck grocery crumble super myself license ghost';
2626
const seed = bip39.mnemonicToSeedSync(mnemonic);
2727
const node = bip32.fromSeed(seed);
28-
const string = node.toBase58();
29-
const restored = bip32.fromBase58(string);
28+
const strng = node.toBase58();
29+
const restored = bip32.fromBase58(strng);
3030

3131
assert.strictEqual(getAddress(node), getAddress(restored)); // same public key
3232
assert.strictEqual(node.toWIF(), restored.toWIF()); // same private key
@@ -37,10 +37,10 @@ describe('bitcoinjs-lib (BIP32)', () => {
3737
'praise you muffin lion enable neck grocery crumble super myself license ghost';
3838
const seed = bip39.mnemonicToSeedSync(mnemonic);
3939
const node = bip32.fromSeed(seed);
40-
const string = node.neutered().toBase58();
40+
const strng = node.neutered().toBase58();
4141

4242
assert.strictEqual(
43-
string,
43+
strng,
4444
'xpub661MyMwAqRbcGhVeaVfEBA25e3cP9DsJQZoE8iep5fZSxy3TnPBNBgWnMZx56oreNc48ZoTkQfatNJ9VWnQ7ZcLZcVStpaXLTeG8bGrzX3n',
4545
);
4646
});

0 commit comments

Comments
 (0)