base58check: fix wrapper and tests

This commit is contained in:
Daniel Cousens 2014-10-15 22:36:10 +11:00
parent 49ab51c227
commit 27a3230662
3 changed files with 19 additions and 16 deletions

View file

@ -3,13 +3,13 @@ var bs58check = require('bs58check')
function decode() { function decode() {
console.warn('bs58check will be removed in 2.0.0. require("bs58check") instead.'); console.warn('bs58check will be removed in 2.0.0. require("bs58check") instead.');
bs58check.decode.apply(undefined, arguments) return bs58check.decode.apply(undefined, arguments)
} }
function encode() { function encode() {
console.warn('bs58check will be removed in 2.0.0. require("bs58check") instead.'); console.warn('bs58check will be removed in 2.0.0. require("bs58check") instead.');
bs58check.encode.apply(undefined, arguments) return bs58check.encode.apply(undefined, arguments)
} }
module.exports = { module.exports = {

View file

@ -1,3 +1,4 @@
var assert = require('assert')
var base58check = require('../src/base58check') var base58check = require('../src/base58check')
var bs58check = require('bs58check') var bs58check = require('bs58check')
var sinon = require('sinon') var sinon = require('sinon')
@ -11,15 +12,15 @@ describe('base58check', function() {
it('wraps bs58check.decode', sinon.test(function() { it('wraps bs58check.decode', sinon.test(function() {
this.mock(bs58check).expects('decode') this.mock(bs58check).expects('decode')
.once().calledWith(param) .once().calledWith(param).returns('foo')
base58check.decode(param) assert.equal(base58check.decode(param), 'foo')
})) }))
it('wraps bs58check.encode', sinon.test(function() { it('wraps bs58check.encode', sinon.test(function() {
this.mock(bs58check).expects('encode') this.mock(bs58check).expects('encode')
.once().calledWith(param) .once().calledWith(param).returns('foo')
base58check.encode(param) assert.equal(base58check.encode(param), 'foo')
})) }))
}) })

View file

@ -1,14 +1,16 @@
var assert = require('assert') var assert = require('assert')
var base58 = require('bs58')
var base58check = require('bs58check')
var networks = require('../src/networks') var networks = require('../src/networks')
var Address = require('../src/address') var base58 = require('bs58')
var BigInteger = require('bigi') //var base58check = require('bs58check')
var ECKey = require('../src/eckey')
var ECSignature = require('../src/ecsignature') var Bitcoin = require('../')
var Transaction = require('../src/transaction') var Address = Bitcoin.Address
var Script = require('../src/script') var base58check = Bitcoin.base58check
var ECKey = Bitcoin.ECKey
var ECSignature = Bitcoin.ECSignature
var Transaction = Bitcoin.Transaction
var Script = Bitcoin.Script
var base58_encode_decode = require("./fixtures/core/base58_encode_decode.json") var base58_encode_decode = require("./fixtures/core/base58_encode_decode.json")
var base58_keys_invalid = require("./fixtures/core/base58_keys_invalid.json") var base58_keys_invalid = require("./fixtures/core/base58_keys_invalid.json")
@ -120,8 +122,8 @@ describe('Bitcoin-core', function() {
it('throws on ' + string, function() { it('throws on ' + string, function() {
assert.throws(function() { assert.throws(function() {
var privKey = ECKey.fromWIF(string) ECKey.fromWIF(string)
var version = base58check.decode(string).version var version = base58check.decode(string).readUInt8(0)
assert.notEqual(allowedNetworks.indexOf(version), -1, 'Invalid network') assert.notEqual(allowedNetworks.indexOf(version), -1, 'Invalid network')
}, /Invalid (checksum|compression flag|network|WIF payload)/) }, /Invalid (checksum|compression flag|network|WIF payload)/)