From e03f938cedfba63001547e3519a3c58a1fd3512a Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Fri, 28 Mar 2014 16:42:39 +1100 Subject: [PATCH] Adds failing test for Message.verifyMessage --- test/message.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/message.js b/test/message.js index d48e839..96a999b 100644 --- a/test/message.js +++ b/test/message.js @@ -1,8 +1,7 @@ -/* global describe, it */ var assert = require('assert'); -var Message = require('../src/message.js'); -var ECKey = require('../src/eckey.js').ECKey; -var hexToBytes = require('../src/convert.js').hexToBytes; +var convert = require('../src/convert') +var Message = require('../src/message') +var ECKey = require('../src/eckey').ECKey var priv = '18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725'; var addr = '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'; @@ -11,7 +10,7 @@ var msg = 'foobar'; describe('Message', function() { describe('verify', function() { it('passes case 1', function() { - var key = new ECKey(hexToBytes(priv)); + var key = new ECKey(priv) assert.equal(key.getAddress().toString(), addr); var sig = Message.signMessage(key, msg); @@ -25,14 +24,13 @@ describe('Message', function() { }) it('passes case 2', function() { - var priv = '5HwoXVkHoRM8sL2KmNRS217n1g8mPPBomrY7yehCuXC1115WWsh'; - var key = new ECKey(hexToBytes(priv)); + var key = new ECKey('5HwoXVkHoRM8sL2KmNRS217n1g8mPPBomrY7yehCuXC1115WWsh') var sig = Message.signMessage(key, msg); assert.ok(!Message.verifyMessage(addr, sig, msg)); }) it('handles compressed keys', function() { - var key = new ECKey(hexToBytes(priv)); + var key = new ECKey(priv) key.compressed = true var addr = key.getAddress().toString() @@ -46,5 +44,14 @@ describe('Message', function() { // wrong address assert.ok(!Message.verifyMessage('1MsHWS1BnwMc3tLE8G35UXsS58fKipzB7a', sig, msg)); }) + + it('handle testnet addresses properly', function() { + var addr = 'mgdnNWji2bXYSi7E9c1DQBSp64kCemaS7V' + var msg = 'vires is numeris' + var sig = convert.base64ToBytes('H+7Ohg6VIlPd9GXNHFrqdqsWKHruCTvm9n0ZbDn1B1Q28EB6TlBpTmlWwGEI+rhgjev5VU115XwRD3xRKm6xXQo=') + sig = convert.bytesToHex(sig) + + assert(Message.verifyMessage(addr, sig, msg)) + }) }) })