ECKey: fix exception tests
These weren't broken as such, but they weren't distinctly checking that the right exception was thrown either.
This commit is contained in:
parent
6cfa729dae
commit
7494a146a6
3 changed files with 19 additions and 19 deletions
|
@ -27,7 +27,7 @@ ECKey.fromWIF = function(string) {
|
|||
var compressed = false
|
||||
|
||||
if (payload.length === 33) {
|
||||
assert.strictEqual(payload[32], 0x01, 'Invalid WIF string')
|
||||
assert.strictEqual(payload[32], 0x01, 'Invalid compression flag')
|
||||
|
||||
payload = payload.slice(0, -1)
|
||||
compressed = true
|
||||
|
|
|
@ -21,8 +21,8 @@ describe('ECKey', function() {
|
|||
assert.equal(privKey.pub.compressed, false)
|
||||
})
|
||||
|
||||
it('calculates the matching pubKey', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
it('calculates the matching pubKey for ' + f.D, function() {
|
||||
var privKey = new ECKey(new BigInteger(f.D))
|
||||
|
||||
assert.equal(privKey.pub.Q.toString(), f.Q.toString())
|
||||
|
@ -30,18 +30,18 @@ describe('ECKey', function() {
|
|||
})
|
||||
|
||||
fixtures.invalid.constructor.forEach(function(f) {
|
||||
it('throws on ' + f.description, function() {
|
||||
it('throws on ' + f.D, function() {
|
||||
assert.throws(function() {
|
||||
new ECKey(new BigInteger(f.D))
|
||||
})
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromWIF', function() {
|
||||
it('matches the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
f.WIFs.forEach(function(wif) {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
f.WIFs.forEach(function(wif) {
|
||||
it('imports ' + wif.string + ' correctly', function() {
|
||||
var privKey = ECKey.fromWIF(wif.string)
|
||||
|
||||
assert.equal(privKey.D.toString(), f.D)
|
||||
|
@ -51,18 +51,18 @@ describe('ECKey', function() {
|
|||
})
|
||||
|
||||
fixtures.invalid.WIF.forEach(function(f) {
|
||||
it('throws on ' + f.description, function() {
|
||||
it('throws on ' + f.string, function() {
|
||||
assert.throws(function() {
|
||||
ECKey.fromWIF(f.string)
|
||||
})
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('toWIF', function() {
|
||||
it('matches the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
f.WIFs.forEach(function(wif) {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
f.WIFs.forEach(function(wif) {
|
||||
it('exports ' + wif.string + ' correctly', function() {
|
||||
var privKey = ECKey.fromWIF(wif.string)
|
||||
var version = networks[wif.network].wif
|
||||
var result = privKey.toWIF(version)
|
||||
|
|
12
test/fixtures/eckey.json
vendored
12
test/fixtures/eckey.json
vendored
|
@ -68,29 +68,29 @@
|
|||
"invalid": {
|
||||
"constructor": [
|
||||
{
|
||||
"description": "Private key ZERO",
|
||||
"exception": "Private key must be greater than 0",
|
||||
"D": "0"
|
||||
},
|
||||
{
|
||||
"description": "Private key equal to the curve order",
|
||||
"exception": "Private key must be less than the curve order",
|
||||
"D": "115792089237316195423570985008687907852837564279074904382605163141518161494337"
|
||||
},
|
||||
{
|
||||
"description": "Private key greater than the curve order",
|
||||
"exception": "Private key must be less than the curve order",
|
||||
"D": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
|
||||
}
|
||||
],
|
||||
"WIF": [
|
||||
{
|
||||
"description": "Invalid compression flag",
|
||||
"exception": "Invalid compression flag",
|
||||
"string": "ju9rooVsmagsb4qmNyTysUSFB1GB6MdpD7eoGjUTPmZRAApJxRz"
|
||||
},
|
||||
{
|
||||
"description": "Payload too short",
|
||||
"exception": "Invalid WIF payload length",
|
||||
"string": "7ZEtRQLhCsDQrd6ZKfmcESdXgas8ggZPN24ByEi5ey6VJW"
|
||||
},
|
||||
{
|
||||
"description": "Payload too long",
|
||||
"exception": "Invalid WIF payload length",
|
||||
"string": "5qibUKwsnMo1qDiNp3prGaQkD2JfVJa8F8Na87H2CkMHvuVg6uKhw67Rh"
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue