syncscript: general cleanup
This commit is contained in:
parent
1e0521f7e5
commit
39d042d058
1 changed files with 36 additions and 44 deletions
80
test/fixtures/syncscript.js
vendored
80
test/fixtures/syncscript.js
vendored
|
@ -8,16 +8,13 @@ var secureRandom = require('secure-random')
|
||||||
|
|
||||||
function b2h(b) { return new Buffer(b).toString('hex') }
|
function b2h(b) { return new Buffer(b).toString('hex') }
|
||||||
function h2b(h) { return new Buffer(h, 'hex') }
|
function h2b(h) { return new Buffer(h, 'hex') }
|
||||||
function randomBuf(s) {
|
function randomBuf(s) { return new Buffer(secureRandom(s)) }
|
||||||
return new Buffer(secureRandom(s))
|
|
||||||
}
|
|
||||||
|
|
||||||
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_encode_decode.json', function (error, response, body) {
|
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_encode_decode.json', function (error, response, body) {
|
||||||
assert.ifError(error)
|
assert.ifError(error)
|
||||||
assert.equal(response.statusCode, 200)
|
assert.equal(response.statusCode, 200)
|
||||||
|
|
||||||
var data = JSON.parse(body)
|
var valid = JSON.parse(body).map(function(x) {
|
||||||
var valid = data.map(function(x) {
|
|
||||||
return {
|
return {
|
||||||
hex: x[0],
|
hex: x[0],
|
||||||
string: x[1]
|
string: x[1]
|
||||||
|
@ -31,7 +28,7 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/
|
||||||
// string: ' \t\n\v\f\r skip \r\f\v\n\t '
|
// string: ' \t\n\v\f\r skip \r\f\v\n\t '
|
||||||
// })
|
// })
|
||||||
|
|
||||||
var fixtureJSON = JSON.stringify({
|
var fixture = JSON.stringify({
|
||||||
valid: valid,
|
valid: valid,
|
||||||
invalid: [
|
invalid: [
|
||||||
{
|
{
|
||||||
|
@ -58,48 +55,43 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/
|
||||||
]
|
]
|
||||||
}, null, ' ')
|
}, null, ' ')
|
||||||
|
|
||||||
fs.writeFileSync('./test/fixtures/base58.js', 'module.exports = ' + fixtureJSON)
|
fs.writeFileSync('./test/fixtures/base58.js', 'module.exports = ' + fixture)
|
||||||
})
|
})
|
||||||
|
|
||||||
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_valid.json', function (error, response, body) {
|
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_valid.json', function (error, response, body) {
|
||||||
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_invalid.json', function (error2, response2, body2) {
|
request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/base58_keys_invalid.json', function (error2, response2, body2) {
|
||||||
assert.ifError(error)
|
assert.ifError(error)
|
||||||
assert.ifError(error2)
|
assert.ifError(error2)
|
||||||
assert.equal(response.statusCode, 200)
|
assert.equal(response.statusCode, 200)
|
||||||
assert.equal(response2.statusCode, 200)
|
assert.equal(response2.statusCode, 200)
|
||||||
|
|
||||||
var validData = JSON.parse(body)
|
var valid = JSON.parse(body).map(function(x) {
|
||||||
var invalidData = JSON.parse(body2)
|
var string = x[0]
|
||||||
|
var hex = x[1]
|
||||||
|
var params = x[2]
|
||||||
|
|
||||||
var valid = validData.map(function(x) {
|
if (params.isCompressed) hex += '01'
|
||||||
var string = x[0]
|
assert.equal(b2h(base58check.decode(string).payload), hex)
|
||||||
var hex = x[1]
|
|
||||||
var params = x[2]
|
|
||||||
|
|
||||||
if (params.isCompressed) {
|
return {
|
||||||
hex += '01'
|
string: string,
|
||||||
|
decode: {
|
||||||
|
version: base58check.decode(string).version,
|
||||||
|
payload: hex,
|
||||||
|
checksum: b2h(base58check.decode(string).checksum),
|
||||||
}
|
}
|
||||||
assert.equal(b2h(base58check.decode(string).payload), hex)
|
}
|
||||||
|
})
|
||||||
|
var invalid2 = JSON.parse(body2).map(function(x) { return x[0] })
|
||||||
|
|
||||||
return {
|
// Our own tests
|
||||||
string: string,
|
var hash = crypto.hash160(randomBuf(65))
|
||||||
decode: {
|
var checksum = base58check.decode(base58check.encode(hash)).checksum
|
||||||
version: base58check.decode(string).version,
|
|
||||||
payload: hex,
|
|
||||||
checksum: b2h(base58check.decode(string).checksum),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
var invalid2 = invalidData.map(function(x) { return x[0] })
|
|
||||||
|
|
||||||
// Our own tests
|
var fixture = JSON.stringify({
|
||||||
var hash = crypto.hash160(randomBuf(65))
|
valid: valid,
|
||||||
var checksum = base58check.decode(base58check.encode(hash)).checksum
|
invalid: [
|
||||||
|
{
|
||||||
var fixtureJSON = JSON.stringify({
|
|
||||||
valid: valid,
|
|
||||||
invalid: [
|
|
||||||
{
|
|
||||||
base58check: base58check.encode(hash.slice(0, 18), 0x05),
|
base58check: base58check.encode(hash.slice(0, 18), 0x05),
|
||||||
description: 'hash too short'
|
description: 'hash too short'
|
||||||
},
|
},
|
||||||
|
@ -119,10 +111,10 @@ request('https://raw.githubusercontent.com/bitcoin/bitcoin/master/src/test/data/
|
||||||
base58check: base58.encode(Buffer.concat([new Buffer([0x05]), hash, randomBuf(4)])),
|
base58check: base58.encode(Buffer.concat([new Buffer([0x05]), hash, randomBuf(4)])),
|
||||||
description: 'bad SHA256 checksum',
|
description: 'bad SHA256 checksum',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
invalid2: invalid2
|
invalid2: invalid2
|
||||||
}, null, ' ')
|
}, null, ' ')
|
||||||
|
|
||||||
fs.writeFileSync('./test/fixtures/base58check.js', 'module.exports = ' + fixtureJSON)
|
fs.writeFileSync('./test/fixtures/base58check.js', 'module.exports = ' + fixture)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue