diff --git a/src/eckey.js b/src/eckey.js index b109ae3..170b9dc 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -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 diff --git a/test/eckey.js b/test/eckey.js index 80afec4..34ce21a 100644 --- a/test/eckey.js +++ b/test/eckey.js @@ -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) diff --git a/test/fixtures/eckey.json b/test/fixtures/eckey.json index 11736ec..923ed42 100644 --- a/test/fixtures/eckey.json +++ b/test/fixtures/eckey.json @@ -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" } ]