From 1ed36fabdbd54f4d31078c2b0eaa3becc0fe2821 Mon Sep 17 00:00:00 2001 From: Geert Weening Date: Thu, 5 Feb 2015 10:52:34 -0800 Subject: [PATCH] [FIX] unsymmetric memo serializing treat memos as unknown binary, with optionally parsing unsynthesized hint fields --- src/js/ripple/serializedtypes.js | 72 ++++++--------- src/js/ripple/transaction.js | 26 ++++-- test/serializedobject-test.js | 115 +++++------------------- test/transaction-test.js | 148 +++++++++++++++++++++++++------ 4 files changed, 186 insertions(+), 175 deletions(-) diff --git a/src/js/ripple/serializedtypes.js b/src/js/ripple/serializedtypes.js index db24532c51..051abcea13 100644 --- a/src/js/ripple/serializedtypes.js +++ b/src/js/ripple/serializedtypes.js @@ -57,13 +57,9 @@ function convertByteArrayToHex (byte_array) { return sjcl.codec.hex.fromBits(sjcl.codec.bytes.toBits(byte_array)).toUpperCase(); } -function convertStringToHex(string) { - var utf8String = sjcl.codec.utf8String.toBits(string); - return sjcl.codec.hex.fromBits(utf8String).toUpperCase(); -} - function convertHexToString(hexString) { - return sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(hexString)); + var bits = sjcl.codec.hex.toBits(hexString); + return sjcl.codec.utf8String.fromBits(bits); } SerializedType.serialize_varint = function (so, val) { @@ -619,38 +615,9 @@ exports.STMemo = new SerializedType({ // Sort fields keys = sort_fields(keys); - // store that we're dealing with json - var isJson = val.MemoFormat === 'json'; - for (var i=0; i'); var expected = [ - { Memo: { - MemoType: 'testkey', - MemoData: 'testvalue' - }}, - { Memo: { - MemoType: 'testkey2', - MemoData: 'testvalue2' - }}, - { Memo: { - MemoType: 'testkey3', - MemoFormat: 'text/html' - }}, - { Memo: { - MemoData: 'testvalue4' - }}, - { Memo: { - MemoType: 'testkey4', - MemoFormat: 'text/html', - MemoData: '' - }} + { + Memo: { + MemoType: '746573746B6579', + MemoData: '7465737476616C7565' + } + }, + { + Memo: { + MemoType: '746573746B657932', + MemoData: '7465737476616C756532' + } + }, + { + Memo: { + MemoType: '746573746B657933', + MemoFormat: '746578742F68746D6C' + } + }, + { + Memo: { + MemoData: '7465737476616C756534' + } + }, + { + Memo: { + MemoType: '746573746B657934', + MemoFormat: '746578742F68746D6C', + MemoData: '3C68746D6C3E' + } + } ]; assert.deepEqual(transaction.tx_json.Memos, expected); @@ -1178,7 +1266,7 @@ describe('Transaction', function() { assert.deepEqual(transaction.tx_json.Memos, [ { Memo: { - MemoData: 'some_string' + MemoData: '736F6D655F737472696E67' } } ]); @@ -1189,6 +1277,7 @@ describe('Transaction', function() { transaction.tx_json.TransactionType = 'Payment'; var memo = { + memoFormat: 'json', memoData: { string: 'string', int: 1, @@ -1208,7 +1297,8 @@ describe('Transaction', function() { assert.deepEqual(transaction.tx_json.Memos, [ { Memo: { - MemoData: memo.memoData + MemoFormat: '6A736F6E', + MemoData: '7B22737472696E67223A22737472696E67222C22696E74223A312C226172726179223A5B7B22737472696E67223A22737472696E67227D5D2C226F626A656374223A7B22737472696E67223A22737472696E67227D7D' } } ]);