tests: forces consistent import syntax

This commit is contained in:
Daniel Cousens 2014-05-13 16:35:07 +10:00
parent 7cac39633c
commit 7a740c2e7b
12 changed files with 126 additions and 44 deletions

View file

@ -1,5 +1,5 @@
var assert = require('assert')
var base58 = require('../').base58
var base58 = require('..').base58
var fixtures = require('./fixtures/base58')
function b2h(b) { return new Buffer(b).toString('hex') }

View file

@ -1,5 +1,5 @@
var assert = require('assert')
var base58check = require('../').base58check
var base58check = require('..').base58check
var fixtures = require('./fixtures/base58check')
function b2h(b) { return new Buffer(b).toString('hex') }

86
test/bufferutils.js Normal file
View file

@ -0,0 +1,86 @@
var assert = require('assert')
var bufferutils = require('..').bufferutils
var fixtures = require('./fixtures/buffer.js')
describe('bufferutils', function() {
describe('readUInt64LE', function() {
it('matches test vectors', function() {
fixtures.valid.forEach(function(f) {
var buffer = new Buffer(f.hex64, 'hex')
var number = bufferutils.readUInt64LE(buffer, 0)
assert.equal(number, f.dec)
})
})
})
describe('readVarInt', function() {
it('matches test vectors', function() {
fixtures.valid.forEach(function(f) {
var buffer = new Buffer(f.hexVI, 'hex')
var d = bufferutils.readVarInt(buffer, 0)
assert.equal(d.number, f.dec)
assert.equal(d.size, buffer.length)
})
})
})
describe('varIntSize', function() {
it('matches test vectors', function() {
fixtures.valid.forEach(function(f) {
var number = parseInt(f.dec)
var size = bufferutils.varIntSize(number)
assert.equal(size, f.hexVI.length / 2)
})
})
})
describe('writeUInt64LE', function() {
it('matches test vectors', function() {
fixtures.valid.forEach(function(f) {
var buffer = new Buffer(8)
buffer.fill(0)
bufferutils.writeUInt64LE(buffer, f.dec, 0)
assert.equal(buffer.toString('hex'), f.hex64)
})
})
fixtures.invalid.forEach(function(f) {
it('throws on ' + f.description, function() {
assert.throws(function() {
var buffer = new Buffer(8)
buffer.fill(0)
bufferutils.writeUInt64LE(buffer, f.dec, 0)
})
})
})
})
describe('writeVarInt', function() {
it('matches test vectors', function() {
fixtures.valid.forEach(function(f) {
var buffer = new Buffer(9)
buffer.fill(0)
var n = bufferutils.writeVarInt(buffer, f.dec, 0)
assert.equal(buffer.slice(0, n).toString('hex'), f.hexVI)
})
})
fixtures.invalid.forEach(function(f) {
it('throws on ' + f.description, function() {
assert.throws(function() {
var buffer = new Buffer(9)
buffer.fill(0)
bufferutils.writeVarInt(buffer, f.dec, 0)
})
})
})
})
})

View file

@ -1,5 +1,5 @@
var assert = require('assert')
var convert = require('../').convert
var convert = require('..').convert
describe('convert', function() {
describe('byte array and word array conversions', function(){

View file

@ -1,13 +1,14 @@
var assert = require('assert')
var crypto = require('../').crypto
var fixture = require('./fixtures/crypto')
var crypto = require('..').crypto
var fixtures = require('./fixtures/crypto')
describe('Crypto', function() {
describe('HASH160', function() {
it('matches the test vector', function() {
fixture.before.hex.forEach(function(hex, i) {
fixtures.before.hex.forEach(function(hex, i) {
var actual = crypto.hash160(new Buffer(hex, 'hex')).toString('hex')
var expected = fixture.after.hash160[i]
var expected = fixtures.after.hash160[i]
assert.equal(actual, expected)
})
@ -16,9 +17,9 @@ describe('Crypto', function() {
describe('HASH256', function() {
it('matches the test vector', function() {
fixture.before.hex.forEach(function(hex, i) {
fixtures.before.hex.forEach(function(hex, i) {
var actual = crypto.hash256(new Buffer(hex, 'hex')).toString('hex')
var expected = fixture.after.hash256[i]
var expected = fixtures.after.hash256[i]
assert.equal(actual, expected)
})
@ -27,9 +28,9 @@ describe('Crypto', function() {
describe('SHA1', function() {
it('matches the test vector', function() {
fixture.before.hex.forEach(function(hex, i) {
fixtures.before.hex.forEach(function(hex, i) {
var actual = crypto.sha1(new Buffer(hex, 'hex')).toString('hex')
var expected = fixture.after.sha1[i]
var expected = fixtures.after.sha1[i]
assert.equal(actual, expected)
})
@ -38,9 +39,9 @@ describe('Crypto', function() {
describe('SHA256', function() {
it('matches the test vector', function() {
fixture.before.hex.forEach(function(hex, i) {
fixtures.before.hex.forEach(function(hex, i) {
var actual = crypto.sha256(new Buffer(hex, 'hex')).toString('hex')
var expected = fixture.after.sha256[i]
var expected = fixtures.after.sha256[i]
assert.equal(actual, expected)
})
@ -49,12 +50,12 @@ describe('Crypto', function() {
describe('HMAC SHA512', function() {
it('matches the test vector', function() {
fixture.before.hex.forEach(function(hex, i) {
fixtures.before.hex.forEach(function(hex, i) {
var data = new Buffer(hex, 'hex')
var secret = new Buffer(fixture.after.hmacsha512.secret)
var secret = new Buffer(fixtures.after.hmacsha512.secret)
var actual = crypto.HmacSHA512(data, secret)
var expected = fixture.after.hmacsha512.hash[i]
var expected = fixtures.after.hmacsha512.hash[i]
assert.equal(actual.toString('hex'), expected)
})

View file

@ -1,10 +1,10 @@
var assert = require('assert')
var sec = require('../').sec
var sec = require('..').sec
var ecparams = sec('secp256k1')
var BigInteger = require('bigi')
var ECPointFp = require('../').ECPointFp
var ECPointFp = require('..').ECPointFp
describe('ec', function() {
describe('ECPointFp', function() {

View file

@ -1,6 +1,7 @@
var assert = require('assert')
var crypto = require('../').crypto
var crypto = require('..').crypto
var ecdsa = require('..').ecdsa
var sec = require('..').sec
var ecparams = sec("secp256k1")

View file

@ -1,8 +1,8 @@
var assert = require('assert')
var crypto = require('..').crypto
var ECKey = require('../src/eckey.js').ECKey
var ECPubKey = require('../src/eckey.js').ECPubKey
var ECKey = require('..').ECKey
var ECPubKey = require('..').ECPubKey
describe('ECKey', function() {
describe('constructor', function() {

View file

@ -1,7 +1,8 @@
var assert = require('assert')
var ECKey = require('../src/eckey').ECKey
var Message = require('../').Message
var networks = require('../').networks
var networks = require('..').networks
var ECKey = require('..').ECKey
var Message = require('..').Message
var fixtures = require('./fixtures/message')

View file

@ -2,8 +2,8 @@ var assert = require('assert')
var crypto = require('..').crypto
var networks = require('..').networks
var Address = require('../src/address.js')
var Script = require('../src/script.js')
var Address = require('..').Address
var Script = require('..').Script
var fixtures = require('./fixtures/script')

View file

@ -1,12 +1,10 @@
var assert = require('assert')
var Address = require('../src/address')
var ECKey = require('../src/eckey').ECKey
var networks = require('..').networks
var T = require('../src/transaction')
var Transaction = T.Transaction
var TransactionOut = T.TransactionOut
var Script = require('../src/script')
var Address = require('..').Address
var ECKey = require('..').ECKey
var Transaction = require('..').Transaction
var Script = require('..').Script
var fixtureTxes = require('./fixtures/mainnet_tx')
var fixtureTx1Hex = fixtureTxes.prevTx
@ -276,8 +274,5 @@ describe('Transaction', function() {
assert.equal(tx.serializeHex(), expected)
})
})
describe('TransactionOut', function() {
})
})

View file

@ -3,12 +3,10 @@ var crypto = require('../').crypto
var sinon = require('sinon')
var Address = require('..').Address
var HDNode = require('../src/hdwallet.js')
var T = require('../src/transaction.js')
var Transaction = T.Transaction
var TransactionOut = T.TransactionOut
var Script = require('../src/script.js')
var Wallet = require('../src/wallet.js')
var HDWallet = require('..').HDWallet
var Script = require('..').Script
var Transaction = require('..').Transaction
var Wallet = require('..').Wallet
var fixtureTxes = require('./fixtures/mainnet_tx')
var fixtureTx1Hex = fixtureTxes.prevTx
@ -32,7 +30,7 @@ describe('Wallet', function() {
it("generates m/0' as the main account", function() {
var mainAccount = wallet.getAccountZero()
assert.equal(mainAccount.index, 0 + HDNode.HIGHEST_BIT)
assert.equal(mainAccount.index, 0 + HDWallet.HIGHEST_BIT)
assert.equal(mainAccount.depth, 1)
})