diff options
author | Gav Wood <i@gavwood.com> | 2014-02-05 01:55:54 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-02-05 01:55:54 +0800 |
commit | 8e90047882d8fb3f6d97b6e7b86532d1b8eec87c (patch) | |
tree | 149aff64ff193a3454df629b7a2cf1d44724360d /rlp.cpp | |
parent | b63fe88df04744e6493728014f8887b60581b2ef (diff) | |
download | dexon-solidity-8e90047882d8fb3f6d97b6e7b86532d1b8eec87c.tar.gz dexon-solidity-8e90047882d8fb3f6d97b6e7b86532d1b8eec87c.tar.zst dexon-solidity-8e90047882d8fb3f6d97b6e7b86532d1b8eec87c.zip |
First effort at new RLP. **UNTESTED**
Diffstat (limited to 'rlp.cpp')
-rw-r--r-- | rlp.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -31,36 +31,36 @@ int rlpTest() assert(asString(rlp(15)) == "\x0f"); // 3-character string - assert(RLP("\x43""dog") == "dog"); - assert(asString(rlp("dog")) == "\x43""dog"); + assert(RLP("\x83""dog") == "dog"); + assert(asString(rlp("dog")) == "\x83""dog"); // 2-item list - string twoItemListString = "\x82\x0f\x43""dog"; + string twoItemListString = "\xc2\x0f\x83""dog"; RLP twoItemList(twoItemListString); assert(twoItemList.itemCount() == 2); assert(twoItemList[0] == 15); assert(twoItemList[1] == "dog"); - assert(asString(rlpList(15, "dog")) == "\x82\x0f\x43""dog"); + assert(asString(rlpList(15, "dog")) == "\xc2\x0f\x83""dog"); + + // null + assert(RLP("\x80") == ""); + assert(asString(rlp("")) == "\x80"); // 1-byte (8-bit) int - assert(RLP("\x18\x45") == 69); - assert(asString(rlp(69)) == "\x18\x45"); + assert(RLP("\x81\x80") == 128); + assert(asString(rlp(128)) == "\x81\x80"); // 2-byte (16-bit) int - assert(RLP("\x19\x01\x01") == 257); - assert(asString(rlp(257)) == "\x19\x01\x01"); + assert(RLP("\x82\x01\x01") == 257); + assert(asString(rlp(257)) == "\x82\x01\x01"); // 32-byte (256-bit) int - assert(RLP("\x37\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") == bigint("0x100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")); + assert(RLP("\xa0\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") == bigint("0x100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")); assert(asString(rlp(bigint("0x100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"))) == "\x37\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"); - // 33-byte (264-bit) int - assert(RLP("\x38\x21\x20\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") == bigint("0x20100102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")); - assert(asString(rlp(bigint("0x20100102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"))) == "\x38\x21\x20\x10\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"); - // 56-character string. - assert(RLP("\x78\x38""Lorem ipsum dolor sit amet, consectetur adipisicing elit") == "Lorem ipsum dolor sit amet, consectetur adipisicing elit"); - assert(asString(rlp("Lorem ipsum dolor sit amet, consectetur adipisicing elit")) == "\x78\x38""Lorem ipsum dolor sit amet, consectetur adipisicing elit"); + assert(RLP("\xb8\x38""Lorem ipsum dolor sit amet, consectetur adipisicing elit") == "Lorem ipsum dolor sit amet, consectetur adipisicing elit"); + assert(asString(rlp("Lorem ipsum dolor sit amet, consectetur adipisicing elit")) == "\xb8\x38""Lorem ipsum dolor sit amet, consectetur adipisicing elit"); return 0; } |