diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-03-13 23:34:20 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-03-13 23:34:20 +0800 |
commit | 1cd179f0d2cec70afdde843927b68c16027f2b0c (patch) | |
tree | 486b347ba1f27b7eb72d622bb09c8dcfcd81d061 | |
parent | 0de5ff34fd14777740ac816d6866f7987f955bc6 (diff) | |
parent | 1bb7f3cbc3737bbdf6653d3721d01dc95a217707 (diff) | |
download | dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.tar dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.tar.gz dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.tar.bz2 dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.tar.lz dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.tar.xz dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.tar.zst dexon-solidity-1cd179f0d2cec70afdde843927b68c16027f2b0c.zip |
Merge pull request #1284 from LefterisJP/sol_SBHCleanup
Solidity StringXX and HashXX types change to BytesXX
-rw-r--r-- | SolidityABIJSON.cpp | 10 | ||||
-rw-r--r-- | SolidityEndToEndTest.cpp | 177 | ||||
-rw-r--r-- | SolidityInterface.cpp | 10 | ||||
-rw-r--r-- | SolidityNameAndTypeResolution.cpp | 147 | ||||
-rw-r--r-- | SolidityParser.cpp | 52 |
5 files changed, 256 insertions, 140 deletions
diff --git a/SolidityABIJSON.cpp b/SolidityABIJSON.cpp index 5f67a566..19527013 100644 --- a/SolidityABIJSON.cpp +++ b/SolidityABIJSON.cpp @@ -339,10 +339,10 @@ BOOST_AUTO_TEST_CASE(inherited) char const* sourceCode = " contract Base { \n" " function baseFunction(uint p) returns (uint i) { return p; } \n" - " event baseEvent(string32 indexed evtArgBase); \n" + " event baseEvent(bytes32 indexed evtArgBase); \n" " } \n" " contract Derived is Base { \n" - " function derivedFunction(string32 p) returns (string32 i) { return p; } \n" + " function derivedFunction(bytes32 p) returns (bytes32 i) { return p; } \n" " event derivedEvent(uint indexed evtArgDerived); \n" " }"; @@ -369,12 +369,12 @@ BOOST_AUTO_TEST_CASE(inherited) "inputs": [{ "name": "p", - "type": "string32" + "type": "bytes32" }], "outputs": [{ "name": "i", - "type": "string32" + "type": "bytes32" }] }, { @@ -394,7 +394,7 @@ BOOST_AUTO_TEST_CASE(inherited) [{ "indexed": true, "name": "evtArgBase", - "type": "string32" + "type": "bytes32" }] }])"; diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index 3205c038..2f965849 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -507,23 +507,23 @@ BOOST_AUTO_TEST_CASE(small_signed_types) BOOST_AUTO_TEST_CASE(strings) { char const* sourceCode = "contract test {\n" - " function fixed() returns(string32 ret) {\n" + " function fixed() returns(bytes32 ret) {\n" " return \"abc\\x00\\xff__\";\n" " }\n" - " function pipeThrough(string2 small, bool one) returns(string16 large, bool oneRet) {\n" + " function pipeThrough(bytes2 small, bool one) returns(bytes16 large, bool oneRet) {\n" " oneRet = one;\n" " large = small;\n" " }\n" "}\n"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("fixed()") == encodeArgs(string("abc\0\xff__", 7))); - BOOST_CHECK(callContractFunction("pipeThrough(string2,bool)", string("\0\x02", 2), true) == encodeArgs(string("\0\x2", 2), true)); + BOOST_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true) == encodeArgs(string("\0\x2", 2), true)); } BOOST_AUTO_TEST_CASE(empty_string_on_stack) { char const* sourceCode = "contract test {\n" - " function run(string0 empty, uint8 inp) returns(uint16 a, string0 b, string4 c) {\n" + " function run(bytes0 empty, uint8 inp) returns(uint16 a, bytes0 b, bytes4 c) {\n" " var x = \"abc\";\n" " var y = \"\";\n" " var z = inp;\n" @@ -531,7 +531,7 @@ BOOST_AUTO_TEST_CASE(empty_string_on_stack) " }\n" "}\n"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("run(string0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0"))); + BOOST_CHECK(callContractFunction("run(bytes0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0"))); } BOOST_AUTO_TEST_CASE(state_smoke_test) @@ -948,8 +948,8 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) { char const* sourceCode = "contract test {\n" " uint256 public data;\n" - " string6 public name;\n" - " hash public a_hash;\n" + " bytes6 public name;\n" + " bytes32 public a_hash;\n" " address public an_address;\n" " function test() {\n" " data = 8;\n" @@ -971,7 +971,7 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) BOOST_AUTO_TEST_CASE(complex_accessors) { char const* sourceCode = "contract test {\n" - " mapping(uint256 => string4) public to_string_map;\n" + " mapping(uint256 => bytes4) public to_string_map;\n" " mapping(uint256 => bool) public to_bool_map;\n" " mapping(uint256 => uint256) public to_uint_map;\n" " mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map;\n" @@ -1076,96 +1076,96 @@ BOOST_AUTO_TEST_CASE(type_conversions_cleanup) 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22})); } -BOOST_AUTO_TEST_CASE(convert_string_to_string) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_smaller_size) { char const* sourceCode = R"( contract Test { - function pipeTrough(string3 input) returns (string3 ret) { - return string3(input); + function pipeTrough(bytes3 input) returns (bytes2 ret) { + return bytes2(input); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("pipeTrough(string3)", "abc") == encodeArgs("abc")); + BOOST_CHECK(callContractFunction("pipeTrough(bytes3)", "abc") == encodeArgs("ab")); } -BOOST_AUTO_TEST_CASE(convert_hash_to_string_same_size) +BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size) { char const* sourceCode = R"( contract Test { - function hashToString(hash h) returns (string32 s) { - return string32(h); + function uintToBytes(uint256 h) returns (bytes32 s) { + return bytes32(h); } })"; compileAndRun(sourceCode); u256 a("0x6162630000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK(callContractFunction("hashToString(hash256)", a) == encodeArgs(a)); + BOOST_CHECK(callContractFunction("uintToBytes(uint256)", a) == encodeArgs(a)); } -BOOST_AUTO_TEST_CASE(convert_hash_to_string_different_size) +BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_different_size) { char const* sourceCode = R"( contract Test { - function hashToString(hash160 h) returns (string20 s) { - return string20(h); + function uintToBytes(uint160 h) returns (bytes20 s) { + return bytes20(h); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("hashToString(hash160)", u160("0x6161626361626361626361616263616263616263")) == - encodeArgs(string("aabcabcabcaabcabcabc"))); + BOOST_CHECK(callContractFunction("uintToBytes(uint160)", + u160("0x6161626361626361626361616263616263616263")) == encodeArgs(string("aabcabcabcaabcabcabc"))); } -BOOST_AUTO_TEST_CASE(convert_string_to_hash_same_size) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size) { char const* sourceCode = R"( contract Test { - function stringToHash(string32 s) returns (hash h) { - return hash(s); + function bytesToUint(bytes32 s) returns (uint256 h) { + return uint(s); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("stringToHash(string32)", string("abc2")) == - encodeArgs(u256("0x6162633200000000000000000000000000000000000000000000000000000000"))); + BOOST_CHECK(callContractFunction("bytesToUint(bytes32)", string("abc2")) == + encodeArgs(u256("0x6162633200000000000000000000000000000000000000000000000000000000"))); } -BOOST_AUTO_TEST_CASE(convert_string_to_hash_different_size) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_different_size) { char const* sourceCode = R"( contract Test { - function stringToHash(string20 s) returns (hash160 h) { - return hash160(s); + function bytesToUint(bytes20 s) returns (uint160 h) { + return uint160(s); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("stringToHash(string20)", string("aabcabcabcaabcabcabc")) == - encodeArgs(u160("0x6161626361626361626361616263616263616263"))); + BOOST_CHECK(callContractFunction("bytesToUint(bytes20)", string("aabcabcabcaabcabcabc")) == + encodeArgs(u160("0x6161626361626361626361616263616263616263"))); } -BOOST_AUTO_TEST_CASE(convert_string_to_hash_different_min_size) +BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_different_min_size) { char const* sourceCode = R"( contract Test { - function stringToHash(string1 s) returns (hash8 h) { - return hash8(s); + function bytesToUint(bytes1 s) returns (uint8 h) { + return uint8(s); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("stringToHash(string1)", string("a")) == - encodeArgs(u256("0x61"))); + BOOST_CHECK(callContractFunction("bytesToUint(bytes1)", string("a")) == + encodeArgs(u256("0x61"))); } -BOOST_AUTO_TEST_CASE(convert_hash_to_string_different_min_size) +BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_different_min_size) { char const* sourceCode = R"( contract Test { - function HashToString(hash8 h) returns (string1 s) { - return string1(h); + function UintToBytes(uint8 h) returns (bytes1 s) { + return bytes1(h); } })"; compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("HashToString(hash8)", u256("0x61")) == - encodeArgs(string("a"))); + BOOST_CHECK(callContractFunction("UintToBytes(uint8)", u256("0x61")) == + encodeArgs(string("a"))); } BOOST_AUTO_TEST_CASE(send_ether) @@ -1299,7 +1299,7 @@ BOOST_AUTO_TEST_CASE(suicide) BOOST_AUTO_TEST_CASE(sha3) { char const* sourceCode = "contract test {\n" - " function a(hash input) returns (hash sha3hash) {\n" + " function a(bytes32 input) returns (bytes32 sha3hash) {\n" " return sha3(input);\n" " }\n" "}\n"; @@ -1308,15 +1308,15 @@ BOOST_AUTO_TEST_CASE(sha3) { return dev::sha3(toBigEndian(_x)); }; - testSolidityAgainstCpp("a(hash256)", f, u256(4)); - testSolidityAgainstCpp("a(hash256)", f, u256(5)); - testSolidityAgainstCpp("a(hash256)", f, u256(-1)); + testSolidityAgainstCpp("a(bytes32)", f, u256(4)); + testSolidityAgainstCpp("a(bytes32)", f, u256(5)); + testSolidityAgainstCpp("a(bytes32)", f, u256(-1)); } BOOST_AUTO_TEST_CASE(sha256) { char const* sourceCode = "contract test {\n" - " function a(hash input) returns (hash sha256hash) {\n" + " function a(bytes32 input) returns (bytes32 sha256hash) {\n" " return sha256(input);\n" " }\n" "}\n"; @@ -1327,15 +1327,15 @@ BOOST_AUTO_TEST_CASE(sha256) dev::sha256(dev::ref(toBigEndian(_input)), bytesRef(&ret[0], 32)); return ret; }; - testSolidityAgainstCpp("a(hash256)", f, u256(4)); - testSolidityAgainstCpp("a(hash256)", f, u256(5)); - testSolidityAgainstCpp("a(hash256)", f, u256(-1)); + testSolidityAgainstCpp("a(bytes32)", f, u256(4)); + testSolidityAgainstCpp("a(bytes32)", f, u256(5)); + testSolidityAgainstCpp("a(bytes32)", f, u256(-1)); } BOOST_AUTO_TEST_CASE(ripemd) { char const* sourceCode = "contract test {\n" - " function a(hash input) returns (hash sha256hash) {\n" + " function a(bytes32 input) returns (bytes32 sha256hash) {\n" " return ripemd160(input);\n" " }\n" "}\n"; @@ -1346,15 +1346,15 @@ BOOST_AUTO_TEST_CASE(ripemd) dev::ripemd160(dev::ref(toBigEndian(_input)), bytesRef(&ret[0], 32)); return u256(ret) >> (256 - 160); }; - testSolidityAgainstCpp("a(hash256)", f, u256(4)); - testSolidityAgainstCpp("a(hash256)", f, u256(5)); - testSolidityAgainstCpp("a(hash256)", f, u256(-1)); + testSolidityAgainstCpp("a(bytes32)", f, u256(4)); + testSolidityAgainstCpp("a(bytes32)", f, u256(5)); + testSolidityAgainstCpp("a(bytes32)", f, u256(-1)); } BOOST_AUTO_TEST_CASE(ecrecover) { char const* sourceCode = "contract test {\n" - " function a(hash h, uint8 v, hash r, hash s) returns (address addr) {\n" + " function a(bytes32 h, uint8 v, bytes32 r, bytes32 s) returns (address addr) {\n" " return ecrecover(h, v, r, s);\n" " }\n" "}\n"; @@ -1364,7 +1364,7 @@ BOOST_AUTO_TEST_CASE(ecrecover) u256 r("0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f"); u256 s("0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549"); u160 addr("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"); - BOOST_CHECK(callContractFunction("a(hash256,uint8,hash256,hash256)", h, v, r, s) == encodeArgs(addr)); + BOOST_CHECK(callContractFunction("a(bytes32,uint8,bytes32,bytes32)", h, v, r, s) == encodeArgs(addr)); } BOOST_AUTO_TEST_CASE(inter_contract_calls) @@ -1524,17 +1524,17 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b + 9)); } -BOOST_AUTO_TEST_CASE(strings_in_calls) +BOOST_AUTO_TEST_CASE(fixed_bytes_in_calls) { char const* sourceCode = R"( contract Helper { - function invoke(string3 x, bool stop) returns (string4 ret) { + function invoke(bytes3 x, bool stop) returns (bytes4 ret) { return x; } } contract Main { Helper h; - function callHelper(string2 x, bool stop) returns (string5 ret) { + function callHelper(bytes2 x, bool stop) returns (bytes5 ret) { return h.invoke(x, stop); } function getHelper() returns (address addr) { @@ -1549,21 +1549,21 @@ BOOST_AUTO_TEST_CASE(strings_in_calls) compileAndRun(sourceCode, 0, "Main"); BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes()); BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress)); - BOOST_CHECK(callContractFunction("callHelper(string2,bool)", string("\0a", 2), true) == encodeArgs(string("\0a\0\0\0", 5))); + BOOST_CHECK(callContractFunction("callHelper(bytes2,bool)", string("\0a", 2), true) == encodeArgs(string("\0a\0\0\0", 5))); } BOOST_AUTO_TEST_CASE(constructor_arguments) { char const* sourceCode = R"( contract Helper { - string3 name; + bytes3 name; bool flag; - function Helper(string3 x, bool f) { + function Helper(bytes3 x, bool f) { name = x; flag = f; } - function getName() returns (string3 ret) { return name; } + function getName() returns (bytes3 ret) { return name; } function getFlag() returns (bool ret) { return flag; } } contract Main { @@ -1572,7 +1572,7 @@ BOOST_AUTO_TEST_CASE(constructor_arguments) h = new Helper("abc", true); } function getFlag() returns (bool ret) { return h.getFlag(); } - function getName() returns (string3 ret) { return h.getName(); } + function getName() returns (bytes3 ret) { return h.getName(); } })"; compileAndRun(sourceCode, 0, "Main"); BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true)); @@ -1583,13 +1583,13 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) { char const* sourceCode = R"( contract Test { - string3 name; + bytes3 name; bool flag; function Test() { setName("abc"); } - function getName() returns (string3 ret) { return name; } - function setName(string3 _name) private { name = _name; } + function getName() returns (bytes3 ret) { return name; } + function setName(bytes3 _name) private { name = _name; } })"; compileAndRun(sourceCode); BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); @@ -1697,13 +1697,13 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) { char const* sourceCode = R"( contract Helper { - string3 name; + bytes3 name; bool flag; - function Helper(string3 x, bool f) { + function Helper(bytes3 x, bool f) { name = x; flag = f; } - function getName() returns (string3 ret) { return name; } + function getName() returns (bytes3 ret) { return name; } function getFlag() returns (bool ret) { return flag; } } contract Main { @@ -1712,7 +1712,7 @@ BOOST_AUTO_TEST_CASE(value_for_constructor) h = new Helper.value(10)("abc", true); } function getFlag() returns (bool ret) { return h.getFlag(); } - function getName() returns (string3 ret) { return h.getName(); } + function getName() returns (bytes3 ret) { return h.getName(); } function getBalances() returns (uint me, uint them) { me = this.balance; them = h.balance;} })"; compileAndRun(sourceCode, 22, "Main"); @@ -2090,13 +2090,13 @@ BOOST_AUTO_TEST_CASE(event) { char const* sourceCode = R"( contract ClientReceipt { - event Deposit(address indexed _from, hash indexed _id, uint _value); - function deposit(hash _id, bool _manually) { + event Deposit(address indexed _from, bytes32 indexed _id, uint _value); + function deposit(bytes32 _id, bool _manually) { if (_manually) { - hash s = 0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20; - log3(msg.value, s, hash32(msg.sender), _id); + bytes32 s = 0x19dacbf83c5de6658e14cbf7bcae5c15eca2eedecf1c66fbca928e4d351bea0f; + log3(bytes32(msg.value), s, bytes32(msg.sender), _id); } else - Deposit(hash32(msg.sender), _id, msg.value); + Deposit(msg.sender, _id, msg.value); } } )"; @@ -2105,12 +2105,12 @@ BOOST_AUTO_TEST_CASE(event) u256 id(0x1234); for (bool manually: {true, false}) { - callContractFunctionWithValue("deposit(hash256,bool)", value, id, manually); + callContractFunctionWithValue("deposit(bytes32,bool)", value, id, manually); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(value))); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 3); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,hash256,uint256)"))); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,bytes32,uint256)"))); BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender)); BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(id)); } @@ -2139,21 +2139,21 @@ BOOST_AUTO_TEST_CASE(event_lots_of_data) { char const* sourceCode = R"( contract ClientReceipt { - event Deposit(address _from, hash _id, uint _value, bool _flag); - function deposit(hash _id) { - Deposit(msg.sender, hash32(_id), msg.value, true); + event Deposit(address _from, bytes32 _id, uint _value, bool _flag); + function deposit(bytes32 _id) { + Deposit(msg.sender, _id, msg.value, true); } } )"; compileAndRun(sourceCode); u256 value(18); u256 id(0x1234); - callContractFunctionWithValue("deposit(hash256)", value, id); + callContractFunctionWithValue("deposit(bytes32)", value, id); BOOST_REQUIRE_EQUAL(m_logs.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK(m_logs[0].data == encodeArgs((u160)m_sender, id, value, true)); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,hash256,uint256,bool)"))); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,bytes32,uint256,bool)"))); } BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one) @@ -2187,7 +2187,7 @@ BOOST_AUTO_TEST_CASE(sha3_multiple_arguments) { char const* sourceCode = R"( contract c { - function foo(uint a, uint b, uint c) returns (hash d) + function foo(uint a, uint b, uint c) returns (bytes32 d) { d = sha3(a, b, c); } @@ -2205,7 +2205,7 @@ BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_numeric_literals) { char const* sourceCode = R"( contract c { - function foo(uint a, uint16 b) returns (hash d) + function foo(uint a, uint16 b) returns (bytes32 d) { d = sha3(a, b, 145); } @@ -2223,11 +2223,11 @@ BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_string_literals) { char const* sourceCode = R"( contract c { - function foo() returns (hash d) + function foo() returns (bytes32 d) { d = sha3("foo"); } - function bar(uint a, uint16 b) returns (hash d) + function bar(uint a, uint16 b) returns (bytes32 d) { d = sha3(a, b, 145, "foo"); } @@ -2254,7 +2254,7 @@ BOOST_AUTO_TEST_CASE(generic_call) contract sender { function doSend(address rec) returns (uint d) { - string4 signature = string4(string32(sha3("receive(uint256)"))); + bytes4 signature = bytes4(bytes32(sha3("receive(uint256)"))); rec.call.value(2)(signature, 23); return receiver(rec).received(); } @@ -2290,7 +2290,7 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) { char const* sourceCode = R"( contract C { - function() returns (hash) { + function() returns (bytes32) { return sha3("abc", msg.data); } } @@ -3181,7 +3181,6 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap) BOOST_CHECK(callContractFunction("m_i()") == encodeArgs(4)); } - BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityInterface.cpp b/SolidityInterface.cpp index ecab64c8..48e2fd7a 100644 --- a/SolidityInterface.cpp +++ b/SolidityInterface.cpp @@ -84,10 +84,10 @@ BOOST_AUTO_TEST_CASE(single_function) BOOST_AUTO_TEST_CASE(single_constant_function) { ContractDefinition const& contract = checkInterface( - "contract test { function f(uint a) constant returns(hash8 x) { 1==2; } }"); + "contract test { function f(uint a) constant returns(bytes1 x) { 1==2; } }"); BOOST_REQUIRE_EQUAL(1, contract.getDefinedFunctions().size()); BOOST_CHECK_EQUAL(getSourcePart(*contract.getDefinedFunctions().front()), - "function f(uint256 a)constant returns(hash8 x){}"); + "function f(uint256 a)constant returns(bytes1 x){}"); } BOOST_AUTO_TEST_CASE(multiple_functions) @@ -128,15 +128,15 @@ BOOST_AUTO_TEST_CASE(inheritance) char const* sourceCode = " contract Base { \n" " function baseFunction(uint p) returns (uint i) { return p; } \n" - " event baseEvent(string32 indexed evtArgBase); \n" + " event baseEvent(bytes32 indexed evtArgBase); \n" " } \n" " contract Derived is Base { \n" - " function derivedFunction(string32 p) returns (string32 i) { return p; } \n" + " function derivedFunction(bytes32 p) returns (bytes32 i) { return p; } \n" " event derivedEvent(uint indexed evtArgDerived); \n" " }"; ContractDefinition const& contract = checkInterface(sourceCode); set<string> expectedFunctions({"function baseFunction(uint256 p)returns(uint256 i){}", - "function derivedFunction(string32 p)returns(string32 i){}"}); + "function derivedFunction(bytes32 p)returns(bytes32 i){}"}); BOOST_REQUIRE_EQUAL(2, contract.getDefinedFunctions().size()); BOOST_CHECK(expectedFunctions == set<string>({getSourcePart(*contract.getDefinedFunctions().at(0)), getSourcePart(*contract.getDefinedFunctions().at(1))})); diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index c3a4a337..a310800f 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -75,6 +75,7 @@ static FunctionTypePointer const& retrieveFunctionBySignature(ContractDefinition FixedHash<4> hash(dev::sha3(_signature)); return _contract->getInterfaceFunctions()[hash]; } + } BOOST_AUTO_TEST_SUITE(SolidityNameAndTypeResolution) @@ -353,7 +354,7 @@ BOOST_AUTO_TEST_CASE(function_canonical_signature) " ret = arg1 + arg2;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text)); + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed"); for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) { @@ -366,16 +367,16 @@ BOOST_AUTO_TEST_CASE(function_canonical_signature_type_aliases) { ASTPointer<SourceUnit> sourceUnit; char const* text = "contract Test {\n" - " function boo(uint arg1, hash arg2, address arg3) returns (uint ret) {\n" + " function boo(uint arg1, bytes32 arg2, address arg3) returns (uint ret) {\n" " ret = 5;\n" " }\n" "}\n"; - BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text)); + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed"); for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) { auto functions = contract->getDefinedFunctions(); - BOOST_CHECK_EQUAL("boo(uint256,hash256,address)", functions[0]->getCanonicalSignature()); + BOOST_CHECK_EQUAL("boo(uint256,bytes32,address)", functions[0]->getCanonicalSignature()); } } @@ -537,7 +538,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation) contract B { function f() mod1(2, true) mod2("0123456") { } modifier mod1(uint a, bool b) { if (b) _ } - modifier mod2(string7 a) { while (a == "1234567") _ } + modifier mod2(bytes7 a) { while (a == "1234567") _ } } )"; ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); @@ -558,9 +559,9 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_parameters) { char const* text = R"( contract B { - function f(uint8 a) mod1(a, true) mod2(r) returns (string7 r) { } + function f(uint8 a) mod1(a, true) mod2(r) returns (bytes7 r) { } modifier mod1(uint a, bool b) { if (b) _ } - modifier mod2(string7 a) { while (a == "1234567") _ } + modifier mod2(bytes7 a) { while (a == "1234567") _ } } )"; ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); @@ -631,8 +632,8 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) " uint64(2);\n" " }\n" "uint256 public foo;\n" - "mapping(uint=>string4) public map;\n" - "mapping(uint=>mapping(uint=>string4)) public multiple_map;\n" + "mapping(uint=>bytes4) public map;\n" + "mapping(uint=>mapping(uint=>bytes4)) public multiple_map;\n" "}\n"; ASTPointer<SourceUnit> source; @@ -650,7 +651,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) auto params = function->getParameterTypeNames(); BOOST_CHECK_EQUAL(params.at(0), "uint256"); returnParams = function->getReturnParameterTypeNames(); - BOOST_CHECK_EQUAL(returnParams.at(0), "string4"); + BOOST_CHECK_EQUAL(returnParams.at(0), "bytes4"); BOOST_CHECK(function->isConstant()); function = retrieveFunctionBySignature(contract, "multiple_map(uint256,uint256)"); @@ -659,7 +660,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_CHECK_EQUAL(params.at(0), "uint256"); BOOST_CHECK_EQUAL(params.at(1), "uint256"); returnParams = function->getReturnParameterTypeNames(); - BOOST_CHECK_EQUAL(returnParams.at(0), "string4"); + BOOST_CHECK_EQUAL(returnParams.at(0), "bytes4"); BOOST_CHECK(function->isConstant()); } @@ -800,7 +801,7 @@ BOOST_AUTO_TEST_CASE(event) { char const* text = R"( contract c { - event e(uint indexed a, string3 indexed s, bool indexed b); + event e(uint indexed a, bytes3 indexed s, bool indexed b); function f() { e(2, "abc", true); } })"; ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); @@ -810,7 +811,7 @@ BOOST_AUTO_TEST_CASE(event_too_many_indexed) { char const* text = R"( contract c { - event e(uint indexed a, string3 indexed b, bool indexed c, uint indexed d); + event e(uint indexed a, bytes3 indexed b, bool indexed c, uint indexed d); function f() { e(2, "abc", true); } })"; BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); @@ -820,7 +821,7 @@ BOOST_AUTO_TEST_CASE(event_call) { char const* text = R"( contract c { - event e(uint a, string3 indexed s, bool indexed b); + event e(uint a, bytes3 indexed s, bool indexed b); function f() { e(2, "abc", true); } })"; ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); @@ -830,7 +831,7 @@ BOOST_AUTO_TEST_CASE(event_inheritance) { char const* text = R"( contract base { - event e(uint a, string3 indexed s, bool indexed b); + event e(uint a, bytes3 indexed s, bool indexed b); } contract c is base { function f() { e(2, "abc", true); } @@ -1287,6 +1288,122 @@ BOOST_AUTO_TEST_CASE(storage_variable_initialization_with_incorrect_type_string) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName) +{ + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int) == *make_shared<IntegerType>(256, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int8) == *make_shared<IntegerType>(8, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int16) == *make_shared<IntegerType>(16, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int24) == *make_shared<IntegerType>(24, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int32) == *make_shared<IntegerType>(32, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int40) == *make_shared<IntegerType>(40, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int48) == *make_shared<IntegerType>(48, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int56) == *make_shared<IntegerType>(56, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int64) == *make_shared<IntegerType>(64, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int72) == *make_shared<IntegerType>(72, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int80) == *make_shared<IntegerType>(80, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int88) == *make_shared<IntegerType>(88, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int96) == *make_shared<IntegerType>(96, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int104) == *make_shared<IntegerType>(104, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int112) == *make_shared<IntegerType>(112, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int120) == *make_shared<IntegerType>(120, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int128) == *make_shared<IntegerType>(128, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int136) == *make_shared<IntegerType>(136, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int144) == *make_shared<IntegerType>(144, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int152) == *make_shared<IntegerType>(152, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int160) == *make_shared<IntegerType>(160, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int168) == *make_shared<IntegerType>(168, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int176) == *make_shared<IntegerType>(176, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int184) == *make_shared<IntegerType>(184, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int192) == *make_shared<IntegerType>(192, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int200) == *make_shared<IntegerType>(200, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int208) == *make_shared<IntegerType>(208, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int216) == *make_shared<IntegerType>(216, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int224) == *make_shared<IntegerType>(224, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int232) == *make_shared<IntegerType>(232, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int240) == *make_shared<IntegerType>(240, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int248) == *make_shared<IntegerType>(248, IntegerType::Modifier::Signed)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Int256) == *make_shared<IntegerType>(256, IntegerType::Modifier::Signed)); + + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt8) == *make_shared<IntegerType>(8, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt16) == *make_shared<IntegerType>(16, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt24) == *make_shared<IntegerType>(24, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt32) == *make_shared<IntegerType>(32, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt40) == *make_shared<IntegerType>(40, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt48) == *make_shared<IntegerType>(48, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt56) == *make_shared<IntegerType>(56, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt64) == *make_shared<IntegerType>(64, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt72) == *make_shared<IntegerType>(72, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt80) == *make_shared<IntegerType>(80, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt88) == *make_shared<IntegerType>(88, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt96) == *make_shared<IntegerType>(96, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt104) == *make_shared<IntegerType>(104, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt112) == *make_shared<IntegerType>(112, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt120) == *make_shared<IntegerType>(120, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt128) == *make_shared<IntegerType>(128, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt136) == *make_shared<IntegerType>(136, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt144) == *make_shared<IntegerType>(144, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt152) == *make_shared<IntegerType>(152, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt160) == *make_shared<IntegerType>(160, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt168) == *make_shared<IntegerType>(168, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt176) == *make_shared<IntegerType>(176, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt184) == *make_shared<IntegerType>(184, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt192) == *make_shared<IntegerType>(192, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt200) == *make_shared<IntegerType>(200, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt208) == *make_shared<IntegerType>(208, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt216) == *make_shared<IntegerType>(216, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt224) == *make_shared<IntegerType>(224, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt232) == *make_shared<IntegerType>(232, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt240) == *make_shared<IntegerType>(240, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt248) == *make_shared<IntegerType>(248, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt256) == *make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned)); + + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Byte) == *make_shared<FixedBytesType>(1)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes0) == *make_shared<FixedBytesType>(0)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes1) == *make_shared<FixedBytesType>(1)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes2) == *make_shared<FixedBytesType>(2)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes3) == *make_shared<FixedBytesType>(3)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes4) == *make_shared<FixedBytesType>(4)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes5) == *make_shared<FixedBytesType>(5)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes6) == *make_shared<FixedBytesType>(6)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes7) == *make_shared<FixedBytesType>(7)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes8) == *make_shared<FixedBytesType>(8)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes9) == *make_shared<FixedBytesType>(9)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes10) == *make_shared<FixedBytesType>(10)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes11) == *make_shared<FixedBytesType>(11)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes12) == *make_shared<FixedBytesType>(12)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes13) == *make_shared<FixedBytesType>(13)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes14) == *make_shared<FixedBytesType>(14)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes15) == *make_shared<FixedBytesType>(15)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes16) == *make_shared<FixedBytesType>(16)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes17) == *make_shared<FixedBytesType>(17)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes18) == *make_shared<FixedBytesType>(18)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes19) == *make_shared<FixedBytesType>(19)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes20) == *make_shared<FixedBytesType>(20)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes21) == *make_shared<FixedBytesType>(21)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes22) == *make_shared<FixedBytesType>(22)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes23) == *make_shared<FixedBytesType>(23)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes24) == *make_shared<FixedBytesType>(24)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes25) == *make_shared<FixedBytesType>(25)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes26) == *make_shared<FixedBytesType>(26)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes27) == *make_shared<FixedBytesType>(27)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes28) == *make_shared<FixedBytesType>(28)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes29) == *make_shared<FixedBytesType>(29)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes30) == *make_shared<FixedBytesType>(30)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes31) == *make_shared<FixedBytesType>(31)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes32) == *make_shared<FixedBytesType>(32)); +} + +BOOST_AUTO_TEST_CASE(test_byte_is_alias_of_byte1) +{ + char const* text = R"( + contract c { + bytes arr; + function f() { byte a = arr[0];} + })"; + ETH_TEST_REQUIRE_NO_THROW(parseTextAndResolveNames(text), "Type resolving failed"); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 88b86e63..2f5d06ef 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(empty_function) { char const* text = "contract test {\n" " uint256 stateVar;\n" - " function functionName(hash160 arg1, address addr) constant\n" + " function functionName(bytes20 arg1, address addr) constant\n" " returns (int id)\n" " { }\n" "}\n"; @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(single_function_param) { char const* text = "contract test {\n" " uint256 stateVar;\n" - " function functionName(hash hashin) returns (hash hashout) {}\n" + " function functionName(bytes32 input) returns (bytes32 out) {}\n" "}\n"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed."); } @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation) char const* text = "contract test {\n" " uint256 stateVar;\n" " /// This is a test function\n" - " function functionName(hash hashin) returns (hash hashout) {}\n" + " function functionName(bytes32 input) returns (bytes32 out) {}\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(function_normal_comments) char const* text = "contract test {\n" " uint256 stateVar;\n" " // We won't see this comment\n" - " function functionName(hash hashin) returns (hash hashout) {}\n" + " function functionName(bytes32 input) returns (bytes32 out) {}\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); @@ -164,13 +164,13 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) char const* text = "contract test {\n" " uint256 stateVar;\n" " /// This is test function 1\n" - " function functionName1(hash hashin) returns (hash hashout) {}\n" + " function functionName1(bytes32 input) returns (bytes32 out) {}\n" " /// This is test function 2\n" - " function functionName2(hash hashin) returns (hash hashout) {}\n" + " function functionName2(bytes32 input) returns (bytes32 out) {}\n" " // nothing to see here\n" - " function functionName3(hash hashin) returns (hash hashout) {}\n" + " function functionName3(bytes32 input) returns (bytes32 out) {}\n" " /// This is test function 4\n" - " function functionName4(hash hashin) returns (hash hashout) {}\n" + " function functionName4(bytes32 input) returns (bytes32 out) {}\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); @@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation) " uint256 stateVar;\n" " /// This is a test function\n" " /// and it has 2 lines\n" - " function functionName1(hash hashin) returns (hash hashout) {}\n" + " function functionName1(bytes32 input) returns (bytes32 out) {}\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); @@ -217,12 +217,12 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) " var b;\n" " /// I should not interfere with actual natspec comments\n" " uint256 c;\n" - " mapping(address=>hash) d;\n" - " string name = \"Solidity\";" + " mapping(address=>bytes32) d;\n" + " bytes7 name = \"Solidity\";" " }\n" " /// This is a test function\n" " /// and it has 2 lines\n" - " function fun(hash hashin) returns (hash hashout) {}\n" + " function fun(bytes32 input) returns (bytes32 out) {}\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); auto functions = contract->getDefinedFunctions(); @@ -246,8 +246,8 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature) " var b;\n" " /// I should not interfere with actual natspec comments\n" " uint256 c;\n" - " mapping(address=>hash) d;\n" - " string name = \"Solidity\";" + " mapping(address=>bytes32) d;\n" + " bytes7 name = \"Solidity\";" " }\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); @@ -269,8 +269,8 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature) " var b;\n" " /// I should not interfere with actual natspec comments\n" " uint256 c;\n" - " mapping(address=>hash) d;\n" - " string name = \"Solidity\";" + " mapping(address=>bytes32) d;\n" + " bytes7 name = \"Solidity\";" " }\n" "}\n"; ETH_TEST_REQUIRE_NO_THROW(contract = parseText(text), "Parsing failed"); @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(struct_definition) BOOST_AUTO_TEST_CASE(mapping) { char const* text = "contract test {\n" - " mapping(address => string) names;\n" + " mapping(address => bytes32) names;\n" "}\n"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } @@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(mapping_in_struct) " struct test_struct {\n" " address addr;\n" " uint256 count;\n" - " mapping(hash => test_struct) self_reference;\n" + " mapping(bytes32 => test_struct) self_reference;\n" " }\n" "}\n"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) char const* text = "contract test {\n" " struct test_struct {\n" " address addr;\n" - " mapping (uint64 => mapping (hash => uint)) complex_mapping;\n" + " mapping (uint64 => mapping (bytes32 => uint)) complex_mapping;\n" " }\n" "}\n"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(variable_definition) " function fun(uint256 a) {\n" " var b;\n" " uint256 c;\n" - " mapping(address=>hash) d;\n" + " mapping(address=>bytes32) d;\n" " customtype varname;\n" " }\n" "}\n"; @@ -343,8 +343,8 @@ BOOST_AUTO_TEST_CASE(variable_definition_with_initialization) " function fun(uint256 a) {\n" " var b = 2;\n" " uint256 c = 0x87;\n" - " mapping(address=>hash) d;\n" - " string name = \"Solidity\";" + " mapping(address=>bytes32) d;\n" + " bytes7 name = \"Solidity\";" " customtype varname;\n" " }\n" "}\n"; @@ -366,7 +366,7 @@ BOOST_AUTO_TEST_CASE(variable_definition_in_mapping) char const* text = R"( contract test { function fun() { - mapping(var=>hash) d; + mapping(var=>bytes32) d; } } )"; @@ -662,7 +662,7 @@ BOOST_AUTO_TEST_CASE(event_arguments) { char const* text = R"( contract c { - event e(uint a, string32 s); + event e(uint a, bytes32 s); })"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } @@ -671,7 +671,7 @@ BOOST_AUTO_TEST_CASE(event_arguments_indexed) { char const* text = R"( contract c { - event e(uint a, string32 indexed s, bool indexed b); + event e(uint a, bytes32 indexed s, bool indexed b); })"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } @@ -799,7 +799,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_events) { char const* text = R"( contract c { - event e(uint[10] a, string7[8] indexed b, c[3] x); + event e(uint[10] a, bytes7[8] indexed b, c[3] x); })"; ETH_TEST_CHECK_NO_THROW(parseText(text), "Parsing failed"); } |