test: change file naming convention.
This commit is contained in:
parent
0e7d5d7ab9
commit
2e8d8f59c6
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const path = require('path');
|
||||||
const fs = require('../../lib/utils/fs');
|
const fs = require('../../lib/utils/fs');
|
||||||
const Block = require('../../lib/primitives/block');
|
const Block = require('../../lib/primitives/block');
|
||||||
const MerkleBlock = require('../../lib/primitives/merkleblock');
|
const MerkleBlock = require('../../lib/primitives/merkleblock');
|
||||||
@ -12,63 +13,57 @@ const CoinView = require('../../lib/coins/coinview');
|
|||||||
const BufferReader = require('../../lib/utils/reader');
|
const BufferReader = require('../../lib/utils/reader');
|
||||||
const BufferWriter = require('../../lib/utils/writer');
|
const BufferWriter = require('../../lib/utils/writer');
|
||||||
|
|
||||||
exports.readBlock = function readBlock(name) {
|
const common = exports;
|
||||||
const height = name.substring(5);
|
|
||||||
const blockFile = `${__dirname}/../data/block${height}.raw`;
|
|
||||||
|
|
||||||
if (!fs.existsSync(blockFile)) {
|
common.readFile = function readFile(name, enc) {
|
||||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
const file = path.resolve(__dirname, '..', 'data', name);
|
||||||
return new BlockContext(Block, raw);
|
return fs.readFileSync(file, enc);
|
||||||
}
|
};
|
||||||
|
|
||||||
const raw = fs.readFileSync(blockFile);
|
common.writeFile = function writeFile(name, data) {
|
||||||
const block = Block.fromRaw(raw);
|
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);
|
return new BlockContext(Block, raw);
|
||||||
|
|
||||||
const undoRaw = fs.readFileSync(undoFile);
|
const undoRaw = common.readFile(`${name}-undo.raw`);
|
||||||
|
|
||||||
return new BlockContext(Block, raw, undoRaw);
|
return new BlockContext(Block, raw, undoRaw);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readMerkle = function readMerkle(name) {
|
common.readMerkle = function readMerkle(name) {
|
||||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
const raw = common.readFile(`${name}.raw`);
|
||||||
return new BlockContext(MerkleBlock, raw);
|
return new BlockContext(MerkleBlock, raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readCompact = function readCompact(name) {
|
common.readCompact = function readCompact(name) {
|
||||||
const raw = fs.readFileSync(`${__dirname}/../data/${name}.raw`);
|
const raw = common.readFile(`${name}.raw`);
|
||||||
return new BlockContext(CompactBlock, raw);
|
return new BlockContext(CompactBlock, raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readTX = function readTX(name) {
|
common.readTX = function readTX(name) {
|
||||||
const index = name.substring(2);
|
const raw = common.readFile(`${name}.raw`);
|
||||||
const txFile = `${__dirname}/../data/tx${index}.raw`;
|
|
||||||
|
|
||||||
if (!fs.existsSync(txFile)) {
|
if (!common.exists(`${name}-undo.raw`))
|
||||||
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))
|
|
||||||
return new TXContext(raw);
|
return new TXContext(raw);
|
||||||
|
|
||||||
const undoRaw = fs.readFileSync(undoFile);
|
const undoRaw = common.readFile(`${name}-undo.raw`);
|
||||||
|
|
||||||
return new TXContext(raw, undoRaw);
|
return new TXContext(raw, undoRaw);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeBlock = function writeBlock(name, block, view) {
|
common.writeBlock = function writeBlock(name, block, view) {
|
||||||
const height = name.substring(5);
|
common.writeFile(`${name}.raw`, block.toRaw());
|
||||||
|
|
||||||
fs.writeFileSync(`${__dirname}/../data/block${height}.raw`, block.toRaw());
|
|
||||||
|
|
||||||
if (!view)
|
if (!view)
|
||||||
return;
|
return;
|
||||||
@ -76,13 +71,13 @@ exports.writeBlock = function writeBlock(name, block, view) {
|
|||||||
const undo = makeBlockUndo(block, view);
|
const undo = makeBlockUndo(block, view);
|
||||||
const undoRaw = serializeUndo(undo);
|
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);
|
const index = name.substring(2);
|
||||||
|
|
||||||
fs.writeFileSync(`${__dirname}/../data/tx${index}.raw`, tx.toRaw());
|
common.writeFile(`${name}.raw`, tx.toRaw());
|
||||||
|
|
||||||
if (!view)
|
if (!view)
|
||||||
return;
|
return;
|
||||||
@ -90,7 +85,7 @@ exports.writeTX = function writeTX(name, tx, view) {
|
|||||||
const undo = makeTXUndo(tx, view);
|
const undo = makeTXUndo(tx, view);
|
||||||
const undoRaw = serializeUndo(undo);
|
const undoRaw = serializeUndo(undo);
|
||||||
|
|
||||||
fs.writeFileSync(`${__dirname}/../data/utx${index}.raw`, undoRaw);
|
common.writeFile(`${name}-undo.raw`, undoRaw);
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseUndo(data) {
|
function parseUndo(data) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user