test: create better interface for block/tx test vectors.
This commit is contained in:
parent
5a751d9ba7
commit
e37d299049
@ -5,9 +5,10 @@ const StaticWriter = require('../lib/utils/staticwriter');
|
||||
const common = require('../test/util/common');
|
||||
const bench = require('./bench');
|
||||
|
||||
const {tx} = common.parseTX('tx5');
|
||||
const tx5 = common.readTX('tx5');
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('serialize (static-writer)');
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
tx.refresh();
|
||||
@ -20,6 +21,7 @@ const {tx} = common.parseTX('tx5');
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('serialize (buffer-writer)');
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
tx.refresh();
|
||||
|
||||
@ -4,7 +4,7 @@ const Coins = require('../lib/coins/coins');
|
||||
const common = require('../test/util/common');
|
||||
const bench = require('./bench');
|
||||
|
||||
const {tx} = common.parseTX('tx5');
|
||||
const [tx] = common.readTX('tx5').getTX();
|
||||
const coins = Coins.fromTX(tx, 1);
|
||||
const raw = coins.toRaw();
|
||||
|
||||
|
||||
65
bench/tx.js
65
bench/tx.js
@ -11,22 +11,12 @@ const random = require('../lib/crypto/random');
|
||||
const common = require('../test/util/common');
|
||||
const bench = require('./bench');
|
||||
|
||||
const blockRaw = fs.readFileSync(`${__dirname}/../test/data/block300025.raw`);
|
||||
const undoRaw = fs.readFileSync(`${__dirname}/../test/data/undo300025.raw`);
|
||||
|
||||
const block = Block.fromRaw(blockRaw);
|
||||
const undo = common.parseUndo(undoRaw);
|
||||
|
||||
const btx = {
|
||||
tx: block.txs[397],
|
||||
view: common.applyBlockUndo(block, undo)
|
||||
};
|
||||
|
||||
const tx3 = common.parseTX('tx3');
|
||||
const tx5 = common.parseTX('tx5');
|
||||
const raw = tx5.tx.toRaw();
|
||||
const tx3 = common.readTX('tx3');
|
||||
const tx5 = common.readTX('tx5');
|
||||
const tx10 = common.readTX('tx10');
|
||||
|
||||
{
|
||||
const raw = tx5.getRaw();
|
||||
const end = bench('parse');
|
||||
|
||||
for (let i = 0; i < 1000; i++)
|
||||
@ -36,110 +26,121 @@ const raw = tx5.tx.toRaw();
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('serialize');
|
||||
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
tx5.tx._raw = null;
|
||||
tx5.tx.toRaw();
|
||||
tx._raw = null;
|
||||
tx.toRaw();
|
||||
}
|
||||
|
||||
end(1000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx3.getTX();
|
||||
const end = bench('hash');
|
||||
|
||||
for (let i = 0; i < 3000; i++) {
|
||||
tx3.tx.hash();
|
||||
tx3.tx._hash = null;
|
||||
tx.hash();
|
||||
tx._hash = null;
|
||||
}
|
||||
|
||||
end(3000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('witness hash');
|
||||
|
||||
for (let i = 0; i < 3000; i++) {
|
||||
tx5.tx.witnessHash();
|
||||
tx5.tx._whash = null;
|
||||
tx.witnessHash();
|
||||
tx._whash = null;
|
||||
}
|
||||
|
||||
end(3000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('sanity');
|
||||
|
||||
for (let i = 0; i < 1000; i++)
|
||||
tx5.tx.isSane();
|
||||
tx.isSane();
|
||||
|
||||
end(1000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('input hashes');
|
||||
|
||||
for (let i = 0; i < 1000; i++)
|
||||
tx5.tx.getInputHashes(null, 'hex');
|
||||
tx.getInputHashes(null, 'hex');
|
||||
|
||||
end(1000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('output hashes');
|
||||
|
||||
for (let i = 0; i < 1000; i++)
|
||||
tx5.tx.getOutputHashes('hex');
|
||||
tx.getOutputHashes('hex');
|
||||
|
||||
end(1000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx] = tx5.getTX();
|
||||
const end = bench('all hashes');
|
||||
|
||||
for (let i = 0; i < 1000; i++)
|
||||
tx5.tx.getHashes(null, 'hex');
|
||||
tx.getHashes(null, 'hex');
|
||||
|
||||
end(1000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx, view] = tx3.getTX();
|
||||
const end = bench('verify');
|
||||
|
||||
for (let i = 0; i < 3000; i++)
|
||||
tx3.tx.verify(tx3.view, Script.flags.VERIFY_P2SH);
|
||||
tx.verify(view, Script.flags.VERIFY_P2SH);
|
||||
|
||||
end(3000 * tx3.tx.inputs.length);
|
||||
end(3000 * tx.inputs.length);
|
||||
}
|
||||
|
||||
{
|
||||
const end = bench('verify2');
|
||||
const {script} = tx3.view.getOutputFor(tx3.tx.inputs[0]);
|
||||
const [tx, view] = tx3.getTX();
|
||||
const {script} = view.getOutputFor(tx.inputs[0]);
|
||||
const end = bench('sighash');
|
||||
|
||||
for (let i = 0; i < 100000; i++)
|
||||
tx3.tx.signatureHashV0(0, script, Script.hashType.ALL);
|
||||
tx.signatureHashV0(0, script, Script.hashType.ALL);
|
||||
|
||||
end(100000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx, view] = tx3.getTX();
|
||||
const end = bench('fee');
|
||||
|
||||
for (let i = 0; i < 1000; i++)
|
||||
tx3.tx.getFee(tx3.view);
|
||||
tx.getFee(view);
|
||||
|
||||
end(1000);
|
||||
}
|
||||
|
||||
{
|
||||
const [tx, view] = tx10.getTX();
|
||||
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG;
|
||||
const end = bench('verify multisig');
|
||||
|
||||
for (let i = 0; i < 3000; i++)
|
||||
btx.tx.verify(btx.view, flags);
|
||||
tx.verify(view, flags);
|
||||
|
||||
end(3000 * btx.tx.inputs.length);
|
||||
end(3000 * tx.inputs.length);
|
||||
}
|
||||
|
||||
const mtx = new MTX();
|
||||
|
||||
@ -5,9 +5,7 @@ const MempoolEntry = require('../lib/mempool/mempoolentry');
|
||||
const Coins = require('../lib/coins/coins');
|
||||
const common = require('../test/util/common');
|
||||
|
||||
const SNAPSHOT = `${__dirname}/../dump.heapsnapshot`;
|
||||
|
||||
const {tx, view} = common.parseTX('tx4');
|
||||
const [tx, view] = common.readTX('tx4').getTX();
|
||||
const coins = Coins.fromTX(tx, 0);
|
||||
const entry = MempoolEntry.fromTX(tx, view, 1000000);
|
||||
|
||||
@ -18,7 +16,7 @@ setInterval(() => {
|
||||
}, 60 * 1000);
|
||||
|
||||
setImmediate(() => {
|
||||
heapdump.writeSnapshot(SNAPSHOT, (err) => {
|
||||
heapdump.writeSnapshot(`${__dirname}/../dump.heapsnapshot`, (err) => {
|
||||
if (err)
|
||||
throw err;
|
||||
});
|
||||
|
||||
@ -19,31 +19,27 @@ const TXRequest = bip152.TXRequest;
|
||||
const TXResponse = bip152.TXResponse;
|
||||
|
||||
// Block test vectors
|
||||
const block300025 = fs.readFileSync(`${__dirname}/data/block300025.raw`);
|
||||
const undo300025 = fs.readFileSync(`${__dirname}/data/undo300025.raw`);
|
||||
const block300025 = common.readBlock('block300025');
|
||||
|
||||
// Merkle block test vectors
|
||||
const merkle300025 = fs.readFileSync(`${__dirname}/data/merkle300025.raw`);
|
||||
const merkle300025 = common.readMerkle('merkle300025');
|
||||
|
||||
// Compact block test vectors
|
||||
const block426884 = fs.readFileSync(`${__dirname}/data/block426884.raw`);
|
||||
const compact426884 = fs.readFileSync(`${__dirname}/data/compact426884.raw`);
|
||||
const block898352 = fs.readFileSync(`${__dirname}/data/block898352.raw`);
|
||||
const compact898352 = fs.readFileSync(`${__dirname}/data/compact898352.raw`);
|
||||
const block426884 = common.readBlock('block426884');
|
||||
const compact426884 = common.readCompact('compact426884');
|
||||
const block898352 = common.readBlock('block898352');
|
||||
const compact898352 = common.readCompact('compact898352');
|
||||
|
||||
// Sigops counting test vectors
|
||||
const block928927 = fs.readFileSync(`${__dirname}/data/block928927.raw`);
|
||||
const undo928927 = fs.readFileSync(`${__dirname}/data/undo928927.raw`);
|
||||
const block928828 = fs.readFileSync(`${__dirname}/data/block928828.raw`);
|
||||
const undo928828 = fs.readFileSync(`${__dirname}/data/undo928828.raw`);
|
||||
const block1087400 = fs.readFileSync(`${__dirname}/data/block1087400.raw`);
|
||||
const undo1087400 = fs.readFileSync(`${__dirname}/data/undo1087400.raw`);
|
||||
const block928927 = common.readBlock('block928927');
|
||||
const block928828 = common.readBlock('block928828');
|
||||
const block1087400 = common.readBlock('block1087400');
|
||||
|
||||
describe('Block', function() {
|
||||
this.timeout(10000);
|
||||
|
||||
it('should parse partial merkle tree', () => {
|
||||
const block = MerkleBlock.fromRaw(merkle300025);
|
||||
const [block] = merkle300025.getBlock();
|
||||
|
||||
assert(block.verifyPOW());
|
||||
assert(block.verifyBody());
|
||||
@ -65,18 +61,18 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should decode/encode merkle block', () => {
|
||||
const block = MerkleBlock.fromRaw(merkle300025);
|
||||
const [block] = merkle300025.getBlock();
|
||||
block.refresh();
|
||||
assert.bufferEqual(block.toRaw(), merkle300025);
|
||||
assert.bufferEqual(block.toRaw(), merkle300025.getRaw());
|
||||
});
|
||||
|
||||
it('should verify merkle block', () => {
|
||||
const block = MerkleBlock.fromRaw(merkle300025);
|
||||
const [block] = merkle300025.getBlock();
|
||||
assert(block.verify());
|
||||
});
|
||||
|
||||
it('should be encoded/decoded and still verify', () => {
|
||||
const block1 = MerkleBlock.fromRaw(merkle300025);
|
||||
const [block1] = merkle300025.getBlock();
|
||||
const raw = block1.toRaw();
|
||||
const block2 = MerkleBlock.fromRaw(raw);
|
||||
assert.bufferEqual(block2.toRaw(), raw);
|
||||
@ -84,7 +80,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should be jsonified/unjsonified and still verify', () => {
|
||||
const block1 = MerkleBlock.fromRaw(merkle300025);
|
||||
const [block1] = merkle300025.getBlock();
|
||||
const json = block1.toJSON();
|
||||
const block2 = MerkleBlock.fromJSON(json);
|
||||
assert.deepStrictEqual(block2.toJSON(), json);
|
||||
@ -109,7 +105,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should parse JSON', () => {
|
||||
const block1 = Block.fromRaw(block300025);
|
||||
const [block1] = block300025.getBlock();
|
||||
const block2 = Block.fromJSON(block1.toJSON());
|
||||
assert.strictEqual(block2.hash('hex'),
|
||||
'8cc72c02a958de5a8b35a23bb7e3bced8bf840cc0a4e1c820000000000000000');
|
||||
@ -129,17 +125,15 @@ describe('Block', function() {
|
||||
filter.add(item1, 'hex');
|
||||
filter.add(item2, 'hex');
|
||||
|
||||
const block1 = Block.fromRaw(block300025);
|
||||
const [block1] = block300025.getBlock();
|
||||
const block2 = MerkleBlock.fromBlock(block1, filter);
|
||||
|
||||
assert(block2.verifyBody());
|
||||
assert.bufferEqual(block2.toRaw(), merkle300025);
|
||||
assert.bufferEqual(block2.toRaw(), merkle300025.getRaw());
|
||||
});
|
||||
|
||||
it('should verify a historical block', () => {
|
||||
const block = Block.fromRaw(block300025);
|
||||
const undo = common.parseUndo(undo300025);
|
||||
const view = common.applyBlockUndo(block, undo);
|
||||
const [block, view] = block300025.getBlock();
|
||||
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG;
|
||||
const height = 300025;
|
||||
|
||||
@ -174,7 +168,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should fail with a bad merkle root', () => {
|
||||
const block = Block.fromRaw(block300025);
|
||||
const [block] = block300025.getBlock();
|
||||
const merkleRoot = block.merkleRoot;
|
||||
block.merkleRoot = encoding.NULL_HASH;
|
||||
block.refresh();
|
||||
@ -188,7 +182,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should fail on merkle block with a bad merkle root', () => {
|
||||
const block = MerkleBlock.fromRaw(merkle300025);
|
||||
const [block] = merkle300025.getBlock();
|
||||
const merkleRoot = block.merkleRoot;
|
||||
block.merkleRoot = encoding.NULL_HASH;
|
||||
block.refresh();
|
||||
@ -202,7 +196,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should fail with a low target', () => {
|
||||
const block = Block.fromRaw(block300025);
|
||||
const [block] = block300025.getBlock();
|
||||
const bits = block.bits;
|
||||
block.bits = 403014710;
|
||||
block.refresh();
|
||||
@ -215,7 +209,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should fail on duplicate txs', () => {
|
||||
const block = Block.fromRaw(block300025);
|
||||
const [block] = block300025.getBlock();
|
||||
block.txs.push(block.txs[block.txs.length - 1]);
|
||||
block.refresh();
|
||||
const [, reason] = block.checkBody();
|
||||
@ -223,21 +217,21 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should verify with headers', () => {
|
||||
const headers = Headers.fromHead(block300025);
|
||||
const headers = block300025.getHeaders();
|
||||
assert(headers.verifyPOW());
|
||||
assert(headers.verifyBody());
|
||||
assert(headers.verify());
|
||||
});
|
||||
|
||||
it('should handle compact block', () => {
|
||||
const block = Block.fromRaw(block426884);
|
||||
const cblock1 = CompactBlock.fromRaw(compact426884);
|
||||
const [block] = block426884.getBlock();
|
||||
const [cblock1] = compact426884.getBlock();
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
|
||||
assert(cblock1.init());
|
||||
|
||||
assert.bufferEqual(cblock1.toRaw(), compact426884);
|
||||
assert.bufferEqual(cblock2.toRaw(), compact426884);
|
||||
assert.bufferEqual(cblock1.toRaw(), compact426884.getRaw());
|
||||
assert.bufferEqual(cblock2.toRaw(), compact426884.getRaw());
|
||||
|
||||
const map = new Map();
|
||||
|
||||
@ -256,14 +250,14 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should handle half-full compact block', () => {
|
||||
const block = Block.fromRaw(block426884);
|
||||
const cblock1 = CompactBlock.fromRaw(compact426884);
|
||||
const [block] = block426884.getBlock();
|
||||
const [cblock1] = compact426884.getBlock();
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
|
||||
assert(cblock1.init());
|
||||
|
||||
assert.bufferEqual(cblock1.toRaw(), compact426884);
|
||||
assert.bufferEqual(cblock2.toRaw(), compact426884);
|
||||
assert.bufferEqual(cblock1.toRaw(), compact426884.getRaw());
|
||||
assert.bufferEqual(cblock2.toRaw(), compact426884.getRaw());
|
||||
|
||||
const map = new Map();
|
||||
|
||||
@ -292,14 +286,14 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should handle compact block', () => {
|
||||
const block = Block.fromRaw(block898352);
|
||||
const cblock1 = CompactBlock.fromRaw(compact898352);
|
||||
const [block] = block898352.getBlock();
|
||||
const [cblock1] = compact898352.getBlock();
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
|
||||
assert(cblock1.init());
|
||||
|
||||
assert.bufferEqual(cblock1.toRaw(), compact898352);
|
||||
assert.bufferEqual(cblock2.toRaw(), compact898352);
|
||||
assert.bufferEqual(cblock1.toRaw(), compact898352.getRaw());
|
||||
assert.bufferEqual(cblock2.toRaw(), compact898352.getRaw());
|
||||
|
||||
assert.strictEqual(cblock1.sid(block.txs[1].hash()), 125673511480291);
|
||||
|
||||
@ -320,14 +314,14 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should handle half-full compact block', () => {
|
||||
const block = Block.fromRaw(block898352);
|
||||
const cblock1 = CompactBlock.fromRaw(compact898352);
|
||||
const [block] = block898352.getBlock();
|
||||
const [cblock1] = compact898352.getBlock();
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
|
||||
assert(cblock1.init());
|
||||
|
||||
assert.bufferEqual(cblock1.toRaw(), compact898352);
|
||||
assert.bufferEqual(cblock2.toRaw(), compact898352);
|
||||
assert.bufferEqual(cblock1.toRaw(), compact898352.getRaw());
|
||||
assert.bufferEqual(cblock2.toRaw(), compact898352.getRaw());
|
||||
|
||||
assert.strictEqual(cblock1.sid(block.txs[1].hash()), 125673511480291);
|
||||
|
||||
@ -359,9 +353,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should count sigops for block 928927 (testnet)', () => {
|
||||
const block = Block.fromRaw(block928927);
|
||||
const undo = common.parseUndo(undo928927);
|
||||
const view = common.applyBlockUndo(block, undo);
|
||||
const [block, view] = block928927.getBlock();
|
||||
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS;
|
||||
|
||||
let sigops = 0;
|
||||
@ -373,9 +365,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should count sigops for block 928828 (testnet)', () => {
|
||||
const block = Block.fromRaw(block928828);
|
||||
const undo = common.parseUndo(undo928828);
|
||||
const view = common.applyBlockUndo(block, undo);
|
||||
const [block, view] = block928828.getBlock();
|
||||
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS;
|
||||
|
||||
let sigops = 0;
|
||||
@ -387,9 +377,7 @@ describe('Block', function() {
|
||||
});
|
||||
|
||||
it('should count sigops for block 1087400 (testnet)', () => {
|
||||
const block = Block.fromRaw(block1087400);
|
||||
const undo = common.parseUndo(undo1087400);
|
||||
const view = common.applyBlockUndo(block, undo);
|
||||
const [block, view] = block1087400.getBlock();
|
||||
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS;
|
||||
|
||||
let sigops = 0;
|
||||
|
||||
@ -11,10 +11,9 @@ const CoinView = require('../lib/coins/coinview');
|
||||
const CoinEntry = require('../lib/coins/coinentry');
|
||||
const StaticWriter = require('../lib/utils/staticwriter');
|
||||
const BufferReader = require('../lib/utils/reader');
|
||||
const {parseTX} = require('./util/common');
|
||||
const common = require('./util/common');
|
||||
|
||||
const data = parseTX('tx1');
|
||||
const tx1 = data.tx;
|
||||
const tx1 = common.readTX('tx1');
|
||||
|
||||
function reserialize(coin) {
|
||||
const raw = coin.toRaw();
|
||||
@ -32,15 +31,16 @@ function deepCoinsEqual(a, b) {
|
||||
|
||||
describe('Coins', function() {
|
||||
it('should instantiate coinview from tx', () => {
|
||||
const hash = tx1.hash('hex');
|
||||
const [tx] = tx1.getTX();
|
||||
const hash = tx.hash('hex');
|
||||
const view = new CoinView();
|
||||
const prevout = new Outpoint(hash, 0);
|
||||
const input = Input.fromOutpoint(prevout);
|
||||
|
||||
view.addTX(tx1, 1);
|
||||
view.addTX(tx, 1);
|
||||
|
||||
const coins = view.get(hash);
|
||||
assert.strictEqual(coins.outputs.size, tx1.outputs.length);
|
||||
assert.strictEqual(coins.outputs.size, tx.outputs.length);
|
||||
|
||||
const entry = coins.get(0);
|
||||
assert(entry);
|
||||
@ -59,10 +59,11 @@ describe('Coins', function() {
|
||||
});
|
||||
|
||||
it('should spend an output', () => {
|
||||
const hash = tx1.hash('hex');
|
||||
const [tx] = tx1.getTX();
|
||||
const hash = tx.hash('hex');
|
||||
const view = new CoinView();
|
||||
|
||||
view.addTX(tx1, 1);
|
||||
view.addTX(tx, 1);
|
||||
|
||||
const coins = view.get(hash);
|
||||
assert(coins);
|
||||
@ -84,20 +85,15 @@ describe('Coins', function() {
|
||||
});
|
||||
|
||||
it('should handle coin view', () => {
|
||||
const view = new CoinView();
|
||||
const [tx, view] = tx1.getTX();
|
||||
|
||||
for (let i = 1; i < data.txs.length; i++) {
|
||||
const tx = data.txs[i];
|
||||
view.addTX(tx, 1);
|
||||
}
|
||||
|
||||
const size = view.getSize(tx1);
|
||||
const size = view.getSize(tx);
|
||||
const bw = new StaticWriter(size);
|
||||
const raw = view.toWriter(bw, tx1).render();
|
||||
const raw = view.toWriter(bw, tx).render();
|
||||
const br = new BufferReader(raw);
|
||||
const res = CoinView.fromReader(br, tx1);
|
||||
const res = CoinView.fromReader(br, tx);
|
||||
|
||||
const prev = tx1.inputs[0].prevout;
|
||||
const prev = tx.inputs[0].prevout;
|
||||
const coins = res.get(prev.hash);
|
||||
|
||||
assert.strictEqual(coins.outputs.size, 1);
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
01000000018177482b65ec42fc43c6b2ad13955d7fdec00edb5dc5ac483d9e31eb06a5a5d5010000006c493046022100955062369843b52db91eb9c1b8fb5ed20b346a62841edfb2ba2097d2a9bc31810221009ace1c91398620b4d1bfa559ca2abcaf6c1a524e606bb5fedf74c9a123ae4ec8012103046d258651af2fbb6acb63414a604314ce94d644a0efd8832ca5275f2bc207c6ffffffff05404b4c0000000000475221033423007d8f263819a2e42becaaf5b06f34cb09919e06304349d950668209eaed21021d69e2b68c3960903b702af7829fadcd80bd89b158150c85c4a75b2c8cb9c39452ae404b4c00000000002752010021021d69e2b68c3960903b702af7829fadcd80bd89b158150c85c4a75b2c8cb9c39452ae404b4c00000000004752210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179821021d69e2b68c3960903b702af7829fadcd80bd89b158150c85c4a75b2c8cb9c39452aeb0f0c304000000001976a9146cce12229300b733cdf0c7ce3079c7503b080fca88ac404b4c000000000047522102c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee521021d69e2b68c3960903b702af7829fadcd80bd89b158150c85c4a75b2c8cb9c39452ae00000000
|
||||
01000000017133b604e8aaa0414a2f3f4c093258acbacd7063cca964cf1dcd3c9afd8be086010000006c493046022100c28bbd00b6ab9af8cf1038139003988f800744d82ed168c39fdcf5958f3348ef022100b7f626763f39d795cc23dc31bb74a6a5b90527c5e909c28b29bbcd3a438aa36101210211b60f23135a806aff2c8f0fbbe620c16ba05a9ca4772735c08a16407f185b34ffffffff02b01df505000000001976a9144e96e751b8f837983046adfc528b11d1dc8200ae88ac00e1f505000000001976a914f5223c1cf62c09a4789c6bdfebaf77b8b7b4dc8f88ac00000000
|
||||
BIN
test/data/tx1.raw
Normal file
BIN
test/data/tx1.raw
Normal file
Binary file not shown.
BIN
test/data/tx10.raw
Normal file
BIN
test/data/tx10.raw
Normal file
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
00000000014ae41d5402fafe7b5c8968bcb588ffe91f282edd9f0773e7abedf5fffd4f77ea000000006b483045022100e3d075434dbce66fce6c1843ebb84c56541f542e7c4c29878b7a38de739e7a9a02202f626ccf7d507291ebc7879f573cb5d229e34b8738a47cb5424d9f14e3d54b2f012103ac81c3203de55b31478da413d9bb68b99dc8e33176f9f48e5efcc0900bb41b4affffffff024e61bc00000000001976a914ab37bf4a3af9bc16025b9c64e82f85838bbc792088aca2583905000000001976a914978cdeb4fa9e180044a62fcc345da48e4e14ce6c88ac00000000
|
||||
0100000002b84833440fb981852d469b12321dc5d30bb71977100ac78a2db1560ae3b65eec010000006a473044022031e0b888652a5c8988b01af7fd1226a0015e38b505868d343e4fe0713b9dd8cc02206c6eeae02976d03147f9fb483ca12a22d16178feee7ab691dc0dd829c375a58e012102d22f286d17a07ac48ad9d22a85db5638082de4bc9fc14f94266bed6318cfffc7ffffffff612b726b05e36cdda64bae4aac34eaf0e4a5ca9a20a4a3ce1d1d2f31d7b94a90000000006b48304502205adf9a67e21c6430cbdd6b2b3037a3f23a393ad25d148dc3068afb01c4a7b8d8022100eabc84aeca4e637bc068a451a98d03f5ad6368e4a701ec4bc6e2548f7e17dc94012103ac81c3203de55b31478da413d9bb68b99dc8e33176f9f48e5efcc0900bb41b4affffffff0200e1f505000000001976a914059fd71b64ece424b1fe97e00082e163ff224ee488aca0f01900000000001976a9146580541e8b9cb88c1659e44f2597b99081ee59eb88ac00000000
|
||||
BIN
test/data/tx2.raw
Normal file
BIN
test/data/tx2.raw
Normal file
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
01000000022f196cf1e5bd426a04f07b882c893b5b5edebad67da6eb50f066c372ed736d5f000000006a47304402201f81ac31b52cb4b1ceb83f97d18476f7339b74f4eecd1a32c251d4c3cccfffa402203c9143c18810ce072969e4132fdab91408816c96b423b2be38eec8a3582ade36012102aa5a2b334bd8f135f11bc5c477bf6307ff98ed52d3ed10f857d5c89adf5b02beffffffffff8755f073f1170c0d519457ffc4acaa7cb2988148163b5dc457fae0fe42aa19000000009200483045022015bd0139bcccf990a6af6ec5c1c52ed8222e03a0d51c334df139968525d2fcd20221009f9efe325476eb64c3958e4713e9eefe49bf1d820ed58d2112721b134e2a1a530347304402206da827fb26e569eb740641f9c1a7121ee59141703cbe0f903a22cc7d9a7ec7ac02204729f989b5348b3669ab020b8c4af01acc4deaba7c0d9f8fa9e06b2106cbbfeb01ffffffff010000000000000000016a00000000
|
||||
010000000143d4b858145e44fbd121dbc592ae931b459f9ec99418a83e8cb6d94330a80c24010000006b483045022100f85c9fceb6d4d38c82a9121acbf68ffffe784017b05554b586464fdbe473340d0220077780b2022c2d97752961c2cb03ed9202cbe57647510746c6bd31276c8a3c5201210314ffdda8717bc586284c05f37192990f774c391e2088516d2983094d3a33e7c3ffffffff02a0860100000000001976a91419660c27383b347112e92caba64fb1d07e9f63bf88ac40c33800000000001976a914825537afe6d73324f862027690651a64c688dfb788ac00000000
|
||||
01000000017a2133643a513a004ff4d09bbcc7a05d7ee7d3a1d28889f0c06d06f9db1d1d8000000000fd4d0200473044022011cb94542051b8be5563b39da022d7531673ed4b53b6b3f8536794150f7d75e802205a6774c0630964457c2d4a087e5a23167155f661082746dc711ba348ca4d4187014d01025121033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b21033d1d799df4bbb828cb8fd9146407ec974948609031e50224b491a6291b77d76b5faeffffffff01a08601000000000091483045022015bd0139bcccf990a6af6ec5c1c52ed8222e03a0d51c334df139968525d2fcd20221009f9efe325476eb64c3958e4713e9eefe49bf1d820ed58d2112721b134e2a1a53037552210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c7152ae00000000
|
||||
BIN
test/data/tx3.raw
Normal file
BIN
test/data/tx3.raw
Normal file
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
01000000018759d7397a86d6c42dfe2c55612e523d171e51708fec9e289118deb5ba99400101000000dc00493046022100da3264579decba370d0b5d896c5f4664dfdf06119cc3ca5cef937389e61b5bf1022100a5584aa704578d35080129edb22d2bea7a24f16f0603cc22a9390cdc0a8f6e6301483045022018478cf5c7ef4cf0b0b6583937bba83b76bf87461825f44130dbb854111a62d8022100e431be966081676b2d785a3260e2a50e250d8a2f5d8364309fe1195dfa87a31d01475221030c341a91e5de82732d6bfb1c3676585b817096cd8bf076cf0ea88c339b9815072102f3f450d36aced52de6023ca5e9d7e256d5c5183f3316211d53bb151c3585222e52ae000000000104c70300000000001976a914a532649591196c7ff3ebd5783c29c9a08d54a3a288ac370c0500
|
||||
0100000001c6ada6066f14a0cd4dc39f086f1f7637b76bfc08da5dc25f8179b0ccfc5d09f7000000006a473044022067934a2152ab5fe96119d702fc48322b967aee669a14e9da8913481d4b7f133402207e444ee1987fcb25ebcb9d98add22e3948ac847a67b306dba106d8e6ba48781001210297812667d2a62d7bbcf17e2d2ade2ade548a9464e9e8e29b42a777f85c93a48effffffff02f4ad2600000000001976a91454987f4e1ea17ec34a489d82ae9d39f6928e61cd88ac14ee03000000000017a914195bde4cd150acf910b5c83a024fd2d9f33306af8700000000
|
||||
BIN
test/data/tx4.raw
Normal file
BIN
test/data/tx4.raw
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
test/data/tx5.raw
Normal file
BIN
test/data/tx5.raw
Normal file
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
0100000002bab3b61c5a7facd63a090addb0a4ea1863ccb0f8d6d8d5c1d7b747b5aa9b17bc01000000fdfe000048304502210089666e61b0486a71f2103414315aa4c418dc65815f8b8bfcfab1037c3c2a66210220428b8162874cfc97e05dee6f901dae03820d11011fa7828ecb8fbca45be2188d01493046022100c6c19d75b6d5c911813b2b64cee07c6338f54bca0395264e53c3b3d8ca8e4f8e022100bbcb8d32960e62f26e3e5bdeca605a8b49f1a42cedd20bad507a1bc23c565faf01ab522103c86390eb5230237f31de1f02e70ce61e77f6dbfefa7d0e4ed4f6b3f78f85d8ec2103193f28067b502b34cac9eae39f74dba4815e1278bab31516efb29bd8de2c1bea21032462c60ebc21f4d38b3c4ccb33be77b57ae72762be12887252db18fd6225befb53aeffffffffb1678d9af66c4b8cde45d0d445749322746ab900e546d3900cf30f436e73428a01000000fd470100483045022100a7af036203a1e6b2e833b0d6b402958d58f9ffaaff4969539f213634f17600ee0220192594a5c60f70e5a97dc48fec06df0d3b17c44850162d3d552c7d8653d159a001483045022072020e687ce937828827e85bc916716a9099a510e7fbd96a2836617afa370108022100ce737ad7b46c249cda2b09cb065ea16078b9a3a31f6fc6b63385f645abfdafdf01493046022100c30c5f6e943a78d502216e019821545b940b940784e83051945d89c92ec245f0022100b5c76266878ee8f29f65401fb0af6ba3941641740d846cb551059c0ad25b798c01ab532103c86390eb5230237f31de1f02e70ce61e77f6dbfefa7d0e4ed4f6b3f78f85d8ec2103193f28067b502b34cac9eae39f74dba4815e1278bab31516efb29bd8de2c1bea21032462c60ebc21f4d38b3c4ccb33be77b57ae72762be12887252db18fd6225befb53aeffffffff0150c300000000000017142c68bb496b123d39920fcfdc206daa08bbe58506b17500000000
|
||||
010000000290c5e425bfba62bd5b294af0414d8fa3ed580c5ca6f351ccc23e360b14ff7f470100000091004730440220739d9ab2c3e7089e7bd311f267a65dc0ea00f49619cb61ec016a5038016ed71202201b88257809b623d471e429787c36e0a9bcd2a058fc0c75fd9c25f905657e3b9e01ab512103c86390eb5230237f31de1f02e70ce61e77f6dbfefa7d0e4ed4f6b3f78f85d8ec2103193f28067b502b34cac9eae39f74dba4815e1278bab31516efb29bd8de2c1bea52aeffffffffdd7f3ce640a2fb04dbe24630aa06e4299fbb1d3fe585fe4f80be4a96b5ff0a0d01000000b400483045022100a28d2ace2f1cb4b2a58d26a5f1a2cc15cdd4cf1c65cee8e4521971c7dc60021c0220476a5ad62bfa7c18f9174d9e5e29bc0062df543e2c336ae2c77507e462bbf95701ab512103c86390eb5230237f31de1f02e70ce61e77f6dbfefa7d0e4ed4f6b3f78f85d8ec2103193f28067b502b34cac9eae39f74dba4815e1278bab31516efb29bd8de2c1bea21032462c60ebc21f4d38b3c4ccb33be77b57ae72762be12887252db18fd6225befb53aeffffffff02e0fd1c00000000001976a9148501106ab5492387998252403d70857acfa1586488ac50c3000000000000171499050637f553f03cc0f82bbfe98dc99f10526311b17500000000
|
||||
0100000001bab3b61c5a7facd63a090addb0a4ea1863ccb0f8d6d8d5c1d7b747b5aa9b17bc000000006b483045022056eaab9d21789a762c7aefdf84d90daf35f7d98bc917c83a1ae6fa24d44f2b94022100a8e1d45d4bc51ad3a192b1b9d582a4711971b0e957012a303950b83eda3d306c01210375228faaa97a02433f4f126ba8d5a295b92466608acf8d13740130d5bbf9cdb4ffffffff0240771b00000000001976a914bb05d829af3b31730e69b7eeb83c1c0d21d362eb88ac50c3000000000000171452cf84e83d1dc919ef4ada30c44cf4349ee55af9b17500000000
|
||||
BIN
test/data/tx6.raw
Normal file
BIN
test/data/tx6.raw
Normal file
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
010000000125393c67cd4f581456dd0805fa8e9db3abdf90dbe1d4b53e286490f35d22b6f2010000006b483045022100f4fa5ced20d2dbd2f905809d79ebe34e03496ef2a48a04d0a9a1db436a211dd202203243d086398feb4ac21b3b79884079036cd5f3707ba153b383eabefa656512dd0121022ebabefede28804b331608d8ef11e1d65b5a920720db8a644f046d156b3a73c0ffffffff0254150000000000001976a9140740345f114e1a1f37ac1cc442b432b91628237e88ace7d27b00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b2e88ac00000000
|
||||
01000000052fa236559f51f343f0905ea627a955f421a198541d928798b8186980273942ec010000006b483045022100ae27626778eba264d56883f5edc1a49897bf209e98f21c870a55d13bec916e1802204b66f4e3235143d11aef327d9454754cd1f28807c3bf9996c107900df9d19ea60121022ebabefede28804b331608d8ef11e1d65b5a920720db8a644f046d156b3a73c0ffffffffe2136f72e4a25e300137b98b402cda91db5c6db6373ba81c722ae1a85315b591000000006b483045022100f84293ea9bfb6d150f3a72d8b5ceb294a77b31442bf9d4ab2058f046a9b65a9f022075935dc0a6a628df26ebb7215634fd33b65f4da105665595028837680b87ea360121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664fffffffff6e67655a42a2f955ec8610940c983042516c32298e57684b3c29fcade7e637a000000006a47304402203bbfb53c3011d742f3f942db18a44d8c3dd111990ee7cc42959383dd7a3e8e8d02207f0f5ed3e165d9db81ac69d36c60a1a4a482f22cb0048dafefa5e704e84dd18e0121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffff9a02e72123a149570c11696d3c798593785e95b8a3c3fc49ae1d07d809d94d5a000000006b483045022100ad0e6f5f73221aa4eda9ad82c7074882298bcf668f34ae81126df0213b2961850220020ba23622d75fb8f95199063b804f62ba103545af4e16b5be0b6dc0cb51aac60121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffffd7db5a3872589ca8aa3cd5ebb0f22dbb3956f8d691e15dc010fe1093c045c3de000000006b48304502210082b91a67da1f02dcb0d00e63b67f10af8ba9639b165f9ff974862a9d4900e27c022069e4a58f591eb3fc7d7d0b176d64d59e90aef0c601b3c84382abad92f6973e630121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffff0254150000000000001976a9140740345f114e1a1f37ac1cc442b432b91628237e88ac4b0f7c00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b2e88ac00000000
|
||||
BIN
test/data/tx7.raw
Normal file
BIN
test/data/tx7.raw
Normal file
Binary file not shown.
@ -1 +0,0 @@
|
||||
0100000004b124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da400000000b400493046022100d3c9ba786488323c975fe61593df6a8041c5442736f361887abfe5c97175c72b022100ca61688f472f4c01ede05ffc50426d68db375f72937b5f39d67835b191b6402f014c67514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294082ba5d4c697bbca7fd83a6af61db7d552aeffffffffb124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da401000000fd150100483045022100a35b7fc1973a0a8962c240a7336b501e149ef167491081e8df91dc761f4e96c2022004ee4d20983a1d0fb96e9bedf86de03b66d7bc50595295b1fb3b5fd2740df3c9014cc9514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599410495b62d1e76a915e5ed3694298c5017d2818d22acbf2a8bd9fa4cf635184e15247dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9ca83341ac90299c697fc94cb4104e3394f3eea40b7abe32f4ad376a80f5a213287d1361b5580e3fe70d13a5db0666e2593283b6b5abc01d98cfff5679d8c36b7caefa1c4df81b10bc45c3812de5f53aeffffffffb124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da402000000fd5e01004730440220606d6187e0ade69192f4a447794cdabb8ea9a4e70df09aa8bc689242c7ffeded02204165ec8edfc9de19d8a94e5f487c8a030187ae16a11e575a955f532a81b631ad01493046022100f7764763d17757ffdeda3d66cfaa6ad3b8f759ddc95e8f73858dba872762658a0221009e903d526595ff9d6d53835889d816de4c47d78371d7a13223f47602b34bc71e014cc9524104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599410495b62d1e76a915e5ed3694298c5017d2818d22acbf2a8bd9fa4cf635184e15247dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9ca83341ac90299c697fc94cb4104e3394f3eea40b7abe32f4ad376a80f5a213287d1361b5580e3fe70d13a5db0666e2593283b6b5abc01d98cfff5679d8c36b7caefa1c4df81b10bc45c3812de5f53aeffffffffb124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da4040000008a473044022075c0666d413fc85cca94ea2f24adc0fedb61a3ba0fcfb240c1a4fd2587b03bf90220525ad4d92c6bf635f8b97c188ebf491c6e342b767a5432f318cbb0245a7f64be014104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348700000000
|
||||
BIN
test/data/tx8.raw
Normal file
BIN
test/data/tx8.raw
Normal file
Binary file not shown.
@ -1 +0,0 @@
|
||||
01000000019457e669dc6b344c0090d10eb22a0377022898d4607fbdf1e3cef2a323c13fa900000000b2004730440220440d67386a27d6776e102b82ce2d583e23d51f8ac3bb94749bd10c03ce71410e022041b46c5d46b14ef72af9d96fb814fa894077d534a4de1215363ee68fb8d4f501014c67514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294082ba5d4c697bbca7fd83a6af61db7d552aeffffffff0250c30000000000001976a9146167aeaeec59836b22447b8af2c5e61fb4f1b7b088ac00a3dc5c0500000017a9149eb21980dc9d413d8eac27314938b9da920ee53e8700000000
|
||||
BIN
test/data/tx9.raw
Normal file
BIN
test/data/tx9.raw
Normal file
Binary file not shown.
BIN
test/data/utx1.raw
Normal file
BIN
test/data/utx1.raw
Normal file
Binary file not shown.
BIN
test/data/utx10.raw
Normal file
BIN
test/data/utx10.raw
Normal file
Binary file not shown.
BIN
test/data/utx2.raw
Normal file
BIN
test/data/utx2.raw
Normal file
Binary file not shown.
BIN
test/data/utx3.raw
Normal file
BIN
test/data/utx3.raw
Normal file
Binary file not shown.
BIN
test/data/utx4.raw
Normal file
BIN
test/data/utx4.raw
Normal file
Binary file not shown.
BIN
test/data/utx6.raw
Normal file
BIN
test/data/utx6.raw
Normal file
Binary file not shown.
BIN
test/data/utx7.raw
Normal file
BIN
test/data/utx7.raw
Normal file
Binary file not shown.
@ -15,8 +15,8 @@ const packets = require('../lib/net/packets');
|
||||
const common = require('./util/common');
|
||||
const network = Network.get('main');
|
||||
|
||||
const tx8 = common.parseTX('tx8');
|
||||
const tx9 = common.parseTX('tx9');
|
||||
const tx8 = common.readTX('tx8');
|
||||
const tx9 = common.readTX('tx9');
|
||||
|
||||
describe('Protocol', function() {
|
||||
const pkg = require('../lib/pkg');
|
||||
@ -117,11 +117,13 @@ describe('Protocol', function() {
|
||||
});
|
||||
|
||||
it('should include the raw data of only one transaction', () => {
|
||||
const raw = Buffer.concat([tx8.tx.toRaw(), tx9.tx.toRaw()]);
|
||||
const [tx1] = tx8.getTX();
|
||||
const [tx2] = tx9.getTX();
|
||||
const raw = Buffer.concat([tx1.toRaw(), tx2.toRaw()]);
|
||||
|
||||
const tx = TX.fromRaw(raw);
|
||||
tx.refresh();
|
||||
|
||||
assert.bufferEqual(tx.toRaw(), tx8.tx.toRaw());
|
||||
assert.bufferEqual(tx.toRaw(), tx1.toRaw());
|
||||
});
|
||||
});
|
||||
|
||||
@ -23,13 +23,13 @@ const validTests = require('./data/tx-valid.json');
|
||||
const invalidTests = require('./data/tx-invalid.json');
|
||||
const sighashTests = require('./data/sighash-tests.json');
|
||||
|
||||
const tx1 = common.parseTX('tx1');
|
||||
const tx2 = common.parseTX('tx2');
|
||||
const tx3 = common.parseTX('tx3');
|
||||
const tx4 = common.parseTX('tx4');
|
||||
const tx5 = common.parseTX('tx5');
|
||||
const tx6 = common.parseTX('tx6');
|
||||
const tx7 = common.parseTX('tx7');
|
||||
const tx1 = common.readTX('tx1');
|
||||
const tx2 = common.readTX('tx2');
|
||||
const tx3 = common.readTX('tx3');
|
||||
const tx4 = common.readTX('tx4');
|
||||
const tx5 = common.readTX('tx5');
|
||||
const tx6 = common.readTX('tx6');
|
||||
const tx7 = common.readTX('tx7');
|
||||
|
||||
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
||||
const MAX_SAFE_ADDITION = 0xfffffffffffff;
|
||||
@ -198,25 +198,25 @@ describe('TX', function() {
|
||||
const suffix = noCache ? 'without cache' : 'with cache';
|
||||
|
||||
it(`should verify non-minimal output ${suffix}`, () => {
|
||||
const {tx, view} = tx1;
|
||||
const [tx, view] = tx1.getTX();
|
||||
clearCache(tx, noCache);
|
||||
assert(tx.verify(view, Script.flags.VERIFY_P2SH));
|
||||
});
|
||||
|
||||
it(`should verify tx.version == 0 ${suffix}`, () => {
|
||||
const {tx, view} = tx2;
|
||||
const [tx, view] = tx2.getTX();
|
||||
clearCache(tx, noCache);
|
||||
assert(tx.verify(view, Script.flags.VERIFY_P2SH));
|
||||
});
|
||||
|
||||
it(`should verify sighash_single bug w/ findanddelete ${suffix}`, () => {
|
||||
const {tx, view} = tx3;
|
||||
const [tx, view] = tx3.getTX();
|
||||
clearCache(tx, noCache);
|
||||
assert(tx.verify(view, Script.flags.VERIFY_P2SH));
|
||||
});
|
||||
|
||||
it(`should verify high S value with only DERSIG enabled ${suffix}`, () => {
|
||||
const {tx, view} = tx4;
|
||||
const [tx, view] = tx4.getTX();
|
||||
const coin = view.getOutputFor(tx.inputs[0]);
|
||||
const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG;
|
||||
clearCache(tx, noCache);
|
||||
@ -224,7 +224,7 @@ describe('TX', function() {
|
||||
});
|
||||
|
||||
it(`should parse witness tx properly ${suffix}`, () => {
|
||||
const {tx} = tx5;
|
||||
const [tx] = tx5.getTX();
|
||||
clearCache(tx, noCache);
|
||||
|
||||
assert.strictEqual(tx.inputs.length, 5);
|
||||
@ -252,13 +252,13 @@ describe('TX', function() {
|
||||
});
|
||||
|
||||
it(`should verify the coolest tx ever sent ${suffix}`, () => {
|
||||
const {tx, view} = tx6;
|
||||
const [tx, view] = tx6.getTX();
|
||||
clearCache(tx, noCache);
|
||||
assert(tx.verify(view, Script.flags.VERIFY_NONE));
|
||||
});
|
||||
|
||||
it(`should verify a historical transaction ${suffix}`, () => {
|
||||
const {tx, view} = tx7;
|
||||
const [tx, view] = tx7.getTX();
|
||||
clearCache(tx, noCache);
|
||||
assert(tx.verify(view));
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@ const assert = require('assert');
|
||||
const fs = require('../../lib/utils/fs');
|
||||
const Block = require('../../lib/primitives/block');
|
||||
const MerkleBlock = require('../../lib/primitives/merkleblock');
|
||||
const Headers = require('../../lib/primitives/headers');
|
||||
const {CompactBlock} = require('../../lib/net/bip152');
|
||||
const TX = require('../../lib/primitives/tx');
|
||||
const Output = require('../../lib/primitives/output');
|
||||
@ -11,37 +12,13 @@ const CoinView = require('../../lib/coins/coinview');
|
||||
const BufferReader = require('../../lib/utils/reader');
|
||||
const BufferWriter = require('../../lib/utils/writer');
|
||||
|
||||
exports.parseTX = function parseTX(name) {
|
||||
const data = fs.readFileSync(`${__dirname}/../data/${name}.hex`, 'utf8');
|
||||
const parts = data.trim().split('\n');
|
||||
const raw = Buffer.from(parts[0], 'hex');
|
||||
const tx = TX.fromRaw(raw);
|
||||
const view = new CoinView();
|
||||
const txs = [tx];
|
||||
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const raw = Buffer.from(parts[i], 'hex');
|
||||
const prev = TX.fromRaw(raw);
|
||||
view.addTX(prev, -1);
|
||||
txs.push(prev);
|
||||
}
|
||||
|
||||
return {
|
||||
tx: tx,
|
||||
view: view,
|
||||
txs: txs
|
||||
};
|
||||
};
|
||||
|
||||
exports.readBlock = function readBlock(name) {
|
||||
const height = name.substring(5);
|
||||
const blockFile = `${__dirname}/../data/block${height}.raw`;
|
||||
|
||||
if (!fs.existsSync(blockFile)) {
|
||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
||||
const block = Block.fromRaw(raw);
|
||||
const view = new CoinView();
|
||||
return { raw, block, view };
|
||||
return new BlockContext(Block, raw);
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(blockFile);
|
||||
@ -49,28 +26,22 @@ exports.readBlock = function readBlock(name) {
|
||||
|
||||
const undoFile = `${__dirname}/../data/undo${height}.raw`;
|
||||
|
||||
if (!fs.existsSync(undoFile)) {
|
||||
const view = new CoinView();
|
||||
return { raw, block, view };
|
||||
}
|
||||
if (!fs.existsSync(undoFile))
|
||||
return new BlockContext(Block, raw);
|
||||
|
||||
const undoRaw = fs.readFileSync(undoFile);
|
||||
const undo = exports.parseUndo(undoRaw);
|
||||
const view = exports.applyBlockUndo(block, undo);
|
||||
|
||||
return { raw, block, view };
|
||||
return new BlockContext(Block, raw, undoRaw);
|
||||
};
|
||||
|
||||
exports.readMerkle = function readMerkle(name) {
|
||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
||||
const block = MerkleBlock.fromRaw(raw);
|
||||
return { raw, block };
|
||||
return new BlockContext(MerkleBlock, raw);
|
||||
};
|
||||
|
||||
exports.readCompact = function readCompact(name) {
|
||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
||||
const block = CompactBlock.fromRaw(raw);
|
||||
return { raw, block };
|
||||
return new BlockContext(CompactBlock, raw);
|
||||
};
|
||||
|
||||
exports.readTX = function readTX(name) {
|
||||
@ -79,29 +50,50 @@ exports.readTX = function readTX(name) {
|
||||
|
||||
if (!fs.existsSync(txFile)) {
|
||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
||||
const tx = TX.fromRaw(raw);
|
||||
const view = new CoinView();
|
||||
return { raw, tx, view };
|
||||
return new TXContext(raw);
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(txFile);
|
||||
const tx = TX.fromRaw(raw);
|
||||
|
||||
const undoFile = `${__dirname}/../data/utx${index}.raw`;
|
||||
|
||||
if (!fs.existsSync(undoFile)) {
|
||||
const view = new CoinView();
|
||||
return { raw, tx, view };
|
||||
}
|
||||
if (!fs.existsSync(undoFile))
|
||||
return new TXContext(raw);
|
||||
|
||||
const undoRaw = fs.readFileSync(undoFile);
|
||||
const undo = exports.parseUndo(undoRaw);
|
||||
const view = exports.applyTXUndo(tx, undo);
|
||||
|
||||
return { raw, tx, view };
|
||||
return new TXContext(raw, undoRaw);
|
||||
};
|
||||
|
||||
exports.parseUndo = function parseUndo(data) {
|
||||
exports.writeBlock = function writeBlock(name, block, view) {
|
||||
const height = name.substring(5);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/block${height}.raw`, block.toRaw());
|
||||
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
const undo = makeBlockUndo(block, view);
|
||||
const undoRaw = serializeUndo(undo);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/undo${height}.raw`, undoRaw);
|
||||
};
|
||||
|
||||
exports.writeTX = function writeTX(name, tx, view) {
|
||||
const index = name.substring(2);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/tx${index}.raw`, tx.toRaw());
|
||||
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
const undo = makeTXUndo(tx, view);
|
||||
const undoRaw = serializeUndo(undo);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/utx${index}.raw`, undoRaw);
|
||||
};
|
||||
|
||||
function parseUndo(data) {
|
||||
const br = new BufferReader(data);
|
||||
const items = [];
|
||||
|
||||
@ -111,9 +103,20 @@ exports.parseUndo = function parseUndo(data) {
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
}
|
||||
|
||||
exports.applyBlockUndo = function applyBlockUndo(block, undo) {
|
||||
function serializeUndo(items) {
|
||||
const bw = new BufferWriter();
|
||||
|
||||
for (const item of items) {
|
||||
bw.writeI64(item.value);
|
||||
bw.writeVarBytes(item.script.toRaw());
|
||||
}
|
||||
|
||||
return bw.render();
|
||||
}
|
||||
|
||||
function applyBlockUndo(block, undo) {
|
||||
const view = new CoinView();
|
||||
let i = 0;
|
||||
|
||||
@ -128,9 +131,9 @@ exports.applyBlockUndo = function applyBlockUndo(block, undo) {
|
||||
assert(i === undo.length, 'Undo coins data inconsistency.');
|
||||
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
exports.applyTXUndo = function applyTXUndo(tx, undo) {
|
||||
function applyTXUndo(tx, undo) {
|
||||
const view = new CoinView();
|
||||
let i = 0;
|
||||
|
||||
@ -140,9 +143,9 @@ exports.applyTXUndo = function applyTXUndo(tx, undo) {
|
||||
assert(i === undo.length, 'Undo coins data inconsistency.');
|
||||
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
exports.makeBlockUndo = function makeBlockUndo(block, view) {
|
||||
function makeBlockUndo(block, view) {
|
||||
const items = [];
|
||||
|
||||
for (const tx of block.txs) {
|
||||
@ -157,9 +160,9 @@ exports.makeBlockUndo = function makeBlockUndo(block, view) {
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
}
|
||||
|
||||
exports.makeTXUndo = function makeTXUndo(tx, view) {
|
||||
function makeTXUndo(tx, view) {
|
||||
const items = [];
|
||||
|
||||
for (const {prevout} of tx.inputs) {
|
||||
@ -169,43 +172,55 @@ exports.makeTXUndo = function makeTXUndo(tx, view) {
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
}
|
||||
|
||||
exports.serializeUndo = function serializeUndo(items) {
|
||||
const bw = new BufferWriter();
|
||||
|
||||
for (const item of items) {
|
||||
bw.writeI64(item.value);
|
||||
bw.writeVarBytes(item.script.toRaw());
|
||||
class BlockContext {
|
||||
constructor(ctor, raw, undoRaw) {
|
||||
this.ctor = ctor;
|
||||
this.raw = raw;
|
||||
this.undoRaw = undoRaw || null;
|
||||
}
|
||||
getRaw() {
|
||||
return this.raw;
|
||||
}
|
||||
getBlock() {
|
||||
const Block = this.ctor;
|
||||
const block = Block.fromRaw(this.raw);
|
||||
|
||||
return bw.render();
|
||||
};
|
||||
if (!this.undoRaw) {
|
||||
const view = new CoinView();
|
||||
return [block, view];
|
||||
}
|
||||
|
||||
exports.writeBlock = function writeBlock(name, block, view) {
|
||||
const height = name.substring(5);
|
||||
const undo = parseUndo(this.undoRaw);
|
||||
const view = applyBlockUndo(block, undo);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/block${height}.raw`, block.toRaw());
|
||||
return [block, view];
|
||||
}
|
||||
getHeaders() {
|
||||
return Headers.fromHead(this.raw);
|
||||
}
|
||||
}
|
||||
|
||||
if (!view)
|
||||
return;
|
||||
class TXContext {
|
||||
constructor(raw, undoRaw) {
|
||||
this.raw = raw;
|
||||
this.undoRaw = undoRaw || null;
|
||||
}
|
||||
getRaw() {
|
||||
return this.raw;
|
||||
}
|
||||
getTX() {
|
||||
const tx = TX.fromRaw(this.raw);
|
||||
|
||||
const undo = exports.makeBlockUndo(block, view);
|
||||
const undoRaw = exports.serializeUndo(undo);
|
||||
if (!this.undoRaw) {
|
||||
const view = new CoinView();
|
||||
return [tx, view];
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/undo${height}.raw`, undoRaw);
|
||||
};
|
||||
const undo = parseUndo(this.undoRaw);
|
||||
const view = applyTXUndo(tx, undo);
|
||||
|
||||
exports.writeTX = function writeTX(name, tx, view) {
|
||||
const index = name.substring(2);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/tx${index}.raw`, tx.toRaw());
|
||||
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
const undo = exports.makeTXUndo(tx, view);
|
||||
const undoRaw = exports.serializeUndo(undo);
|
||||
|
||||
fs.writeFileSync(`${__dirname}/../data/utx${index}.raw`, undoRaw);
|
||||
};
|
||||
return [tx, view];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user