diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-03-19 00:42:11 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-03-19 04:14:45 +0800 |
commit | b278b62fb4850a6aa655f267c15de3e472c11da4 (patch) | |
tree | b74bdc2e0d20cda2a1e9f37dd41eaeb647e88274 | |
parent | cd9785d2ffb8bea54f205384526f3c1bec96b83b (diff) | |
download | dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.tar dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.tar.gz dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.tar.bz2 dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.tar.lz dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.tar.xz dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.tar.zst dexon-solidity-b278b62fb4850a6aa655f267c15de3e472c11da4.zip |
Reorganizing conversion EndToEndTests
- Adding/Renaming tests so that we have one for each of the following:
* FixedBytes to Uint all sizes
* FixedBytes to FixedBytes all sizes
* Uint to FixedBytes all sizes
- Grouped them together location-wise to make more sense
-rw-r--r-- | SolidityEndToEndTest.cpp | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 6ad84341..0bd27a5f 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -1127,45 +1127,43 @@ BOOST_AUTO_TEST_CASE(type_conversions_cleanup) 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22})); } - +// fixed bytes to fixed bytes conversion tests BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_smaller_size) { char const* sourceCode = R"( contract Test { - function pipeTrough(bytes3 input) returns (bytes2 ret) { + function bytesToBytes(bytes4 input) returns (bytes2 ret) { return bytes2(input); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("pipeTrough(bytes3)", "abc") == encodeArgs("ab")); + BOOST_CHECK(callContractFunction("bytesToBytes(bytes4)", "abcd") == encodeArgs("ab")); } -BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_greater_size) { char const* sourceCode = R"( contract Test { - function uintToBytes(uint256 h) returns (bytes32 s) { - return bytes32(h); + function bytesToBytes(bytes2 input) returns (bytes4 ret) { + return bytes4(input); } })"; compileAndRun(sourceCode); - u256 a("0x6162630000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK(callContractFunction("uintToBytes(uint256)", a) == encodeArgs(a)); + BOOST_CHECK(callContractFunction("bytesToBytes(bytes2)", "ab") == encodeArgs("ab")); } -BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_different_size) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function uintToBytes(uint160 h) returns (bytes20 s) { - return bytes20(h); + function bytesToBytes(bytes4 input) returns (bytes4 ret) { + return bytes4(input); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("uintToBytes(uint160)", - u160("0x6161626361626361626361616263616263616263")) == encodeArgs(string("aabcabcabcaabcabcabc"))); + BOOST_CHECK(callContractFunction("bytesToBytes(bytes4)", "abcd") == encodeArgs("abcd")); } - +// fixed bytes to uint conversion tests BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size) { char const* sourceCode = R"( @@ -1179,17 +1177,30 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size) encodeArgs(u256("0x6162633200000000000000000000000000000000000000000000000000000000"))); } -BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_different_size) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_min_size) +{ + char const* sourceCode = R"( + contract Test { + function bytesToUint(bytes1 s) returns (uint8 h) { + return uint8(s); + } + })"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("bytesToUint(bytes1)", string("a")) == + encodeArgs(u256("0x61"))); +} + +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_smaller_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes20 s) returns (uint160 h) { - return uint160(s); + function bytesToUint(bytes4 s) returns (uint16 h) { + return uint16(s); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("bytesToUint(bytes20)", string("aabcabcabcaabcabcabc")) == - encodeArgs(u160("0x6161626361626361626361616263616263616263"))); + BOOST_CHECK(callContractFunction("bytesToUint(bytes4)", string("abcd")) == + encodeArgs(u256("0x6364"))); } BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size) @@ -1204,22 +1215,21 @@ BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size) BOOST_CHECK(callContractFunction("bytesToUint(bytes4)", string("abcd")) == encodeArgs(u256("0x61626364"))); } - -BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_different_min_size) +// uint fixed bytes conversion tests +BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function bytesToUint(bytes1 s) returns (uint8 h) { - return uint8(s); + function uintToBytes(uint256 h) returns (bytes32 s) { + return bytes32(h); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("bytesToUint(bytes1)", string("a")) == - encodeArgs(u256("0x61"))); + u256 a("0x6162630000000000000000000000000000000000000000000000000000000000"); + BOOST_CHECK(callContractFunction("uintToBytes(uint256)", a) == encodeArgs(a)); } - -BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_different_min_size) +BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_min_size) { char const* sourceCode = R"( contract Test { @@ -1232,6 +1242,19 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_different_min_size) encodeArgs(string("a"))); } +BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_smaller_size) +{ + char const* sourceCode = R"( + contract Test { + function uintToBytes(uint32 h) returns (bytes2 s) { + return bytes2(h); + } + })"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("uintToBytes(uint32)", + u160("0x61626364")) == encodeArgs(string("cd"))); +} + BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_greater_size) { char const* sourceCode = R"( |