From 2e8d8f59c63a760c34f925839a50897235ac03f2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 12 Aug 2017 20:28:53 -0700 Subject: [PATCH] test: change file naming convention. --- ...{undo1087400.raw => block1087400-undo.raw} | Bin .../{undo300025.raw => block300025-undo.raw} | Bin .../{undo928816.raw => block928816-undo.raw} | Bin .../{undo928828.raw => block928828-undo.raw} | Bin .../{undo928831.raw => block928831-undo.raw} | Bin .../{undo928848.raw => block928848-undo.raw} | Bin .../{undo928849.raw => block928849-undo.raw} | Bin .../{undo928927.raw => block928927-undo.raw} | Bin test/data/{utx1.raw => tx1-undo.raw} | Bin test/data/{utx10.raw => tx10-undo.raw} | Bin test/data/{utx2.raw => tx2-undo.raw} | Bin test/data/{utx3.raw => tx3-undo.raw} | Bin test/data/{utx4.raw => tx4-undo.raw} | Bin test/data/{utx6.raw => tx6-undo.raw} | Bin test/data/{utx7.raw => tx7-undo.raw} | Bin test/util/common.js | 71 ++++++++---------- 16 files changed, 33 insertions(+), 38 deletions(-) rename test/data/{undo1087400.raw => block1087400-undo.raw} (100%) rename test/data/{undo300025.raw => block300025-undo.raw} (100%) rename test/data/{undo928816.raw => block928816-undo.raw} (100%) rename test/data/{undo928828.raw => block928828-undo.raw} (100%) rename test/data/{undo928831.raw => block928831-undo.raw} (100%) rename test/data/{undo928848.raw => block928848-undo.raw} (100%) rename test/data/{undo928849.raw => block928849-undo.raw} (100%) rename test/data/{undo928927.raw => block928927-undo.raw} (100%) rename test/data/{utx1.raw => tx1-undo.raw} (100%) rename test/data/{utx10.raw => tx10-undo.raw} (100%) rename test/data/{utx2.raw => tx2-undo.raw} (100%) rename test/data/{utx3.raw => tx3-undo.raw} (100%) rename test/data/{utx4.raw => tx4-undo.raw} (100%) rename test/data/{utx6.raw => tx6-undo.raw} (100%) rename test/data/{utx7.raw => tx7-undo.raw} (100%) diff --git a/test/data/undo1087400.raw b/test/data/block1087400-undo.raw similarity index 100% rename from test/data/undo1087400.raw rename to test/data/block1087400-undo.raw diff --git a/test/data/undo300025.raw b/test/data/block300025-undo.raw similarity index 100% rename from test/data/undo300025.raw rename to test/data/block300025-undo.raw diff --git a/test/data/undo928816.raw b/test/data/block928816-undo.raw similarity index 100% rename from test/data/undo928816.raw rename to test/data/block928816-undo.raw diff --git a/test/data/undo928828.raw b/test/data/block928828-undo.raw similarity index 100% rename from test/data/undo928828.raw rename to test/data/block928828-undo.raw diff --git a/test/data/undo928831.raw b/test/data/block928831-undo.raw similarity index 100% rename from test/data/undo928831.raw rename to test/data/block928831-undo.raw diff --git a/test/data/undo928848.raw b/test/data/block928848-undo.raw similarity index 100% rename from test/data/undo928848.raw rename to test/data/block928848-undo.raw diff --git a/test/data/undo928849.raw b/test/data/block928849-undo.raw similarity index 100% rename from test/data/undo928849.raw rename to test/data/block928849-undo.raw diff --git a/test/data/undo928927.raw b/test/data/block928927-undo.raw similarity index 100% rename from test/data/undo928927.raw rename to test/data/block928927-undo.raw diff --git a/test/data/utx1.raw b/test/data/tx1-undo.raw similarity index 100% rename from test/data/utx1.raw rename to test/data/tx1-undo.raw diff --git a/test/data/utx10.raw b/test/data/tx10-undo.raw similarity index 100% rename from test/data/utx10.raw rename to test/data/tx10-undo.raw diff --git a/test/data/utx2.raw b/test/data/tx2-undo.raw similarity index 100% rename from test/data/utx2.raw rename to test/data/tx2-undo.raw diff --git a/test/data/utx3.raw b/test/data/tx3-undo.raw similarity index 100% rename from test/data/utx3.raw rename to test/data/tx3-undo.raw diff --git a/test/data/utx4.raw b/test/data/tx4-undo.raw similarity index 100% rename from test/data/utx4.raw rename to test/data/tx4-undo.raw diff --git a/test/data/utx6.raw b/test/data/tx6-undo.raw similarity index 100% rename from test/data/utx6.raw rename to test/data/tx6-undo.raw diff --git a/test/data/utx7.raw b/test/data/tx7-undo.raw similarity index 100% rename from test/data/utx7.raw rename to test/data/tx7-undo.raw diff --git a/test/util/common.js b/test/util/common.js index bdab238b..6fbf3434 100644 --- a/test/util/common.js +++ b/test/util/common.js @@ -1,6 +1,7 @@ 'use strict'; const assert = require('assert'); +const path = require('path'); const fs = require('../../lib/utils/fs'); const Block = require('../../lib/primitives/block'); const MerkleBlock = require('../../lib/primitives/merkleblock'); @@ -12,63 +13,57 @@ const CoinView = require('../../lib/coins/coinview'); const BufferReader = require('../../lib/utils/reader'); const BufferWriter = require('../../lib/utils/writer'); -exports.readBlock = function readBlock(name) { - const height = name.substring(5); - const blockFile = `${__dirname}/../data/block${height}.raw`; +const common = exports; - if (!fs.existsSync(blockFile)) { - const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`); - return new BlockContext(Block, raw); - } +common.readFile = function readFile(name, enc) { + const file = path.resolve(__dirname, '..', 'data', name); + return fs.readFileSync(file, enc); +}; - const raw = fs.readFileSync(blockFile); - const block = Block.fromRaw(raw); +common.writeFile = function writeFile(name, data) { + const file = path.resolve(__dirname, '..', 'data', name); + return fs.writeFileSync(file, data); +}; - const undoFile = `${__dirname}/../data/undo${height}.raw`; +common.exists = function exists(name) { + const file = path.resolve(__dirname, '..', 'data', name); + return fs.existsSync(file); +}; - if (!fs.existsSync(undoFile)) +common.readBlock = function readBlock(name) { + const raw = common.readFile(`${name}.raw`); + + if (!common.exists(`${name}-undo.raw`)) return new BlockContext(Block, raw); - const undoRaw = fs.readFileSync(undoFile); + const undoRaw = common.readFile(`${name}-undo.raw`); return new BlockContext(Block, raw, undoRaw); }; -exports.readMerkle = function readMerkle(name) { - const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`); +common.readMerkle = function readMerkle(name) { + const raw = common.readFile(`${name}.raw`); return new BlockContext(MerkleBlock, raw); }; -exports.readCompact = function readCompact(name) { - const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`); +common.readCompact = function readCompact(name) { + const raw = common.readFile(`${name}.raw`); return new BlockContext(CompactBlock, raw); }; -exports.readTX = function readTX(name) { - const index = name.substring(2); - const txFile = `${__dirname}/../data/tx${index}.raw`; +common.readTX = function readTX(name) { + const raw = common.readFile(`${name}.raw`); - if (!fs.existsSync(txFile)) { - const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`); - return new TXContext(raw); - } - - const raw = fs.readFileSync(txFile); - - const undoFile = `${__dirname}/../data/utx${index}.raw`; - - if (!fs.existsSync(undoFile)) + if (!common.exists(`${name}-undo.raw`)) return new TXContext(raw); - const undoRaw = fs.readFileSync(undoFile); + const undoRaw = common.readFile(`${name}-undo.raw`); return new TXContext(raw, undoRaw); }; -exports.writeBlock = function writeBlock(name, block, view) { - const height = name.substring(5); - - fs.writeFileSync(`${__dirname}/../data/block${height}.raw`, block.toRaw()); +common.writeBlock = function writeBlock(name, block, view) { + common.writeFile(`${name}.raw`, block.toRaw()); if (!view) return; @@ -76,13 +71,13 @@ exports.writeBlock = function writeBlock(name, block, view) { const undo = makeBlockUndo(block, view); const undoRaw = serializeUndo(undo); - fs.writeFileSync(`${__dirname}/../data/undo${height}.raw`, undoRaw); + common.writeFile(`${name}-undo.raw`, undoRaw); }; -exports.writeTX = function writeTX(name, tx, view) { +common.writeTX = function writeTX(name, tx, view) { const index = name.substring(2); - fs.writeFileSync(`${__dirname}/../data/tx${index}.raw`, tx.toRaw()); + common.writeFile(`${name}.raw`, tx.toRaw()); if (!view) return; @@ -90,7 +85,7 @@ exports.writeTX = function writeTX(name, tx, view) { const undo = makeTXUndo(tx, view); const undoRaw = serializeUndo(undo); - fs.writeFileSync(`${__dirname}/../data/utx${index}.raw`, undoRaw); + common.writeFile(`${name}-undo.raw`, undoRaw); }; function parseUndo(data) {