From f48669e57ef19c4592c12caaaea1d499f2a524d7 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Wed, 15 Jan 2020 10:57:15 +0100 Subject: [PATCH] fix(bufferutils): remove pushdata re-exports Remove these exports: * `bufferutils.pushDataSize` * `bufferutils.readPushDataInt` * `bufferutils.writePushDataInt` They are not needed and are already removed upstream. While this changes the public API, none of our projects use these functions. Issue: BG-16466 --- package.json | 2 +- src/bufferutils.js | 4 --- test/bufferutils.js | 52 ---------------------------------- test/fixtures/bufferutils.json | 14 --------- 4 files changed, 1 insertion(+), 71 deletions(-) diff --git a/package.json b/package.json index 9e7b5bac..d16374ac 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "scripts": { "coverage-report": "nyc report --reporter=lcov", "coverage-html": "nyc report --reporter=html", - "coverage": "BITGO_UTXO_LIB_TEST_EXPECTED_COUNT=3535 nyc --check-coverage --branches 90 --functions 90 mocha --recursive", + "coverage": "BITGO_UTXO_LIB_TEST_EXPECTED_COUNT=3496 nyc --check-coverage --branches 90 --functions 90 mocha --recursive", "integration": "mocha test/integration/", "standard": "standard", "test": "npm run standard && npm run coverage", diff --git a/src/bufferutils.js b/src/bufferutils.js index 244cc3f3..99f76625 100644 --- a/src/bufferutils.js +++ b/src/bufferutils.js @@ -1,4 +1,3 @@ -var pushdata = require('pushdata-bitcoin') var varuint = require('varuint-bitcoin') // https://github.com/feross/buffer/blob/master/index.js#L1127 @@ -52,14 +51,11 @@ function writeVarInt (buffer, number, offset) { } module.exports = { - pushDataSize: pushdata.encodingLength, - readPushDataInt: pushdata.decode, readUInt64LE: readUInt64LE, readInt64LE: readInt64LE, readVarInt: readVarInt, varIntBuffer: varuint.encode, varIntSize: varuint.encodingLength, - writePushDataInt: pushdata.encode, writeUInt64LE: writeUInt64LE, writeVarInt: writeVarInt } diff --git a/test/bufferutils.js b/test/bufferutils.js index ac625a8c..ebe9ed95 100644 --- a/test/bufferutils.js +++ b/test/bufferutils.js @@ -6,45 +6,6 @@ var bufferutils = require('../src/bufferutils') var fixtures = require('./fixtures/bufferutils.json') describe('bufferutils', function () { - describe('pushDataSize', function () { - fixtures.valid.forEach(function (f) { - it('determines the pushDataSize of ' + f.dec + ' correctly', function () { - if (!f.hexPD) return - - var size = bufferutils.pushDataSize(f.dec) - - assert.strictEqual(size, f.hexPD.length / 2) - }) - }) - }) - - describe('readPushDataInt', function () { - fixtures.valid.forEach(function (f) { - if (!f.hexPD) return - - it('decodes ' + f.hexPD + ' correctly', function () { - var buffer = Buffer.from(f.hexPD, 'hex') - var d = bufferutils.readPushDataInt(buffer, 0) - var fopcode = parseInt(f.hexPD.substr(0, 2), 16) - - assert.strictEqual(d.opcode, fopcode) - assert.strictEqual(d.number, f.dec) - assert.strictEqual(d.size, buffer.length) - }) - }) - - fixtures.invalid.readPushDataInt.forEach(function (f) { - if (!f.hexPD) return - - it('decodes ' + f.hexPD + ' as null', function () { - var buffer = Buffer.from(f.hexPD, 'hex') - - var n = bufferutils.readPushDataInt(buffer, 0) - assert.strictEqual(n, null) - }) - }) - }) - describe('readInt64LE', function () { fixtures.negative.forEach(function (f) { it('decodes ' + f.hex64 + ' correctly', function () { @@ -119,19 +80,6 @@ describe('bufferutils', function () { }) }) - describe('writePushDataInt', function () { - fixtures.valid.forEach(function (f) { - if (!f.hexPD) return - - it('encodes ' + f.dec + ' correctly', function () { - var buffer = Buffer.alloc(5, 0) - - var n = bufferutils.writePushDataInt(buffer, f.dec, 0) - assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexPD) - }) - }) - }) - describe('writeUInt64LE', function () { fixtures.valid.forEach(function (f) { it('encodes ' + f.dec + ' correctly', function () { diff --git a/test/fixtures/bufferutils.json b/test/fixtures/bufferutils.json index 55ba9b20..84824345 100644 --- a/test/fixtures/bufferutils.json +++ b/test/fixtures/bufferutils.json @@ -98,20 +98,6 @@ "hexVI": "ff0100000000000020", "dec": 9007199254740993 } - ], - "readPushDataInt": [ - { - "description": "OP_PUSHDATA1, no size", - "hexPD": "4c" - }, - { - "description": "OP_PUSHDATA2, no size", - "hexPD": "4d" - }, - { - "description": "OP_PUSHDATA4, no size", - "hexPD": "4e" - } ] }, "negative": [