diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-03-07 07:03:49 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-03-07 07:04:11 +0800 |
commit | 9bd8c5f723abef25b8864457df7207eb361be8e3 (patch) | |
tree | 93ba58224b857f2db55b75caff3ad3159e17dedd /test/unit | |
parent | f9b2c12dc34992deb1ef95f4a1f7572aac4aa1af (diff) | |
download | tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.gz tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.bz2 tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.lz tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.xz tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.tar.zst tangerine-wallet-browser-9bd8c5f723abef25b8864457df7207eb361be8e3.zip |
Render personal_sign messages as utf-8 text
Calls to `personal_sign` are now:
- When hex encoded, preserved as hex encoded, but displayed as utf-8 text.
- When not hex encoded, decoded as utf-8 text as hex for signing.
- The messages proposed for signing are displayed as UTF-8 text.
- When the message cannot be rendered as UTF-8 text, it is displayed as hexadecimal.
Fixes #1173
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/components/binary-renderer-test.js | 25 | ||||
-rw-r--r-- | test/unit/personal-message-manager-test.js | 23 |
2 files changed, 47 insertions, 1 deletions
diff --git a/test/unit/components/binary-renderer-test.js b/test/unit/components/binary-renderer-test.js new file mode 100644 index 000000000..3264faddc --- /dev/null +++ b/test/unit/components/binary-renderer-test.js @@ -0,0 +1,25 @@ +var assert = require('assert') +var BinaryRenderer = require('../../../ui/app/components/binary-renderer') + +describe('BinaryRenderer', function() { + + let binaryRenderer + const message = 'Hello, world!' + const buffer = new Buffer(message, 'utf8') + const hex = buffer.toString('hex') + + beforeEach(function() { + binaryRenderer = new BinaryRenderer() + }) + + it('recovers message', function() { + const result = binaryRenderer.hexToText(hex) + assert.equal(result, message) + }) + + + it('recovers message with hex prefix', function() { + const result = binaryRenderer.hexToText('0x' + hex) + assert.equal(result, message) + }) +}) diff --git a/test/unit/personal-message-manager-test.js b/test/unit/personal-message-manager-test.js index 657d5e675..69d373ed3 100644 --- a/test/unit/personal-message-manager-test.js +++ b/test/unit/personal-message-manager-test.js @@ -4,7 +4,7 @@ const EventEmitter = require('events') const PersonalMessageManager = require('../../app/scripts/lib/personal-message-manager') -describe('Transaction Manager', function() { +describe('Personal Message Manager', function() { let messageManager beforeEach(function() { @@ -86,4 +86,25 @@ describe('Transaction Manager', function() { assert.equal(messageManager.getMsg('2').status, 'approved') }) }) + + describe('#normalizeMsgData', function() { + it('converts text to a utf8 buffer', function() { + var input = 'hello' + var output = messageManager.normalizeMsgdata(input) + assert.equal(output, '68656c6c6f', 'predictably hex encoded') + }) + + it('tolerates a hex prefix', function() { + var input = '0x12' + var output = messageManager.normalizeMsgdata(input) + assert.equal(output, '12', 'prefix stripped') + }) + + it('tolerates normal hex', function() { + var input = '12' + var output = messageManager.normalizeMsgdata(input) + assert.equal(output, '12', 'not modified') + }) + }) + }) |