tests: use JSON fixtures exclusively

This commit is contained in:
Daniel Cousens 2014-05-18 19:47:39 +10:00
parent 0fcda5835e
commit b2351f9026
26 changed files with 152 additions and 155 deletions

View file

@ -3,8 +3,8 @@ var Address = require('../src/address')
var networks = require('../src/networks')
var Script = require('../src/script')
var b58fixtures = require('./fixtures/base58')
var fixtures = require('./fixtures/address')
var b58fixtures = require('./fixtures/base58.json')
var fixtures = require('./fixtures/address.json')
function h2b(h) { return new Buffer(h, 'hex') }

View file

@ -1,9 +1,7 @@
var assert = require('assert')
var base58 = require('../src/base58')
var fixtures = require('./fixtures/base58')
function b2h(b) { return new Buffer(b).toString('hex') }
function h2b(h) { return new Buffer(h, 'hex') }
var fixtures = require('./fixtures/base58.json')
describe('base58', function() {
describe('decode', function() {
@ -12,7 +10,7 @@ describe('base58', function() {
var actual = base58.decode(f.string)
var expected = f.hex
assert.strictEqual(b2h(actual), expected)
assert.strictEqual(actual.toString('hex'), expected)
})
})
@ -28,7 +26,7 @@ describe('base58', function() {
describe('encode', function() {
it('can encode Bitcoin core test data', function() {
fixtures.valid.forEach(function(f) {
var actual = base58.encode(h2b(f.hex))
var actual = base58.encode(new Buffer(f.hex, 'hex'))
var expected = f.string.trim()
assert.strictEqual(actual, expected)

View file

@ -1,6 +1,7 @@
var assert = require('assert')
var base58check = require('../src/base58check')
var fixtures = require('./fixtures/base58check')
var fixtures = require('./fixtures/base58check.json')
function b2h(b) { return new Buffer(b).toString('hex') }
function h2b(h) { return new Buffer(h, 'hex') }

View file

@ -1,7 +1,7 @@
var assert = require('assert')
var bufferutils = require('../src/bufferutils')
var fixtures = require('./fixtures/buffer.js')
var fixtures = require('./fixtures/buffer.json')
describe('bufferutils', function() {
describe('readUInt64LE', function() {

View file

@ -1,7 +1,7 @@
var assert = require('assert')
var crypto = require('../src/crypto')
var fixtures = require('./fixtures/crypto')
var fixtures = require('./fixtures/crypto.json')
describe('Crypto', function() {
describe('HASH160', function() {

View file

@ -6,7 +6,7 @@ var ecparams = sec('secp256k1')
var BigInteger = require('bigi')
var ECPointFp = require('../src/ec').ECPointFp
var fixtures = require('./fixtures/ec.js')
var fixtures = require('./fixtures/ec.json')
describe('ec', function() {
describe('ECPointFp', function() {

View file

@ -8,10 +8,8 @@ var sec = require('../src/sec')
var ecparams = sec("secp256k1")
var BigInteger = require('bigi')
var ECKey = require('../src/eckey')
var ECPubKey = require('../src/ecpubkey')
var fixtures = require('./fixtures/ecdsa.js')
var fixtures = require('./fixtures/ecdsa.json')
describe('ecdsa', function() {
describe('deterministicGenerateK', function() {

View file

@ -4,7 +4,7 @@ var crypto = require('../src/crypto')
var BigInteger = require('bigi')
var ECKey = require('../src/eckey')
var fixtures = require('./fixtures/eckey')
var fixtures = require('./fixtures/eckey.json')
var networks = require('../src/networks')
describe('ECKey', function() {

View file

@ -7,7 +7,7 @@ var BigInteger = require('bigi')
var ECPointFp = require('../src/ec').ECPointFp
var ECPubKey = require('../src/ecpubkey')
var fixtures = require('./fixtures/ecpubkey')
var fixtures = require('./fixtures/ecpubkey.json')
describe('ECPubKey', function() {
var Q

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": [
{
"description": "pubKeyHash",
@ -42,4 +42,4 @@ module.exports = {
}
]
}
}
}

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": [
{
"hex": "",

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": [
{
"string": "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
@ -475,4 +475,4 @@ module.exports = {
"Ky1YjoZNgQ196HJV3HpdkecfhRBmRZdMJk89Hi5KGfpfPwS2bUbfd",
"2A1q1YsMZowabbvta7kTy2Fd6qN4r5ZCeG3qLpvZBMzCixMUdkN2Y4dHB1wPsZAeVXUGD83MfRED"
]
}
}

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": [
{
"dec": 0,

View file

@ -1,50 +0,0 @@
module.exports = {
before: {
secret: 'vires is numeris',
hex: [
'0000000000000001',
'0101010101010101',
'FFFFFFFFFFFFFFFF',
'4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20446f6e65632061742066617563696275732073617069656e2c2076656c20666163696c6973697320617263752e20536564207574206d61737361206e6962682e205574206d6f6c6c69732070756c76696e6172206d617373612e20557420756c6c616d636f7270657220646f6c6f7220656e696d2c20696e206d6f6c657374696520656e696d20636f6e64696d656e74756d2061632e20416c697175616d206572617420766f6c75747061742e204e756c6c6120736f64616c657320617420647569206e656320'
],
},
after: {
hash160: [
'cdb00698f02afd929ffabea308340fa99ac2afa8',
'abaf1119f83e384210fe8e222eac76e2f0da39dc',
'f86221f5a1fca059a865c0b7d374dfa9d5f3aeb4',
'9763e6b367c363bd6b88a7b361c98e6beee243a5'
],
hash256: [
'3ae5c198d17634e79059c2cd735491553d22c4e09d1d9fea3ecf214565df2284',
'728338d99f356175c4945ef5cccfa61b7b56143cbbf426ddd0e0fc7cfe8c3c23',
'752adad0a7b9ceca853768aebb6965eca126a62965f698a0c1bc43d83db632ad',
'033588797115feb3545052670cac2a46584ab3cb460de63756ee0275e66b5799'
],
sha1: [
'cb473678976f425d6ec1339838f11011007ad27d',
'c0357a32ed1f6a03be92dd094476f7f1a2e214ec',
'be673e8a56eaa9d8c1d35064866701c11ef8e089',
'10d96fb43aca84e342206887bbeed3065d4e4344'
],
sha256: [
'cd2662154e6d76b2b2b92e70c0cac3ccf534f9b74eb5b89819ec509083d00a50',
'04abc8821a06e5a30937967d11ad10221cb5ac3b5273e434f1284ee87129a061',
'12a3ae445661ce5dee78d0650d33362dec29c4f82af05e7e57fb595bbbacf0ca',
'a7fb8276035057ed6479c5f2305a96da100ac43f0ac10f277e5ab8c5457429da'
],
hmacsha256: [
'73442dc8dd7f71a106a20fddd49d31856b1db12956c75070c8186b0b3eb71251',
'7204c72af7c73f5e84447a752dc8a2708f91b896f29de5fcf4b7f42f13a30c6e',
'a03c2ac6e9ca86678b5608a3d8682de46d17026f5fac4fd7147d2e5022061833',
'a780cd6e5c29cf11f756536ea5779992687c1b3b5e37f31b027a392d94e91fb8'
],
hmacsha512: [
'4c0595aed1f5d066ea9f797727c060eb86cb55ff29d4d4fd2cd0ad3a012386763aea604c030619c79aa7fd8d03cda1b73a9ebd17906a3d2a350108d1a98b24ac',
'f80b90d63b804b3d2ab03b9bfb3ac94ee271352eb8bddfb6b4f5cf2a4fc9176acea35f517728e64943d1eb8af1e4674a114082c81bc8874d88b408b3b406d6a4',
'134cf60c30a5cd412c7a5cd6c3f878279e139b47c19550b7456fa137fbf90e580ae0a923a22052f42ec801ac658db32821e271161b563eac4926285ba6b8f410',
'7dee95aa3c462d3eb7ecb61536cb215e471d1fa73d8643a967905946e26c536588c5058abd5a049a22b987db95a7fb420f3bff12359dc53d03d7ce7df714e029'
]
}
}

50
test/fixtures/crypto.json vendored Normal file
View file

@ -0,0 +1,50 @@
{
"before": {
"secret": "vires is numeris",
"hex": [
"0000000000000001",
"0101010101010101",
"FFFFFFFFFFFFFFFF",
"4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20446f6e65632061742066617563696275732073617069656e2c2076656c20666163696c6973697320617263752e20536564207574206d61737361206e6962682e205574206d6f6c6c69732070756c76696e6172206d617373612e20557420756c6c616d636f7270657220646f6c6f7220656e696d2c20696e206d6f6c657374696520656e696d20636f6e64696d656e74756d2061632e20416c697175616d206572617420766f6c75747061742e204e756c6c6120736f64616c657320617420647569206e656320"
]
},
"after": {
"hash160": [
"cdb00698f02afd929ffabea308340fa99ac2afa8",
"abaf1119f83e384210fe8e222eac76e2f0da39dc",
"f86221f5a1fca059a865c0b7d374dfa9d5f3aeb4",
"9763e6b367c363bd6b88a7b361c98e6beee243a5"
],
"hash256": [
"3ae5c198d17634e79059c2cd735491553d22c4e09d1d9fea3ecf214565df2284",
"728338d99f356175c4945ef5cccfa61b7b56143cbbf426ddd0e0fc7cfe8c3c23",
"752adad0a7b9ceca853768aebb6965eca126a62965f698a0c1bc43d83db632ad",
"033588797115feb3545052670cac2a46584ab3cb460de63756ee0275e66b5799"
],
"sha1": [
"cb473678976f425d6ec1339838f11011007ad27d",
"c0357a32ed1f6a03be92dd094476f7f1a2e214ec",
"be673e8a56eaa9d8c1d35064866701c11ef8e089",
"10d96fb43aca84e342206887bbeed3065d4e4344"
],
"sha256": [
"cd2662154e6d76b2b2b92e70c0cac3ccf534f9b74eb5b89819ec509083d00a50",
"04abc8821a06e5a30937967d11ad10221cb5ac3b5273e434f1284ee87129a061",
"12a3ae445661ce5dee78d0650d33362dec29c4f82af05e7e57fb595bbbacf0ca",
"a7fb8276035057ed6479c5f2305a96da100ac43f0ac10f277e5ab8c5457429da"
],
"hmacsha256": [
"73442dc8dd7f71a106a20fddd49d31856b1db12956c75070c8186b0b3eb71251",
"7204c72af7c73f5e84447a752dc8a2708f91b896f29de5fcf4b7f42f13a30c6e",
"a03c2ac6e9ca86678b5608a3d8682de46d17026f5fac4fd7147d2e5022061833",
"a780cd6e5c29cf11f756536ea5779992687c1b3b5e37f31b027a392d94e91fb8"
],
"hmacsha512": [
"4c0595aed1f5d066ea9f797727c060eb86cb55ff29d4d4fd2cd0ad3a012386763aea604c030619c79aa7fd8d03cda1b73a9ebd17906a3d2a350108d1a98b24ac",
"f80b90d63b804b3d2ab03b9bfb3ac94ee271352eb8bddfb6b4f5cf2a4fc9176acea35f517728e64943d1eb8af1e4674a114082c81bc8874d88b408b3b406d6a4",
"134cf60c30a5cd412c7a5cd6c3f878279e139b47c19550b7456fa137fbf90e580ae0a923a22052f42ec801ac658db32821e271161b563eac4926285ba6b8f410",
"7dee95aa3c462d3eb7ecb61536cb215e471d1fa73d8643a967905946e26c536588c5058abd5a049a22b987db95a7fb420f3bff12359dc53d03d7ce7df714e029"
]
}
}

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": {
"ECPointFp": [
{

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": [
{
"D": "0000000000000000000000000000000000000000000000000000000000000001",

View file

@ -1,4 +1,4 @@
module.exports = {
{
"valid": [
{
"D": "1",
@ -95,4 +95,4 @@ module.exports = {
}
]
}
}
}

View file

@ -1,4 +1,4 @@
module.exports = {
{
"Q": {
"x": "55066263022277343669578718895168534326250603453777594175500187360389116729240",
"y": "32670510020758816978083085130507043184471273380659243275938904335757337482424"
@ -16,4 +16,4 @@ module.exports = {
"r": "68972263025625296948424563184904289678530916807200550828762374724416876919710",
"s": "43478152510424186005054433052302509227777805602212468112169549534899266476898"
}
}
}

View file

@ -1,19 +0,0 @@
module.exports = {
magicHash: [
{
network: 'bitcoin',
message: '',
magicHash: '80e795d4a4caadd7047af389d9f7f220562feb6196032e2131e10563352c4bcc'
},
{
network: 'bitcoin',
message: 'Vires is Numeris',
magicHash: 'f8a5affbef4a3241b19067aa694562f64f513310817297089a8929a930f4f933'
},
{
network: 'dogecoin',
message: 'Vires is Numeris',
magicHash: 'c0963d20d0accd0ea0df6c1020bf85a7e629a40e7b5363f2c3e9dcafd5638f12'
}
]
}

19
test/fixtures/message.json vendored Normal file
View file

@ -0,0 +1,19 @@
{
"magicHash": [
{
"network": "bitcoin",
"message": "",
"magicHash": "80e795d4a4caadd7047af389d9f7f220562feb6196032e2131e10563352c4bcc"
},
{
"network": "bitcoin",
"message": "Vires is Numeris",
"magicHash": "f8a5affbef4a3241b19067aa694562f64f513310817297089a8929a930f4f933"
},
{
"network": "dogecoin",
"message": "Vires is Numeris",
"magicHash": "c0963d20d0accd0ea0df6c1020bf85a7e629a40e7b5363f2c3e9dcafd5638f12"
}
]
}

View file

@ -1,54 +0,0 @@
module.exports = {
valid: [
{
description: 'P2SH ScriptPubKey',
hex: 'a914e8c300c87986efa84c37c0519929019ef86eb5b487',
type: 'scripthash',
hash: '0ba47b56a573bab4b430ad6ed3ec79270e04b066',
scriptPubKey: true
},
{
description: 'PubKeyHash ScriptPubKey',
hex: '76a9145a3acbc7bbcc97c5ff16f5909c9d7d3fadb293a888ac',
type: 'pubkeyhash',
hash: 'a5313f33d5c7b81674b35f7f3febc3522ef234db',
scriptPubKey: true
},
{
description: 'pubKeyHash scriptSig',
hex: '48304502206becda98cecf7a545d1a640221438ff8912d9b505ede67e0138485111099f696022100ccd616072501310acba10feb97cecc918e21c8e92760cd35144efec7622938f30141040cd2d2ce17a1e9b2b3b2cb294d40eecf305a25b7e7bfdafae6bb2639f4ee399b3637706c3d377ec4ab781355add443ae864b134c5e523001c442186ea60f0eb8',
type: 'pubkeyhash',
hash: 'b9bac2a5c5c29bb27c382d41fa3d179c646c78fd',
scriptPubKey: false
},
{
description: 'Valid multisig script',
hex: '5121032487c2a32f7c8d57d2a93906a6457afd00697925b0e6e145d89af6d3bca330162102308673d16987eaa010e540901cc6fe3695e758c19f46ce604e174dac315e685a52ae',
type: 'multisig',
hash: 'f1c98f0b74ecabcf78ae20dfa224bb6666051fbe',
scriptPubKey: true
},
{
description: 'OP_RETURN script',
hex:'6a2606deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474',
type: 'nulldata',
hash: 'ec88f016655477663455fe6a8e83508c348ea145',
scriptPubKey: true
},
{
description: 'Non standard script',
hex: 'aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087',
type: 'nonstandard',
hash: '3823382e70d1930989813d3459988e0d7c2861d8',
scriptPubKey: true
},
{
description: 'Invalid multisig script',
asm: '0 0 0 OP_CHECKmulTISIG',
hex: '000000ae',
type: 'nonstandard',
hash: '62ede8963f9387544935f168745262f703dab1fb',
scriptPubKey: true
}
]
}

54
test/fixtures/script.json vendored Normal file
View file

@ -0,0 +1,54 @@
{
"valid": [
{
"description": "P2SH ScriptPubKey",
"hex": "a914e8c300c87986efa84c37c0519929019ef86eb5b487",
"type": "scripthash",
"hash": "0ba47b56a573bab4b430ad6ed3ec79270e04b066",
"scriptPubKey": true
},
{
"description": "PubKeyHash ScriptPubKey",
"hex": "76a9145a3acbc7bbcc97c5ff16f5909c9d7d3fadb293a888ac",
"type": "pubkeyhash",
"hash": "a5313f33d5c7b81674b35f7f3febc3522ef234db",
"scriptPubKey": true
},
{
"description": "pubKeyHash scriptSig",
"hex": "48304502206becda98cecf7a545d1a640221438ff8912d9b505ede67e0138485111099f696022100ccd616072501310acba10feb97cecc918e21c8e92760cd35144efec7622938f30141040cd2d2ce17a1e9b2b3b2cb294d40eecf305a25b7e7bfdafae6bb2639f4ee399b3637706c3d377ec4ab781355add443ae864b134c5e523001c442186ea60f0eb8",
"type": "pubkeyhash",
"hash": "b9bac2a5c5c29bb27c382d41fa3d179c646c78fd",
"scriptPubKey": false
},
{
"description": "Valid multisig script",
"hex": "5121032487c2a32f7c8d57d2a93906a6457afd00697925b0e6e145d89af6d3bca330162102308673d16987eaa010e540901cc6fe3695e758c19f46ce604e174dac315e685a52ae",
"type": "multisig",
"hash": "f1c98f0b74ecabcf78ae20dfa224bb6666051fbe",
"scriptPubKey": true
},
{
"description": "OP_RETURN script",
"hex":"6a2606deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474",
"type": "nulldata",
"hash": "ec88f016655477663455fe6a8e83508c348ea145",
"scriptPubKey": true
},
{
"description": "Non standard script",
"hex": "aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087",
"type": "nonstandard",
"hash": "3823382e70d1930989813d3459988e0d7c2861d8",
"scriptPubKey": true
},
{
"description": "Invalid multisig script",
"asm": "0 0 0 OP_CHECKmulTISIG",
"hex": "000000ae",
"type": "nonstandard",
"hash": "62ede8963f9387544935f168745262f703dab1fb",
"scriptPubKey": true
}
]
}

View file

@ -55,7 +55,7 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/
]
}, null, ' ')
fs.writeFileSync('./test/fixtures/base58.js', 'module.exports = ' + fixture)
fs.writeFileSync('./test/fixtures/base58.json', fixture)
})
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_valid.json', function (error, response, body) {
@ -115,6 +115,6 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/
invalid2: invalid2
}, null, ' ')
fs.writeFileSync('./test/fixtures/base58check.js', 'module.exports = ' + fixture)
fs.writeFileSync('./test/fixtures/base58check.json', fixture)
})
})

View file

@ -5,7 +5,7 @@ var BigInteger = require('bigi')
var ECKey = require('../src/eckey')
var Message = require('../src/message')
var fixtures = require('./fixtures/message')
var fixtures = require('./fixtures/message.json')
describe('Message', function() {
var message

View file

@ -6,7 +6,7 @@ var Address = require('../src/address')
var ECPubKey = require('../src/ecpubkey')
var Script = require('../src/script')
var fixtures = require('./fixtures/script')
var fixtures = require('./fixtures/script.json')
function b2h(b) { return new Buffer(b).toString('hex') }
function h2b(h) { return new Buffer(h, 'hex') }