From 93c8006537d0529ff3603aca6df93ded74c4c049 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 25 Jun 2015 12:40:03 +0200 Subject: [PATCH] tests for encoding and decoding prematurely terminated strings and strings containing internal zeros --- test/coder.decodeParam.js | 14 ++++++++++++++ test/coder.encodeParam.js | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/test/coder.decodeParam.js b/test/coder.decodeParam.js index 92c7421..5273f9c 100644 --- a/test/coder.decodeParam.js +++ b/test/coder.decodeParam.js @@ -39,6 +39,20 @@ describe('lib/solidity/coder', function () { test({ type: 'string', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); + test({ type: 'string', expected: '\xc3\xa4\x00\x00\xc3\xa4', + value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000006' + + 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); + test({ type: 'string', expected: '\xc3', + value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + + 'c300000000000000000000000000000000000000000000000000000000000000'}); + test({ type: 'bytes', expected: '0xc3a40000c3a4', + value: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000006' + + 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); + test({ type: 'bytes32', expected: '0xc3a40000c3a40000000000000000000000000000000000000000000000000000', + value: 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); test({ type: 'int[]', expected: [], value: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000000'}); test({ type: 'int[]', expected: [new bn(3)], value: '0000000000000000000000000000000000000000000000000000000000000020' + diff --git a/test/coder.encodeParam.js b/test/coder.encodeParam.js index 7a06d22..a9468c3 100644 --- a/test/coder.encodeParam.js +++ b/test/coder.encodeParam.js @@ -20,13 +20,13 @@ describe('lib/solidity/coder', function () { test({ type: 'int256', value: 1, expected: '0000000000000000000000000000000000000000000000000000000000000001'}); test({ type: 'int256', value: 16, expected: '0000000000000000000000000000000000000000000000000000000000000010'}); test({ type: 'int256', value: -1, expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'}); - test({ type: 'bytes32', value: '0x6761766f66796f726b', + test({ type: 'bytes32', value: '0x6761766f66796f726b', expected: '6761766f66796f726b0000000000000000000000000000000000000000000000'}); test({ type: 'bytes32', value: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b', expected: '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'}); test({ type: 'bytes32', value: '0x02838654a83c213dae3698391eabbd54a5b6e1fb3452bc7fa4ea0dd5c8ce7e29', expected: '02838654a83c213dae3698391eabbd54a5b6e1fb3452bc7fa4ea0dd5c8ce7e29'}); - test({ type: 'bytes', value: '0x6761766f66796f726b', + test({ type: 'bytes', value: '0x6761766f66796f726b', expected: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); @@ -37,6 +37,20 @@ describe('lib/solidity/coder', function () { test({ type: 'string', value: 'gavofyork', expected: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000009' + '6761766f66796f726b0000000000000000000000000000000000000000000000'}); + test({ type: 'bytes', value: '0xc3a40000c3a4', + expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000006' + + 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); + test({ type: 'bytes32', value: '0xc3a40000c3a4', + expected: 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); + test({ type: 'string', value: '\xc3\xa4\x00\x00\xc3\xa4', + expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000006' + + 'c3a40000c3a40000000000000000000000000000000000000000000000000000'}); + test({ type: 'string', value: '\xc3', + expected: '0000000000000000000000000000000000000000000000000000000000000020' + + '0000000000000000000000000000000000000000000000000000000000000001' + + 'c300000000000000000000000000000000000000000000000000000000000000'}); test({ type: 'int[]', value: [], expected: '0000000000000000000000000000000000000000000000000000000000000020' + '0000000000000000000000000000000000000000000000000000000000000000'}); test({ type: 'int[]', value: [3], expected: '0000000000000000000000000000000000000000000000000000000000000020' +