Skip to content

Commit

Permalink
test: create better interface for block/tx test vectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 13, 2017
1 parent 5a751d9 commit e37d299
Show file tree
Hide file tree
Showing 35 changed files with 218 additions and 233 deletions.
4 changes: 3 additions & 1 deletion bench/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion bench/coins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
65 changes: 33 additions & 32 deletions bench/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions scripts/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -18,7 +16,7 @@ setInterval(() => {
}, 60 * 1000);

setImmediate(() => {
heapdump.writeSnapshot(SNAPSHOT, (err) => {
heapdump.writeSnapshot(`${__dirname}/../dump.heapsnapshot`, (err) => {
if (err)
throw err;
});
Expand Down
Loading

0 comments on commit e37d299

Please sign in to comment.