tests: use safe-buffers throughout
This commit is contained in:
parent
aeb0312d63
commit
f1ab151c31
20 changed files with 88 additions and 94 deletions
|
@ -58,7 +58,7 @@ ECSignature.prototype.toCompact = function (i, compressed) {
|
|||
|
||||
i += 27
|
||||
|
||||
var buffer = Buffer.allocUnsafe(65)
|
||||
var buffer = Buffer.alloc(65)
|
||||
buffer.writeUInt8(i, 0)
|
||||
this.r.toBuffer(32).copy(buffer, 1)
|
||||
this.s.toBuffer(32).copy(buffer, 33)
|
||||
|
@ -77,7 +77,7 @@ ECSignature.prototype.toScriptSignature = function (hashType) {
|
|||
var hashTypeMod = hashType & ~0x80
|
||||
if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType)
|
||||
|
||||
var hashTypeBuffer = Buffer.allocUnsafe(1)
|
||||
var hashTypeBuffer = Buffer.alloc(1)
|
||||
hashTypeBuffer.writeUInt8(hashType, 0)
|
||||
|
||||
return Buffer.concat([this.toDER(), hashTypeBuffer])
|
||||
|
|
|
@ -50,7 +50,7 @@ describe('address', function () {
|
|||
describe('toBase58Check', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('formats ' + f.hash + ' (' + f.network + ')', function () {
|
||||
var address = baddress.toBase58Check(new Buffer(f.hash, 'hex'), f.version)
|
||||
var address = baddress.toBase58Check(Buffer.from(f.hash, 'hex'), f.version)
|
||||
|
||||
assert.strictEqual(address, f.base58check)
|
||||
})
|
||||
|
|
|
@ -28,7 +28,7 @@ describe('Bitcoin-core', function () {
|
|||
})
|
||||
|
||||
it('can encode ' + fhex, function () {
|
||||
var buffer = new Buffer(fhex, 'hex')
|
||||
var buffer = Buffer.from(fhex, 'hex')
|
||||
var actual = base58.encode(buffer)
|
||||
|
||||
assert.strictEqual(actual, fb58)
|
||||
|
@ -45,7 +45,7 @@ describe('Bitcoin-core', function () {
|
|||
|
||||
base58KeysValid.forEach(function (f) {
|
||||
var expected = f[0]
|
||||
var hash = new Buffer(f[1], 'hex')
|
||||
var hash = Buffer.from(f[1], 'hex')
|
||||
var params = f[2]
|
||||
|
||||
if (params.isPrivkey) return
|
||||
|
@ -150,7 +150,7 @@ describe('Bitcoin-core', function () {
|
|||
var input = inputs[i]
|
||||
|
||||
// reverse because test data is reversed
|
||||
var prevOutHash = new Buffer(input[0], 'hex').reverse()
|
||||
var prevOutHash = Buffer.from(input[0], 'hex').reverse()
|
||||
var prevOutIndex = input[1]
|
||||
|
||||
assert.deepEqual(txIn.hash, prevOutHash)
|
||||
|
@ -186,7 +186,7 @@ describe('Bitcoin-core', function () {
|
|||
var transaction = bitcoin.Transaction.fromHex(txHex)
|
||||
assert.strictEqual(transaction.toHex(), txHex)
|
||||
|
||||
var script = new Buffer(scriptHex, 'hex')
|
||||
var script = Buffer.from(scriptHex, 'hex')
|
||||
var scriptChunks = bitcoin.script.decompile(script)
|
||||
assert.strictEqual(bitcoin.script.compile(scriptChunks).toString('hex'), scriptHex)
|
||||
|
||||
|
@ -200,7 +200,7 @@ describe('Bitcoin-core', function () {
|
|||
|
||||
describe('ECSignature.parseScriptSignature', function () {
|
||||
sigCanonical.forEach(function (hex) {
|
||||
var buffer = new Buffer(hex, 'hex')
|
||||
var buffer = Buffer.from(hex, 'hex')
|
||||
|
||||
it('can parse ' + hex, function () {
|
||||
var parsed = bitcoin.ECSignature.parseScriptSignature(buffer)
|
||||
|
@ -214,7 +214,7 @@ describe('Bitcoin-core', function () {
|
|||
if (i % 2 !== 0) return
|
||||
|
||||
var description = sigNoncanonical[i - 1].slice(0, -1)
|
||||
var buffer = new Buffer(hex, 'hex')
|
||||
var buffer = Buffer.from(hex, 'hex')
|
||||
|
||||
it('throws on ' + description, function () {
|
||||
assert.throws(function () {
|
||||
|
|
|
@ -23,7 +23,7 @@ describe('bufferutils', function () {
|
|||
if (!f.hexPD) return
|
||||
|
||||
it('decodes ' + f.hexPD + ' correctly', function () {
|
||||
var buffer = new Buffer(f.hexPD, 'hex')
|
||||
var buffer = Buffer.from(f.hexPD, 'hex')
|
||||
var d = bufferutils.readPushDataInt(buffer, 0)
|
||||
var fopcode = parseInt(f.hexPD.substr(0, 2), 16)
|
||||
|
||||
|
@ -37,7 +37,7 @@ describe('bufferutils', function () {
|
|||
if (!f.hexPD) return
|
||||
|
||||
it('decodes ' + f.hexPD + ' as null', function () {
|
||||
var buffer = new Buffer(f.hexPD, 'hex')
|
||||
var buffer = Buffer.from(f.hexPD, 'hex')
|
||||
|
||||
var n = bufferutils.readPushDataInt(buffer, 0)
|
||||
assert.strictEqual(n, null)
|
||||
|
@ -48,7 +48,7 @@ describe('bufferutils', function () {
|
|||
describe('readUInt64LE', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('decodes ' + f.hex64 + ' correctly', function () {
|
||||
var buffer = new Buffer(f.hex64, 'hex')
|
||||
var buffer = Buffer.from(f.hex64, 'hex')
|
||||
var number = bufferutils.readUInt64LE(buffer, 0)
|
||||
|
||||
assert.strictEqual(number, f.dec)
|
||||
|
@ -57,7 +57,7 @@ describe('bufferutils', function () {
|
|||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = new Buffer(f.hex64, 'hex')
|
||||
var buffer = Buffer.from(f.hex64, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.readUInt64LE(buffer, 0)
|
||||
|
@ -69,7 +69,7 @@ describe('bufferutils', function () {
|
|||
describe('readVarInt', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('decodes ' + f.hexVI + ' correctly', function () {
|
||||
var buffer = new Buffer(f.hexVI, 'hex')
|
||||
var buffer = Buffer.from(f.hexVI, 'hex')
|
||||
var d = bufferutils.readVarInt(buffer, 0)
|
||||
|
||||
assert.strictEqual(d.number, f.dec)
|
||||
|
@ -79,7 +79,7 @@ describe('bufferutils', function () {
|
|||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = new Buffer(f.hexVI, 'hex')
|
||||
var buffer = Buffer.from(f.hexVI, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.readVarInt(buffer, 0)
|
||||
|
@ -113,8 +113,7 @@ describe('bufferutils', function () {
|
|||
if (!f.hexPD) return
|
||||
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
var buffer = new Buffer(5)
|
||||
buffer.fill(0)
|
||||
var buffer = Buffer.alloc(5, 0)
|
||||
|
||||
var n = bufferutils.writePushDataInt(buffer, f.dec, 0)
|
||||
assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexPD)
|
||||
|
@ -125,8 +124,7 @@ describe('bufferutils', function () {
|
|||
describe('writeUInt64LE', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
var buffer = new Buffer(8)
|
||||
buffer.fill(0)
|
||||
var buffer = Buffer.alloc(8, 0)
|
||||
|
||||
bufferutils.writeUInt64LE(buffer, f.dec, 0)
|
||||
assert.strictEqual(buffer.toString('hex'), f.hex64)
|
||||
|
@ -135,8 +133,7 @@ describe('bufferutils', function () {
|
|||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = new Buffer(8)
|
||||
buffer.fill(0)
|
||||
var buffer = Buffer.alloc(8, 0)
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.writeUInt64LE(buffer, f.dec, 0)
|
||||
|
@ -148,8 +145,7 @@ describe('bufferutils', function () {
|
|||
describe('writeVarInt', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
var buffer = new Buffer(9)
|
||||
buffer.fill(0)
|
||||
var buffer = Buffer.alloc(9, 0)
|
||||
|
||||
var n = bufferutils.writeVarInt(buffer, f.dec, 0)
|
||||
assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexVI)
|
||||
|
@ -158,8 +154,7 @@ describe('bufferutils', function () {
|
|||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = new Buffer(9)
|
||||
buffer.fill(0)
|
||||
var buffer = Buffer.alloc(9, 0)
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.writeVarInt(buffer, f.dec, 0)
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('crypto', function () {
|
|||
var expected = f[algorithm]
|
||||
|
||||
it('returns ' + expected + ' for ' + f.hex, function () {
|
||||
var data = new Buffer(f.hex, 'hex')
|
||||
var data = Buffer.from(f.hex, 'hex')
|
||||
var actual = fn(data).toString('hex')
|
||||
|
||||
assert.strictEqual(actual, expected)
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('ecdsa', function () {
|
|||
.onCall(2).returns(new BigInteger('42')) // valid
|
||||
|
||||
var x = new BigInteger('1').toBuffer(32)
|
||||
var h1 = new Buffer(32)
|
||||
var h1 = Buffer.alloc(32)
|
||||
var k = ecdsa.deterministicGenerateK(h1, x, checkSig)
|
||||
|
||||
assert.strictEqual(k.toString(), '42')
|
||||
|
@ -56,7 +56,7 @@ describe('ecdsa', function () {
|
|||
mockCheckSig.onCall(1).returns(true) // good signature
|
||||
|
||||
var x = new BigInteger('1').toBuffer(32)
|
||||
var h1 = new Buffer(32)
|
||||
var h1 = Buffer.alloc(32)
|
||||
var k = ecdsa.deterministicGenerateK(h1, x, mockCheckSig)
|
||||
|
||||
assert.strictEqual(k.toString(), '53')
|
||||
|
@ -107,7 +107,7 @@ describe('ecdsa', function () {
|
|||
it('verifies a valid signature for "' + f.message + '"', function () {
|
||||
var d = BigInteger.fromHex(f.d)
|
||||
var H = bcrypto.sha256(f.message)
|
||||
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
|
||||
var signature = ECSignature.fromDER(Buffer.from(f.signature, 'hex'))
|
||||
var Q = curve.G.multiply(d)
|
||||
|
||||
assert(ecdsa.verify(H, signature, Q))
|
||||
|
@ -121,7 +121,7 @@ describe('ecdsa', function () {
|
|||
|
||||
var signature
|
||||
if (f.signature) {
|
||||
signature = ECSignature.fromDER(new Buffer(f.signature, 'hex'))
|
||||
signature = ECSignature.fromDER(Buffer.from(f.signature, 'hex'))
|
||||
} else if (f.signatureRaw) {
|
||||
signature = new ECSignature(new BigInteger(f.signatureRaw.r, 16), new BigInteger(f.signatureRaw.s, 16))
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ describe('ECPair', function () {
|
|||
fixtures.invalid.constructor.forEach(function (f) {
|
||||
it('throws ' + f.exception, function () {
|
||||
var d = f.d && new BigInteger(f.d)
|
||||
var Q = f.Q && ecurve.Point.decodeFrom(curve, new Buffer(f.Q, 'hex'))
|
||||
var Q = f.Q && ecurve.Point.decodeFrom(curve, Buffer.from(f.Q, 'hex'))
|
||||
|
||||
assert.throws(function () {
|
||||
new ECPair(d, Q, f.options)
|
||||
|
@ -127,7 +127,7 @@ describe('ECPair', function () {
|
|||
})
|
||||
|
||||
describe('makeRandom', function () {
|
||||
var d = new Buffer('0404040404040404040404040404040404040404040404040404040404040404', 'hex')
|
||||
var d = Buffer.from('0404040404040404040404040404040404040404040404040404040404040404', 'hex')
|
||||
var exWIF = 'KwMWvwRJeFqxYyhZgNwYuYjbQENDAPAudQx5VEmKJrUZcq6aL2pv'
|
||||
|
||||
describe('uses randombytes RNG', function () {
|
||||
|
@ -211,7 +211,7 @@ describe('ECPair', function () {
|
|||
|
||||
beforeEach(function () {
|
||||
keyPair = ECPair.makeRandom()
|
||||
hash = new Buffer(32)
|
||||
hash = Buffer.alloc(32)
|
||||
})
|
||||
|
||||
describe('signing', function () {
|
||||
|
|
|
@ -22,7 +22,7 @@ describe('ECSignature', function () {
|
|||
describe('parseCompact', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('imports ' + f.compact.hex + ' correctly', function () {
|
||||
var buffer = new Buffer(f.compact.hex, 'hex')
|
||||
var buffer = Buffer.from(f.compact.hex, 'hex')
|
||||
var parsed = ECSignature.parseCompact(buffer)
|
||||
|
||||
assert.strictEqual(parsed.compressed, f.compact.compressed)
|
||||
|
@ -34,7 +34,7 @@ describe('ECSignature', function () {
|
|||
|
||||
fixtures.invalid.compact.forEach(function (f) {
|
||||
it('throws on ' + f.hex, function () {
|
||||
var buffer = new Buffer(f.hex, 'hex')
|
||||
var buffer = Buffer.from(f.hex, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
ECSignature.parseCompact(buffer)
|
||||
|
@ -57,7 +57,7 @@ describe('ECSignature', function () {
|
|||
describe('fromDER', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('imports ' + f.DER + ' correctly', function () {
|
||||
var buffer = new Buffer(f.DER, 'hex')
|
||||
var buffer = Buffer.from(f.DER, 'hex')
|
||||
var signature = ECSignature.fromDER(buffer)
|
||||
|
||||
assert.strictEqual(signature.r.toString(), f.signature.r)
|
||||
|
@ -67,7 +67,7 @@ describe('ECSignature', function () {
|
|||
|
||||
fixtures.invalid.DER.forEach(function (f) {
|
||||
it('throws "' + f.exception + '" for ' + f.hex, function () {
|
||||
var buffer = new Buffer(f.hex, 'hex')
|
||||
var buffer = Buffer.from(f.hex, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
ECSignature.fromDER(buffer)
|
||||
|
@ -100,7 +100,7 @@ describe('ECSignature', function () {
|
|||
describe('parseScriptSignature', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('imports ' + f.scriptSignature.hex + ' correctly', function () {
|
||||
var buffer = new Buffer(f.scriptSignature.hex, 'hex')
|
||||
var buffer = Buffer.from(f.scriptSignature.hex, 'hex')
|
||||
var parsed = ECSignature.parseScriptSignature(buffer)
|
||||
|
||||
assert.strictEqual(parsed.signature.r.toString(), f.signature.r)
|
||||
|
@ -111,7 +111,7 @@ describe('ECSignature', function () {
|
|||
|
||||
fixtures.invalid.scriptSignature.forEach(function (f) {
|
||||
it('throws on ' + f.hex, function () {
|
||||
var buffer = new Buffer(f.hex, 'hex')
|
||||
var buffer = Buffer.from(f.hex, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
ECSignature.parseScriptSignature(buffer)
|
||||
|
|
|
@ -36,8 +36,7 @@ describe('HDNode', function () {
|
|||
var d = BigInteger.ONE
|
||||
|
||||
keyPair = new ECPair(d, null)
|
||||
chainCode = new Buffer(32)
|
||||
chainCode.fill(1)
|
||||
chainCode = Buffer.alloc(32, 1)
|
||||
})
|
||||
|
||||
it('stores the keyPair/chainCode directly', function () {
|
||||
|
@ -64,7 +63,7 @@ describe('HDNode', function () {
|
|||
|
||||
it('throws when an invalid length chain code is given', function () {
|
||||
assert.throws(function () {
|
||||
new HDNode(keyPair, new Buffer(20))
|
||||
new HDNode(keyPair, Buffer.alloc(20))
|
||||
}, /Expected property "1" of type Buffer\(Length: 32\), got Buffer\(Length: 20\)/)
|
||||
})
|
||||
})
|
||||
|
@ -116,9 +115,9 @@ describe('HDNode', function () {
|
|||
|
||||
beforeEach(function () {
|
||||
keyPair = ECPair.makeRandom()
|
||||
hash = new Buffer(32)
|
||||
hash = Buffer.alloc(32)
|
||||
|
||||
var chainCode = new Buffer(32)
|
||||
var chainCode = Buffer.alloc(32)
|
||||
hd = new HDNode(keyPair, chainCode)
|
||||
})
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('bitcoinjs-lib (advanced)', function () {
|
|||
if (err) return done(err)
|
||||
|
||||
var tx = new bitcoin.TransactionBuilder(network)
|
||||
var data = new Buffer('bitcoinjs-lib')
|
||||
var data = Buffer.from('bitcoinjs-lib')
|
||||
var dataScript = bitcoin.script.nullData.output.encode(data)
|
||||
|
||||
tx.addInput(unspent.txId, unspent.vout)
|
||||
|
|
|
@ -8,7 +8,7 @@ var blockchain = require('./_blockchain')
|
|||
describe('bitcoinjs-lib (basic)', function () {
|
||||
it('can generate a random bitcoin address', function () {
|
||||
// for testing only
|
||||
function rng () { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') }
|
||||
function rng () { return Buffer.from('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') }
|
||||
|
||||
// generate random keyPair
|
||||
var keyPair = bitcoin.ECPair.makeRandom({ rng: rng })
|
||||
|
@ -29,7 +29,7 @@ describe('bitcoinjs-lib (basic)', function () {
|
|||
|
||||
it('can generate a random keypair for alternative networks', function () {
|
||||
// for testing only
|
||||
function rng () { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') }
|
||||
function rng () { return Buffer.from('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz') }
|
||||
|
||||
var litecoin = bitcoin.networks.litecoin
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
|
||||
var d1 = child.keyPair.d
|
||||
var d2
|
||||
var data = new Buffer(37)
|
||||
var data = Buffer.alloc(37)
|
||||
serQP.copy(data, 0)
|
||||
|
||||
// search index space until we find it
|
||||
|
|
|
@ -45,7 +45,7 @@ describe('bitcoinjs-lib (crypto)', function () {
|
|||
|
||||
assert(bitcoin.script.pubKeyHash.input.check(scriptChunks), 'Expected pubKeyHash script')
|
||||
|
||||
var prevOutTxId = new Buffer(transaction.ins[input.vout].hash).reverse().toString('hex')
|
||||
var prevOutTxId = Buffer.from(transaction.ins[input.vout].hash).reverse().toString('hex')
|
||||
var prevVout = transaction.ins[input.vout].index
|
||||
|
||||
tasks.push(function (callback) {
|
||||
|
|
|
@ -12,7 +12,7 @@ describe('bitcoinjs-lib (multisig)', function () {
|
|||
'02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
|
||||
'03c6103b3b83e4a24a0e33a4df246ef11772f9992663db0c35759a5e2ebf68d8e9'
|
||||
].map(function (hex) {
|
||||
return new Buffer(hex, 'hex')
|
||||
return Buffer.from(hex, 'hex')
|
||||
})
|
||||
|
||||
var redeemScript = bitcoin.script.multisig.output.encode(2, pubKeys) // 2 of 3
|
||||
|
|
|
@ -14,7 +14,7 @@ describe('script', function () {
|
|||
})
|
||||
it('rejects smaller than 33', function () {
|
||||
for (var i = 0; i < 33; i++) {
|
||||
assert.strictEqual(false, bscript.isCanonicalPubKey(new Buffer('', i)))
|
||||
assert.strictEqual(false, bscript.isCanonicalPubKey(Buffer.from('', i)))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -86,13 +86,13 @@ describe('script', function () {
|
|||
describe('decompile', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('decompiles ' + f.asm, function () {
|
||||
var chunks = bscript.decompile(new Buffer(f.script, 'hex'))
|
||||
var chunks = bscript.decompile(Buffer.from(f.script, 'hex'))
|
||||
|
||||
assert.strictEqual(bscript.compile(chunks).toString('hex'), f.script)
|
||||
assert.strictEqual(bscript.toASM(chunks), f.asm)
|
||||
|
||||
if (f.nonstandard) {
|
||||
var chunksNS = bscript.decompile(new Buffer(f.nonstandard.scriptSigHex, 'hex'))
|
||||
var chunksNS = bscript.decompile(Buffer.from(f.nonstandard.scriptSigHex, 'hex'))
|
||||
|
||||
assert.strictEqual(bscript.compile(chunksNS).toString('hex'), f.script)
|
||||
|
||||
|
@ -104,7 +104,7 @@ describe('script', function () {
|
|||
|
||||
fixtures.invalid.decompile.forEach(function (f) {
|
||||
it('decompiles ' + f.script + ' to [] because of "' + f.description + '"', function () {
|
||||
var chunks = bscript.decompile(new Buffer(f.script, 'hex'))
|
||||
var chunks = bscript.decompile(Buffer.from(f.script, 'hex'))
|
||||
|
||||
assert.strictEqual(chunks.length, 0)
|
||||
})
|
||||
|
@ -114,7 +114,7 @@ describe('script', function () {
|
|||
describe('SCRIPT_VERIFY_MINIMALDATA policy', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('compliant for ' + f.type + ' scriptSig ' + f.asm, function () {
|
||||
var script = new Buffer(f.script, 'hex')
|
||||
var script = Buffer.from(f.script, 'hex')
|
||||
|
||||
assert(minimalData(script))
|
||||
})
|
||||
|
@ -122,7 +122,7 @@ describe('script', function () {
|
|||
|
||||
function testEncodingForSize (i) {
|
||||
it('compliant for data PUSH of length ' + i, function () {
|
||||
var buffer = new Buffer(i)
|
||||
var buffer = Buffer.alloc(i)
|
||||
var script = bscript.compile([buffer])
|
||||
|
||||
assert(minimalData(script), 'Failed for ' + i + ' length script: ' + script.toString('hex'))
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('script-number', function () {
|
|||
describe('decode', function () {
|
||||
fixtures.forEach(function (f) {
|
||||
it(f.hex + ' returns ' + f.number, function () {
|
||||
var actual = scriptNumber.decode(new Buffer(f.hex, 'hex'), f.bytes)
|
||||
var actual = scriptNumber.decode(Buffer.from(f.hex, 'hex'), f.bytes)
|
||||
|
||||
assert.strictEqual(actual, f.number)
|
||||
})
|
||||
|
|
|
@ -93,7 +93,7 @@ describe('script-templates', function () {
|
|||
if (f.input) {
|
||||
input = bscript.fromASM(f.input)
|
||||
} else {
|
||||
input = new Buffer(f.inputHex, 'hex')
|
||||
input = Buffer.from(f.inputHex, 'hex')
|
||||
}
|
||||
|
||||
assert.strictEqual(inputType.check(input), false)
|
||||
|
@ -131,7 +131,7 @@ describe('script-templates', function () {
|
|||
if (f.output) {
|
||||
output = bscript.fromASM(f.output)
|
||||
} else {
|
||||
output = new Buffer(f.outputHex, 'hex')
|
||||
output = Buffer.from(f.outputHex, 'hex')
|
||||
}
|
||||
|
||||
assert.strictEqual(outputType.check(output), false)
|
||||
|
@ -144,7 +144,7 @@ describe('script-templates', function () {
|
|||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkey') return
|
||||
|
||||
var signature = new Buffer(f.signature, 'hex')
|
||||
var signature = Buffer.from(f.signature, 'hex')
|
||||
var input = bscript.pubKey.input.encode(signature)
|
||||
|
||||
it('encodes to ' + f.input, function () {
|
||||
|
@ -161,7 +161,7 @@ describe('script-templates', function () {
|
|||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkey') return
|
||||
|
||||
var pubKey = new Buffer(f.pubKey, 'hex')
|
||||
var pubKey = Buffer.from(f.pubKey, 'hex')
|
||||
var output = bscript.pubKey.output.encode(pubKey)
|
||||
|
||||
it('encodes to ' + f.output, function () {
|
||||
|
@ -178,8 +178,8 @@ describe('script-templates', function () {
|
|||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkeyhash') return
|
||||
|
||||
var pubKey = new Buffer(f.pubKey, 'hex')
|
||||
var signature = new Buffer(f.signature, 'hex')
|
||||
var pubKey = Buffer.from(f.pubKey, 'hex')
|
||||
var signature = Buffer.from(f.signature, 'hex')
|
||||
var input = bscript.pubKeyHash.input.encode(signature, pubKey)
|
||||
|
||||
it('encodes to ' + f.input, function () {
|
||||
|
@ -199,7 +199,7 @@ describe('script-templates', function () {
|
|||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkeyhash') return
|
||||
|
||||
var pubKey = new Buffer(f.pubKey, 'hex')
|
||||
var pubKey = Buffer.from(f.pubKey, 'hex')
|
||||
var pubKeyHash = bcrypto.hash160(pubKey)
|
||||
var output = bscript.pubKeyHash.output.encode(pubKeyHash)
|
||||
|
||||
|
@ -214,7 +214,7 @@ describe('script-templates', function () {
|
|||
|
||||
fixtures.invalid.pubKeyHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
var hash = Buffer.from(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
|
@ -230,7 +230,7 @@ describe('script-templates', function () {
|
|||
var allowIncomplete = f.typeIncomplete !== undefined
|
||||
|
||||
var signatures = f.signatures.map(function (signature) {
|
||||
return signature ? new Buffer(signature, 'hex') : ops.OP_0
|
||||
return signature ? Buffer.from(signature, 'hex') : ops.OP_0
|
||||
})
|
||||
|
||||
var input = bscript.multisig.input.encode(signatures)
|
||||
|
@ -250,7 +250,7 @@ describe('script-templates', function () {
|
|||
|
||||
it('throws on ' + f.exception, function () {
|
||||
var signatures = f.signatures.map(function (signature) {
|
||||
return signature ? new Buffer(signature, 'hex') : ops.OP_0
|
||||
return signature ? Buffer.from(signature, 'hex') : ops.OP_0
|
||||
})
|
||||
|
||||
assert.throws(function () {
|
||||
|
@ -264,7 +264,7 @@ describe('script-templates', function () {
|
|||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'multisig') return
|
||||
|
||||
var pubKeys = f.pubKeys.map(function (p) { return new Buffer(p, 'hex') })
|
||||
var pubKeys = f.pubKeys.map(function (p) { return Buffer.from(p, 'hex') })
|
||||
var m = pubKeys.length
|
||||
|
||||
var output = bscript.multisig.output.encode(m, pubKeys)
|
||||
|
@ -284,7 +284,7 @@ describe('script-templates', function () {
|
|||
fixtures.invalid.multisig.outputs.forEach(function (f) {
|
||||
if (!f.pubKeys) return
|
||||
var pubKeys = f.pubKeys.map(function (p) {
|
||||
return new Buffer(p, 'hex')
|
||||
return Buffer.from(p, 'hex')
|
||||
})
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
|
@ -340,7 +340,7 @@ describe('script-templates', function () {
|
|||
|
||||
fixtures.invalid.scriptHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
var hash = Buffer.from(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
|
@ -355,7 +355,7 @@ describe('script-templates', function () {
|
|||
if (f.type !== 'witnesspubkeyhash') return
|
||||
if (!f.output) return
|
||||
|
||||
var pubKey = new Buffer(f.pubKey, 'hex')
|
||||
var pubKey = Buffer.from(f.pubKey, 'hex')
|
||||
var pubKeyHash = bcrypto.hash160(pubKey)
|
||||
var output = bscript.witnessPubKeyHash.output.encode(pubKeyHash)
|
||||
|
||||
|
@ -370,7 +370,7 @@ describe('script-templates', function () {
|
|||
|
||||
fixtures.invalid.witnessPubKeyHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
var hash = Buffer.from(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
|
@ -400,7 +400,7 @@ describe('script-templates', function () {
|
|||
|
||||
fixtures.invalid.witnessScriptHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
var hash = Buffer.from(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
|
@ -415,7 +415,7 @@ describe('script-templates', function () {
|
|||
if (f.type !== 'witnesscommitment') return
|
||||
if (!f.scriptPubKey) return
|
||||
|
||||
var commitment = new Buffer(f.witnessCommitment, 'hex')
|
||||
var commitment = Buffer.from(f.witnessCommitment, 'hex')
|
||||
var scriptPubKey = bscript.witnessCommitment.output.encode(commitment)
|
||||
|
||||
it('encodes to ' + f.scriptPubKey, function () {
|
||||
|
@ -429,7 +429,7 @@ describe('script-templates', function () {
|
|||
|
||||
fixtures.invalid.witnessCommitment.outputs.forEach(function (f) {
|
||||
if (f.commitment) {
|
||||
var hash = new Buffer(f.commitment, 'hex')
|
||||
var hash = Buffer.from(f.commitment, 'hex')
|
||||
it('throws on bad encode data', function () {
|
||||
assert.throws(function () {
|
||||
bscript.witnessCommitment.output.encode(hash)
|
||||
|
@ -440,7 +440,7 @@ describe('script-templates', function () {
|
|||
if (f.scriptPubKeyHex) {
|
||||
it('.decode throws on ' + f.description, function () {
|
||||
assert.throws(function () {
|
||||
bscript.witnessCommitment.output.decode(new Buffer(f.scriptPubKeyHex, 'hex'))
|
||||
bscript.witnessCommitment.output.decode(Buffer.from(f.scriptPubKeyHex, 'hex'))
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ describe('script-templates', function () {
|
|||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'nulldata') return
|
||||
|
||||
var data = new Buffer(f.data, 'hex')
|
||||
var data = Buffer.from(f.data, 'hex')
|
||||
var output = bscript.nullData.output.encode(data)
|
||||
|
||||
it('encodes to ' + f.output, function () {
|
||||
|
|
|
@ -12,11 +12,11 @@ describe('Transaction', function () {
|
|||
tx.locktime = raw.locktime
|
||||
|
||||
raw.ins.forEach(function (txIn, i) {
|
||||
var txHash = new Buffer(txIn.hash, 'hex')
|
||||
var txHash = Buffer.from(txIn.hash, 'hex')
|
||||
var scriptSig
|
||||
|
||||
if (txIn.data) {
|
||||
scriptSig = new Buffer(txIn.data, 'hex')
|
||||
scriptSig = Buffer.from(txIn.data, 'hex')
|
||||
} else if (txIn.script) {
|
||||
scriptSig = bscript.fromASM(txIn.script)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ describe('Transaction', function () {
|
|||
|
||||
if (!noWitness && txIn.witness) {
|
||||
var witness = txIn.witness.map(function (x) {
|
||||
return new Buffer(x, 'hex')
|
||||
return Buffer.from(x, 'hex')
|
||||
})
|
||||
|
||||
tx.setWitness(i, witness)
|
||||
|
@ -36,7 +36,7 @@ describe('Transaction', function () {
|
|||
var script
|
||||
|
||||
if (txOut.data) {
|
||||
script = new Buffer(txOut.data, 'hex')
|
||||
script = Buffer.from(txOut.data, 'hex')
|
||||
} else if (txOut.script) {
|
||||
script = bscript.fromASM(txOut.script)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ describe('Transaction', function () {
|
|||
var actual = fromRaw(f.raw)
|
||||
var byteLength = actual.byteLength()
|
||||
|
||||
var target = new Buffer(byteLength * 2)
|
||||
var target = Buffer.alloc(byteLength * 2)
|
||||
var a = actual.toBuffer(target, 0)
|
||||
var b = actual.toBuffer(target, byteLength)
|
||||
|
||||
|
@ -132,7 +132,7 @@ describe('Transaction', function () {
|
|||
describe('addInput', function () {
|
||||
var prevTxHash
|
||||
beforeEach(function () {
|
||||
prevTxHash = new Buffer('ffffffff00ffff000000000000000000000000000000000000000000101010ff', 'hex')
|
||||
prevTxHash = Buffer.from('ffffffff00ffff000000000000000000000000000000000000000000101010ff', 'hex')
|
||||
})
|
||||
|
||||
it('returns an index', function () {
|
||||
|
@ -153,7 +153,7 @@ describe('Transaction', function () {
|
|||
fixtures.invalid.addInput.forEach(function (f) {
|
||||
it('throws on ' + f.exception, function () {
|
||||
var tx = new Transaction()
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
var hash = Buffer.from(f.hash, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
tx.addInput(hash, f.index)
|
||||
|
@ -165,8 +165,8 @@ describe('Transaction', function () {
|
|||
describe('addOutput', function () {
|
||||
it('returns an index', function () {
|
||||
var tx = new Transaction()
|
||||
assert.strictEqual(tx.addOutput(new Buffer(0), 0), 0)
|
||||
assert.strictEqual(tx.addOutput(new Buffer(0), 0), 1)
|
||||
assert.strictEqual(tx.addOutput(Buffer.alloc(0), 0), 0)
|
||||
assert.strictEqual(tx.addOutput(Buffer.alloc(0), 0), 1)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -216,10 +216,10 @@ describe('Transaction', function () {
|
|||
|
||||
describe('hashForSignature', function () {
|
||||
it('does not use Witness serialization', function () {
|
||||
var randScript = new Buffer('6a', 'hex')
|
||||
var randScript = Buffer.from('6a', 'hex')
|
||||
|
||||
var tx = new Transaction()
|
||||
tx.addInput(new Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), 0)
|
||||
tx.addInput(Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), 0)
|
||||
tx.addOutput(randScript, 5000000000)
|
||||
|
||||
var original = tx.__toBuffer
|
||||
|
|
|
@ -82,7 +82,7 @@ describe('TransactionBuilder', function () {
|
|||
].map(function (x) {
|
||||
return baddress.toOutputScript(x)
|
||||
})
|
||||
var txHash = new Buffer('0e7cea811c0be9f73c0aca591034396e7264473fc25c1ca45195d7417b36cbe2', 'hex')
|
||||
var txHash = Buffer.from('0e7cea811c0be9f73c0aca591034396e7264473fc25c1ca45195d7417b36cbe2', 'hex')
|
||||
|
||||
describe('fromTransaction', function () {
|
||||
fixtures.valid.build.forEach(function (f) {
|
||||
|
@ -101,7 +101,7 @@ describe('TransactionBuilder', function () {
|
|||
var tx = new Transaction()
|
||||
|
||||
f.inputs.forEach(function (input) {
|
||||
var txHash2 = new Buffer(input.txId, 'hex').reverse()
|
||||
var txHash2 = Buffer.from(input.txId, 'hex').reverse()
|
||||
|
||||
tx.addInput(txHash2, input.vout, undefined, bscript.fromASM(input.scriptSig))
|
||||
})
|
||||
|
@ -411,8 +411,8 @@ describe('TransactionBuilder', function () {
|
|||
var redeemScript = bscript.fromASM('OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 OP_3 OP_CHECKMULTISIG')
|
||||
|
||||
var tx = new Transaction()
|
||||
tx.addInput(new Buffer('cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f07149', 'hex'), 0, undefined, redeemScripSig)
|
||||
tx.addOutput(new Buffer('76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac', 'hex'), 1000)
|
||||
tx.addInput(Buffer.from('cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f07149', 'hex'), 0, undefined, redeemScripSig)
|
||||
tx.addOutput(Buffer.from('76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac', 'hex'), 1000)
|
||||
|
||||
// now import the Transaction
|
||||
var txb = TransactionBuilder.fromTransaction(tx, NETWORKS.testnet)
|
||||
|
|
|
@ -18,8 +18,8 @@ describe('types', function () {
|
|||
})
|
||||
|
||||
describe('Buffer Hash160/Hash256', function () {
|
||||
var buffer20byte = new Buffer(20)
|
||||
var buffer32byte = new Buffer(32)
|
||||
var buffer20byte = Buffer.alloc(20)
|
||||
var buffer32byte = Buffer.alloc(32)
|
||||
|
||||
it('return true for valid size', function () {
|
||||
assert(types.Hash160bit(buffer20byte))
|
||||
|
|
Loading…
Add table
Reference in a new issue