diff --git a/AccountHolder.cpp b/AccountHolder.cpp
deleted file mode 100644
index e8e42ff18..000000000
--- a/AccountHolder.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
- */
-/**
- * @author Christian R
- * @date 2015
- * Unit tests for the account holder used by the WebThreeStubServer.
- */
-
-#include
-#include
-
-namespace dev
-{
-namespace test
-{
-
-BOOST_AUTO_TEST_SUITE(AccountHolderTest)
-
-BOOST_AUTO_TEST_CASE(ProxyAccountUseCase)
-{
- AccountHolder h = AccountHolder(std::function());
- BOOST_CHECK(h.getAllAccounts().empty());
- BOOST_CHECK(h.getRealAccounts().empty());
- Address addr("abababababababababababababababababababab");
- Address addr2("abababababababababababababababababababab");
- int id = h.addProxyAccount(addr);
- BOOST_CHECK(h.getQueuedTransactions(id).empty());
- // register it again
- int secondID = h.addProxyAccount(addr);
- BOOST_CHECK(h.getQueuedTransactions(secondID).empty());
-
- eth::TransactionSkeleton t1;
- eth::TransactionSkeleton t2;
- t1.from = addr;
- t1.data = fromHex("12345678");
- t2.from = addr;
- t2.data = fromHex("abcdef");
- BOOST_CHECK(h.getQueuedTransactions(id).empty());
- h.queueTransaction(t1);
- BOOST_CHECK_EQUAL(1, h.getQueuedTransactions(id).size());
- h.queueTransaction(t2);
- BOOST_REQUIRE_EQUAL(2, h.getQueuedTransactions(id).size());
-
- // second proxy should not see transactions
- BOOST_CHECK(h.getQueuedTransactions(secondID).empty());
-
- BOOST_CHECK(h.getQueuedTransactions(id)[0].data == t1.data);
- BOOST_CHECK(h.getQueuedTransactions(id)[1].data == t2.data);
-
- h.clearQueue(id);
- BOOST_CHECK(h.getQueuedTransactions(id).empty());
- // removing fails because it never existed
- BOOST_CHECK(!h.removeProxyAccount(secondID));
- BOOST_CHECK(h.removeProxyAccount(id));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index bc14918b8..000000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-cmake_policy(SET CMP0015 NEW)
-
-aux_source_directory(. SRC_LIST)
-list(REMOVE_ITEM SRC_LIST "./createRandomTest.cpp")
-list(REMOVE_ITEM SRC_LIST "./checkRandomTest.cpp")
-
-include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
-include_directories(BEFORE ..)
-include_directories(${Boost_INCLUDE_DIRS})
-include_directories(${CRYPTOPP_INCLUDE_DIRS})
-include_directories(${JSON_RPC_CPP_INCLUDE_DIRS})
-
-
-file(GLOB HEADERS "*.h")
-add_executable(testeth ${SRC_LIST} ${HEADERS})
-add_executable(createRandomTest createRandomTest.cpp vm.cpp TestHelper.cpp)
-add_executable(checkRandomTest checkRandomTest.cpp vm.cpp TestHelper.cpp)
-
-target_link_libraries(testeth ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
-target_link_libraries(testeth ${CURL_LIBRARIES})
-target_link_libraries(testeth ethereum)
-target_link_libraries(testeth ethcore)
-target_link_libraries(testeth secp256k1)
-target_link_libraries(testeth solidity)
-if (NOT HEADLESS)
- target_link_libraries(testeth webthree)
- target_link_libraries(testeth natspec)
-endif()
-if (JSONRPC)
- target_link_libraries(testeth web3jsonrpc)
- target_link_libraries(testeth ${JSON_RPC_CPP_CLIENT_LIBRARIES})
-endif()
-
-target_link_libraries(createRandomTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
-target_link_libraries(createRandomTest ethereum)
-target_link_libraries(createRandomTest ethcore)
-target_link_libraries(checkRandomTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
-target_link_libraries(checkRandomTest ethereum)
-target_link_libraries(checkRandomTest ethcore)
-
diff --git a/ManyFunctions.sol b/ManyFunctions.sol
deleted file mode 100644
index 691d98f46..000000000
--- a/ManyFunctions.sol
+++ /dev/null
@@ -1,1513 +0,0 @@
-
-// Based on input param calls ~100 functions from ~200, random algorithm is really bad.
-contract ManyFunctions {
-
- function start(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**78)
- return left1(r);
- return right1(r);
- }
-
- function finish(uint seed) returns (uint) {
- return seed;
- }
-
- function nextRand(uint seed) returns (uint) {
- var a = 39948330534945941795786356397633709378407037920056054402537049186942880579585;
- return a * seed + 1;
- }
-
- function right100(uint seed) returns (uint) {
- return finish(seed);
- }
-
- function left100(uint seed) returns (uint) {
- return finish(nextRand(seed));
- }
-
- function right1(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**79)
- return right2(r);
- return left2(r);
- }
-
- function left1(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**79)
- return left2(r);
- return right2(r);
- }
-
-
- function right2(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**80)
- return right3(r);
- return left3(r);
- }
-
- function left2(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**80)
- return left3(r);
- return right3(r);
- }
-
-
- function right3(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**81)
- return right4(r);
- return left4(r);
- }
-
- function left3(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**81)
- return left4(r);
- return right4(r);
- }
-
-
- function right4(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**82)
- return right5(r);
- return left5(r);
- }
-
- function left4(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**82)
- return left5(r);
- return right5(r);
- }
-
-
- function right5(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**83)
- return right6(r);
- return left6(r);
- }
-
- function left5(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**83)
- return left6(r);
- return right6(r);
- }
-
-
- function right6(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**84)
- return right7(r);
- return left7(r);
- }
-
- function left6(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**84)
- return left7(r);
- return right7(r);
- }
-
-
- function right7(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**85)
- return right8(r);
- return left8(r);
- }
-
- function left7(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**85)
- return left8(r);
- return right8(r);
- }
-
-
- function right8(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**86)
- return right9(r);
- return left9(r);
- }
-
- function left8(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**86)
- return left9(r);
- return right9(r);
- }
-
-
- function right9(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**87)
- return right10(r);
- return left10(r);
- }
-
- function left9(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**87)
- return left10(r);
- return right10(r);
- }
-
-
- function right10(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**88)
- return right11(r);
- return left11(r);
- }
-
- function left10(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**88)
- return left11(r);
- return right11(r);
- }
-
-
- function right11(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**89)
- return right12(r);
- return left12(r);
- }
-
- function left11(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**89)
- return left12(r);
- return right12(r);
- }
-
-
- function right12(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**90)
- return right13(r);
- return left13(r);
- }
-
- function left12(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**90)
- return left13(r);
- return right13(r);
- }
-
-
- function right13(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**91)
- return right14(r);
- return left14(r);
- }
-
- function left13(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**91)
- return left14(r);
- return right14(r);
- }
-
-
- function right14(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**92)
- return right15(r);
- return left15(r);
- }
-
- function left14(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**92)
- return left15(r);
- return right15(r);
- }
-
-
- function right15(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**93)
- return right16(r);
- return left16(r);
- }
-
- function left15(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**93)
- return left16(r);
- return right16(r);
- }
-
-
- function right16(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**94)
- return right17(r);
- return left17(r);
- }
-
- function left16(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**94)
- return left17(r);
- return right17(r);
- }
-
-
- function right17(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**95)
- return right18(r);
- return left18(r);
- }
-
- function left17(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**95)
- return left18(r);
- return right18(r);
- }
-
-
- function right18(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**96)
- return right19(r);
- return left19(r);
- }
-
- function left18(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**96)
- return left19(r);
- return right19(r);
- }
-
-
- function right19(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**97)
- return right20(r);
- return left20(r);
- }
-
- function left19(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**97)
- return left20(r);
- return right20(r);
- }
-
-
- function right20(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**98)
- return right21(r);
- return left21(r);
- }
-
- function left20(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**98)
- return left21(r);
- return right21(r);
- }
-
-
- function right21(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**99)
- return right22(r);
- return left22(r);
- }
-
- function left21(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**99)
- return left22(r);
- return right22(r);
- }
-
-
- function right22(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**100)
- return right23(r);
- return left23(r);
- }
-
- function left22(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**100)
- return left23(r);
- return right23(r);
- }
-
-
- function right23(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**101)
- return right24(r);
- return left24(r);
- }
-
- function left23(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**101)
- return left24(r);
- return right24(r);
- }
-
-
- function right24(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**102)
- return right25(r);
- return left25(r);
- }
-
- function left24(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**102)
- return left25(r);
- return right25(r);
- }
-
-
- function right25(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**103)
- return right26(r);
- return left26(r);
- }
-
- function left25(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**103)
- return left26(r);
- return right26(r);
- }
-
-
- function right26(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**104)
- return right27(r);
- return left27(r);
- }
-
- function left26(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**104)
- return left27(r);
- return right27(r);
- }
-
-
- function right27(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**105)
- return right28(r);
- return left28(r);
- }
-
- function left27(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**105)
- return left28(r);
- return right28(r);
- }
-
-
- function right28(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**106)
- return right29(r);
- return left29(r);
- }
-
- function left28(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**106)
- return left29(r);
- return right29(r);
- }
-
-
- function right29(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**107)
- return right30(r);
- return left30(r);
- }
-
- function left29(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**107)
- return left30(r);
- return right30(r);
- }
-
-
- function right30(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**108)
- return right31(r);
- return left31(r);
- }
-
- function left30(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**108)
- return left31(r);
- return right31(r);
- }
-
-
- function right31(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**109)
- return right32(r);
- return left32(r);
- }
-
- function left31(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**109)
- return left32(r);
- return right32(r);
- }
-
-
- function right32(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**110)
- return right33(r);
- return left33(r);
- }
-
- function left32(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**110)
- return left33(r);
- return right33(r);
- }
-
-
- function right33(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**111)
- return right34(r);
- return left34(r);
- }
-
- function left33(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**111)
- return left34(r);
- return right34(r);
- }
-
-
- function right34(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**112)
- return right35(r);
- return left35(r);
- }
-
- function left34(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**112)
- return left35(r);
- return right35(r);
- }
-
-
- function right35(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**113)
- return right36(r);
- return left36(r);
- }
-
- function left35(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**113)
- return left36(r);
- return right36(r);
- }
-
-
- function right36(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**114)
- return right37(r);
- return left37(r);
- }
-
- function left36(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**114)
- return left37(r);
- return right37(r);
- }
-
-
- function right37(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**115)
- return right38(r);
- return left38(r);
- }
-
- function left37(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**115)
- return left38(r);
- return right38(r);
- }
-
-
- function right38(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**116)
- return right39(r);
- return left39(r);
- }
-
- function left38(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**116)
- return left39(r);
- return right39(r);
- }
-
-
- function right39(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**117)
- return right40(r);
- return left40(r);
- }
-
- function left39(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**117)
- return left40(r);
- return right40(r);
- }
-
-
- function right40(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**118)
- return right41(r);
- return left41(r);
- }
-
- function left40(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**118)
- return left41(r);
- return right41(r);
- }
-
-
- function right41(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**119)
- return right42(r);
- return left42(r);
- }
-
- function left41(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**119)
- return left42(r);
- return right42(r);
- }
-
-
- function right42(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**120)
- return right43(r);
- return left43(r);
- }
-
- function left42(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**120)
- return left43(r);
- return right43(r);
- }
-
-
- function right43(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**121)
- return right44(r);
- return left44(r);
- }
-
- function left43(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**121)
- return left44(r);
- return right44(r);
- }
-
-
- function right44(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**122)
- return right45(r);
- return left45(r);
- }
-
- function left44(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**122)
- return left45(r);
- return right45(r);
- }
-
-
- function right45(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**123)
- return right46(r);
- return left46(r);
- }
-
- function left45(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**123)
- return left46(r);
- return right46(r);
- }
-
-
- function right46(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**124)
- return right47(r);
- return left47(r);
- }
-
- function left46(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**124)
- return left47(r);
- return right47(r);
- }
-
-
- function right47(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**125)
- return right48(r);
- return left48(r);
- }
-
- function left47(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**125)
- return left48(r);
- return right48(r);
- }
-
-
- function right48(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**126)
- return right49(r);
- return left49(r);
- }
-
- function left48(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**126)
- return left49(r);
- return right49(r);
- }
-
-
- function right49(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**127)
- return right50(r);
- return left50(r);
- }
-
- function left49(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**127)
- return left50(r);
- return right50(r);
- }
-
-
- function right50(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**128)
- return right51(r);
- return left51(r);
- }
-
- function left50(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**128)
- return left51(r);
- return right51(r);
- }
-
-
- function right51(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**129)
- return right52(r);
- return left52(r);
- }
-
- function left51(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**129)
- return left52(r);
- return right52(r);
- }
-
-
- function right52(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**130)
- return right53(r);
- return left53(r);
- }
-
- function left52(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**130)
- return left53(r);
- return right53(r);
- }
-
-
- function right53(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**131)
- return right54(r);
- return left54(r);
- }
-
- function left53(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**131)
- return left54(r);
- return right54(r);
- }
-
-
- function right54(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**132)
- return right55(r);
- return left55(r);
- }
-
- function left54(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**132)
- return left55(r);
- return right55(r);
- }
-
-
- function right55(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**133)
- return right56(r);
- return left56(r);
- }
-
- function left55(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**133)
- return left56(r);
- return right56(r);
- }
-
-
- function right56(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**134)
- return right57(r);
- return left57(r);
- }
-
- function left56(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**134)
- return left57(r);
- return right57(r);
- }
-
-
- function right57(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**135)
- return right58(r);
- return left58(r);
- }
-
- function left57(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**135)
- return left58(r);
- return right58(r);
- }
-
-
- function right58(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**136)
- return right59(r);
- return left59(r);
- }
-
- function left58(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**136)
- return left59(r);
- return right59(r);
- }
-
-
- function right59(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**137)
- return right60(r);
- return left60(r);
- }
-
- function left59(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**137)
- return left60(r);
- return right60(r);
- }
-
-
- function right60(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**138)
- return right61(r);
- return left61(r);
- }
-
- function left60(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**138)
- return left61(r);
- return right61(r);
- }
-
-
- function right61(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**139)
- return right62(r);
- return left62(r);
- }
-
- function left61(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**139)
- return left62(r);
- return right62(r);
- }
-
-
- function right62(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**140)
- return right63(r);
- return left63(r);
- }
-
- function left62(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**140)
- return left63(r);
- return right63(r);
- }
-
-
- function right63(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**141)
- return right64(r);
- return left64(r);
- }
-
- function left63(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**141)
- return left64(r);
- return right64(r);
- }
-
-
- function right64(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**142)
- return right65(r);
- return left65(r);
- }
-
- function left64(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**142)
- return left65(r);
- return right65(r);
- }
-
-
- function right65(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**143)
- return right66(r);
- return left66(r);
- }
-
- function left65(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**143)
- return left66(r);
- return right66(r);
- }
-
-
- function right66(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**144)
- return right67(r);
- return left67(r);
- }
-
- function left66(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**144)
- return left67(r);
- return right67(r);
- }
-
-
- function right67(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**145)
- return right68(r);
- return left68(r);
- }
-
- function left67(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**145)
- return left68(r);
- return right68(r);
- }
-
-
- function right68(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**146)
- return right69(r);
- return left69(r);
- }
-
- function left68(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**146)
- return left69(r);
- return right69(r);
- }
-
-
- function right69(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**147)
- return right70(r);
- return left70(r);
- }
-
- function left69(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**147)
- return left70(r);
- return right70(r);
- }
-
-
- function right70(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**148)
- return right71(r);
- return left71(r);
- }
-
- function left70(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**148)
- return left71(r);
- return right71(r);
- }
-
-
- function right71(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**149)
- return right72(r);
- return left72(r);
- }
-
- function left71(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**149)
- return left72(r);
- return right72(r);
- }
-
-
- function right72(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**150)
- return right73(r);
- return left73(r);
- }
-
- function left72(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**150)
- return left73(r);
- return right73(r);
- }
-
-
- function right73(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**151)
- return right74(r);
- return left74(r);
- }
-
- function left73(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**151)
- return left74(r);
- return right74(r);
- }
-
-
- function right74(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**152)
- return right75(r);
- return left75(r);
- }
-
- function left74(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**152)
- return left75(r);
- return right75(r);
- }
-
-
- function right75(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**153)
- return right76(r);
- return left76(r);
- }
-
- function left75(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**153)
- return left76(r);
- return right76(r);
- }
-
-
- function right76(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**154)
- return right77(r);
- return left77(r);
- }
-
- function left76(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**154)
- return left77(r);
- return right77(r);
- }
-
-
- function right77(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**155)
- return right78(r);
- return left78(r);
- }
-
- function left77(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**155)
- return left78(r);
- return right78(r);
- }
-
-
- function right78(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**156)
- return right79(r);
- return left79(r);
- }
-
- function left78(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**156)
- return left79(r);
- return right79(r);
- }
-
-
- function right79(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**157)
- return right80(r);
- return left80(r);
- }
-
- function left79(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**157)
- return left80(r);
- return right80(r);
- }
-
-
- function right80(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**158)
- return right81(r);
- return left81(r);
- }
-
- function left80(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**158)
- return left81(r);
- return right81(r);
- }
-
-
- function right81(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**159)
- return right82(r);
- return left82(r);
- }
-
- function left81(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**159)
- return left82(r);
- return right82(r);
- }
-
-
- function right82(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**160)
- return right83(r);
- return left83(r);
- }
-
- function left82(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**160)
- return left83(r);
- return right83(r);
- }
-
-
- function right83(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**161)
- return right84(r);
- return left84(r);
- }
-
- function left83(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**161)
- return left84(r);
- return right84(r);
- }
-
-
- function right84(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**162)
- return right85(r);
- return left85(r);
- }
-
- function left84(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**162)
- return left85(r);
- return right85(r);
- }
-
-
- function right85(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**163)
- return right86(r);
- return left86(r);
- }
-
- function left85(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**163)
- return left86(r);
- return right86(r);
- }
-
-
- function right86(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**164)
- return right87(r);
- return left87(r);
- }
-
- function left86(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**164)
- return left87(r);
- return right87(r);
- }
-
-
- function right87(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**165)
- return right88(r);
- return left88(r);
- }
-
- function left87(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**165)
- return left88(r);
- return right88(r);
- }
-
-
- function right88(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**166)
- return right89(r);
- return left89(r);
- }
-
- function left88(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**166)
- return left89(r);
- return right89(r);
- }
-
-
- function right89(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**167)
- return right90(r);
- return left90(r);
- }
-
- function left89(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**167)
- return left90(r);
- return right90(r);
- }
-
-
- function right90(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**168)
- return right91(r);
- return left91(r);
- }
-
- function left90(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**168)
- return left91(r);
- return right91(r);
- }
-
-
- function right91(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**169)
- return right92(r);
- return left92(r);
- }
-
- function left91(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**169)
- return left92(r);
- return right92(r);
- }
-
-
- function right92(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**170)
- return right93(r);
- return left93(r);
- }
-
- function left92(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**170)
- return left93(r);
- return right93(r);
- }
-
-
- function right93(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**171)
- return right94(r);
- return left94(r);
- }
-
- function left93(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**171)
- return left94(r);
- return right94(r);
- }
-
-
- function right94(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**172)
- return right95(r);
- return left95(r);
- }
-
- function left94(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**172)
- return left95(r);
- return right95(r);
- }
-
-
- function right95(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**173)
- return right96(r);
- return left96(r);
- }
-
- function left95(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**173)
- return left96(r);
- return right96(r);
- }
-
-
- function right96(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**174)
- return right97(r);
- return left97(r);
- }
-
- function left96(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**174)
- return left97(r);
- return right97(r);
- }
-
-
- function right97(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**175)
- return right98(r);
- return left98(r);
- }
-
- function left97(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**175)
- return left98(r);
- return right98(r);
- }
-
-
- function right98(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**176)
- return right99(r);
- return left99(r);
- }
-
- function left98(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**176)
- return left99(r);
- return right99(r);
- }
-
-
- function right99(uint seed) returns (uint) {
- var r = nextRand(seed);
- if (r >= 2**177)
- return right100(r);
- return left100(r);
- }
-
- function left99(uint seed) returns (uint) {
- var r = nextRand(nextRand(seed));
- if (r >= 2**177)
- return left100(r);
- return right100(r);
- }
-
-}
\ No newline at end of file
diff --git a/ManyFunctionsGenerator.py b/ManyFunctionsGenerator.py
deleted file mode 100644
index b4f36af0e..000000000
--- a/ManyFunctionsGenerator.py
+++ /dev/null
@@ -1,24 +0,0 @@
-
-n = 100
-
-splitNumBegin = 128 - (n / 2)
-i = 1
-
-template = """
- function right{0}(uint seed) returns (uint) {{
- var r = nextRand(seed);
- if (r >= 2**{2})
- return right{1}(r);
- return left{1}(r);
- }}
-
- function left{0}(uint seed) returns (uint) {{
- var r = nextRand(nextRand(seed));
- if (r >= 2**{2})
- return left{1}(r);
- return right{1}(r);
- }}
-"""
-
-for i in range(1, n):
- print template.format(i, i + 1, i + splitNumBegin)
\ No newline at end of file
diff --git a/MemTrie.cpp b/MemTrie.cpp
deleted file mode 100644
index c3a44e1e5..000000000
--- a/MemTrie.cpp
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file MemTrie.cpp
- * @author Gav Wood
- * @date 2014
- */
-
-#include "MemTrie.h"
-
-#include
-#include
-#include
-using namespace std;
-using namespace dev;
-using namespace dev::eth;
-
-namespace dev
-{
-
-#define ENABLE_DEBUG_PRINT 0
-
-/*/
-#define APPEND_CHILD appendData
-/*/
-#define APPEND_CHILD appendRaw
-/**/
-
-class MemTrieNode
-{
-public:
- MemTrieNode() {}
- virtual ~MemTrieNode() {}
-
- virtual std::string const& at(bytesConstRef _key) const = 0;
- virtual MemTrieNode* insert(bytesConstRef _key, std::string const& _value) = 0;
- virtual MemTrieNode* remove(bytesConstRef _key) = 0;
- void putRLP(RLPStream& _parentStream) const;
-
-#if ENABLE_DEBUG_PRINT
- void debugPrint(std::string const& _indent = "") const { std::cerr << std::hex << hash256() << ":" << std::dec << std::endl; debugPrintBody(_indent); }
-#endif
-
- /// 256-bit hash of the node - this is a SHA-3/256 hash of the RLP of the node.
- h256 hash256() const { RLPStream s; makeRLP(s); return dev::sha3(s.out()); }
- bytes rlp() const { RLPStream s; makeRLP(s); return s.out(); }
- void mark() { m_hash256 = h256(); }
-
-protected:
- virtual void makeRLP(RLPStream& _intoStream) const = 0;
-
-#if ENABLE_DEBUG_PRINT
- virtual void debugPrintBody(std::string const& _indent = "") const = 0;
-#endif
-
- static MemTrieNode* newBranch(bytesConstRef _k1, std::string const& _v1, bytesConstRef _k2, std::string const& _v2);
-
-private:
- mutable h256 m_hash256;
-};
-
-static const std::string c_nullString;
-
-class TrieExtNode: public MemTrieNode
-{
-public:
- TrieExtNode(bytesConstRef _bytes): m_ext(_bytes.begin(), _bytes.end()) {}
-
- bytes m_ext;
-};
-
-class TrieBranchNode: public MemTrieNode
-{
-public:
- TrieBranchNode(std::string const& _value): m_value(_value)
- {
- memset(m_nodes.data(), 0, sizeof(MemTrieNode*) * 16);
- }
-
- TrieBranchNode(byte _i1, MemTrieNode* _n1, std::string const& _value = std::string()): m_value(_value)
- {
- memset(m_nodes.data(), 0, sizeof(MemTrieNode*) * 16);
- m_nodes[_i1] = _n1;
- }
-
- TrieBranchNode(byte _i1, MemTrieNode* _n1, byte _i2, MemTrieNode* _n2)
- {
- memset(m_nodes.data(), 0, sizeof(MemTrieNode*) * 16);
- m_nodes[_i1] = _n1;
- m_nodes[_i2] = _n2;
- }
-
- virtual ~TrieBranchNode()
- {
- for (auto i: m_nodes)
- delete i;
- }
-
-#if ENABLE_DEBUG_PRINT
- virtual void debugPrintBody(std::string const& _indent) const
- {
-
- if (m_value.size())
- std::cerr << _indent << "@: " << m_value << std::endl;
- for (auto i = 0; i < 16; ++i)
- if (m_nodes[i])
- {
- std::cerr << _indent << std::hex << i << ": " << std::dec;
- m_nodes[i]->debugPrint(_indent + " ");
- }
- }
-#endif
-
- virtual std::string const& at(bytesConstRef _key) const override;
- virtual MemTrieNode* insert(bytesConstRef _key, std::string const& _value) override;
- virtual MemTrieNode* remove(bytesConstRef _key) override;
- virtual void makeRLP(RLPStream& _parentStream) const override;
-
-private:
- /// @returns (byte)-1 when no active branches, 16 when multiple active and the index of the active branch otherwise.
- byte activeBranch() const;
-
- MemTrieNode* rejig();
-
- std::array m_nodes;
- std::string m_value;
-};
-
-class TrieLeafNode: public TrieExtNode
-{
-public:
- TrieLeafNode(bytesConstRef _key, std::string const& _value): TrieExtNode(_key), m_value(_value) {}
-
-#if ENABLE_DEBUG_PRINT
- virtual void debugPrintBody(std::string const& _indent) const
- {
- assert(m_value.size());
- std::cerr << _indent;
- if (m_ext.size())
- std::cerr << toHex(m_ext, 1) << ": ";
- else
- std::cerr << "@: ";
- std::cerr << m_value << std::endl;
- }
-#endif
-
- virtual std::string const& at(bytesConstRef _key) const override { return contains(_key) ? m_value : c_nullString; }
- virtual MemTrieNode* insert(bytesConstRef _key, std::string const& _value) override;
- virtual MemTrieNode* remove(bytesConstRef _key) override;
- virtual void makeRLP(RLPStream& _parentStream) const override;
-
-private:
- bool contains(bytesConstRef _key) const { return _key.size() == m_ext.size() && !memcmp(_key.data(), m_ext.data(), _key.size()); }
-
- std::string m_value;
-};
-
-class TrieInfixNode: public TrieExtNode
-{
-public:
- TrieInfixNode(bytesConstRef _key, MemTrieNode* _next): TrieExtNode(_key), m_next(_next) {}
- virtual ~TrieInfixNode() { delete m_next; }
-
-#if ENABLE_DEBUG_PRINT
- virtual void debugPrintBody(std::string const& _indent) const
- {
- std::cerr << _indent << toHex(m_ext, 1) << ": ";
- m_next->debugPrint(_indent + " ");
- }
-#endif
-
- virtual std::string const& at(bytesConstRef _key) const override { assert(m_next); return contains(_key) ? m_next->at(_key.cropped(m_ext.size())) : c_nullString; }
- virtual MemTrieNode* insert(bytesConstRef _key, std::string const& _value) override;
- virtual MemTrieNode* remove(bytesConstRef _key) override;
- virtual void makeRLP(RLPStream& _parentStream) const override;
-
-private:
- bool contains(bytesConstRef _key) const { return _key.size() >= m_ext.size() && !memcmp(_key.data(), m_ext.data(), m_ext.size()); }
-
- MemTrieNode* m_next;
-};
-
-void MemTrieNode::putRLP(RLPStream& _parentStream) const
-{
- RLPStream s;
- makeRLP(s);
- if (s.out().size() < 32)
- _parentStream.APPEND_CHILD(s.out());
- else
- _parentStream << dev::sha3(s.out());
-}
-
-void TrieBranchNode::makeRLP(RLPStream& _intoStream) const
-{
- _intoStream.appendList(17);
- for (auto i: m_nodes)
- if (i)
- i->putRLP(_intoStream);
- else
- _intoStream << "";
- _intoStream << m_value;
-}
-
-void TrieLeafNode::makeRLP(RLPStream& _intoStream) const
-{
- _intoStream.appendList(2) << hexPrefixEncode(m_ext, true) << m_value;
-}
-
-void TrieInfixNode::makeRLP(RLPStream& _intoStream) const
-{
- assert(m_next);
- _intoStream.appendList(2);
- _intoStream << hexPrefixEncode(m_ext, false);
- m_next->putRLP(_intoStream);
-}
-
-MemTrieNode* MemTrieNode::newBranch(bytesConstRef _k1, std::string const& _v1, bytesConstRef _k2, std::string const& _v2)
-{
- unsigned prefix = commonPrefix(_k1, _k2);
-
- MemTrieNode* ret;
- if (_k1.size() == prefix)
- ret = new TrieBranchNode(_k2[prefix], new TrieLeafNode(_k2.cropped(prefix + 1), _v2), _v1);
- else if (_k2.size() == prefix)
- ret = new TrieBranchNode(_k1[prefix], new TrieLeafNode(_k1.cropped(prefix + 1), _v1), _v2);
- else // both continue after split
- ret = new TrieBranchNode(_k1[prefix], new TrieLeafNode(_k1.cropped(prefix + 1), _v1), _k2[prefix], new TrieLeafNode(_k2.cropped(prefix + 1), _v2));
-
- if (prefix)
- // have shared prefix - split.
- ret = new TrieInfixNode(_k1.cropped(0, prefix), ret);
-
- return ret;
-}
-
-std::string const& TrieBranchNode::at(bytesConstRef _key) const
-{
- if (_key.empty())
- return m_value;
- else if (m_nodes[_key[0]] != nullptr)
- return m_nodes[_key[0]]->at(_key.cropped(1));
- return c_nullString;
-}
-
-MemTrieNode* TrieBranchNode::insert(bytesConstRef _key, std::string const& _value)
-{
- assert(_value.size());
- mark();
- if (_key.empty())
- m_value = _value;
- else
- if (!m_nodes[_key[0]])
- m_nodes[_key[0]] = new TrieLeafNode(_key.cropped(1), _value);
- else
- m_nodes[_key[0]] = m_nodes[_key[0]]->insert(_key.cropped(1), _value);
- return this;
-}
-
-MemTrieNode* TrieBranchNode::remove(bytesConstRef _key)
-{
- if (_key.empty())
- if (m_value.size())
- {
- m_value.clear();
- return rejig();
- }
- else {}
- else if (m_nodes[_key[0]] != nullptr)
- {
- m_nodes[_key[0]] = m_nodes[_key[0]]->remove(_key.cropped(1));
- return rejig();
- }
- return this;
-}
-
-MemTrieNode* TrieBranchNode::rejig()
-{
- mark();
- byte n = activeBranch();
-
- if (n == (byte)-1 && m_value.size())
- {
- // switch to leaf
- auto r = new TrieLeafNode(bytesConstRef(), m_value);
- delete this;
- return r;
- }
- else if (n < 16 && m_value.empty())
- {
- // only branching to n...
- if (auto b = dynamic_cast(m_nodes[n]))
- {
- // switch to infix
- m_nodes[n] = nullptr;
- delete this;
- return new TrieInfixNode(bytesConstRef(&n, 1), b);
- }
- else
- {
- auto x = dynamic_cast(m_nodes[n]);
- assert(x);
- // include in child
- pushFront(x->m_ext, n);
- m_nodes[n] = nullptr;
- delete this;
- return x;
- }
- }
-
- return this;
-}
-
-byte TrieBranchNode::activeBranch() const
-{
- byte n = (byte)-1;
- for (int i = 0; i < 16; ++i)
- if (m_nodes[i] != nullptr)
- {
- if (n == (byte)-1)
- n = (byte)i;
- else
- return 16;
- }
- return n;
-}
-
-MemTrieNode* TrieInfixNode::insert(bytesConstRef _key, std::string const& _value)
-{
- assert(_value.size());
- mark();
- if (contains(_key))
- {
- m_next = m_next->insert(_key.cropped(m_ext.size()), _value);
- return this;
- }
- else
- {
- unsigned prefix = commonPrefix(_key, m_ext);
- if (prefix)
- {
- // one infix becomes two infixes, then insert into the second
- // instead of pop_front()...
- trimFront(m_ext, prefix);
-
- return new TrieInfixNode(_key.cropped(0, prefix), insert(_key.cropped(prefix), _value));
- }
- else
- {
- // split here.
- auto f = m_ext[0];
- trimFront(m_ext, 1);
- MemTrieNode* n = m_ext.empty() ? m_next : this;
- if (n != this)
- {
- m_next = nullptr;
- delete this;
- }
- TrieBranchNode* ret = new TrieBranchNode(f, n);
- ret->insert(_key, _value);
- return ret;
- }
- }
-}
-
-MemTrieNode* TrieInfixNode::remove(bytesConstRef _key)
-{
- if (contains(_key))
- {
- mark();
- m_next = m_next->remove(_key.cropped(m_ext.size()));
- if (auto p = dynamic_cast(m_next))
- {
- // merge with child...
- m_ext.reserve(m_ext.size() + p->m_ext.size());
- for (auto i: p->m_ext)
- m_ext.push_back(i);
- p->m_ext = m_ext;
- p->mark();
- m_next = nullptr;
- delete this;
- return p;
- }
- if (!m_next)
- {
- delete this;
- return nullptr;
- }
- }
- return this;
-}
-
-MemTrieNode* TrieLeafNode::insert(bytesConstRef _key, std::string const& _value)
-{
- assert(_value.size());
- mark();
- if (contains(_key))
- {
- m_value = _value;
- return this;
- }
- else
- {
- // create new trie.
- auto n = MemTrieNode::newBranch(_key, _value, bytesConstRef(&m_ext), m_value);
- delete this;
- return n;
- }
-}
-
-MemTrieNode* TrieLeafNode::remove(bytesConstRef _key)
-{
- if (contains(_key))
- {
- delete this;
- return nullptr;
- }
- return this;
-}
-
-MemTrie::~MemTrie()
-{
- delete m_root;
-}
-
-h256 MemTrie::hash256() const
-{
- return m_root ? m_root->hash256() : sha3(dev::rlp(bytesConstRef()));
-}
-
-bytes MemTrie::rlp() const
-{
- return m_root ? m_root->rlp() : dev::rlp(bytesConstRef());
-}
-
-void MemTrie::debugPrint()
-{
-#if ENABLE_DEBUG_PRINT
- if (m_root)
- m_root->debugPrint();
-#endif
-}
-
-std::string const& MemTrie::at(std::string const& _key) const
-{
- if (!m_root)
- return c_nullString;
- auto h = asNibbles(_key);
- return m_root->at(bytesConstRef(&h));
-}
-
-void MemTrie::insert(std::string const& _key, std::string const& _value)
-{
- if (_value.empty())
- remove(_key);
- auto h = asNibbles(_key);
- m_root = m_root ? m_root->insert(&h, _value) : new TrieLeafNode(bytesConstRef(&h), _value);
-}
-
-void MemTrie::remove(std::string const& _key)
-{
- if (m_root)
- {
- auto h = asNibbles(_key);
- m_root = m_root->remove(&h);
- }
-}
-
-}
-
diff --git a/MemTrie.h b/MemTrie.h
deleted file mode 100644
index 86b09540f..000000000
--- a/MemTrie.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file MemTrie.h
- * @author Gav Wood
- * @date 2014
- */
-
-#pragma once
-
-#include
-#include
-
-namespace dev
-{
-
-class MemTrieNode;
-
-/**
- * @brief Merkle Patricia Tree "Trie": a modifed base-16 Radix tree.
- */
-class MemTrie
-{
-public:
- MemTrie(): m_root(nullptr) {}
- ~MemTrie();
-
- h256 hash256() const;
- bytes rlp() const;
-
- void debugPrint();
-
- std::string const& at(std::string const& _key) const;
- void insert(std::string const& _key, std::string const& _value);
- void remove(std::string const& _key);
-
-private:
- MemTrieNode* m_root;
-};
-
-}
diff --git a/PerformaceTester.sol b/PerformaceTester.sol
deleted file mode 100644
index 3b1202cea..000000000
--- a/PerformaceTester.sol
+++ /dev/null
@@ -1,17 +0,0 @@
-contract PerformanceTester {
- function ackermann(uint m, uint n) returns (uint) {
- if (m == 0)
- return n + 1;
-
- if (n == 0)
- return ackermann(m - 1, 1);
-
- return ackermann(m - 1, ackermann(m, n - 1));
- }
-
- function fibonacci(uint n) returns (uint) {
- if (n == 0 || n == 1)
- return n;
- return fibonacci(n - 1) + fibonacci(n - 2);
- }
-}
\ No newline at end of file
diff --git a/SolidityABIJSON.cpp b/SolidityABIJSON.cpp
deleted file mode 100644
index 10873b5ab..000000000
--- a/SolidityABIJSON.cpp
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
- */
-/**
- * @author Marek Kotewicz
- * @date 2014
- * Unit tests for the solidity compiler JSON Interface output.
- */
-
-#include
-#include
-#include
-#include
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-class JSONInterfaceChecker
-{
-public:
- JSONInterfaceChecker(): m_compilerStack(false) {}
-
- void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
- {
- try
- {
- m_compilerStack.parse(_code);
- }
- catch(boost::exception const& _e)
- {
- auto msg = std::string("Parsing contract failed with: ") + boost::diagnostic_information(_e);
- BOOST_FAIL(msg);
- }
- std::string generatedInterfaceString = m_compilerStack.getMetadata("", DocumentationType::ABIInterface);
- Json::Value generatedInterface;
- m_reader.parse(generatedInterfaceString, generatedInterface);
- Json::Value expectedInterface;
- m_reader.parse(_expectedInterfaceString, expectedInterface);
- BOOST_CHECK_MESSAGE(expectedInterface == generatedInterface,
- "Expected:\n" << expectedInterface.toStyledString() <<
- "\n but got:\n" << generatedInterface.toStyledString());
- }
-
-private:
- CompilerStack m_compilerStack;
- Json::Reader m_reader;
-};
-
-BOOST_FIXTURE_TEST_SUITE(SolidityABIJSON, JSONInterfaceChecker)
-
-BOOST_AUTO_TEST_CASE(basic_test)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- "}\n";
-
- char const* interface = R"([
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "a",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "d",
- "type": "uint256"
- }
- ]
- }
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(empty_contract)
-{
- char const* sourceCode = "contract test {\n"
- "}\n";
- char const* interface = "[]";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(multiple_methods)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- " function g(uint b) returns(uint e) { return b * 8; }\n"
- "}\n";
-
- char const* interface = R"([
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "a",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "d",
- "type": "uint256"
- }
- ]
- },
- {
- "name": "g",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "b",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "e",
- "type": "uint256"
- }
- ]
- }
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(multiple_params)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a, uint b) returns(uint d) { return a + b; }\n"
- "}\n";
-
- char const* interface = R"([
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "a",
- "type": "uint256"
- },
- {
- "name": "b",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "d",
- "type": "uint256"
- }
- ]
- }
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(multiple_methods_order)
-{
- // methods are expected to be in alpabetical order
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- " function c(uint b) returns(uint e) { return b * 8; }\n"
- "}\n";
-
- char const* interface = R"([
- {
- "name": "c",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "b",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "e",
- "type": "uint256"
- }
- ]
- },
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "a",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "d",
- "type": "uint256"
- }
- ]
- }
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(const_function)
-{
- char const* sourceCode = "contract test {\n"
- " function foo(uint a, uint b) returns(uint d) { return a + b; }\n"
- " function boo(uint32 a) constant returns(uint b) { return a * 4; }\n"
- "}\n";
-
- char const* interface = R"([
- {
- "name": "foo",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "a",
- "type": "uint256"
- },
- {
- "name": "b",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "d",
- "type": "uint256"
- }
- ]
- },
- {
- "name": "boo",
- "constant": true,
- "type": "function",
- "inputs": [{
- "name": "a",
- "type": "uint32"
- }],
- "outputs": [
- {
- "name": "b",
- "type": "uint256"
- }
- ]
- }
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(exclude_fallback_function)
-{
- char const* sourceCode = "contract test { function() {} }";
-
- char const* interface = "[]";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(events)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- " event e1(uint b, address indexed c); \n"
- " event e2(); \n"
- "}\n";
- char const* interface = R"([
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "a",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "d",
- "type": "uint256"
- }
- ]
- },
- {
- "name": "e1",
- "type": "event",
- "inputs": [
- {
- "indexed": false,
- "name": "b",
- "type": "uint256"
- },
- {
- "indexed": true,
- "name": "c",
- "type": "address"
- }
- ]
- },
- {
- "name": "e2",
- "type": "event",
- "inputs": []
- }
-
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-
-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"
- " } \n"
- " contract Derived is Base { \n"
- " function derivedFunction(string32 p) returns (string32 i) { return p; } \n"
- " event derivedEvent(uint indexed evtArgDerived); \n"
- " }";
-
- char const* interface = R"([
- {
- "name": "baseFunction",
- "constant": false,
- "type": "function",
- "inputs":
- [{
- "name": "p",
- "type": "uint256"
- }],
- "outputs":
- [{
- "name": "i",
- "type": "uint256"
- }]
- },
- {
- "name": "derivedFunction",
- "constant": false,
- "type": "function",
- "inputs":
- [{
- "name": "p",
- "type": "string32"
- }],
- "outputs":
- [{
- "name": "i",
- "type": "string32"
- }]
- },
- {
- "name": "derivedEvent",
- "type": "event",
- "inputs":
- [{
- "indexed": true,
- "name": "evtArgDerived",
- "type": "uint256"
- }]
- },
- {
- "name": "baseEvent",
- "type": "event",
- "inputs":
- [{
- "indexed": true,
- "name": "evtArgBase",
- "type": "string32"
- }]
- }])";
-
-
- checkInterface(sourceCode, interface);
-}
-BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
-{
- char const* sourceCode = R"(
- contract test {
- function f(uint, uint k) returns(uint ret_k, uint ret_g){
- uint g = 8;
- ret_k = k;
- ret_g = g;
- }
- })";
-
- char const* interface = R"([
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "",
- "type": "uint256"
- },
- {
- "name": "k",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "ret_k",
- "type": "uint256"
- },
- {
- "name": "ret_g",
- "type": "uint256"
- }
- ]
- }
- ])";
-
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
-{
- char const* sourceCode = R"(
- contract test {
- function f(uint k) returns(uint){
- return k;
- }
- })";
-
- char const* interface = R"([
- {
- "name": "f",
- "constant": false,
- "type": "function",
- "inputs": [
- {
- "name": "k",
- "type": "uint256"
- }
- ],
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ]
- }
- ])";
- checkInterface(sourceCode, interface);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-}
diff --git a/SolidityCompiler.cpp b/SolidityCompiler.cpp
deleted file mode 100644
index 1369b038f..000000000
--- a/SolidityCompiler.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @date 2014
- * Unit tests for the solidity compiler.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-using namespace dev::eth;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-namespace
-{
-
-bytes compileContract(const string& _sourceCode)
-{
- Parser parser;
- ASTPointer sourceUnit;
- BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode))));
- NameAndTypeResolver resolver({});
- resolver.registerDeclarations(*sourceUnit);
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract));
- }
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract));
- }
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- Compiler compiler;
- compiler.compileContract(*contract, map{});
-
- // debug
- //compiler.streamAssembly(cout);
- return compiler.getAssembledBytecode();
- }
- BOOST_FAIL("No contract found in source.");
- return bytes();
-}
-
-/// Checks that @a _compiledCode is present starting from offset @a _offset in @a _expectation.
-/// This is necessary since the compiler will add boilerplate add the beginning that is not
-/// tested here.
-void checkCodePresentAt(bytes const& _compiledCode, bytes const& _expectation, unsigned _offset)
-{
- BOOST_REQUIRE(_compiledCode.size() >= _offset + _expectation.size());
- auto checkStart = _compiledCode.begin() + _offset;
- BOOST_CHECK_EQUAL_COLLECTIONS(checkStart, checkStart + _expectation.size(),
- _expectation.begin(), _expectation.end());
-}
-
-} // end anonymous namespace
-
-BOOST_AUTO_TEST_SUITE(SolidityCompiler)
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { var x = 2; }\n"
- "}\n";
- bytes code = compileContract(sourceCode);
-
- unsigned boilerplateSize = 70;
- bytes expectation({byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x0, // initialize local variable x
- byte(Instruction::PUSH1), 0x2,
- byte(Instruction::SWAP1),
- byte(Instruction::POP),
- byte(Instruction::JUMPDEST),
- byte(Instruction::POP),
- byte(Instruction::JUMP)});
- checkCodePresentAt(code, expectation, boilerplateSize);
-}
-
-BOOST_AUTO_TEST_CASE(ifStatement)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { bool x; if (x) 77; else if (!x) 78; else 79; }"
- "}\n";
- bytes code = compileContract(sourceCode);
- unsigned shift = 57;
- unsigned boilerplateSize = 70;
- bytes expectation({byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x0,
- byte(Instruction::DUP1),
- byte(Instruction::PUSH1), byte(0x1b + shift), // "true" target
- byte(Instruction::JUMPI),
- // new check "else if" condition
- byte(Instruction::DUP1),
- byte(Instruction::ISZERO),
- byte(Instruction::PUSH1), byte(0x13 + shift),
- byte(Instruction::JUMPI),
- // "else" body
- byte(Instruction::PUSH1), 0x4f,
- byte(Instruction::POP),
- byte(Instruction::PUSH1), byte(0x17 + shift), // exit path of second part
- byte(Instruction::JUMP),
- // "else if" body
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x4e,
- byte(Instruction::POP),
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), byte(0x1f + shift),
- byte(Instruction::JUMP),
- // "if" body
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x4d,
- byte(Instruction::POP),
- byte(Instruction::JUMPDEST),
- byte(Instruction::JUMPDEST),
- byte(Instruction::POP),
- byte(Instruction::JUMP)});
- checkCodePresentAt(code, expectation, boilerplateSize);
-}
-
-BOOST_AUTO_TEST_CASE(loops)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { while(true){1;break;2;continue;3;return;4;} }"
- "}\n";
- bytes code = compileContract(sourceCode);
- unsigned shift = 57;
- unsigned boilerplateSize = 70;
- bytes expectation({byte(Instruction::JUMPDEST),
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x1,
- byte(Instruction::ISZERO),
- byte(Instruction::PUSH1), byte(0x21 + shift),
- byte(Instruction::JUMPI),
- byte(Instruction::PUSH1), 0x1,
- byte(Instruction::POP),
- byte(Instruction::PUSH1), byte(0x21 + shift),
- byte(Instruction::JUMP), // break
- byte(Instruction::PUSH1), 0x2,
- byte(Instruction::POP),
- byte(Instruction::PUSH1), byte(0x2 + shift),
- byte(Instruction::JUMP), // continue
- byte(Instruction::PUSH1), 0x3,
- byte(Instruction::POP),
- byte(Instruction::PUSH1), byte(0x22 + shift),
- byte(Instruction::JUMP), // return
- byte(Instruction::PUSH1), 0x4,
- byte(Instruction::POP),
- byte(Instruction::PUSH1), byte(0x2 + shift),
- byte(Instruction::JUMP),
- byte(Instruction::JUMPDEST),
- byte(Instruction::JUMPDEST),
- byte(Instruction::JUMP)});
-
- checkCodePresentAt(code, expectation, boilerplateSize);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
-
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
deleted file mode 100644
index 8c87db2d8..000000000
--- a/SolidityEndToEndTest.cpp
+++ /dev/null
@@ -1,2621 +0,0 @@
-
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @author Gav Wood
- * @date 2014
- * Unit tests for the solidity expression compiler, testing the behaviour of the code.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, ExecutionFramework)
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- "}\n";
- compileAndRun(sourceCode);
- testSolidityAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return a * 7; }, 0, 100);
-}
-
-BOOST_AUTO_TEST_CASE(empty_contract)
-{
- char const* sourceCode = "contract test {\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()).empty());
-}
-
-BOOST_AUTO_TEST_CASE(exp_operator)
-{
- char const* sourceCode = R"(
- contract test {
- function f(uint a) returns(uint d) { return 2 ** a; }
- })";
- compileAndRun(sourceCode);
- testSolidityAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return u256(1 << a.convert_to()); }, 0, 16);
-}
-
-BOOST_AUTO_TEST_CASE(exp_operator_const)
-{
- char const* sourceCode = R"(
- contract test {
- function f() returns(uint d) { return 2 ** 3; }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(8)));
-}
-
-BOOST_AUTO_TEST_CASE(exp_operator_const_signed)
-{
- char const* sourceCode = R"(
- contract test {
- function f() returns(int d) { return (-2) ** 3; }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(-8)));
-}
-
-BOOST_AUTO_TEST_CASE(recursive_calls)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint n) returns(uint nfac) {\n"
- " if (n <= 1) return 1;\n"
- " else return n * f(n - 1);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- function recursive_calls_cpp = [&recursive_calls_cpp](u256 const& n) -> u256
- {
- if (n <= 1)
- return 1;
- else
- return n * recursive_calls_cpp(n - 1);
- };
-
- testSolidityAgainstCppOnRange("f(uint256)", recursive_calls_cpp, 0, 5);
-}
-
-BOOST_AUTO_TEST_CASE(multiple_functions)
-{
- char const* sourceCode = "contract test {\n"
- " function a() returns(uint n) { return 0; }\n"
- " function b() returns(uint n) { return 1; }\n"
- " function c() returns(uint n) { return 2; }\n"
- " function f() returns(uint n) { return 3; }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("a()", bytes()) == toBigEndian(u256(0)));
- BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(1)));
- BOOST_CHECK(callContractFunction("c()", bytes()) == toBigEndian(u256(2)));
- BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(3)));
- BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()) == bytes());
-}
-
-BOOST_AUTO_TEST_CASE(named_args)
-{
- char const* sourceCode = "contract test {\n"
- " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n"
- " function b() returns (uint r) { r = a({a: 1, b: 2, c: 3}); }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123)));
-}
-
-BOOST_AUTO_TEST_CASE(disorder_named_args)
-{
- char const* sourceCode = "contract test {\n"
- " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n"
- " function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123)));
-}
-
-BOOST_AUTO_TEST_CASE(while_loop)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint n) returns(uint nfac) {\n"
- " nfac = 1;\n"
- " var i = 2;\n"
- " while (i <= n) nfac *= i++;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto while_loop_cpp = [](u256 const& n) -> u256
- {
- u256 nfac = 1;
- u256 i = 2;
- while (i <= n)
- nfac *= i++;
-
- return nfac;
- };
-
- testSolidityAgainstCppOnRange("f(uint256)", while_loop_cpp, 0, 5);
-}
-
-BOOST_AUTO_TEST_CASE(break_outside_loop)
-{
- // break and continue outside loops should be simply ignored
- char const* sourceCode = "contract test {\n"
- " function f(uint x) returns(uint y) {\n"
- " break; continue; return 2;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- testSolidityAgainstCpp("f(uint256)", [](u256 const&) -> u256 { return 2; }, u256(0));
-}
-
-BOOST_AUTO_TEST_CASE(nested_loops)
-{
- // tests that break and continue statements in nested loops jump to the correct place
- char const* sourceCode = "contract test {\n"
- " function f(uint x) returns(uint y) {\n"
- " while (x > 1) {\n"
- " if (x == 10) break;\n"
- " while (x > 5) {\n"
- " if (x == 8) break;\n"
- " x--;\n"
- " if (x == 6) continue;\n"
- " return x;\n"
- " }\n"
- " x--;\n"
- " if (x == 3) continue;\n"
- " break;\n"
- " }\n"
- " return x;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto nested_loops_cpp = [](u256 n) -> u256
- {
- while (n > 1)
- {
- if (n == 10)
- break;
- while (n > 5)
- {
- if (n == 8)
- break;
- n--;
- if (n == 6)
- continue;
- return n;
- }
- n--;
- if (n == 3)
- continue;
- break;
- }
-
- return n;
- };
-
- testSolidityAgainstCppOnRange("f(uint256)", nested_loops_cpp, 0, 12);
-}
-
-BOOST_AUTO_TEST_CASE(for_loop)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint n) returns(uint nfac) {\n"
- " nfac = 1;\n"
- " for (var i = 2; i <= n; i++)\n"
- " nfac *= i;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto for_loop_cpp = [](u256 const& n) -> u256
- {
- u256 nfac = 1;
- for (auto i = 2; i <= n; i++)
- nfac *= i;
- return nfac;
- };
-
- testSolidityAgainstCppOnRange("f(uint256)", for_loop_cpp, 0, 5);
-}
-
-BOOST_AUTO_TEST_CASE(for_loop_empty)
-{
- char const* sourceCode = "contract test {\n"
- " function f() returns(uint ret) {\n"
- " ret = 1;\n"
- " for (;;)\n"
- " {\n"
- " ret += 1;\n"
- " if (ret >= 10) break;\n"
- " }\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto for_loop_empty_cpp = []() -> u256
- {
- u256 ret = 1;
- for (;;)
- {
- ret += 1;
- if (ret >= 10) break;
- }
- return ret;
- };
-
- testSolidityAgainstCpp("f()", for_loop_empty_cpp);
-}
-
-BOOST_AUTO_TEST_CASE(for_loop_simple_init_expr)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint n) returns(uint nfac) {\n"
- " nfac = 1;\n"
- " uint256 i;\n"
- " for (i = 2; i <= n; i++)\n"
- " nfac *= i;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto for_loop_simple_init_expr_cpp = [](u256 const& n) -> u256
- {
- u256 nfac = 1;
- u256 i;
- for (i = 2; i <= n; i++)
- nfac *= i;
- return nfac;
- };
-
- testSolidityAgainstCppOnRange("f(uint256)", for_loop_simple_init_expr_cpp, 0, 5);
-}
-
-BOOST_AUTO_TEST_CASE(calling_other_functions)
-{
- // note that the index of a function is its index in the sorted sequence of functions
- char const* sourceCode = "contract collatz {\n"
- " function run(uint x) returns(uint y) {\n"
- " while ((y = x) > 1) {\n"
- " if (x % 2 == 0) x = evenStep(x);\n"
- " else x = oddStep(x);\n"
- " }\n"
- " }\n"
- " function evenStep(uint x) returns(uint y) {\n"
- " return x / 2;\n"
- " }\n"
- " function oddStep(uint x) returns(uint y) {\n"
- " return 3 * x + 1;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto evenStep_cpp = [](u256 const& n) -> u256
- {
- return n / 2;
- };
-
- auto oddStep_cpp = [](u256 const& n) -> u256
- {
- return 3 * n + 1;
- };
-
- auto collatz_cpp = [&evenStep_cpp, &oddStep_cpp](u256 n) -> u256
- {
- u256 y;
- while ((y = n) > 1)
- {
- if (n % 2 == 0)
- n = evenStep_cpp(n);
- else
- n = oddStep_cpp(n);
- }
- return y;
- };
-
- testSolidityAgainstCpp("run(uint256)", collatz_cpp, u256(0));
- testSolidityAgainstCpp("run(uint256)", collatz_cpp, u256(1));
- testSolidityAgainstCpp("run(uint256)", collatz_cpp, u256(2));
- testSolidityAgainstCpp("run(uint256)", collatz_cpp, u256(8));
- testSolidityAgainstCpp("run(uint256)", collatz_cpp, u256(127));
-}
-
-BOOST_AUTO_TEST_CASE(many_local_variables)
-{
- char const* sourceCode = "contract test {\n"
- " function run(uint x1, uint x2, uint x3) returns(uint y) {\n"
- " var a = 0x1; var b = 0x10; var c = 0x100;\n"
- " y = a + b + c + x1 + x2 + x3;\n"
- " y += b + x2;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto f = [](u256 const& x1, u256 const& x2, u256 const& x3) -> u256
- {
- u256 a = 0x1;
- u256 b = 0x10;
- u256 c = 0x100;
- u256 y = a + b + c + x1 + x2 + x3;
- return y + b + x2;
- };
- testSolidityAgainstCpp("run(uint256,uint256,uint256)", f, u256(0x1000), u256(0x10000), u256(0x100000));
-}
-
-BOOST_AUTO_TEST_CASE(packing_unpacking_types)
-{
- char const* sourceCode = "contract test {\n"
- " function run(bool a, uint32 b, uint64 c) returns(uint256 y) {\n"
- " if (a) y = 1;\n"
- " y = y * 0x100000000 | ~b;\n"
- " y = y * 0x10000000000000000 | ~c;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("run(bool,uint32,uint64)", true, fromHex("0f0f0f0f"), fromHex("f0f0f0f0f0f0f0f0"))
- == fromHex("00000000000000000000000000000000000000""01""f0f0f0f0""0f0f0f0f0f0f0f0f"));
-}
-
-BOOST_AUTO_TEST_CASE(packing_signed_types)
-{
- char const* sourceCode = "contract test {\n"
- " function run() returns(int8 y) {\n"
- " uint8 x = 0xfa;\n"
- " return int8(x);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("run()")
- == fromHex("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa"));
-}
-
-BOOST_AUTO_TEST_CASE(multiple_return_values)
-{
- char const* sourceCode = "contract test {\n"
- " function run(bool x1, uint x2) returns(uint y1, bool y2, uint y3) {\n"
- " y1 = x2; y2 = x1;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("run(bool,uint256)", true, 0xcd) == encodeArgs(0xcd, true, 0));
-}
-
-BOOST_AUTO_TEST_CASE(short_circuiting)
-{
- char const* sourceCode = "contract test {\n"
- " function run(uint x) returns(uint y) {\n"
- " x == 0 || ((x = 8) > 0);\n"
- " return x;"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- auto short_circuiting_cpp = [](u256 n) -> u256
- {
- n == 0 || (n = 8) > 0;
- return n;
- };
-
- testSolidityAgainstCppOnRange("run(uint256)", short_circuiting_cpp, 0, 2);
-}
-
-BOOST_AUTO_TEST_CASE(high_bits_cleaning)
-{
- char const* sourceCode = "contract test {\n"
- " function run() returns(uint256 y) {\n"
- " uint32 t = uint32(0xffffffff);\n"
- " uint32 x = t + 10;\n"
- " if (x >= 0xffffffff) return 0;\n"
- " return x;"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto high_bits_cleaning_cpp = []() -> u256
- {
- uint32_t t = uint32_t(0xffffffff);
- uint32_t x = t + 10;
- if (x >= 0xffffffff)
- return 0;
- return x;
- };
- testSolidityAgainstCpp("run()", high_bits_cleaning_cpp);
-}
-
-BOOST_AUTO_TEST_CASE(sign_extension)
-{
- char const* sourceCode = "contract test {\n"
- " function run() returns(uint256 y) {\n"
- " int64 x = -int32(0xff);\n"
- " if (x >= 0xff) return 0;\n"
- " return -uint256(x);"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto sign_extension_cpp = []() -> u256
- {
- int64_t x = -int32_t(0xff);
- if (x >= 0xff)
- return 0;
- return u256(x) * -1;
- };
- testSolidityAgainstCpp("run()", sign_extension_cpp);
-}
-
-BOOST_AUTO_TEST_CASE(small_unsigned_types)
-{
- char const* sourceCode = "contract test {\n"
- " function run() returns(uint256 y) {\n"
- " uint32 t = uint32(0xffffff);\n"
- " uint32 x = t * 0xffffff;\n"
- " return x / 0x100;"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto small_unsigned_types_cpp = []() -> u256
- {
- uint32_t t = uint32_t(0xffffff);
- uint32_t x = t * 0xffffff;
- return x / 0x100;
- };
- testSolidityAgainstCpp("run()", small_unsigned_types_cpp);
-}
-
-BOOST_AUTO_TEST_CASE(small_signed_types)
-{
- char const* sourceCode = "contract test {\n"
- " function run() returns(int256 y) {\n"
- " return -int32(10) * -int64(20);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto small_signed_types_cpp = []() -> u256
- {
- return -int32_t(10) * -int64_t(20);
- };
- testSolidityAgainstCpp("run()", small_signed_types_cpp);
-}
-
-BOOST_AUTO_TEST_CASE(strings)
-{
- char const* sourceCode = "contract test {\n"
- " function fixed() returns(string32 ret) {\n"
- " return \"abc\\x00\\xff__\";\n"
- " }\n"
- " function pipeThrough(string2 small, bool one) returns(string16 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_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"
- " var x = \"abc\";\n"
- " var y = \"\";\n"
- " var z = inp;\n"
- " a = z; b = y; c = x;"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("run(string0,uint8)", string(), byte(0x02)) == encodeArgs(0x2, string(""), string("abc\0")));
-}
-
-BOOST_AUTO_TEST_CASE(state_smoke_test)
-{
- char const* sourceCode = "contract test {\n"
- " uint256 value1;\n"
- " uint256 value2;\n"
- " function get(uint8 which) returns (uint256 value) {\n"
- " if (which == 0) return value1;\n"
- " else return value2;\n"
- " }\n"
- " function set(uint8 which, uint256 value) {\n"
- " if (which == 0) value1 = value;\n"
- " else value2 = value;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(0));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(0));
- BOOST_CHECK(callContractFunction("set(uint8,uint256)", byte(0x00), 0x1234) == encodeArgs());
- BOOST_CHECK(callContractFunction("set(uint8,uint256)", byte(0x01), 0x8765) == encodeArgs());
- BOOST_CHECK(callContractFunction("get(uint8)", byte( 0x00)) == encodeArgs(0x1234));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(0x8765));
- BOOST_CHECK(callContractFunction("set(uint8,uint256)", byte(0x00), 0x3) == encodeArgs());
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(0x3));
-}
-
-BOOST_AUTO_TEST_CASE(compound_assign)
-{
- char const* sourceCode = "contract test {\n"
- " uint value1;\n"
- " uint value2;\n"
- " function f(uint x, uint y) returns (uint w) {\n"
- " uint value3 = y;"
- " value1 += x;\n"
- " value3 *= x;"
- " value2 *= value3 + value1;\n"
- " return value2 += 7;"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- u256 value1;
- u256 value2;
- auto f = [&](u256 const& _x, u256 const& _y) -> u256
- {
- u256 value3 = _y;
- value1 += _x;
- value3 *= _x;
- value2 *= value3 + value1;
- return value2 += 7;
- };
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(0), u256(6));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(1), u256(3));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(2), u256(25));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(3), u256(69));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(4), u256(84));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(5), u256(2));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(6), u256(51));
- testSolidityAgainstCpp("f(uint256,uint256)", f, u256(7), u256(48));
-}
-
-BOOST_AUTO_TEST_CASE(simple_mapping)
-{
- char const* sourceCode = "contract test {\n"
- " mapping(uint8 => uint8) table;\n"
- " function get(uint8 k) returns (uint8 v) {\n"
- " return table[k];\n"
- " }\n"
- " function set(uint8 k, uint8 v) {\n"
- " table[k] = v;\n"
- " }\n"
- "}";
- compileAndRun(sourceCode);
-
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0)) == encodeArgs(byte(0x00)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0x00)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00)));
- callContractFunction("set(uint8,uint8)", byte(0x01), byte(0xa1));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(byte(0x00)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0xa1)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00)));
- callContractFunction("set(uint8,uint8)", byte(0x00), byte(0xef));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(byte(0xef)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0xa1)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00)));
- callContractFunction("set(uint8,uint8)", byte(0x01), byte(0x05));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x00)) == encodeArgs(byte(0xef)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0x01)) == encodeArgs(byte(0x05)));
- BOOST_CHECK(callContractFunction("get(uint8)", byte(0xa7)) == encodeArgs(byte(0x00)));
-}
-
-BOOST_AUTO_TEST_CASE(mapping_state)
-{
- char const* sourceCode = "contract Ballot {\n"
- " mapping(address => bool) canVote;\n"
- " mapping(address => uint) voteCount;\n"
- " mapping(address => bool) voted;\n"
- " function getVoteCount(address addr) returns (uint retVoteCount) {\n"
- " return voteCount[addr];\n"
- " }\n"
- " function grantVoteRight(address addr) {\n"
- " canVote[addr] = true;\n"
- " }\n"
- " function vote(address voter, address vote) returns (bool success) {\n"
- " if (!canVote[voter] || voted[voter]) return false;\n"
- " voted[voter] = true;\n"
- " voteCount[vote] = voteCount[vote] + 1;\n"
- " return true;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- class Ballot
- {
- public:
- u256 getVoteCount(u160 _address) { return m_voteCount[_address]; }
- void grantVoteRight(u160 _address) { m_canVote[_address] = true; }
- bool vote(u160 _voter, u160 _vote)
- {
- if (!m_canVote[_voter] || m_voted[_voter]) return false;
- m_voted[_voter] = true;
- m_voteCount[_vote]++;
- return true;
- }
- private:
- map m_canVote;
- map m_voteCount;
- map m_voted;
- } ballot;
-
- auto getVoteCount = bind(&Ballot::getVoteCount, &ballot, _1);
- auto grantVoteRight = bind(&Ballot::grantVoteRight, &ballot, _1);
- auto vote = bind(&Ballot::vote, &ballot, _1, _2);
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
- // voting without vote right should be rejected
- testSolidityAgainstCpp("vote(address,address)", vote, u160(0), u160(2));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
- // grant vote rights
- testSolidityAgainstCpp("grantVoteRight(address)", grantVoteRight, u160(0));
- testSolidityAgainstCpp("grantVoteRight(address)", grantVoteRight, u160(1));
- // vote, should increase 2's vote count
- testSolidityAgainstCpp("vote(address,address)", vote, u160(0), u160(2));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
- // vote again, should be rejected
- testSolidityAgainstCpp("vote(address,address)", vote, u160(0), u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
- // vote without right to vote
- testSolidityAgainstCpp("vote(address,address)", vote, u160(2), u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
- // grant vote right and now vote again
- testSolidityAgainstCpp("grantVoteRight(address)", grantVoteRight, u160(2));
- testSolidityAgainstCpp("vote(address,address)", vote, u160(2), u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
- testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
-}
-
-BOOST_AUTO_TEST_CASE(mapping_state_inc_dec)
-{
- char const* sourceCode = "contract test {\n"
- " uint value;\n"
- " mapping(uint => uint) table;\n"
- " function f(uint x) returns (uint y) {\n"
- " value = x;\n"
- " if (x > 0) table[++value] = 8;\n"
- " if (x > 1) value--;\n"
- " if (x > 2) table[value]++;\n"
- " return --table[value++];\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- u256 value = 0;
- map table;
- auto f = [&](u256 const& _x) -> u256
- {
- value = _x;
- if (_x > 0)
- table[++value] = 8;
- if (_x > 1)
- value --;
- if (_x > 2)
- table[value]++;
- return --table[value++];
- };
- testSolidityAgainstCppOnRange("f(uint256)", f, 0, 5);
-}
-
-BOOST_AUTO_TEST_CASE(multi_level_mapping)
-{
- char const* sourceCode = "contract test {\n"
- " mapping(uint => mapping(uint => uint)) table;\n"
- " function f(uint x, uint y, uint z) returns (uint w) {\n"
- " if (z == 0) return table[x][y];\n"
- " else return table[x][y] = z;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
-
- map> table;
- auto f = [&](u256 const& _x, u256 const& _y, u256 const& _z) -> u256
- {
- if (_z == 0) return table[_x][_y];
- else return table[_x][_y] = _z;
- };
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(4), u256(5), u256(0));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(5), u256(4), u256(0));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(4), u256(5), u256(9));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(4), u256(5), u256(0));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(5), u256(4), u256(0));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(5), u256(4), u256(7));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(4), u256(5), u256(0));
- testSolidityAgainstCpp("f(uint256,uint256,uint256)", f, u256(5), u256(4), u256(0));
-}
-
-BOOST_AUTO_TEST_CASE(structs)
-{
- char const* sourceCode = "contract test {\n"
- " struct s1 {\n"
- " uint8 x;\n"
- " bool y;\n"
- " }\n"
- " struct s2 {\n"
- " uint32 z;\n"
- " s1 s1data;\n"
- " mapping(uint8 => s2) recursive;\n"
- " }\n"
- " s2 data;\n"
- " function check() returns (bool ok) {\n"
- " return data.z == 1 && data.s1data.x == 2 && \n"
- " data.s1data.y == true && \n"
- " data.recursive[3].recursive[4].z == 5 && \n"
- " data.recursive[4].recursive[3].z == 6 && \n"
- " data.recursive[0].s1data.y == false && \n"
- " data.recursive[4].z == 9;\n"
- " }\n"
- " function set() {\n"
- " data.z = 1;\n"
- " data.s1data.x = 2;\n"
- " data.s1data.y = true;\n"
- " data.recursive[3].recursive[4].z = 5;\n"
- " data.recursive[4].recursive[3].z = 6;\n"
- " data.recursive[0].s1data.y = false;\n"
- " data.recursive[4].z = 9;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("check()") == encodeArgs(false));
- BOOST_CHECK(callContractFunction("set()") == bytes());
- BOOST_CHECK(callContractFunction("check()") == encodeArgs(true));
-}
-
-BOOST_AUTO_TEST_CASE(struct_reference)
-{
- char const* sourceCode = "contract test {\n"
- " struct s2 {\n"
- " uint32 z;\n"
- " mapping(uint8 => s2) recursive;\n"
- " }\n"
- " s2 data;\n"
- " function check() returns (bool ok) {\n"
- " return data.z == 2 && \n"
- " data.recursive[0].z == 3 && \n"
- " data.recursive[0].recursive[1].z == 0 && \n"
- " data.recursive[0].recursive[0].z == 1;\n"
- " }\n"
- " function set() {\n"
- " data.z = 2;\n"
- " var map = data.recursive;\n"
- " s2 inner = map[0];\n"
- " inner.z = 3;\n"
- " inner.recursive[0].z = inner.recursive[1].z + 1;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("check()") == encodeArgs(false));
- BOOST_CHECK(callContractFunction("set()") == bytes());
- BOOST_CHECK(callContractFunction("check()") == encodeArgs(true));
-}
-
-BOOST_AUTO_TEST_CASE(deleteStruct)
-{
- char const* sourceCode = R"(
- contract test {
- struct topStruct {
- nestedStruct nstr;
- emptyStruct empty;
- uint topValue;
- mapping (uint => uint) topMapping;
- }
- uint toDelete;
- topStruct str;
- struct nestedStruct {
- uint nestedValue;
- mapping (uint => bool) nestedMapping;
- }
- struct emptyStruct{
- }
- function test(){
- toDelete = 5;
- str.topValue = 1;
- str.topMapping[0] = 1;
- str.topMapping[1] = 2;
-
- str.nstr.nestedValue = 2;
- str.nstr.nestedMapping[0] = true;
- str.nstr.nestedMapping[1] = false;
- delete str;
- delete toDelete;
- }
- function getToDelete() returns (uint res){
- res = toDelete;
- }
- function getTopValue() returns(uint topValue){
- topValue = str.topValue;
- }
- function getNestedValue() returns(uint nestedValue){
- nestedValue = str.nstr.nestedValue;
- }
- function getTopMapping(uint index) returns(uint ret) {
- ret = str.topMapping[index];
- }
- function getNestedMapping(uint index) returns(bool ret) {
- return str.nstr.nestedMapping[index];
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getToDelete()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("getTopValue()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("getNestedValue()") == encodeArgs(0));
- // mapping values should be the same
- BOOST_CHECK(callContractFunction("getTopMapping(uint256)", 0) == encodeArgs(1));
- BOOST_CHECK(callContractFunction("getTopMapping(uint256)", 1) == encodeArgs(2));
- BOOST_CHECK(callContractFunction("getNestedMapping(uint256)", 0) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("getNestedMapping(uint256)", 1) == encodeArgs(false));
-}
-
-BOOST_AUTO_TEST_CASE(deleteLocal)
-{
- char const* sourceCode = R"(
- contract test {
- function delLocal() returns (uint res){
- uint v = 5;
- delete v;
- res = v;
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("delLocal()") == encodeArgs(0));
-}
-
-BOOST_AUTO_TEST_CASE(deleteLocals)
-{
- char const* sourceCode = R"(
- contract test {
- function delLocal() returns (uint res1, uint res2){
- uint v = 5;
- uint w = 6;
- uint x = 7;
- delete v;
- res1 = w;
- res2 = x;
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("delLocal()") == encodeArgs(6, 7));
-}
-
-BOOST_AUTO_TEST_CASE(constructor)
-{
- char const* sourceCode = "contract test {\n"
- " mapping(uint => uint) data;\n"
- " function test() {\n"
- " data[7] = 8;\n"
- " }\n"
- " function get(uint key) returns (uint value) {\n"
- " return data[key];"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- map data;
- data[7] = 8;
- auto get = [&](u256 const& _x) -> u256
- {
- return data[_x];
- };
- testSolidityAgainstCpp("get(uint256)", get, u256(6));
- testSolidityAgainstCpp("get(uint256)", get, u256(7));
-}
-
-BOOST_AUTO_TEST_CASE(simple_accessor)
-{
- char const* sourceCode = "contract test {\n"
- " uint256 public data;\n"
- " function test() {\n"
- " data = 8;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("data()") == encodeArgs(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"
- " address public an_address;\n"
- " function test() {\n"
- " data = 8;\n"
- " name = \"Celina\";\n"
- " a_hash = sha3(123);\n"
- " an_address = address(0x1337);\n"
- " super_secret_data = 42;\n"
- " }\n"
- " uint256 super_secret_data;"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("data()") == encodeArgs(8));
- BOOST_CHECK(callContractFunction("name()") == encodeArgs("Celina"));
- BOOST_CHECK(callContractFunction("a_hash()") == encodeArgs(dev::sha3(bytes(1, 0x7b))));
- BOOST_CHECK(callContractFunction("an_address()") == encodeArgs(toBigEndian(u160(0x1337))));
- BOOST_CHECK(callContractFunction("super_secret_data()") == bytes());
-}
-
-BOOST_AUTO_TEST_CASE(complex_accessors)
-{
- char const* sourceCode = "contract test {\n"
- " mapping(uint256 => string4) 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"
- " function test() {\n"
- " to_string_map[42] = \"24\";\n"
- " to_bool_map[42] = false;\n"
- " to_uint_map[42] = 12;\n"
- " to_multiple_map[42][23] = 31;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("to_string_map(uint256)", 42) == encodeArgs("24"));
- BOOST_CHECK(callContractFunction("to_bool_map(uint256)", 42) == encodeArgs(false));
- BOOST_CHECK(callContractFunction("to_uint_map(uint256)", 42) == encodeArgs(12));
- BOOST_CHECK(callContractFunction("to_multiple_map(uint256,uint256)", 42, 23) == encodeArgs(31));
-}
-
-BOOST_AUTO_TEST_CASE(struct_accessor)
-{
- char const* sourceCode = R"(
- contract test {
- struct Data { uint a; uint8 b; mapping(uint => uint) c; bool d; }
- mapping(uint => Data) public data;
- function test() {
- data[7].a = 1;
- data[7].b = 2;
- data[7].c[0] = 3;
- data[7].d = true;
- }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("data(uint256)", 7) == encodeArgs(1, 2, true));
-}
-
-BOOST_AUTO_TEST_CASE(balance)
-{
- char const* sourceCode = "contract test {\n"
- " function getBalance() returns (uint256 balance) {\n"
- " return address(this).balance;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode, 23);
- BOOST_CHECK(callContractFunction("getBalance()") == encodeArgs(23));
-}
-
-BOOST_AUTO_TEST_CASE(blockchain)
-{
- char const* sourceCode = "contract test {\n"
- " function someInfo() returns (uint256 value, address coinbase, uint256 blockNumber) {\n"
- " value = msg.value;\n"
- " coinbase = block.coinbase;\n"
- " blockNumber = block.number;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode, 27);
- BOOST_CHECK(callContractFunctionWithValue("someInfo()", 28) == encodeArgs(28, 0, 1));
-}
-
-BOOST_AUTO_TEST_CASE(function_types)
-{
- char const* sourceCode = "contract test {\n"
- " function a(bool selector) returns (uint b) {\n"
- " var f = fun1;\n"
- " if (selector) f = fun2;\n"
- " return f(9);\n"
- " }\n"
- " function fun1(uint x) returns (uint b) {\n"
- " return 11;\n"
- " }\n"
- " function fun2(uint x) returns (uint b) {\n"
- " return 12;\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("a(bool)", false) == encodeArgs(11));
- BOOST_CHECK(callContractFunction("a(bool)", true) == encodeArgs(12));
-}
-
-BOOST_AUTO_TEST_CASE(type_conversions_cleanup)
-{
- // 22-byte integer converted to a contract (i.e. address, 20 bytes), converted to a 32 byte
- // integer should drop the first two bytes
- char const* sourceCode = R"(
- contract Test {
- function test() returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); }
- })";
- compileAndRun(sourceCode);
- BOOST_REQUIRE(callContractFunction("test()") == bytes({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22,
- 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22}));
-}
-
-BOOST_AUTO_TEST_CASE(convert_string_to_string)
-{
- char const* sourceCode = R"(
- contract Test {
- function pipeTrough(string3 input) returns (string3 ret) {
- return string3(input);
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("pipeTrough(string3)", "abc") == encodeArgs("abc"));
-}
-
-BOOST_AUTO_TEST_CASE(convert_hash_to_string_same_size)
-{
- char const* sourceCode = R"(
- contract Test {
- function hashToString(hash h) returns (string32 s) {
- return string32(h);
- }
- })";
- compileAndRun(sourceCode);
- u256 a("0x6162630000000000000000000000000000000000000000000000000000000000");
- BOOST_CHECK(callContractFunction("hashToString(hash256)", a) == encodeArgs(a));
-}
-
-BOOST_AUTO_TEST_CASE(convert_hash_to_string_different_size)
-{
- char const* sourceCode = R"(
- contract Test {
- function hashToString(hash160 h) returns (string20 s) {
- return string20(h);
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("hashToString(hash160)", u160("0x6161626361626361626361616263616263616263")) ==
- encodeArgs(string("aabcabcabcaabcabcabc")));
-}
-
-BOOST_AUTO_TEST_CASE(convert_string_to_hash_same_size)
-{
- char const* sourceCode = R"(
- contract Test {
- function stringToHash(string32 s) returns (hash h) {
- return hash(s);
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("stringToHash(string32)", string("abc2")) ==
- encodeArgs(u256("0x6162633200000000000000000000000000000000000000000000000000000000")));
-}
-
-BOOST_AUTO_TEST_CASE(convert_string_to_hash_different_size)
-{
- char const* sourceCode = R"(
- contract Test {
- function stringToHash(string20 s) returns (hash160 h) {
- return hash160(s);
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("stringToHash(string20)", string("aabcabcabcaabcabcabc")) ==
- encodeArgs(u160("0x6161626361626361626361616263616263616263")));
-}
-
-
-BOOST_AUTO_TEST_CASE(convert_string_to_hash_different_min_size)
-{
- char const* sourceCode = R"(
- contract Test {
- function stringToHash(string1 s) returns (hash8 h) {
- return hash8(s);
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("stringToHash(string1)", string("a")) ==
- encodeArgs(u256("0x61")));
-}
-
-
-BOOST_AUTO_TEST_CASE(convert_hash_to_string_different_min_size)
-{
- char const* sourceCode = R"(
- contract Test {
- function HashToString(hash8 h) returns (string1 s) {
- return string1(h);
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("HashToString(hash8)", u256("0x61")) ==
- encodeArgs(string("a")));
-}
-
-BOOST_AUTO_TEST_CASE(send_ether)
-{
- char const* sourceCode = "contract test {\n"
- " function a(address addr, uint amount) returns (uint ret) {\n"
- " addr.send(amount);\n"
- " return address(this).balance;\n"
- " }\n"
- "}\n";
- u256 amount(130);
- compileAndRun(sourceCode, amount + 1);
- u160 address(23);
- BOOST_CHECK(callContractFunction("a(address,uint256)", address, amount) == encodeArgs(1));
- BOOST_CHECK_EQUAL(m_state.balance(address), amount);
-}
-
-BOOST_AUTO_TEST_CASE(log0)
-{
- char const* sourceCode = "contract test {\n"
- " function a() {\n"
- " log0(1);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- callContractFunction("a()");
- BOOST_CHECK_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
- BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 0);
-}
-
-BOOST_AUTO_TEST_CASE(log1)
-{
- char const* sourceCode = "contract test {\n"
- " function a() {\n"
- " log1(1, 2);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- callContractFunction("a()");
- BOOST_CHECK_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
- BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(u256(2)));
-}
-
-BOOST_AUTO_TEST_CASE(log2)
-{
- char const* sourceCode = "contract test {\n"
- " function a() {\n"
- " log2(1, 2, 3);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- callContractFunction("a()");
- BOOST_CHECK_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
- BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 2);
- for (unsigned i = 0; i < 2; ++i)
- BOOST_CHECK_EQUAL(m_logs[0].topics[i], h256(u256(i + 2)));
-}
-
-BOOST_AUTO_TEST_CASE(log3)
-{
- char const* sourceCode = "contract test {\n"
- " function a() {\n"
- " log3(1, 2, 3, 4);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- callContractFunction("a()");
- BOOST_CHECK_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
- BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 3);
- for (unsigned i = 0; i < 3; ++i)
- BOOST_CHECK_EQUAL(m_logs[0].topics[i], h256(u256(i + 2)));
-}
-
-BOOST_AUTO_TEST_CASE(log4)
-{
- char const* sourceCode = "contract test {\n"
- " function a() {\n"
- " log4(1, 2, 3, 4, 5);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- callContractFunction("a()");
- BOOST_CHECK_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
- BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 4);
- for (unsigned i = 0; i < 4; ++i)
- BOOST_CHECK_EQUAL(m_logs[0].topics[i], h256(u256(i + 2)));
-}
-
-BOOST_AUTO_TEST_CASE(log_in_constructor)
-{
- char const* sourceCode = "contract test {\n"
- " function test() {\n"
- " log1(1, 2);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- BOOST_CHECK_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
- BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(u256(2)));
-}
-
-BOOST_AUTO_TEST_CASE(suicide)
-{
- char const* sourceCode = "contract test {\n"
- " function a(address receiver) returns (uint ret) {\n"
- " suicide(receiver);\n"
- " return 10;\n"
- " }\n"
- "}\n";
- u256 amount(130);
- compileAndRun(sourceCode, amount);
- u160 address(23);
- BOOST_CHECK(callContractFunction("a(address)", address) == bytes());
- BOOST_CHECK(!m_state.addressHasCode(m_contractAddress));
- BOOST_CHECK_EQUAL(m_state.balance(address), amount);
-}
-
-BOOST_AUTO_TEST_CASE(sha3)
-{
- char const* sourceCode = "contract test {\n"
- " function a(hash input) returns (hash sha3hash) {\n"
- " return sha3(input);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto f = [&](u256 const& _x) -> u256
- {
- return dev::sha3(toBigEndian(_x));
- };
- testSolidityAgainstCpp("a(hash256)", f, u256(4));
- testSolidityAgainstCpp("a(hash256)", f, u256(5));
- testSolidityAgainstCpp("a(hash256)", f, u256(-1));
-}
-
-BOOST_AUTO_TEST_CASE(sha256)
-{
- char const* sourceCode = "contract test {\n"
- " function a(hash input) returns (hash sha256hash) {\n"
- " return sha256(input);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto f = [&](u256 const& _input) -> u256
- {
- h256 ret;
- 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));
-}
-
-BOOST_AUTO_TEST_CASE(ripemd)
-{
- char const* sourceCode = "contract test {\n"
- " function a(hash input) returns (hash sha256hash) {\n"
- " return ripemd160(input);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- auto f = [&](u256 const& _input) -> u256
- {
- h256 ret;
- 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));
-}
-
-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"
- " return ecrecover(h, v, r, s);\n"
- " }\n"
- "}\n";
- compileAndRun(sourceCode);
- u256 h("0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c");
- byte v = 28;
- u256 r("0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f");
- u256 s("0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549");
- u160 addr("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b");
- BOOST_CHECK(callContractFunction("a(hash256,uint8,hash256,hash256)", h, v, r, s) == encodeArgs(addr));
-}
-
-BOOST_AUTO_TEST_CASE(inter_contract_calls)
-{
- char const* sourceCode = R"(
- contract Helper {
- function multiply(uint a, uint b) returns (uint c) {
- return a * b;
- }
- }
- contract Main {
- Helper h;
- function callHelper(uint a, uint b) returns (uint c) {
- return h.multiply(a, b);
- }
- function getHelper() returns (address haddress) {
- return address(h);
- }
- function setHelper(address haddress) {
- h = Helper(haddress);
- }
- })";
- compileAndRun(sourceCode, 0, "Helper");
- u160 const c_helperAddress = m_contractAddress;
- compileAndRun(sourceCode, 0, "Main");
- BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
- BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
- u256 a(3456789);
- u256 b("0x282837623374623234aa74");
- BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b));
-}
-
-BOOST_AUTO_TEST_CASE(inter_contract_calls_with_complex_parameters)
-{
- char const* sourceCode = R"(
- contract Helper {
- function sel(uint a, bool select, uint b) returns (uint c) {
- if (select) return a; else return b;
- }
- }
- contract Main {
- Helper h;
- function callHelper(uint a, bool select, uint b) returns (uint c) {
- return h.sel(a, select, b) * 3;
- }
- function getHelper() returns (address haddress) {
- return address(h);
- }
- function setHelper(address haddress) {
- h = Helper(haddress);
- }
- })";
- compileAndRun(sourceCode, 0, "Helper");
- u160 const c_helperAddress = m_contractAddress;
- compileAndRun(sourceCode, 0, "Main");
- BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
- BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
- u256 a(3456789);
- u256 b("0x282837623374623234aa74");
- BOOST_REQUIRE(callContractFunction("callHelper(uint256,bool,uint256)", a, true, b) == encodeArgs(a * 3));
- BOOST_REQUIRE(callContractFunction("callHelper(uint256,bool,uint256)", a, false, b) == encodeArgs(b * 3));
-}
-
-BOOST_AUTO_TEST_CASE(inter_contract_calls_accessing_this)
-{
- char const* sourceCode = R"(
- contract Helper {
- function getAddress() returns (address addr) {
- return address(this);
- }
- }
- contract Main {
- Helper h;
- function callHelper() returns (address addr) {
- return h.getAddress();
- }
- function getHelper() returns (address addr) {
- return address(h);
- }
- function setHelper(address addr) {
- h = Helper(addr);
- }
- })";
- compileAndRun(sourceCode, 0, "Helper");
- u160 const c_helperAddress = m_contractAddress;
- compileAndRun(sourceCode, 0, "Main");
- BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
- BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
- BOOST_REQUIRE(callContractFunction("callHelper()") == encodeArgs(c_helperAddress));
-}
-
-BOOST_AUTO_TEST_CASE(calls_to_this)
-{
- char const* sourceCode = R"(
- contract Helper {
- function invoke(uint a, uint b) returns (uint c) {
- return this.multiply(a, b, 10);
- }
- function multiply(uint a, uint b, uint8 c) returns (uint ret) {
- return a * b + c;
- }
- }
- contract Main {
- Helper h;
- function callHelper(uint a, uint b) returns (uint ret) {
- return h.invoke(a, b);
- }
- function getHelper() returns (address addr) {
- return address(h);
- }
- function setHelper(address addr) {
- h = Helper(addr);
- }
- })";
- compileAndRun(sourceCode, 0, "Helper");
- u160 const c_helperAddress = m_contractAddress;
- compileAndRun(sourceCode, 0, "Main");
- BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
- BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
- u256 a(3456789);
- u256 b("0x282837623374623234aa74");
- BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b + 10));
-}
-
-BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars)
-{
- // note that a reference to another contract's function occupies two stack slots,
- // so this tests correct stack slot allocation
- char const* sourceCode = R"(
- contract Helper {
- function multiply(uint a, uint b) returns (uint c) {
- return a * b;
- }
- }
- contract Main {
- Helper h;
- function callHelper(uint a, uint b) returns (uint c) {
- var fu = h.multiply;
- var y = 9;
- var ret = fu(a, b);
- return ret + y;
- }
- function getHelper() returns (address haddress) {
- return address(h);
- }
- function setHelper(address haddress) {
- h = Helper(haddress);
- }
- })";
- compileAndRun(sourceCode, 0, "Helper");
- u160 const c_helperAddress = m_contractAddress;
- compileAndRun(sourceCode, 0, "Main");
- BOOST_REQUIRE(callContractFunction("setHelper(address)", c_helperAddress) == bytes());
- BOOST_REQUIRE(callContractFunction("getHelper()", c_helperAddress) == encodeArgs(c_helperAddress));
- u256 a(3456789);
- u256 b("0x282837623374623234aa74");
- BOOST_REQUIRE(callContractFunction("callHelper(uint256,uint256)", a, b) == encodeArgs(a * b + 9));
-}
-
-BOOST_AUTO_TEST_CASE(strings_in_calls)
-{
- char const* sourceCode = R"(
- contract Helper {
- function invoke(string3 x, bool stop) returns (string4 ret) {
- return x;
- }
- }
- contract Main {
- Helper h;
- function callHelper(string2 x, bool stop) returns (string5 ret) {
- return h.invoke(x, stop);
- }
- function getHelper() returns (address addr) {
- return address(h);
- }
- function setHelper(address addr) {
- h = Helper(addr);
- }
- })";
- compileAndRun(sourceCode, 0, "Helper");
- u160 const c_helperAddress = m_contractAddress;
- 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_AUTO_TEST_CASE(constructor_arguments)
-{
- char const* sourceCode = R"(
- contract Helper {
- string3 name;
- bool flag;
-
- function Helper(string3 x, bool f) {
- name = x;
- flag = f;
- }
- function getName() returns (string3 ret) { return name; }
- function getFlag() returns (bool ret) { return flag; }
- }
- contract Main {
- Helper h;
- function Main() {
- h = new Helper("abc", true);
- }
- function getFlag() returns (bool ret) { return h.getFlag(); }
- function getName() returns (string3 ret) { return h.getName(); }
- })";
- compileAndRun(sourceCode, 0, "Main");
- BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true));
- BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc"));
-}
-
-BOOST_AUTO_TEST_CASE(functions_called_by_constructor)
-{
- char const* sourceCode = R"(
- contract Test {
- string3 name;
- bool flag;
- function Test() {
- setName("abc");
- }
- function getName() returns (string3 ret) { return name; }
- function setName(string3 _name) private { name = _name; }
- })";
- compileAndRun(sourceCode);
- BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc"));
-}
-
-BOOST_AUTO_TEST_CASE(contracts_as_addresses)
-{
- char const* sourceCode = R"(
- contract helper {
- }
- contract test {
- helper h;
- function test() { h = new helper(); h.send(5); }
- function getBalance() returns (uint256 myBalance, uint256 helperBalance) {
- myBalance = this.balance;
- helperBalance = h.balance;
- }
- }
- )";
- compileAndRun(sourceCode, 20);
- BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5)));
-}
-
-BOOST_AUTO_TEST_CASE(gas_and_value_basic)
-{
- char const* sourceCode = R"(
- contract helper {
- bool flag;
- function getBalance() returns (uint256 myBalance) {
- return this.balance;
- }
- function setFlag() { flag = true; }
- function getFlag() returns (bool fl) { return flag; }
- }
- contract test {
- helper h;
- function test() { h = new helper(); }
- function sendAmount(uint amount) returns (uint256 bal) {
- return h.getBalance.value(amount)();
- }
- function outOfGas() returns (bool flagBefore, bool flagAfter, uint myBal) {
- flagBefore = h.getFlag();
- h.setFlag.gas(2)(); // should fail due to OOG, return value can be garbage
- flagAfter = h.getFlag();
- myBal = this.balance;
- }
- }
- )";
- compileAndRun(sourceCode, 20);
- BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(5));
- // call to helper should not succeed but amount should be transferred anyway
- BOOST_REQUIRE(callContractFunction("outOfGas()", 5) == encodeArgs(false, false, 20 - 5));
-}
-
-BOOST_AUTO_TEST_CASE(value_complex)
-{
- char const* sourceCode = R"(
- contract helper {
- function getBalance() returns (uint256 myBalance) {
- return this.balance;
- }
- }
- contract test {
- helper h;
- function test() { h = new helper(); }
- function sendAmount(uint amount) returns (uint256 bal) {
- var x1 = h.getBalance.value(amount);
- uint someStackElement = 20;
- var x2 = x1.gas(1000);
- return x2.value(amount + 3)();// overwrite value
- }
- }
- )";
- compileAndRun(sourceCode, 20);
- BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(8));
-}
-
-BOOST_AUTO_TEST_CASE(value_insane)
-{
- char const* sourceCode = R"(
- contract helper {
- function getBalance() returns (uint256 myBalance) {
- return this.balance;
- }
- }
- contract test {
- helper h;
- function test() { h = new helper(); }
- function sendAmount(uint amount) returns (uint256 bal) {
- var x1 = h.getBalance.value;
- uint someStackElement = 20;
- var x2 = x1(amount).gas;
- var x3 = x2(1000).value;
- return x3(amount + 3)();// overwrite value
- }
- }
- )";
- compileAndRun(sourceCode, 20);
- BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(8));
-}
-
-BOOST_AUTO_TEST_CASE(value_for_constructor)
-{
- char const* sourceCode = R"(
- contract Helper {
- string3 name;
- bool flag;
- function Helper(string3 x, bool f) {
- name = x;
- flag = f;
- }
- function getName() returns (string3 ret) { return name; }
- function getFlag() returns (bool ret) { return flag; }
- }
- contract Main {
- Helper h;
- function Main() {
- h = new Helper.value(10)("abc", true);
- }
- function getFlag() returns (bool ret) { return h.getFlag(); }
- function getName() returns (string3 ret) { return h.getName(); }
- function getBalances() returns (uint me, uint them) { me = this.balance; them = h.balance;}
- })";
- compileAndRun(sourceCode, 22, "Main");
- BOOST_REQUIRE(callContractFunction("getFlag()") == encodeArgs(true));
- BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc"));
- BOOST_REQUIRE(callContractFunction("getBalances()") == encodeArgs(12, 10));
-}
-
-BOOST_AUTO_TEST_CASE(virtual_function_calls)
-{
- char const* sourceCode = R"(
- contract Base {
- function f() returns (uint i) { return g(); }
- function g() returns (uint i) { return 1; }
- }
- contract Derived is Base {
- function g() returns (uint i) { return 2; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("g()") == encodeArgs(2));
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(2));
-}
-
-BOOST_AUTO_TEST_CASE(access_base_storage)
-{
- char const* sourceCode = R"(
- contract Base {
- uint dataBase;
- function getViaBase() returns (uint i) { return dataBase; }
- }
- contract Derived is Base {
- uint dataDerived;
- function setData(uint base, uint derived) returns (bool r) {
- dataBase = base;
- dataDerived = derived;
- return true;
- }
- function getViaDerived() returns (uint base, uint derived) {
- base = dataBase;
- derived = dataDerived;
- }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("setData(uint256,uint256)", 1, 2) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("getViaBase()") == encodeArgs(1));
- BOOST_CHECK(callContractFunction("getViaDerived()") == encodeArgs(1, 2));
-}
-
-BOOST_AUTO_TEST_CASE(single_copy_with_multiple_inheritance)
-{
- char const* sourceCode = R"(
- contract Base {
- uint data;
- function setData(uint i) { data = i; }
- function getViaBase() returns (uint i) { return data; }
- }
- contract A is Base { function setViaA(uint i) { setData(i); } }
- contract B is Base { function getViaB() returns (uint i) { return getViaBase(); } }
- contract Derived is Base, B, A { }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("getViaB()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("setViaA(uint256)", 23) == encodeArgs());
- BOOST_CHECK(callContractFunction("getViaB()") == encodeArgs(23));
-}
-
-BOOST_AUTO_TEST_CASE(explicit_base_cass)
-{
- char const* sourceCode = R"(
- contract BaseBase { function g() returns (uint r) { return 1; } }
- contract Base is BaseBase { function g() returns (uint r) { return 2; } }
- contract Derived is Base {
- function f() returns (uint r) { return BaseBase.g(); }
- function g() returns (uint r) { return 3; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("g()") == encodeArgs(3));
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(1));
-}
-
-BOOST_AUTO_TEST_CASE(base_constructor_arguments)
-{
- char const* sourceCode = R"(
- contract BaseBase {
- uint m_a;
- function BaseBase(uint a) {
- m_a = a;
- }
- }
- contract Base is BaseBase(7) {
- function Base() {
- m_a *= m_a;
- }
- }
- contract Derived is Base() {
- function getA() returns (uint r) { return m_a; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("getA()") == encodeArgs(7 * 7));
-}
-
-BOOST_AUTO_TEST_CASE(function_usage_in_constructor_arguments)
-{
- char const* sourceCode = R"(
- contract BaseBase {
- uint m_a;
- function BaseBase(uint a) {
- m_a = a;
- }
- function g() returns (uint r) { return 2; }
- }
- contract Base is BaseBase(BaseBase.g()) {
- }
- contract Derived is Base() {
- function getA() returns (uint r) { return m_a; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("getA()") == encodeArgs(2));
-}
-
-BOOST_AUTO_TEST_CASE(virtual_function_usage_in_constructor_arguments)
-{
- char const* sourceCode = R"(
- contract BaseBase {
- uint m_a;
- function BaseBase(uint a) {
- m_a = a;
- }
- function overridden() returns (uint r) { return 1; }
- function g() returns (uint r) { return overridden(); }
- }
- contract Base is BaseBase(BaseBase.g()) {
- }
- contract Derived is Base() {
- function getA() returns (uint r) { return m_a; }
- function overridden() returns (uint r) { return 2; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("getA()") == encodeArgs(2));
-}
-
-BOOST_AUTO_TEST_CASE(constructor_argument_overriding)
-{
- char const* sourceCode = R"(
- contract BaseBase {
- uint m_a;
- function BaseBase(uint a) {
- m_a = a;
- }
- }
- contract Base is BaseBase(2) { }
- contract Derived is BaseBase(3), Base {
- function getA() returns (uint r) { return m_a; }
- }
- )";
- compileAndRun(sourceCode, 0, "Derived");
- BOOST_CHECK(callContractFunction("getA()") == encodeArgs(3));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier)
-{
- char const* sourceCode = R"(
- contract C {
- function getOne() nonFree returns (uint r) { return 1; }
- modifier nonFree { if (msg.value > 0) _ }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getOne()") == encodeArgs(0));
- BOOST_CHECK(callContractFunctionWithValue("getOne()", 1) == encodeArgs(1));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_local_variables)
-{
- char const* sourceCode = R"(
- contract C {
- modifier mod1 { var a = 1; var b = 2; _ }
- modifier mod2(bool a) { if (a) return; else _ }
- function f(bool a) mod1 mod2(a) returns (uint r) { return 3; }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(0));
- BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(3));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_loop)
-{
- char const* sourceCode = R"(
- contract C {
- modifier repeat(uint count) { for (var i = 0; i < count; ++i) _ }
- function f() repeat(10) returns (uint r) { r += 1; }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(10));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_multi_invocation)
-{
- char const* sourceCode = R"(
- contract C {
- modifier repeat(bool twice) { if (twice) _ _ }
- function f(bool twice) repeat(twice) returns (uint r) { r += 1; }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(1));
- BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(2));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_multi_with_return)
-{
- // Here, the explicit return prevents the second execution
- char const* sourceCode = R"(
- contract C {
- modifier repeat(bool twice) { if (twice) _ _ }
- function f(bool twice) repeat(twice) returns (uint r) { r += 1; return r; }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(1));
- BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(1));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_overriding)
-{
- char const* sourceCode = R"(
- contract A {
- function f() mod returns (bool r) { return true; }
- modifier mod { _ }
- }
- contract C is A {
- modifier mod { }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(false));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_calling_functions_in_creation_context)
-{
- char const* sourceCode = R"(
- contract A {
- uint data;
- function A() mod1 { f1(); }
- function f1() mod2 { data |= 0x1; }
- function f2() { data |= 0x20; }
- function f3() { }
- modifier mod1 { f2(); _ }
- modifier mod2 { f3(); }
- function getData() returns (uint r) { return data; }
- }
- contract C is A {
- modifier mod1 { f4(); _ }
- function f3() { data |= 0x300; }
- function f4() { data |= 0x4000; }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0x4300));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_for_constructor)
-{
- char const* sourceCode = R"(
- contract A {
- uint data;
- function A() mod1 { data |= 2; }
- modifier mod1 { data |= 1; _ }
- function getData() returns (uint r) { return data; }
- }
- contract C is A {
- modifier mod1 { data |= 4; _ }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getData()") == encodeArgs(4 | 2));
-}
-
-BOOST_AUTO_TEST_CASE(use_std_lib)
-{
- char const* sourceCode = R"(
- import "mortal";
- contract Icarus is mortal { }
- )";
- m_addStandardSources = true;
- u256 amount(130);
- u160 address(23);
- compileAndRun(sourceCode, amount, "Icarus");
- u256 balanceBefore = m_state.balance(m_sender);
- BOOST_CHECK(callContractFunction("kill()") == bytes());
- BOOST_CHECK(!m_state.addressHasCode(m_contractAddress));
- BOOST_CHECK(m_state.balance(m_sender) > balanceBefore);
-}
-
-BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack)
-{
- char const* sourceCode = R"(
- contract C {
- function f() returns (uint r) {
- uint; uint; uint; uint;
- int x = -7;
- var a = uint;
- return a(x);
- }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(-7)));
-}
-
-BOOST_AUTO_TEST_CASE(super)
-{
- char const* sourceCode = R"(
- contract A { function f() returns (uint r) { return 1; } }
- contract B is A { function f() returns (uint r) { return super.f() | 2; } }
- contract C is A { function f() returns (uint r) { return super.f() | 4; } }
- contract D is B, C { function f() returns (uint r) { return super.f() | 8; } }
- )";
- compileAndRun(sourceCode, 0, "D");
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(1 | 2 | 4 | 8));
-}
-
-BOOST_AUTO_TEST_CASE(super_in_constructor)
-{
- char const* sourceCode = R"(
- contract A { function f() returns (uint r) { return 1; } }
- contract B is A { function f() returns (uint r) { return super.f() | 2; } }
- contract C is A { function f() returns (uint r) { return super.f() | 4; } }
- contract D is B, C { uint data; function D() { data = super.f() | 8; } function f() returns (uint r) { return data; } }
- )";
- compileAndRun(sourceCode, 0, "D");
- BOOST_CHECK(callContractFunction("f()") == encodeArgs(1 | 2 | 4 | 8));
-}
-
-BOOST_AUTO_TEST_CASE(fallback_function)
-{
- char const* sourceCode = R"(
- contract A {
- uint data;
- function() returns (uint r) { data = 1; return 2; }
- function getData() returns (uint r) { return data; }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("") == encodeArgs(2));
- BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1));
-}
-
-BOOST_AUTO_TEST_CASE(inherited_fallback_function)
-{
- char const* sourceCode = R"(
- contract A {
- uint data;
- function() returns (uint r) { data = 1; return 2; }
- function getData() returns (uint r) { return data; }
- }
- contract B is A {}
- )";
- compileAndRun(sourceCode, 0, "B");
- BOOST_CHECK(callContractFunction("getData()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("") == encodeArgs(2));
- BOOST_CHECK(callContractFunction("getData()") == encodeArgs(1));
-}
-
-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) {
- if (_manually) {
- hash s = 0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20;
- log3(msg.value, s, hash32(msg.sender), _id);
- } else
- Deposit(hash32(msg.sender), _id, msg.value);
- }
- }
- )";
- compileAndRun(sourceCode);
- u256 value(18);
- u256 id(0x1234);
- for (bool manually: {true, false})
- {
- callContractFunctionWithValue("deposit(hash256,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[1], h256(m_sender));
- BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(id));
- }
-}
-
-BOOST_AUTO_TEST_CASE(event_no_arguments)
-{
- char const* sourceCode = R"(
- contract ClientReceipt {
- event Deposit;
- function deposit() {
- Deposit();
- }
- }
- )";
- compileAndRun(sourceCode);
- callContractFunction("deposit()");
- BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK(m_logs[0].data.empty());
- BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
- BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit()")));
-}
-
-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);
- }
- }
- )";
- compileAndRun(sourceCode);
- u256 value(18);
- u256 id(0x1234);
- callContractFunctionWithValue("deposit(hash256)", 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(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_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
-{
- char const* sourceCode = R"(
- contract test {
- function f(uint, uint k) returns(uint ret_k, uint ret_g){
- uint g = 8;
- ret_k = k;
- ret_g = g;
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f(uint256,uint256)", 5, 9) != encodeArgs(5, 8));
- BOOST_CHECK(callContractFunction("f(uint256,uint256)", 5, 9) == encodeArgs(9, 8));
-}
-
-BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
-{
- char const* sourceCode = R"(
- contract test {
- function f(uint k) returns(uint){
- return k;
- }
- })";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("f(uint256)", 9) == encodeArgs(9));
-}
-
-BOOST_AUTO_TEST_CASE(sha3_multiple_arguments)
-{
- char const* sourceCode = R"(
- contract c {
- function foo(uint a, uint b, uint c) returns (hash d)
- {
- d = sha3(a, b, c);
- }
- })";
- compileAndRun(sourceCode);
-
- BOOST_CHECK(callContractFunction("foo(uint256,uint256,uint256)", 10, 12, 13) == encodeArgs(
- dev::sha3(
- toBigEndian(u256(10)) +
- toBigEndian(u256(12)) +
- toBigEndian(u256(13)))));
-}
-
-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)
- {
- d = sha3(a, b, 145);
- }
- })";
- compileAndRun(sourceCode);
-
- BOOST_CHECK(callContractFunction("foo(uint256,uint16)", 10, 12) == encodeArgs(
- dev::sha3(
- toBigEndian(u256(10)) +
- bytes{0x0, 0xc} +
- bytes(1, 0x91))));
-}
-
-BOOST_AUTO_TEST_CASE(sha3_multiple_arguments_with_string_literals)
-{
- char const* sourceCode = R"(
- contract c {
- function foo() returns (hash d)
- {
- d = sha3("foo");
- }
- function bar(uint a, uint16 b) returns (hash d)
- {
- d = sha3(a, b, 145, "foo");
- }
- })";
- compileAndRun(sourceCode);
-
- BOOST_CHECK(callContractFunction("foo()") == encodeArgs(dev::sha3("foo")));
-
- BOOST_CHECK(callContractFunction("bar(uint256,uint16)", 10, 12) == encodeArgs(
- dev::sha3(
- toBigEndian(u256(10)) +
- bytes{0x0, 0xc} +
- bytes(1, 0x91) +
- bytes{0x66, 0x6f, 0x6f})));
-}
-
-BOOST_AUTO_TEST_CASE(generic_call)
-{
- char const* sourceCode = R"**(
- contract receiver {
- uint public received;
- function receive(uint256 x) { received = x; }
- }
- contract sender {
- function doSend(address rec) returns (uint d)
- {
- string4 signature = string4(string32(sha3("receive(uint256)")));
- rec.call.value(2)(signature, 23);
- return receiver(rec).received();
- }
- }
- )**";
- compileAndRun(sourceCode, 0, "receiver");
- u160 const c_receiverAddress = m_contractAddress;
- compileAndRun(sourceCode, 50, "sender");
- BOOST_REQUIRE(callContractFunction("doSend(address)", c_receiverAddress) == encodeArgs(23));
- BOOST_CHECK_EQUAL(m_state.balance(m_contractAddress), 50 - 2);
-}
-
-BOOST_AUTO_TEST_CASE(store_bytes)
-{
- // this test just checks that the copy loop does not mess up the stack
- char const* sourceCode = R"(
- contract C {
- function save() returns (uint r) {
- r = 23;
- savedData = msg.data;
- r = 24;
- }
- bytes savedData;
- }
- )";
- compileAndRun(sourceCode);
- // empty copy loop
- BOOST_CHECK(callContractFunction("save()") == encodeArgs(24));
- BOOST_CHECK(callContractFunction("save()", "abcdefg") == encodeArgs(24));
-}
-
-BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory)
-{
- char const* sourceCode = R"(
- contract C {
- function() returns (hash) {
- return sha3("abc", msg.data);
- }
- }
- )";
- compileAndRun(sourceCode);
- bytes calldata1 = bytes(61, 0x22) + bytes(12, 0x12);
- sendMessage(calldata1, false);
- BOOST_CHECK(m_output == encodeArgs(dev::sha3(bytes{'a', 'b', 'c'} + calldata1)));
-}
-
-BOOST_AUTO_TEST_CASE(call_forward_bytes)
-{
- char const* sourceCode = R"(
- contract receiver {
- uint public received;
- function receive(uint x) { received += x + 1; }
- function() { received = 0x80; }
- }
- contract sender {
- function sender() { rec = new receiver(); }
- function() { savedData = msg.data; }
- function forward() returns (bool) { rec.call(savedData); return true; }
- function clear() returns (bool) { delete savedData; return true; }
- function val() returns (uint) { return rec.received(); }
- receiver rec;
- bytes savedData;
- }
- )";
- compileAndRun(sourceCode, 0, "sender");
- BOOST_CHECK(callContractFunction("receive(uint256)", 7) == bytes());
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("forward()") == encodeArgs(true));
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(8));
- BOOST_CHECK(callContractFunction("clear()") == encodeArgs(true));
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(8));
- BOOST_CHECK(callContractFunction("forward()") == encodeArgs(true));
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(0x80));
-}
-
-BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)
-{
- char const* sourceCode = R"(
- contract receiver {
- uint public received;
- function receive(uint x) { received += x + 1; }
- function() { received = 0x80; }
- }
- contract sender {
- function sender() { rec = new receiver(); }
- function() { savedData1 = savedData2 = msg.data; }
- function forward(bool selector) returns (bool) {
- if (selector) { rec.call(savedData1); delete savedData1; }
- else { rec.call(savedData2); delete savedData2; }
- return true;
- }
- function val() returns (uint) { return rec.received(); }
- receiver rec;
- bytes savedData1;
- bytes savedData2;
- }
- )";
- compileAndRun(sourceCode, 0, "sender");
- BOOST_CHECK(callContractFunction("receive(uint256)", 7) == bytes());
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("forward(bool)", true) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(8));
- BOOST_CHECK(callContractFunction("forward(bool)", false) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(16));
- BOOST_CHECK(callContractFunction("forward(bool)", true) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("val()") == encodeArgs(0x80));
-}
-
-BOOST_AUTO_TEST_CASE(delete_removes_bytes_data)
-{
- char const* sourceCode = R"(
- contract c {
- function() { data = msg.data; }
- function del() returns (bool) { delete data; return true; }
- bytes data;
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("---", 7) == bytes());
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("del()", 7) == encodeArgs(true));
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
-}
-
-BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data)
-{
- char const* sourceCode = R"(
- contract c {
- function set() returns (bool) { data = msg.data; return true; }
- function() { data = msg.data; }
- bytes data;
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("set()", 1, 2, 3, 4, 5) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- sendMessage(bytes(), false);
- BOOST_CHECK(m_output == bytes());
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
-}
-
-BOOST_AUTO_TEST_CASE(copy_removes_bytes_data)
-{
- char const* sourceCode = R"(
- contract c {
- function set() returns (bool) { data1 = msg.data; return true; }
- function reset() returns (bool) { data1 = data2; return true; }
- bytes data1;
- bytes data2;
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("set()", 1, 2, 3, 4, 5) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("reset()") == encodeArgs(true));
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
-}
-
-BOOST_AUTO_TEST_CASE(bytes_inside_mappings)
-{
- char const* sourceCode = R"(
- contract c {
- function set(uint key) returns (bool) { data[key] = msg.data; return true; }
- function copy(uint from, uint to) returns (bool) { data[to] = data[from]; return true; }
- mapping(uint => bytes) data;
- }
- )";
- compileAndRun(sourceCode);
- // store a short byte array at 1 and a longer one at 2
- BOOST_CHECK(callContractFunction("set(uint256)", 1, 2) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("set(uint256)", 2, 2, 3, 4, 5) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- // copy shorter to longer
- BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 1, 2) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- // copy empty to both
- BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 99, 1) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 99, 2) == encodeArgs(true));
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
-}
-
-BOOST_AUTO_TEST_CASE(bytes_length_member)
-{
- char const* sourceCode = R"(
- contract c {
- function set() returns (bool) { data = msg.data; return true; }
- function getLength() returns (uint) { return data.length; }
- bytes data;
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getLength()") == encodeArgs(0));
- BOOST_CHECK(callContractFunction("set()", 1, 2) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("getLength()") == encodeArgs(4+32+32));
-}
-
-BOOST_AUTO_TEST_CASE(struct_copy)
-{
- char const* sourceCode = R"(
- contract c {
- struct Nested { uint x; uint y; }
- struct Struct { uint a; mapping(uint => Struct) b; Nested nested; uint c; }
- mapping(uint => Struct) public data;
- function set(uint k) returns (bool) {
- data[k].a = 1;
- data[k].nested.x = 3;
- data[k].nested.y = 4;
- data[k].c = 2;
- return true;
- }
- function copy(uint from, uint to) returns (bool) {
- data[to] = data[from];
- return true;
- }
- function retrieve(uint k) returns (uint a, uint x, uint y, uint c)
- {
- a = data[k].a;
- x = data[k].nested.x;
- y = data[k].nested.y;
- c = data[k].c;
- }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("set(uint256)", 7) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("retrieve(uint256)", 7) == encodeArgs(1, 3, 4, 2));
- BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 7, 8) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("retrieve(uint256)", 7) == encodeArgs(1, 3, 4, 2));
- BOOST_CHECK(callContractFunction("retrieve(uint256)", 8) == encodeArgs(1, 3, 4, 2));
- BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 0, 7) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("retrieve(uint256)", 7) == encodeArgs(0, 0, 0, 0));
- BOOST_CHECK(callContractFunction("retrieve(uint256)", 8) == encodeArgs(1, 3, 4, 2));
- BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 7, 8) == encodeArgs(true));
- BOOST_CHECK(callContractFunction("retrieve(uint256)", 8) == encodeArgs(0, 0, 0, 0));
-}
-
-BOOST_AUTO_TEST_CASE(struct_containing_bytes_copy_and_delete)
-{
- char const* sourceCode = R"(
- contract c {
- struct Struct { uint a; bytes data; uint b; }
- Struct data1;
- Struct data2;
- function set(uint _a, bytes _data, uint _b) external returns (bool) {
- data1.a = _a;
- data1.b = _b;
- data1.data = _data;
- return true;
- }
- function copy() returns (bool) {
- data1 = data2;
- return true;
- }
- function del() returns (bool) {
- delete data1;
- return true;
- }
- }
- )";
- compileAndRun(sourceCode);
- string data = "123456789012345678901234567890123";
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("set(uint256,bytes,uint256)", u256(data.length()), 12, data, 13) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("copy()") == encodeArgs(true));
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("set(uint256,bytes,uint256)", u256(data.length()), 12, data, 13) == encodeArgs(true));
- BOOST_CHECK(!m_state.storage(m_contractAddress).empty());
- BOOST_CHECK(callContractFunction("del()") == encodeArgs(true));
- BOOST_CHECK(m_state.storage(m_contractAddress).empty());
-}
-
-BOOST_AUTO_TEST_CASE(struct_copy_via_local)
-{
- char const* sourceCode = R"(
- contract c {
- struct Struct { uint a; uint b; }
- Struct data1;
- Struct data2;
- function test() returns (bool) {
- data1.a = 1;
- data1.b = 2;
- var x = data1;
- data2 = x;
- return data2.a == data1.a && data2.b == data1.b;
- }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("test()") == encodeArgs(true));
-}
-
-BOOST_AUTO_TEST_CASE(using_enums)
-{
- char const* sourceCode = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
- function test()
- {
- choices = ActionChoices.GoStraight;
- }
- function getChoice() returns (uint d)
- {
- d = uint256(choices);
- }
- ActionChoices choices;
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("getChoice()") == encodeArgs(2));
-}
-
-BOOST_AUTO_TEST_CASE(constructing_enums_from_ints)
-{
- char const* sourceCode = R"(
- contract c {
- enum Truth { False, True }
- function test() returns (uint)
- {
- return uint(Truth(uint8(0x701)));
- }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("test()") == encodeArgs(1));
-}
-
-BOOST_AUTO_TEST_CASE(external_function)
-{
- char const* sourceCode = R"(
- contract c {
- function f(uint a) returns (uint) { return a; }
- function test(uint a, uint b) external returns (uint r_a, uint r_b) {
- r_a = f(a + 7);
- r_b = b;
- }
- }
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("test(uint256,uint256)", 2, 3) == encodeArgs(2+7, 3));
-}
-
-BOOST_AUTO_TEST_CASE(bytes_in_arguments)
-{
- char const* sourceCode = R"(
- contract c {
- uint result;
- function f(uint a, uint b) { result += a + b; }
- function g(uint a) { result *= a; }
- function test(uint a, bytes data1, bytes data2, uint b) external returns (uint r_a, uint r, uint r_b, uint l) {
- r_a = a;
- this.call(data1);
- this.call(data2);
- r = result;
- r_b = b;
- l = data1.length;
- }
- }
- )";
- compileAndRun(sourceCode);
- string innercalldata1 = asString(FixedHash<4>(dev::sha3("f(uint256,uint256)")).asBytes() + encodeArgs(8, 9));
- bytes calldata1 = encodeArgs(u256(innercalldata1.length()), 12, innercalldata1, 13);
- string innercalldata2 = asString(FixedHash<4>(dev::sha3("g(uint256)")).asBytes() + encodeArgs(3));
- bytes calldata = encodeArgs(
- u256(innercalldata1.length()), u256(innercalldata2.length()),
- 12, innercalldata1, innercalldata2, 13);
- BOOST_CHECK(callContractFunction("test(uint256,bytes,bytes,uint256)", calldata)
- == encodeArgs(12, (8 + 9) * 3, 13, u256(innercalldata1.length())));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
-
diff --git a/SolidityExpressionCompiler.cpp b/SolidityExpressionCompiler.cpp
deleted file mode 100644
index 9cd13dcfd..000000000
--- a/SolidityExpressionCompiler.cpp
+++ /dev/null
@@ -1,492 +0,0 @@
-
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @date 2014
- * Unit tests for the solidity expression compiler.
- */
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-namespace
-{
-
-/// Helper class that extracts the first expression in an AST.
-class FirstExpressionExtractor: private ASTVisitor
-{
-public:
- FirstExpressionExtractor(ASTNode& _node): m_expression(nullptr) { _node.accept(*this); }
- Expression* getExpression() const { return m_expression; }
-private:
- virtual bool visit(Expression& _expression) override { return checkExpression(_expression); }
- virtual bool visit(Assignment& _expression) override { return checkExpression(_expression); }
- virtual bool visit(UnaryOperation& _expression) override { return checkExpression(_expression); }
- virtual bool visit(BinaryOperation& _expression) override { return checkExpression(_expression); }
- virtual bool visit(FunctionCall& _expression) override { return checkExpression(_expression); }
- virtual bool visit(MemberAccess& _expression) override { return checkExpression(_expression); }
- virtual bool visit(IndexAccess& _expression) override { return checkExpression(_expression); }
- virtual bool visit(PrimaryExpression& _expression) override { return checkExpression(_expression); }
- virtual bool visit(Identifier& _expression) override { return checkExpression(_expression); }
- virtual bool visit(ElementaryTypeNameExpression& _expression) override { return checkExpression(_expression); }
- virtual bool visit(Literal& _expression) override { return checkExpression(_expression); }
- bool checkExpression(Expression& _expression)
- {
- if (m_expression == nullptr)
- m_expression = &_expression;
- return false;
- }
-private:
- Expression* m_expression;
-};
-
-Declaration const& resolveDeclaration(vector const& _namespacedName,
- NameAndTypeResolver const& _resolver)
-{
- Declaration const* declaration = nullptr;
- // bracers are required, cause msvc couldnt handle this macro in for statement
- for (string const& namePart: _namespacedName)
- {
- BOOST_REQUIRE(declaration = _resolver.resolveName(namePart, declaration));
- }
- BOOST_REQUIRE(declaration);
- return *declaration;
-}
-
-bytes compileFirstExpression(const string& _sourceCode, vector> _functions = {},
- vector> _localVariables = {},
- vector> _globalDeclarations = {})
-{
- Parser parser;
- ASTPointer sourceUnit;
- try
- {
- sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)));
- }
- catch(boost::exception const& _e)
- {
- auto msg = std::string("Parsing source code failed with: \n") + boost::diagnostic_information(_e);
- BOOST_FAIL(msg);
- }
-
- vector declarations;
- declarations.reserve(_globalDeclarations.size() + 1);
- for (ASTPointer const& variable: _globalDeclarations)
- declarations.push_back(variable.get());
- NameAndTypeResolver resolver(declarations);
- resolver.registerDeclarations(*sourceUnit);
-
- vector inheritanceHierarchy;
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract));
- inheritanceHierarchy = vector(1, contract);
- }
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract));
- }
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- FirstExpressionExtractor extractor(*contract);
- BOOST_REQUIRE(extractor.getExpression() != nullptr);
-
- CompilerContext context;
- context.setInheritanceHierarchy(inheritanceHierarchy);
- unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack
- context.adjustStackOffset(parametersSize);
- for (vector const& variable: _localVariables)
- context.addVariable(dynamic_cast(resolveDeclaration(variable, resolver)),
- parametersSize--);
-
- ExpressionCompiler::compileExpression(context, *extractor.getExpression());
-
- for (vector const& function: _functions)
- context << context.getFunctionEntryLabel(dynamic_cast(resolveDeclaration(function, resolver)));
- bytes instructions = context.getAssembledBytecode();
- // debug
- // cout << eth::disassemble(instructions) << endl;
- return instructions;
- }
- BOOST_FAIL("No contract found in source.");
- return bytes();
-}
-
-} // end anonymous namespace
-
-BOOST_AUTO_TEST_SUITE(SolidityExpressionCompiler)
-
-BOOST_AUTO_TEST_CASE(literal_true)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { var x = true; }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x1});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(literal_false)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { var x = false; }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x0});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(int_literal)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { var x = 0x12345678901234567890; }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH10), 0x12, 0x34, 0x56, 0x78, 0x90,
- 0x12, 0x34, 0x56, 0x78, 0x90});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination)
-{
- char const* sourceCode = R"(
- contract test {
- function test ()
- {
- var x = 1 wei;
- }
- })";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x1});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination)
-{
- char const* sourceCode = R"(
- contract test {
- function test ()
- {
- var x = 1 szabo;
- }
- })";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(int_with_finney_ether_subdenomination)
-{
- char const* sourceCode = R"(
- contract test {
- function test ()
- {
- var x = 1 finney;
- }
- })";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH7), 0x3, 0x8d, 0x7e, 0xa4, 0xc6, 0x80, 0x00});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination)
-{
- char const* sourceCode = R"(
- contract test {
- function test ()
- {
- var x = 1 ether;
- }
- })";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(comparison)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { var x = (0x10aa < 0x11aa) != true; }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::PUSH2), 0x11, 0xaa,
- byte(eth::Instruction::PUSH2), 0x10, 0xaa,
- byte(eth::Instruction::LT),
- byte(eth::Instruction::EQ),
- byte(eth::Instruction::ISZERO)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(short_circuiting)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { var x = true != (4 <= 8 + 10 || 9 != 2); }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x12, // 8 + 10
- byte(eth::Instruction::PUSH1), 0x4,
- byte(eth::Instruction::GT),
- byte(eth::Instruction::ISZERO), // after this we have 4 <= 8 + 10
- byte(eth::Instruction::DUP1),
- byte(eth::Instruction::PUSH1), 0x11,
- byte(eth::Instruction::JUMPI), // short-circuit if it is true
- byte(eth::Instruction::POP),
- byte(eth::Instruction::PUSH1), 0x2,
- byte(eth::Instruction::PUSH1), 0x9,
- byte(eth::Instruction::EQ),
- byte(eth::Instruction::ISZERO), // after this we have 9 != 2
- byte(eth::Instruction::JUMPDEST),
- byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::EQ),
- byte(eth::Instruction::ISZERO)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(arithmetics)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint y) { var x = ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
- bytes expectation({byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::PUSH1), 0x2,
- byte(eth::Instruction::PUSH1), 0x3,
- byte(eth::Instruction::PUSH1), 0x4,
- byte(eth::Instruction::PUSH1), 0x5,
- byte(eth::Instruction::PUSH1), 0x6,
- byte(eth::Instruction::PUSH1), 0x7,
- byte(eth::Instruction::PUSH1), 0x8,
- byte(eth::Instruction::DUP10),
- byte(eth::Instruction::XOR),
- byte(eth::Instruction::AND),
- byte(eth::Instruction::OR),
- byte(eth::Instruction::SUB),
- byte(eth::Instruction::ADD),
- byte(eth::Instruction::MOD),
- byte(eth::Instruction::DIV),
- byte(eth::Instruction::MUL)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(unary_operators)
-{
- char const* sourceCode = "contract test {\n"
- " function f(int y) { var x = !(~+- y == 2); }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x2,
- byte(eth::Instruction::DUP3),
- byte(eth::Instruction::PUSH1), 0x0,
- byte(eth::Instruction::SUB),
- byte(eth::Instruction::NOT),
- byte(eth::Instruction::EQ),
- byte(eth::Instruction::ISZERO)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(unary_inc_dec)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
-
- // Stack: a, x
- bytes expectation({byte(eth::Instruction::DUP2),
- byte(eth::Instruction::DUP1),
- byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::ADD),
- // Stack here: a x a (a+1)
- byte(eth::Instruction::SWAP3),
- byte(eth::Instruction::POP), // first ++
- // Stack here: (a+1) x a
- byte(eth::Instruction::DUP3),
- byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::ADD),
- // Stack here: (a+1) x a (a+2)
- byte(eth::Instruction::SWAP3),
- byte(eth::Instruction::POP),
- // Stack here: (a+2) x a
- byte(eth::Instruction::DUP3), // second ++
- byte(eth::Instruction::XOR),
- // Stack here: (a+2) x a^(a+2)
- byte(eth::Instruction::DUP3),
- byte(eth::Instruction::DUP1),
- byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::SWAP1),
- byte(eth::Instruction::SUB),
- // Stack here: (a+2) x a^(a+2) (a+2) (a+1)
- byte(eth::Instruction::SWAP4),
- byte(eth::Instruction::POP), // first --
- byte(eth::Instruction::XOR),
- // Stack here: (a+1) x a^(a+2)^(a+2)
- byte(eth::Instruction::DUP3),
- byte(eth::Instruction::PUSH1), 0x1,
- byte(eth::Instruction::SWAP1),
- byte(eth::Instruction::SUB),
- // Stack here: (a+1) x a^(a+2)^(a+2) a
- byte(eth::Instruction::SWAP3),
- byte(eth::Instruction::POP), // second ++
- // Stack here: a x a^(a+2)^(a+2)
- byte(eth::Instruction::DUP3), // will change
- byte(eth::Instruction::XOR)});
- // Stack here: a x a^(a+2)^(a+2)^a
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(assignment)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a, uint b) { (a += b) * 2; }"
- "}\n";
- bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
-
- // Stack: a, b
- bytes expectation({byte(eth::Instruction::PUSH1), 0x2,
- byte(eth::Instruction::DUP2),
- byte(eth::Instruction::DUP4),
- byte(eth::Instruction::ADD),
- // Stack here: a b 2 a+b
- byte(eth::Instruction::SWAP3),
- byte(eth::Instruction::POP),
- byte(eth::Instruction::DUP3),
- // Stack here: a+b b 2 a+b
- byte(eth::Instruction::MUL)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(function_call)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a, uint b) { a += g(a + 1, b) * 2; }\n"
- " function g(uint a, uint b) returns (uint c) {}\n"
- "}\n";
- bytes code = compileFirstExpression(sourceCode, {{"test", "g"}},
- {{"test", "f", "a"}, {"test", "f", "b"}});
-
- // Stack: a, b
- bytes expectation({byte(eth::Instruction::PUSH1), 0x02,
- byte(eth::Instruction::PUSH1), 0x0c,
- byte(eth::Instruction::PUSH1), 0x01,
- byte(eth::Instruction::DUP5),
- byte(eth::Instruction::ADD),
- // Stack here: a b 2 (a+1)
- byte(eth::Instruction::DUP4),
- byte(eth::Instruction::PUSH1), 0x13,
- byte(eth::Instruction::JUMP),
- byte(eth::Instruction::JUMPDEST),
- // Stack here: a b 2 g(a+1, b)
- byte(eth::Instruction::MUL),
- // Stack here: a b g(a+1, b)*2
- byte(eth::Instruction::DUP3),
- byte(eth::Instruction::ADD),
- // Stack here: a b a+g(a+1, b)*2
- byte(eth::Instruction::SWAP2),
- byte(eth::Instruction::POP),
- byte(eth::Instruction::DUP2),
- byte(eth::Instruction::JUMPDEST)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(negative_literals_8bits)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { int8 x = -0x80; }\n"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80));
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(negative_literals_16bits)
-{
- char const* sourceCode = "contract test {\n"
- " function f() { int64 x = ~0xabc; }\n"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(30, 0xff) + bytes{0xf5, 0x43});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals)
-{
- // first literal itself is too large for 256 bits but it fits after all constant operations
- // have been applied
- char const* sourceCode = "contract test {\n"
- " function f() { var x = (0xffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; }\n"
- "}\n";
- bytes code = compileFirstExpression(sourceCode);
-
- bytes expectation(bytes({byte(eth::Instruction::PUSH1), 0xbf}));
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_CASE(blockhash)
-{
- char const* sourceCode = "contract test {\n"
- " function f() {\n"
- " block.blockhash(3);\n"
- " }\n"
- "}\n";
- bytes code = compileFirstExpression(sourceCode, {}, {},
- {make_shared("block", make_shared(MagicType::Kind::Block))});
-
- bytes expectation({byte(eth::Instruction::PUSH1), 0x03,
- byte(eth::Instruction::BLOCKHASH)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
-
diff --git a/SolidityInterface.cpp b/SolidityInterface.cpp
deleted file mode 100644
index a73c118bb..000000000
--- a/SolidityInterface.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
- */
-/**
- * @author Christian
- * @date 2015
- * Unit tests for generating source interfaces for Solidity contracts.
- */
-
-#include
-#include
-#include
-
-using namespace std;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-class SolidityInterfaceChecker
-{
-public:
- SolidityInterfaceChecker(): m_compilerStack(false) {}
-
- /// Compiles the given code, generates the interface and parses that again.
- ContractDefinition const& checkInterface(string const& _code, string const& _contractName = "")
- {
- m_code = _code;
- BOOST_REQUIRE_NO_THROW(m_compilerStack.parse(_code));
- m_interface = m_compilerStack.getMetadata("", DocumentationType::ABISolidityInterface);
- BOOST_REQUIRE_NO_THROW(m_reCompiler.parse(m_interface));
- return m_reCompiler.getContractDefinition(_contractName);
- }
-
- string getSourcePart(ASTNode const& _node) const
- {
- Location location = _node.getLocation();
- BOOST_REQUIRE(!location.isEmpty());
- return m_interface.substr(location.start, location.end - location.start);
- }
-
-protected:
- string m_code;
- string m_interface;
- CompilerStack m_compilerStack;
- CompilerStack m_reCompiler;
-};
-
-BOOST_FIXTURE_TEST_SUITE(SolidityInterface, SolidityInterfaceChecker)
-
-BOOST_AUTO_TEST_CASE(empty_contract)
-{
- ContractDefinition const& contract = checkInterface("contract test {}");
- BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}");
-}
-
-BOOST_AUTO_TEST_CASE(single_function)
-{
- ContractDefinition const& contract = checkInterface(
- "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- "}\n");
- BOOST_REQUIRE_EQUAL(1, contract.getDefinedFunctions().size());
- BOOST_CHECK_EQUAL(getSourcePart(*contract.getDefinedFunctions().front()),
- "function f(uint256 a)returns(uint256 d){}");
-}
-
-BOOST_AUTO_TEST_CASE(single_constant_function)
-{
- ContractDefinition const& contract = checkInterface(
- "contract test { function f(uint a) constant returns(hash8 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){}");
-}
-
-BOOST_AUTO_TEST_CASE(multiple_functions)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- " function g(uint b) returns(uint e) { return b * 8; }\n"
- "}\n";
- ContractDefinition const& contract = checkInterface(sourceCode);
- set expectation({"function f(uint256 a)returns(uint256 d){}",
- "function g(uint256 b)returns(uint256 e){}"});
- BOOST_REQUIRE_EQUAL(2, contract.getDefinedFunctions().size());
- BOOST_CHECK(expectation == set({getSourcePart(*contract.getDefinedFunctions().at(0)),
- getSourcePart(*contract.getDefinedFunctions().at(1))}));
-}
-
-BOOST_AUTO_TEST_CASE(exclude_fallback_function)
-{
- char const* sourceCode = "contract test { function() {} }";
- ContractDefinition const& contract = checkInterface(sourceCode);
- BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}");
-}
-
-BOOST_AUTO_TEST_CASE(events)
-{
- char const* sourceCode = "contract test {\n"
- " function f(uint a) returns(uint d) { return a * 7; }\n"
- " event e1(uint b, address indexed c); \n"
- " event e2(); \n"
- "}\n";
- ContractDefinition const& contract = checkInterface(sourceCode);
- // events should not appear in the Solidity Interface
- BOOST_REQUIRE_EQUAL(0, contract.getEvents().size());
-}
-
-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"
- " } \n"
- " contract Derived is Base { \n"
- " function derivedFunction(string32 p) returns (string32 i) { return p; } \n"
- " event derivedEvent(uint indexed evtArgDerived); \n"
- " }";
- ContractDefinition const& contract = checkInterface(sourceCode);
- set expectedFunctions({"function baseFunction(uint256 p)returns(uint256 i){}",
- "function derivedFunction(string32 p)returns(string32 i){}"});
- BOOST_REQUIRE_EQUAL(2, contract.getDefinedFunctions().size());
- BOOST_CHECK(expectedFunctions == set({getSourcePart(*contract.getDefinedFunctions().at(0)),
- getSourcePart(*contract.getDefinedFunctions().at(1))}));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-}
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
deleted file mode 100644
index da6c2a88a..000000000
--- a/SolidityNameAndTypeResolution.cpp
+++ /dev/null
@@ -1,1184 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @date 2014
- * Unit tests for the name and type resolution of the solidity parser.
- */
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-namespace
-{
-
-ASTPointer parseTextAndResolveNames(std::string const& _source)
-{
- Parser parser;
- ASTPointer sourceUnit = parser.parse(std::make_shared(CharStream(_source)));
- NameAndTypeResolver resolver({});
- resolver.registerDeclarations(*sourceUnit);
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- resolver.resolveNamesAndTypes(*contract);
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- resolver.checkTypeRequirements(*contract);
-
- return sourceUnit;
-}
-
-ASTPointer parseTextAndResolveNamesWithChecks(std::string const& _source)
-{
- Parser parser;
- ASTPointer sourceUnit;
- try
- {
- sourceUnit = parser.parse(std::make_shared(CharStream(_source)));
- NameAndTypeResolver resolver({});
- resolver.registerDeclarations(*sourceUnit);
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- resolver.resolveNamesAndTypes(*contract);
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- resolver.checkTypeRequirements(*contract);
- }
- catch(boost::exception const& _e)
- {
- auto msg = std::string("Parsing text and resolving names failed with: \n") + boost::diagnostic_information(_e);
- BOOST_FAIL(msg);
- }
- return sourceUnit;
-}
-
-static ContractDefinition const* retrieveContract(ASTPointer _source, unsigned index)
-{
- ContractDefinition* contract;
- unsigned counter = 0;
- for (ASTPointer const& node: _source->getNodes())
- if ((contract = dynamic_cast(node.get())) && counter == index)
- return contract;
-
- return NULL;
-}
-
-static FunctionTypePointer const& retrieveFunctionBySignature(ContractDefinition const* _contract,
- std::string const& _signature)
-{
- FixedHash<4> hash(dev::sha3(_signature));
- return _contract->getInterfaceFunctions()[hash];
-}
-}
-
-BOOST_AUTO_TEST_SUITE(SolidityNameAndTypeResolution)
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- char const* text = "contract test {\n"
- " uint256 stateVariable1;\n"
- " function fun(uint256 arg1) { var x; uint256 y; }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text));
-}
-
-BOOST_AUTO_TEST_CASE(double_stateVariable_declaration)
-{
- char const* text = "contract test {\n"
- " uint256 variable;\n"
- " uint128 variable;\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(double_function_declaration)
-{
- char const* text = "contract test {\n"
- " function fun() { var x; }\n"
- " function fun() { var x; }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(double_variable_declaration)
-{
- char const* text = "contract test {\n"
- " function f() { uint256 x; if (true) { uint256 x; } }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(name_shadowing)
-{
- char const* text = "contract test {\n"
- " uint256 variable;\n"
- " function f() { uint32 variable ; }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(name_references)
-{
- char const* text = "contract test {\n"
- " uint256 variable;\n"
- " function f(uint256 arg) returns (uint out) { f(variable); test; out; }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(undeclared_name)
-{
- char const* text = "contract test {\n"
- " uint256 variable;\n"
- " function f(uint256 arg) { f(notfound); }"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(reference_to_later_declaration)
-{
- char const* text = "contract test {\n"
- " function g() { f(); }"
- " function f() { }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition_directly_recursive)
-{
- char const* text = "contract test {\n"
- " struct MyStructName {\n"
- " address addr;\n"
- " MyStructName x;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition_indirectly_recursive)
-{
- char const* text = "contract test {\n"
- " struct MyStructName1 {\n"
- " address addr;\n"
- " uint256 count;\n"
- " MyStructName2 x;\n"
- " }\n"
- " struct MyStructName2 {\n"
- " MyStructName1 x;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition_recursion_via_mapping)
-{
- char const* text = "contract test {\n"
- " struct MyStructName1 {\n"
- " address addr;\n"
- " uint256 count;\n"
- " mapping(uint => MyStructName1) x;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(type_inference_smoke_test)
-{
- char const* text = "contract test {\n"
- " function f(uint256 arg1, uint32 arg2) returns (bool ret) { var x = arg1 + arg2 == 8; ret = x; }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(type_checking_return)
-{
- char const* text = "contract test {\n"
- " function f() returns (bool r) { return 1 >= 2; }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(type_checking_return_wrong_number)
-{
- char const* text = "contract test {\n"
- " function f() returns (bool r1, bool r2) { return 1 >= 2; }"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(type_checking_return_wrong_type)
-{
- char const* text = "contract test {\n"
- " function f() returns (uint256 r) { return 1 >= 2; }"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(type_checking_function_call)
-{
- char const* text = "contract test {\n"
- " function f() returns (bool r) { return g(12, true) == 3; }\n"
- " function g(uint256 a, bool b) returns (uint256 r) { }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(type_conversion_for_comparison)
-{
- char const* text = "contract test {\n"
- " function f() { uint32(2) == int64(2); }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(type_conversion_for_comparison_invalid)
-{
- char const* text = "contract test {\n"
- " function f() { int32(2) == uint64(2); }"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion)
-{
- char const* text = "contract test {\n"
- " function f() returns (int256 r) { var x = int256(uint32(2)); return x; }"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(large_string_literal)
-{
- char const* text = "contract test {\n"
- " function f() { var x = \"123456789012345678901234567890123\"; }"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(balance)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " uint256 x = address(0).balance;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(balance_invalid)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " address(0).balance = 7;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(assignment_to_mapping)
-{
- char const* text = "contract test {\n"
- " struct str {\n"
- " mapping(uint=>uint) map;\n"
- " }\n"
- " str data;"
- " function fun() {\n"
- " var a = data.map;\n"
- " data.map = a;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(assignment_to_struct)
-{
- char const* text = "contract test {\n"
- " struct str {\n"
- " mapping(uint=>uint) map;\n"
- " }\n"
- " str data;"
- " function fun() {\n"
- " var a = data;\n"
- " data = a;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(returns_in_constructor)
-{
- char const* text = "contract test {\n"
- " function test() returns (uint a) {\n"
- " }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(forward_function_reference)
-{
- char const* text = "contract First {\n"
- " function fun() returns (bool ret) {\n"
- " return Second(1).fun(1, true, 3) > 0;\n"
- " }\n"
- "}\n"
- "contract Second {\n"
- " function fun(uint a, bool b, uint c) returns (uint ret) {\n"
- " if (First(2).fun() == true) return 1;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(comparison_bitop_precedence)
-{
- char const* text = "contract First {\n"
- " function fun() returns (bool ret) {\n"
- " return 1 & 2 == 8 & 9 && 1 ^ 2 < 4 | 6;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(function_canonical_signature)
-{
- ASTPointer sourceUnit;
- char const* text = "contract Test {\n"
- " function foo(uint256 arg1, uint64 arg2, bool arg3) returns (uint256 ret) {\n"
- " ret = arg1 + arg2;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text));
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_EQUAL("foo(uint256,uint64,bool)", functions[0]->getCanonicalSignature());
- }
-}
-
-BOOST_AUTO_TEST_CASE(function_canonical_signature_type_aliases)
-{
- ASTPointer sourceUnit;
- char const* text = "contract Test {\n"
- " function boo(uint arg1, hash arg2, address arg3) returns (uint ret) {\n"
- " ret = 5;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text));
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ContractDefinition* contract = dynamic_cast(node.get()))
- {
- auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_EQUAL("boo(uint256,hash256,address)", functions[0]->getCanonicalSignature());
- }
-}
-
-BOOST_AUTO_TEST_CASE(hash_collision_in_interface)
-{
- char const* text = "contract test {\n"
- " function gsf() {\n"
- " }\n"
- " function tgeo() {\n"
- " }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(inheritance_basic)
-{
- char const* text = R"(
- contract base { uint baseMember; struct BaseType { uint element; } }
- contract derived is base {
- BaseType data;
- function f() { baseMember = 7; }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(inheritance_diamond_basic)
-{
- char const* text = R"(
- contract root { function rootFunction() {} }
- contract inter1 is root { function f() {} }
- contract inter2 is root { function f() {} }
- contract derived is root, inter2, inter1 {
- function g() { f(); rootFunction(); }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(cyclic_inheritance)
-{
- char const* text = R"(
- contract A is B { }
- contract B is A { }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(illegal_override_direct)
-{
- char const* text = R"(
- contract B { function f() {} }
- contract C is B { function f(uint i) {} }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(illegal_override_indirect)
-{
- char const* text = R"(
- contract A { function f(uint a) {} }
- contract B { function f() {} }
- contract C is A, B { }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(illegal_override_visibility)
-{
- char const* text = R"(
- contract B { function f() inheritable {} }
- contract C is B { function f() public {} }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(illegal_override_constness)
-{
- char const* text = R"(
- contract B { function f() constant {} }
- contract C is B { function f() {} }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(complex_inheritance)
-{
- char const* text = R"(
- contract A { function f() { uint8 x = C(0).g(); } }
- contract B { function f() {} function g() returns (uint8 r) {} }
- contract C is A, B { }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(constructor_visibility)
-{
- // The constructor of a base class should not be visible in the derived class
- char const* text = R"(
- contract A { function A() { } }
- contract B is A { function f() { A x = A(0); } }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(overriding_constructor)
-{
- // It is fine to "override" constructor of a base class since it is invisible
- char const* text = R"(
- contract A { function A() { } }
- contract B is A { function A() returns (uint8 r) {} }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(missing_base_constructor_arguments)
-{
- char const* text = R"(
- contract A { function A(uint a) { } }
- contract B is A { }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(base_constructor_arguments_override)
-{
- char const* text = R"(
- contract A { function A(uint a) { } }
- contract B is A { }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion)
-{
- char const* text = R"(
- contract A { }
- contract B is A {
- function f() { A a = B(1); }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(implicit_base_to_derived_conversion)
-{
- char const* text = R"(
- contract A { }
- contract B is A {
- function f() { B b = A(1); }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_invocation)
-{
- char const* text = R"(
- contract B {
- function f() mod1(2, true) mod2("0123456") { }
- modifier mod1(uint a, bool b) { if (b) _ }
- modifier mod2(string7 a) { while (a == "1234567") _ }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(invalid_function_modifier_type)
-{
- char const* text = R"(
- contract B {
- function f() mod1(true) { }
- modifier mod1(uint a) { if (a > 0) _ }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-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) { }
- modifier mod1(uint a, bool b) { if (b) _ }
- modifier mod2(string7 a) { while (a == "1234567") _ }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables)
-{
- char const* text = R"(
- contract B {
- function f() mod(x) { uint x = 7; }
- modifier mod(uint a) { if (a > 0) _ }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(legal_modifier_override)
-{
- char const* text = R"(
- contract A { modifier mod(uint a) {} }
- contract B is A { modifier mod(uint a) {} }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(illegal_modifier_override)
-{
- char const* text = R"(
- contract A { modifier mod(uint a) {} }
- contract B is A { modifier mod(uint8 a) {} }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(modifier_overrides_function)
-{
- char const* text = R"(
- contract A { modifier mod(uint a) {} }
- contract B is A { function mod(uint a) {} }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(function_overrides_modifier)
-{
- char const* text = R"(
- contract A { function mod(uint a) {} }
- contract B is A { modifier mod(uint a) {} }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(modifier_returns_value)
-{
- char const* text = R"(
- contract A {
- function f(uint a) mod(2) returns (uint r) {}
- modifier mod(uint a) { return 7; }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(state_variable_accessors)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "uint256 public foo;\n"
- "mapping(uint=>string4) public map;\n"
- "mapping(uint=>mapping(uint=>string4)) public multiple_map;\n"
- "}\n";
-
- ASTPointer source;
- ContractDefinition const* contract;
- BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text));
- BOOST_REQUIRE((contract = retrieveContract(source, 0)) != nullptr);
- FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()");
- BOOST_REQUIRE(function && function->hasDeclaration());
- auto returnParams = function->getReturnParameterTypeNames();
- BOOST_CHECK_EQUAL(returnParams.at(0), "uint256");
- BOOST_CHECK(function->isConstant());
-
- function = retrieveFunctionBySignature(contract, "map(uint256)");
- BOOST_REQUIRE(function && function->hasDeclaration());
- auto params = function->getParameterTypeNames();
- BOOST_CHECK_EQUAL(params.at(0), "uint256");
- returnParams = function->getReturnParameterTypeNames();
- BOOST_CHECK_EQUAL(returnParams.at(0), "string4");
- BOOST_CHECK(function->isConstant());
-
- function = retrieveFunctionBySignature(contract, "multiple_map(uint256,uint256)");
- BOOST_REQUIRE(function && function->hasDeclaration());
- params = function->getParameterTypeNames();
- 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(function->isConstant());
-}
-
-BOOST_AUTO_TEST_CASE(function_clash_with_state_variable_accessor)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "uint256 foo;\n"
- " function foo() {}\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(private_state_variable)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "uint256 private foo;\n"
- "uint256 inheritable bar;\n"
- "}\n";
-
- ASTPointer source;
- ContractDefinition const* contract;
- BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text));
- BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr);
- FunctionTypePointer function;
- function = retrieveFunctionBySignature(contract, "foo()");
- BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a private variable should not exist");
- function = retrieveFunctionBySignature(contract, "bar()");
- BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of an inheritable variable should not exist");
-}
-
-BOOST_AUTO_TEST_CASE(fallback_function)
-{
- char const* text = R"(
- contract C {
- uint x;
- function() { x = 2; }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(fallback_function_with_arguments)
-{
- char const* text = R"(
- contract C {
- uint x;
- function(uint a) { x = 2; }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(fallback_function_twice)
-{
- char const* text = R"(
- contract C {
- uint x;
- function() { x = 2; }
- function() { x = 3; }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(fallback_function_inheritance)
-{
- char const* text = R"(
- contract A {
- uint x;
- function() { x = 1; }
- }
- contract C is A {
- function() { x = 2; }
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(event)
-{
- char const* text = R"(
- contract c {
- event e(uint indexed a, string3 indexed s, bool indexed b);
- function f() { e(2, "abc", true); }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-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);
- function f() { e(2, "abc", true); }
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(event_call)
-{
- char const* text = R"(
- contract c {
- event e(uint a, string3 indexed s, bool indexed b);
- function f() { e(2, "abc", true); }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(event_inheritance)
-{
- char const* text = R"(
- contract base {
- event e(uint a, string3 indexed s, bool indexed b);
- }
- contract c is base {
- function f() { e(2, "abc", true); }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(multiple_events_argument_clash)
-{
- char const* text = R"(
- contract c {
- event e1(uint a, uint e1, uint e2);
- event e2(uint a, uint e1, uint e2);
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(access_to_default_function_visibility)
-{
- char const* text = R"(
- contract c {
- function f() {}
- }
- contract d {
- function g() { c(0).f(); }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(access_to_inheritable_function)
-{
- char const* text = R"(
- contract c {
- function f() inheritable {}
- }
- contract d {
- function g() { c(0).f(); }
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(access_to_default_state_variable_visibility)
-{
- char const* text = R"(
- contract c {
- uint a;
- }
- contract d {
- function g() { c(0).a(); }
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(access_to_inheritable_state_variable)
-{
- char const* text = R"(
- contract c {
- uint public a;
- }
- contract d {
- function g() { c(0).a(); }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(error_count_in_named_args)
-{
- char const* sourceCode = "contract test {\n"
- " function a(uint a, uint b) returns (uint r) { r = a + b; }\n"
- " function b() returns (uint r) { r = a({a: 1}); }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(empty_in_named_args)
-{
- char const* sourceCode = "contract test {\n"
- " function a(uint a, uint b) returns (uint r) { r = a + b; }\n"
- " function b() returns (uint r) { r = a({}); }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(duplicate_parameter_names_in_named_args)
-{
- char const* sourceCode = "contract test {\n"
- " function a(uint a, uint b) returns (uint r) { r = a + b; }\n"
- " function b() returns (uint r) { r = a({a: 1, a: 2}); }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(invalid_parameter_names_in_named_args)
-{
- char const* sourceCode = "contract test {\n"
- " function a(uint a, uint b) returns (uint r) { r = a + b; }\n"
- " function b() returns (uint r) { r = a({a: 1, c: 2}); }\n"
- "}\n";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(empty_name_input_parameter)
-{
- char const* text = R"(
- contract test {
- function f(uint){
- }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
-{
- char const* text = R"(
- contract test {
- function f() returns(bool){
- }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
-{
- char const* text = R"(
- contract test {
- function f(uint, uint k) returns(uint ret_k){
- return k;
- }
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
-}
-
-BOOST_AUTO_TEST_CASE(empty_name_return_parameter_with_named_one)
-{
- char const* text = R"(
- contract test {
- function f() returns(uint ret_k, uint){
- return 5;
- }
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type)
-{
- char const* sourceCode = "contract c { function f() { var x = f(); } }";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units)
-{
- char const* sourceCodeFine = R"(
- contract c {
- function c ()
- {
- a = 115792089237316195423570985008687907853269984665640564039458;
- }
- uint256 a;
- })";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCodeFine));
- char const* sourceCode = R"(
- contract c {
- function c ()
- {
- a = 115792089237316195423570985008687907853269984665640564039458 ether;
- }
- uint256 a;
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(exp_operator_negative_exponent)
-{
- char const* sourceCode = R"(
- contract test {
- function f() returns(uint d) { return 2 ** -3; }
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big)
-{
- char const* sourceCode = R"(
- contract test {
- function f() returns(uint d) { return 2 ** 10000000000; }
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(enum_member_access)
-{
- char const* text = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
- function test()
- {
- choices = ActionChoices.GoStraight;
- }
- ActionChoices choices;
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text));
-}
-
-BOOST_AUTO_TEST_CASE(enum_invalid_member_access)
-{
- char const* text = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
- function test()
- {
- choices = ActionChoices.RunAroundWavingYourHands;
- }
- ActionChoices choices;
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay)
-{
- char const* text = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
- function test()
- {
- a = uint256(ActionChoices.GoStraight);
- b = uint64(ActionChoices.Sit);
- }
- uint256 a;
- uint64 b;
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text));
-}
-
-BOOST_AUTO_TEST_CASE(int_to_enum_explicit_conversion_is_okay)
-{
- char const* text = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
- function test()
- {
- a = 2;
- b = ActionChoices(a);
- }
- uint256 a;
- ActionChoices b;
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text));
-}
-
-BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay)
-{
- char const* text = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
- function test()
- {
- a = ActionChoices.GoStraight;
- b = ActionChoices.Sit;
- }
- uint256 a;
- uint64 b;
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(enum_duplicate_values)
-{
- char const* text = R"(
- contract test {
- enum ActionChoices { GoLeft, GoRight, GoLeft, Sit }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(private_visibility)
-{
- char const* sourceCode = R"(
- contract base {
- function f() private {}
- }
- contract derived is base {
- function g() { f(); }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(private_visibility_via_explicit_base_access)
-{
- char const* sourceCode = R"(
- contract base {
- function f() private {}
- }
- contract derived is base {
- function g() { base.f(); }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(external_visibility)
-{
- char const* sourceCode = R"(
- contract c {
- function f() external {}
- function g() { f(); }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), DeclarationError);
-}
-
-BOOST_AUTO_TEST_CASE(external_base_visibility)
-{
- char const* sourceCode = R"(
- contract base {
- function f() external {}
- }
- contract derived is base {
- function g() { base.f(); }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(external_argument_assign)
-{
- char const* sourceCode = R"(
- contract c {
- function f(uint a) external { a = 1; }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(external_argument_increment)
-{
- char const* sourceCode = R"(
- contract c {
- function f(uint a) external { a++; }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(external_argument_delete)
-{
- char const* sourceCode = R"(
- contract c {
- function f(uint a) external { delete a; }
- }
- )";
- BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
-}
-
-BOOST_AUTO_TEST_CASE(test_for_bug_override_function_with_bytearray_type)
-{
- char const* sourceCode = R"(
- contract Vehicle {
- function f(bytes _a) external returns (uint256 r) {r = 1;}
- }
- contract Bike is Vehicle {
- function f(bytes _a) external returns (uint256 r) {r = 42;}
- }
- )";
- BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(sourceCode));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
-
diff --git a/SolidityNatspecJSON.cpp b/SolidityNatspecJSON.cpp
deleted file mode 100644
index d1a443c21..000000000
--- a/SolidityNatspecJSON.cpp
+++ /dev/null
@@ -1,546 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
- */
-/**
- * @author Lefteris Karapetsas
- * @date 2014
- * Unit tests for the solidity compiler JSON Interface output.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-class DocumentationChecker
-{
-public:
- DocumentationChecker(): m_compilerStack(false) {}
-
- void checkNatspec(std::string const& _code,
- std::string const& _expectedDocumentationString,
- bool _userDocumentation)
- {
- std::string generatedDocumentationString;
- try
- {
- m_compilerStack.parse(_code);
- }
- catch(boost::exception const& _e)
- {
- auto msg = std::string("Parsing contract failed with: ") + boost::diagnostic_information(_e);
- BOOST_FAIL(msg);
- }
-
- if (_userDocumentation)
- generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NatspecUser);
- else
- generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NatspecDev);
- Json::Value generatedDocumentation;
- m_reader.parse(generatedDocumentationString, generatedDocumentation);
- Json::Value expectedDocumentation;
- m_reader.parse(_expectedDocumentationString, expectedDocumentation);
- BOOST_CHECK_MESSAGE(expectedDocumentation == generatedDocumentation,
- "Expected " << _expectedDocumentationString <<
- "\n but got:\n" << generatedDocumentationString);
- }
-
-private:
- CompilerStack m_compilerStack;
- Json::Reader m_reader;
-};
-
-BOOST_FIXTURE_TEST_SUITE(SolidityNatspecJSON, DocumentationChecker)
-
-BOOST_AUTO_TEST_CASE(user_basic_test)
-{
- char const* sourceCode = "contract test {\n"
- " /// @notice Multiplies `a` by 7\n"
- " function mul(uint a) returns(uint d) { return a * 7; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256)\":{ \"notice\": \"Multiplies `a` by 7\"}"
- "}}";
-
- checkNatspec(sourceCode, natspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(dev_and_user_basic_test)
-{
- char const* sourceCode = "contract test {\n"
- " /// @notice Multiplies `a` by 7\n"
- " /// @dev Multiplies a number by 7\n"
- " function mul(uint a) returns(uint d) { return a * 7; }\n"
- "}\n";
-
- char const* devNatspec = "{"
- "\"methods\":{"
- " \"mul(uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7\"\n"
- " }\n"
- " }\n"
- "}}";
-
- char const* userNatspec = "{"
- "\"methods\":{"
- " \"mul(uint256)\":{ \"notice\": \"Multiplies `a` by 7\"}"
- "}}";
-
- checkNatspec(sourceCode, devNatspec, false);
- checkNatspec(sourceCode, userNatspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(user_multiline_comment)
-{
- char const* sourceCode = "contract test {\n"
- " /// @notice Multiplies `a` by 7\n"
- " /// and then adds `b`\n"
- " function mul_and_add(uint a, uint256 b) returns(uint256 d)\n"
- " {\n"
- " return (a * 7) + b;\n"
- " }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul_and_add(uint256,uint256)\":{ \"notice\": \"Multiplies `a` by 7 and then adds `b`\"}"
- "}}";
-
- checkNatspec(sourceCode, natspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(user_multiple_functions)
-{
- char const* sourceCode = "contract test {\n"
- " /// @notice Multiplies `a` by 7 and then adds `b`\n"
- " function mul_and_add(uint a, uint256 b) returns(uint256 d)\n"
- " {\n"
- " return (a * 7) + b;\n"
- " }\n"
- "\n"
- " /// @notice Divides `input` by `div`\n"
- " function divide(uint input, uint div) returns(uint d)\n"
- " {\n"
- " return input / div;\n"
- " }\n"
- " /// @notice Subtracts 3 from `input`\n"
- " function sub(int input) returns(int d)\n"
- " {\n"
- " return input - 3;\n"
- " }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul_and_add(uint256,uint256)\":{ \"notice\": \"Multiplies `a` by 7 and then adds `b`\"},"
- " \"divide(uint256,uint256)\":{ \"notice\": \"Divides `input` by `div`\"},"
- " \"sub(int256)\":{ \"notice\": \"Subtracts 3 from `input`\"}"
- "}}";
-
- checkNatspec(sourceCode, natspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(user_empty_contract)
-{
- char const* sourceCode = "contract test {\n"
- "}\n";
-
- char const* natspec = "{\"methods\":{} }";
-
- checkNatspec(sourceCode, natspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(dev_and_user_no_doc)
-{
- char const* sourceCode = "contract test {\n"
- " function mul(uint a) returns(uint d) { return a * 7; }\n"
- " function sub(int input) returns(int d)\n"
- " {\n"
- " return input - 3;\n"
- " }\n"
- "}\n";
-
- char const* devNatspec = "{\"methods\":{}}";
-
- char const* userNatspec = "{\"methods\":{}}";
-
- checkNatspec(sourceCode, devNatspec, false);
- checkNatspec(sourceCode, userNatspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(dev_desc_after_nl)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev\n"
- " /// Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter\n"
- " /// @param second Documentation for the second parameter\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \" Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " }\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_multiple_params)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter\n"
- " /// @param second Documentation for the second parameter\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " }\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter starts here.\n"
- " /// Since it's a really complicated parameter we need 2 lines\n"
- " /// @param second Documentation for the second parameter\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " }\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_multiple_functions)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter\n"
- " /// @param second Documentation for the second parameter\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- " \n"
- " /// @dev Divides 2 numbers\n"
- " /// @param input Documentation for the input parameter\n"
- " /// @param div Documentation for the div parameter\n"
- " function divide(uint input, uint div) returns(uint d)\n"
- " {\n"
- " return input / div;\n"
- " }\n"
- " /// @dev Subtracts 3 from `input`\n"
- " /// @param input Documentation for the input parameter\n"
- " function sub(int input) returns(int d)\n"
- " {\n"
- " return input - 3;\n"
- " }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " }\n"
- " },\n"
- " \"divide(uint256,uint256)\":{ \n"
- " \"details\": \"Divides 2 numbers\",\n"
- " \"params\": {\n"
- " \"input\": \"Documentation for the input parameter\",\n"
- " \"div\": \"Documentation for the div parameter\"\n"
- " }\n"
- " },\n"
- " \"sub(int256)\":{ \n"
- " \"details\": \"Subtracts 3 from `input`\",\n"
- " \"params\": {\n"
- " \"input\": \"Documentation for the input parameter\"\n"
- " }\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_return)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter starts here.\n"
- " /// Since it's a really complicated parameter we need 2 lines\n"
- " /// @param second Documentation for the second parameter\n"
- " /// @return The result of the multiplication\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " },\n"
- " \"return\": \"The result of the multiplication\"\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-BOOST_AUTO_TEST_CASE(dev_return_desc_after_nl)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter starts here.\n"
- " /// Since it's a really complicated parameter we need 2 lines\n"
- " /// @param second Documentation for the second parameter\n"
- " /// @return\n"
- " /// The result of the multiplication\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " },\n"
- " \"return\": \" The result of the multiplication\"\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-
-BOOST_AUTO_TEST_CASE(dev_multiline_return)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Multiplies a number by 7 and adds second parameter\n"
- " /// @param a Documentation for the first parameter starts here.\n"
- " /// Since it's a really complicated parameter we need 2 lines\n"
- " /// @param second Documentation for the second parameter\n"
- " /// @return The result of the multiplication\n"
- " /// and cookies with nutella\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " },\n"
- " \"return\": \"The result of the multiplication and cookies with nutella\"\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_multiline_comment)
-{
- char const* sourceCode = "contract test {\n"
- " /**\n"
- " * @dev Multiplies a number by 7 and adds second parameter\n"
- " * @param a Documentation for the first parameter starts here.\n"
- " * Since it's a really complicated parameter we need 2 lines\n"
- " * @param second Documentation for the second parameter\n"
- " * @return The result of the multiplication\n"
- " * and cookies with nutella\n"
- " */"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
- " \"params\": {\n"
- " \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n"
- " \"second\": \"Documentation for the second parameter\"\n"
- " },\n"
- " \"return\": \"The result of the multiplication and cookies with nutella\"\n"
- " }\n"
- "}}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_contract_no_doc)
-{
- char const* sourceCode = "contract test {\n"
- " /// @dev Mul function\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- " \"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Mul function\"\n"
- " }\n"
- " }\n"
- "}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_contract_doc)
-{
- char const* sourceCode = " /// @author Lefteris\n"
- " /// @title Just a test contract\n"
- "contract test {\n"
- " /// @dev Mul function\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- " \"author\": \"Lefteris\","
- " \"title\": \"Just a test contract\","
- " \"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Mul function\"\n"
- " }\n"
- " }\n"
- "}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_author_at_function)
-{
- char const* sourceCode = " /// @author Lefteris\n"
- " /// @title Just a test contract\n"
- "contract test {\n"
- " /// @dev Mul function\n"
- " /// @author John Doe\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- " \"author\": \"Lefteris\","
- " \"title\": \"Just a test contract\","
- " \"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Mul function\",\n"
- " \"author\": \"John Doe\",\n"
- " }\n"
- " }\n"
- "}";
-
- checkNatspec(sourceCode, natspec, false);
-}
-
-BOOST_AUTO_TEST_CASE(dev_title_at_function_error)
-{
- char const* sourceCode = " /// @author Lefteris\n"
- " /// @title Just a test contract\n"
- "contract test {\n"
- " /// @dev Mul function\n"
- " /// @title I really should not be here\n"
- " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
- "}\n";
-
- char const* natspec = "{"
- " \"author\": \"Lefteris\","
- " \"title\": \"Just a test contract\","
- " \"methods\":{"
- " \"mul(uint256,uint256)\":{ \n"
- " \"details\": \"Mul function\"\n"
- " }\n"
- " }\n"
- "}";
-
- BOOST_CHECK_THROW(checkNatspec(sourceCode, natspec, false), DocstringParsingError);
-}
-
-BOOST_AUTO_TEST_CASE(natspec_notice_without_tag)
-{
- char const* sourceCode = "contract test {\n"
- " /// I do something awesome\n"
- " function mul(uint a) returns(uint d) { return a * 7; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256)\":{ \"notice\": \"I do something awesome\"}"
- "}}";
-
- checkNatspec(sourceCode, natspec, true);
-}
-
-BOOST_AUTO_TEST_CASE(natspec_multiline_notice_without_tag)
-{
- char const* sourceCode = "contract test {\n"
- " /// I do something awesome\n"
- " /// which requires two lines to explain\n"
- " function mul(uint a) returns(uint d) { return a * 7; }\n"
- "}\n";
-
- char const* natspec = "{"
- "\"methods\":{"
- " \"mul(uint256)\":{ \"notice\": \"I do something awesome which requires two lines to explain\"}"
- "}}";
-
- checkNatspec(sourceCode, natspec, true);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-}
diff --git a/SolidityOptimizer.cpp b/SolidityOptimizer.cpp
deleted file mode 100644
index 41ec1f90c..000000000
--- a/SolidityOptimizer.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @date 2014
- * Tests for the Solidity optimizer.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-class OptimizerTestFramework: public ExecutionFramework
-{
-public:
- OptimizerTestFramework() { }
- /// Compiles the source code with and without optimizing.
- void compileBothVersions(unsigned _expectedSizeDecrease, std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") {
- m_optimize = false;
- bytes nonOptimizedBytecode = compileAndRun(_sourceCode, _value, _contractName);
- m_nonOptimizedContract = m_contractAddress;
- m_optimize = true;
- bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName);
- int sizeDiff = nonOptimizedBytecode.size() - optimizedBytecode.size();
- BOOST_CHECK_MESSAGE(sizeDiff == int(_expectedSizeDecrease), "Bytecode shrank by "
- + boost::lexical_cast(sizeDiff) + " bytes, expected: "
- + boost::lexical_cast(_expectedSizeDecrease));
- m_optimizedContract = m_contractAddress;
- }
-
- template
- void compareVersions(std::string _sig, Args const&... _arguments)
- {
- m_contractAddress = m_nonOptimizedContract;
- bytes nonOptimizedOutput = callContractFunction(_sig, _arguments...);
- m_contractAddress = m_optimizedContract;
- bytes optimizedOutput = callContractFunction(_sig, _arguments...);
- BOOST_CHECK_MESSAGE(nonOptimizedOutput == optimizedOutput, "Computed values do not match."
- "\nNon-Optimized: " + toHex(nonOptimizedOutput) +
- "\nOptimized: " + toHex(optimizedOutput));
- }
-
-protected:
- Address m_optimizedContract;
- Address m_nonOptimizedContract;
-};
-
-BOOST_FIXTURE_TEST_SUITE(SolidityOptimizer, OptimizerTestFramework)
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- char const* sourceCode = R"(
- contract test {
- function f(uint a) returns (uint b) {
- return a;
- }
- })";
- compileBothVersions(29, sourceCode);
- compareVersions("f(uint256)", u256(7));
-}
-
-BOOST_AUTO_TEST_CASE(large_integers)
-{
- char const* sourceCode = R"(
- contract test {
- function f() returns (uint a, uint b) {
- a = 0x234234872642837426347000000;
- b = 0x10000000000000000000000002;
- }
- })";
- compileBothVersions(36, sourceCode);
- compareVersions("f()");
-}
-
-BOOST_AUTO_TEST_CASE(invariants)
-{
- char const* sourceCode = R"(
- contract test {
- function f(int a) returns (int b) {
- return int(0) | (int(1) * (int(0) ^ (0 + a)));
- }
- })";
- compileBothVersions(41, sourceCode);
- compareVersions("f(uint256)", u256(0x12334664));
-}
-
-BOOST_AUTO_TEST_CASE(unused_expressions)
-{
- char const* sourceCode = R"(
- contract test {
- uint data;
- function f() returns (uint a, uint b) {
- 10 + 20;
- data;
- }
- })";
- compileBothVersions(33, sourceCode);
- compareVersions("f()");
-}
-
-BOOST_AUTO_TEST_CASE(constant_folding_both_sides)
-{
- // if constants involving the same associative and commutative operator are applied from both
- // sides, the operator should be applied only once, because the expression compiler pushes
- // literals as late as possible
- char const* sourceCode = R"(
- contract test {
- function f(uint x) returns (uint y) {
- return 98 ^ (7 * ((1 | (x | 1000)) * 40) ^ 102);
- }
- })";
- compileBothVersions(37, sourceCode);
- compareVersions("f(uint256)");
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
diff --git a/SolidityParser.cpp b/SolidityParser.cpp
deleted file mode 100644
index ddb582447..000000000
--- a/SolidityParser.cpp
+++ /dev/null
@@ -1,761 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @date 2014
- * Unit tests for the solidity parser.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-namespace
-{
-ASTPointer parseText(std::string const& _source)
-{
- Parser parser;
- ASTPointer sourceUnit = parser.parse(std::make_shared(CharStream(_source)));
- for (ASTPointer const& node: sourceUnit->getNodes())
- if (ASTPointer contract = dynamic_pointer_cast(node))
- return contract;
- BOOST_FAIL("No contract found in source.");
- return ASTPointer();
-}
-
-ASTPointer parseTextExplainError(std::string const& _source)
-{
- try
- {
- return parseText(_source);
- }
- catch (Exception const& exception)
- {
- // LTODO: Print the error in a kind of a better way?
- // In absence of CompilerStack we can't use SourceReferenceFormatter
- cout << "Exception while parsing: " << diagnostic_information(exception);
- // rethrow to signal test failure
- throw exception;
- }
-}
-
-static void checkFunctionNatspec(ASTPointer _function,
- std::string const& _expectedDoc)
-{
- auto doc = _function->getDocumentation();
- BOOST_CHECK_MESSAGE(doc != nullptr, "Function does not have Natspec Doc as expected");
- BOOST_CHECK_EQUAL(*doc, _expectedDoc);
-}
-
-}
-
-
-BOOST_AUTO_TEST_SUITE(SolidityParser)
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- char const* text = "contract test {\n"
- " uint256 stateVariable1;\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(missing_variable_name_in_declaration)
-{
- char const* text = "contract test {\n"
- " uint256 ;\n"
- "}\n";
- BOOST_CHECK_THROW(parseText(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(empty_function)
-{
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " function functionName(hash160 arg1, address addr) constant\n"
- " returns (int id)\n"
- " { }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(no_function_params)
-{
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " function functionName() {}\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(single_function_param)
-{
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " function functionName(hash hashin) returns (hash hashout) {}\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args)
-{
- char const* text = "contract test {\n"
- " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n"
- " function b() returns (uint r) { r = a({: 1, : 2, : 3}); }\n"
- "}\n";
- BOOST_CHECK_THROW(parseText(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(missing_argument_in_named_args)
-{
- char const* text = "contract test {\n"
- " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n"
- " function b() returns (uint r) { r = a({a: , b: , c: }); }\n"
- "}\n";
- BOOST_CHECK_THROW(parseText(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(function_natspec_documentation)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " /// This is a test function\n"
- " function functionName(hash hashin) returns (hash hashout) {}\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- checkFunctionNatspec(function, "This is a test function");
-}
-
-BOOST_AUTO_TEST_CASE(function_normal_comments)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " // We won't see this comment\n"
- " function functionName(hash hashin) returns (hash hashout) {}\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
- "Should not have gotten a Natspecc comment for this function");
-}
-
-BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " /// This is test function 1\n"
- " function functionName1(hash hashin) returns (hash hashout) {}\n"
- " /// This is test function 2\n"
- " function functionName2(hash hashin) returns (hash hashout) {}\n"
- " // nothing to see here\n"
- " function functionName3(hash hashin) returns (hash hashout) {}\n"
- " /// This is test function 4\n"
- " function functionName4(hash hashin) returns (hash hashout) {}\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- checkFunctionNatspec(function, "This is test function 1");
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(1));
- checkFunctionNatspec(function, "This is test function 2");
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(2));
- BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
- "Should not have gotten natspec comment for functionName3()");
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(3));
- checkFunctionNatspec(function, "This is test function 4");
-}
-
-BOOST_AUTO_TEST_CASE(multiline_function_documentation)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " /// This is a test function\n"
- " /// and it has 2 lines\n"
- " function functionName1(hash hashin) returns (hash hashout) {}\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- checkFunctionNatspec(function, "This is a test function\n"
- " and it has 2 lines");
-}
-
-BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " /// fun1 description\n"
- " function fun1(uint256 a) {\n"
- " var b;\n"
- " /// I should not interfere with actual natspec comments\n"
- " uint256 c;\n"
- " mapping(address=>hash) d;\n"
- " string name = \"Solidity\";"
- " }\n"
- " /// This is a test function\n"
- " /// and it has 2 lines\n"
- " function fun(hash hashin) returns (hash hashout) {}\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- checkFunctionNatspec(function, "fun1 description");
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(1));
- checkFunctionNatspec(function, "This is a test function\n"
- " and it has 2 lines");
-}
-
-BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " function ///I am in the wrong place \n"
- " fun1(uint256 a) {\n"
- " var b;\n"
- " /// I should not interfere with actual natspec comments\n"
- " uint256 c;\n"
- " mapping(address=>hash) d;\n"
- " string name = \"Solidity\";"
- " }\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_MESSAGE(!function->getDocumentation(),
- "Shouldn't get natspec docstring for this function");
-}
-
-BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature)
-{
- ASTPointer contract;
- ASTPointer function;
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " function fun1(uint256 a) {\n"
- " /// I should have been above the function signature\n"
- " var b;\n"
- " /// I should not interfere with actual natspec comments\n"
- " uint256 c;\n"
- " mapping(address=>hash) d;\n"
- " string name = \"Solidity\";"
- " }\n"
- "}\n";
- BOOST_REQUIRE_NO_THROW(contract = parseText(text));
- auto functions = contract->getDefinedFunctions();
-
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_MESSAGE(!function->getDocumentation(),
- "Shouldn't get natspec docstring for this function");
-}
-
-BOOST_AUTO_TEST_CASE(struct_definition)
-{
- char const* text = "contract test {\n"
- " uint256 stateVar;\n"
- " struct MyStructName {\n"
- " address addr;\n"
- " uint256 count;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(mapping)
-{
- char const* text = "contract test {\n"
- " mapping(address => string) names;\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(mapping_in_struct)
-{
- char const* text = "contract test {\n"
- " struct test_struct {\n"
- " address addr;\n"
- " uint256 count;\n"
- " mapping(hash => test_struct) self_reference;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-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"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(variable_definition)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " var b;\n"
- " uint256 c;\n"
- " mapping(address=>hash) d;\n"
- " customtype varname;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(variable_definition_with_initialization)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " var b = 2;\n"
- " uint256 c = 0x87;\n"
- " mapping(address=>hash) d;\n"
- " string name = \"Solidity\";"
- " customtype varname;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(operator_expression)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " uint256 x = (1 + 4) || false && (1 - 12) + -9;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(complex_expression)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " uint256 x = (1 + 4).member(++67)[a/=9] || true;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(exp_expression)
-{
- char const* text = R"(
- contract test {
- function fun(uint256 a) {
- uint256 x = 3 ** a;
- }
- })";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(while_loop)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " while (true) { uint256 x = 1; break; continue; } x = 9;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " for (uint256 i = 0; i < 10; i++)\n"
- " { uint256 x = i; break; continue; }\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " uint256 i =0;\n"
- " for (i = 0; i < 10; i++)\n"
- " { uint256 x = i; break; continue; }\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " uint256 i =0;\n"
- " for (;;)\n"
- " { uint256 x = i; break; continue; }\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " uint256 i =0;\n"
- " for (i = 0; i < 10; i++)\n"
- " continue;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(if_statement)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) {\n"
- " if (a >= 8) return 2; else { var b = 7; }\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(else_if_statement)
-{
- char const* text = "contract test {\n"
- " function fun(uint256 a) returns (address b) {\n"
- " if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78;\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(import_directive)
-{
- char const* text = "import \"abc\";\n"
- "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(multiple_contracts)
-{
- char const* text = "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n"
- "contract test2 {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(multiple_contracts_and_imports)
-{
- char const* text = "import \"abc\";\n"
- "contract test {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n"
- "import \"def\";\n"
- "contract test2 {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n"
- "import \"ghi\";\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(contract_inheritance)
-{
- char const* text = "contract base {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n"
- "contract derived is base {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(contract_multiple_inheritance)
-{
- char const* text = "contract base {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n"
- "contract derived is base, nonExisting {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments)
-{
- char const* text = "contract base {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n"
- "contract derived is base(2), nonExisting(\"abc\", \"def\", base.fun()) {\n"
- " function fun() {\n"
- " uint64(2);\n"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(placeholder_in_function_context)
-{
- char const* text = "contract c {\n"
- " function fun() returns (uint r) {\n"
- " var _ = 8;\n"
- " return _ + 1;"
- " }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(modifier)
-{
- char const* text = "contract c {\n"
- " modifier mod { if (msg.sender == 0) _ }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(modifier_arguments)
-{
- char const* text = "contract c {\n"
- " modifier mod(uint a) { if (msg.sender == a) _ }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(modifier_invocation)
-{
- char const* text = "contract c {\n"
- " modifier mod1(uint a) { if (msg.sender == a) _ }\n"
- " modifier mod2 { if (msg.sender == 2) _ }\n"
- " function f() mod1(7) mod2 { }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(fallback_function)
-{
- char const* text = "contract c {\n"
- " function() { }\n"
- "}\n";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(event)
-{
- char const* text = R"(
- contract c {
- event e();
- })";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(event_arguments)
-{
- char const* text = R"(
- contract c {
- event e(uint a, string32 s);
- })";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(event_arguments_indexed)
-{
- char const* text = R"(
- contract c {
- event e(uint a, string32 indexed s, bool indexed b);
- })";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(visibility_specifiers)
-{
- char const* text = R"(
- contract c {
- uint private a;
- uint inheritable b;
- uint public c;
- uint d;
- function f() {}
- function f_priv() private {}
- function f_public() public {}
- function f_inheritable() inheritable {}
- })";
- BOOST_CHECK_NO_THROW(parseText(text));
-}
-
-BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers)
-{
- char const* text = R"(
- contract c {
- uint private inheritable a;
- })";
- BOOST_CHECK_THROW(parseText(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations)
-{
- char const* text = R"(
- contract c {
- function c ()
- {
- a = 1 wei;
- b = 2 szabo;
- c = 3 finney;
- b = 4 ether;
- }
- uint256 a;
- uint256 b;
- uint256 c;
- uint256 d;
- })";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expressions)
-{
- char const* text = R"(
- contract c {
- function c ()
- {
- a = 1 wei * 100 wei + 7 szabo - 3;
- }
- uint256 a;
- })";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(enum_valid_declaration)
-{
- char const* text = R"(
- contract c {
- enum validEnum { Value1, Value2, Value3, Value4 }
- function c ()
- {
- a = foo.Value3;
- }
- uint256 a;
- })";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(empty_enum_declaration)
-{
- char const* text = R"(
- contract c {
- enum foo { }
- })";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(malformed_enum_declaration)
-{
- char const* text = R"(
- contract c {
- enum foo { WARNING,}
- })";
- BOOST_CHECK_THROW(parseText(text), ParserError);
-}
-
-BOOST_AUTO_TEST_CASE(external_function)
-{
- char const* text = R"(
- contract c {
- function x() external {}
- })";
- BOOST_CHECK_NO_THROW(parseTextExplainError(text));
-}
-
-BOOST_AUTO_TEST_CASE(external_variable)
-{
- char const* text = R"(
- contract c {
- uint external x;
- })";
- BOOST_CHECK_THROW(parseText(text), ParserError);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
-
diff --git a/SolidityScanner.cpp b/SolidityScanner.cpp
deleted file mode 100644
index 2e4e5db08..000000000
--- a/SolidityScanner.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/**
- * @author Christian
- * @date 2014
- * Unit tests for the solidity scanner.
- */
-
-#include
-#include
-
-namespace dev
-{
-namespace solidity
-{
-namespace test
-{
-
-BOOST_AUTO_TEST_SUITE(SolidityScanner)
-
-BOOST_AUTO_TEST_CASE(test_empty)
-{
- Scanner scanner(CharStream(""));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
-}
-
-BOOST_AUTO_TEST_CASE(smoke_test)
-{
- Scanner scanner(CharStream("function break;765 \t \"string1\",'string2'\nidentifier1"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Function);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Break);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "765");
- BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "string1");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Comma);
- BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "string2");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "identifier1");
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
-}
-
-BOOST_AUTO_TEST_CASE(string_escapes)
-{
- Scanner scanner(CharStream(" { \"a\\x61\""));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::LBrace);
- BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "aa");
-}
-
-BOOST_AUTO_TEST_CASE(string_escapes_with_zero)
-{
- Scanner scanner(CharStream(" { \"a\\x61\\x00abc\""));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::LBrace);
- BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), std::string("aa\0abc", 6));
-}
-
-BOOST_AUTO_TEST_CASE(string_escape_illegal)
-{
- Scanner scanner(CharStream(" bla \"\\x6rf\" (illegalescape)"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "");
- // TODO recovery from illegal tokens should be improved
- BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
-}
-
-BOOST_AUTO_TEST_CASE(hex_numbers)
-{
- Scanner scanner(CharStream("var x = 0x765432536763762734623472346;"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Var);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Assign);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "0x765432536763762734623472346");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
-}
-
-BOOST_AUTO_TEST_CASE(negative_numbers)
-{
- Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Var);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Assign);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Sub);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), ".2");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Sub);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "0x78");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Sub);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "7.3");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLiteral(), "8.9");
- BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
-}
-
-BOOST_AUTO_TEST_CASE(locations)
-{
- Scanner scanner(CharStream("function_identifier has ; -0x743/*comment*/\n ident //comment"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 0);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 19);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 20);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 23);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 24);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 25);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Sub);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 27);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 32);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().start, 45);
- BOOST_CHECK_EQUAL(scanner.getCurrentLocation().end, 50);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
-}
-
-BOOST_AUTO_TEST_CASE(ambiguities)
-{
- // test scanning of some operators which need look-ahead
- Scanner scanner(CharStream("<=""<""+ +=a++ =>""<<"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::LessThanOrEqual);
- BOOST_CHECK_EQUAL(scanner.next(), Token::LessThan);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
- BOOST_CHECK_EQUAL(scanner.next(), Token::AssignAdd);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Inc);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Arrow);
- BOOST_CHECK_EQUAL(scanner.next(), Token::SHL);
-}
-
-BOOST_AUTO_TEST_CASE(documentation_comments_parsed_begin)
-{
- Scanner scanner(CharStream("/// Send $(value / 1000) chocolates to the user"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
-}
-
-BOOST_AUTO_TEST_CASE(multiline_documentation_comments_parsed_begin)
-{
- Scanner scanner(CharStream("/** Send $(value / 1000) chocolates to the user*/"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
-}
-
-BOOST_AUTO_TEST_CASE(documentation_comments_parsed)
-{
- Scanner scanner(CharStream("some other tokens /// Send $(value / 1000) chocolates to the user"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
-}
-
-BOOST_AUTO_TEST_CASE(multiline_documentation_comments_parsed)
-{
- Scanner scanner(CharStream("some other tokens /**\n"
- "* Send $(value / 1000) chocolates to the user\n"
- "*/"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
-}
-
-BOOST_AUTO_TEST_CASE(multiline_documentation_no_stars)
-{
- Scanner scanner(CharStream("some other tokens /**\n"
- " Send $(value / 1000) chocolates to the user\n"
- "*/"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
-}
-
-BOOST_AUTO_TEST_CASE(multiline_documentation_whitespace_hell)
-{
- Scanner scanner(CharStream("some other tokens /** \t \r \n"
- "\t \r * Send $(value / 1000) chocolates to the user\n"
- "*/"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "Send $(value / 1000) chocolates to the user");
-}
-
-BOOST_AUTO_TEST_CASE(comment_before_eos)
-{
- Scanner scanner(CharStream("//"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "");
-}
-
-BOOST_AUTO_TEST_CASE(documentation_comment_before_eos)
-{
- Scanner scanner(CharStream("///"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "");
-}
-
-BOOST_AUTO_TEST_CASE(empty_multiline_comment)
-{
- Scanner scanner(CharStream("/**/"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "");
-}
-
-BOOST_AUTO_TEST_CASE(empty_multiline_documentation_comment_before_eos)
-{
- Scanner scanner(CharStream("/***/"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "");
-}
-
-BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
-{
- Scanner scanner(CharStream("hello_world ///documentation comment \n"
- "//simple comment \n"
- "<<"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::Identifier);
- BOOST_CHECK_EQUAL(scanner.next(), Token::SHL);
- BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), "documentation comment ");
-}
-
-BOOST_AUTO_TEST_CASE(ether_subdenominations)
-{
- Scanner scanner(CharStream("wei szabo finney ether"));
- BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::SubWei);
- BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo);
- BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney);
- BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-}
-}
-} // end namespaces
diff --git a/TestHelper.cpp b/TestHelper.cpp
deleted file mode 100644
index ff6939a5f..000000000
--- a/TestHelper.cpp
+++ /dev/null
@@ -1,574 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file TestHelper.cpp
- * @author Marko Simovic
- * @date 2014
- */
-
-#include "TestHelper.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace std;
-using namespace dev::eth;
-
-namespace dev
-{
-namespace eth
-{
-
-void mine(Client& c, int numBlocks)
-{
- auto startBlock = c.blockChain().details().number;
-
- c.startMining();
- while(c.blockChain().details().number < startBlock + numBlocks)
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- c.stopMining();
-}
-
-void connectClients(Client& c1, Client& c2)
-{
- (void)c1;
- (void)c2;
- // TODO: Move to WebThree. eth::Client no longer handles networking.
-#if 0
- short c1Port = 20000;
- short c2Port = 21000;
- c1.startNetwork(c1Port);
- c2.startNetwork(c2Port);
- c2.connect("127.0.0.1", c1Port);
-#endif
-}
-}
-
-namespace test
-{
-
-struct ValueTooLarge: virtual Exception {};
-bigint const c_max256plus1 = bigint(1) << 256;
-
-ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o)
-{
- importEnv(_o["env"].get_obj());
- importState(_o["pre"].get_obj(), m_statePre);
- importTransaction(_o["transaction"].get_obj());
-
- if (!isFiller)
- {
- importState(_o["post"].get_obj(), m_statePost);
- m_environment.sub.logs = importLog(_o["logs"].get_array());
- }
-}
-
-void ImportTest::importEnv(json_spirit::mObject& _o)
-{
- BOOST_REQUIRE(_o.count("previousHash") > 0);
- BOOST_REQUIRE(_o.count("currentGasLimit") > 0);
- BOOST_REQUIRE(_o.count("currentDifficulty") > 0);
- BOOST_REQUIRE(_o.count("currentTimestamp") > 0);
- BOOST_REQUIRE(_o.count("currentCoinbase") > 0);
- BOOST_REQUIRE(_o.count("currentNumber") > 0);
-
- m_environment.previousBlock.hash = h256(_o["previousHash"].get_str());
- m_environment.currentBlock.number = toInt(_o["currentNumber"]);
- m_environment.currentBlock.gasLimit = toInt(_o["currentGasLimit"]);
- m_environment.currentBlock.difficulty = toInt(_o["currentDifficulty"]);
- m_environment.currentBlock.timestamp = toInt(_o["currentTimestamp"]);
- m_environment.currentBlock.coinbaseAddress = Address(_o["currentCoinbase"].get_str());
-
- m_statePre.m_previousBlock = m_environment.previousBlock;
- m_statePre.m_currentBlock = m_environment.currentBlock;
-}
-
-void ImportTest::importState(json_spirit::mObject& _o, State& _state)
-{
- for (auto& i: _o)
- {
- json_spirit::mObject o = i.second.get_obj();
-
- BOOST_REQUIRE(o.count("balance") > 0);
- BOOST_REQUIRE(o.count("nonce") > 0);
- BOOST_REQUIRE(o.count("storage") > 0);
- BOOST_REQUIRE(o.count("code") > 0);
-
- if (bigint(o["balance"].get_str()) >= c_max256plus1)
- BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'balance' is equal or greater than 2**256") );
- if (bigint(o["nonce"].get_str()) >= c_max256plus1)
- BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("State 'nonce' is equal or greater than 2**256") );
-
- Address address = Address(i.first);
-
- bytes code = importCode(o);
-
- if (code.size())
- {
- _state.m_cache[address] = Account(toInt(o["balance"]), Account::ContractConception);
- _state.m_cache[address].setCode(code);
- }
- else
- _state.m_cache[address] = Account(toInt(o["balance"]), Account::NormalCreation);
-
- for (auto const& j: o["storage"].get_obj())
- _state.setStorage(address, toInt(j.first), toInt(j.second));
-
- for(int i=0; i 0);
- BOOST_REQUIRE(_o.count("gasPrice") > 0);
- BOOST_REQUIRE(_o.count("gasLimit") > 0);
- BOOST_REQUIRE(_o.count("to") > 0);
- BOOST_REQUIRE(_o.count("value") > 0);
- BOOST_REQUIRE(_o.count("secretKey") > 0);
- BOOST_REQUIRE(_o.count("data") > 0);
-
- if (bigint(_o["nonce"].get_str()) >= c_max256plus1)
- BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'nonce' is equal or greater than 2**256") );
- if (bigint(_o["gasPrice"].get_str()) >= c_max256plus1)
- BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasPrice' is equal or greater than 2**256") );
- if (bigint(_o["gasLimit"].get_str()) >= c_max256plus1)
- BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasLimit' is equal or greater than 2**256") );
- if (bigint(_o["value"].get_str()) >= c_max256plus1)
- BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'value' is equal or greater than 2**256") );
-
- m_transaction = _o["to"].get_str().empty() ?
- Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) :
- Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), Address(_o["to"].get_str()), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str()));
-}
-
-void ImportTest::exportTest(bytes _output, State& _statePost)
-{
- // export output
- m_TestObject["out"] = "0x" + toHex(_output);
-
- // export logs
- m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
-
- // export post state
- json_spirit::mObject postState;
-
- std::map genesis = genesisState();
-
- for (auto const& a: _statePost.addresses())
- {
- if (genesis.count(a.first))
- continue;
-
- json_spirit::mObject o;
- o["balance"] = toString(_statePost.balance(a.first));
- o["nonce"] = toString(_statePost.transactionsFrom(a.first));
- {
- json_spirit::mObject store;
- for (auto const& s: _statePost.storage(a.first))
- store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second));
- o["storage"] = store;
- }
- o["code"] = "0x" + toHex(_statePost.code(a.first));
-
- postState[toString(a.first)] = o;
- }
- m_TestObject["post"] = json_spirit::mValue(postState);
-
- // export pre state
- json_spirit::mObject preState;
-
- for (auto const& a: m_statePre.addresses())
- {
- if (genesis.count(a.first))
- continue;
-
- json_spirit::mObject o;
- o["balance"] = toString(m_statePre.balance(a.first));
- o["nonce"] = toString(m_statePre.transactionsFrom(a.first));
- {
- json_spirit::mObject store;
- for (auto const& s: m_statePre.storage(a.first))
- store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second));
- o["storage"] = store;
- }
- o["code"] = "0x" + toHex(m_statePre.code(a.first));
-
- preState[toString(a.first)] = o;
- }
- m_TestObject["pre"] = json_spirit::mValue(preState);
-}
-
-u256 toInt(json_spirit::mValue const& _v)
-{
- switch (_v.type())
- {
- case json_spirit::str_type: return u256(_v.get_str());
- case json_spirit::int_type: return (u256)_v.get_uint64();
- case json_spirit::bool_type: return (u256)(uint64_t)_v.get_bool();
- case json_spirit::real_type: return (u256)(uint64_t)_v.get_real();
- default: cwarn << "Bad type for scalar: " << _v.type();
- }
- return 0;
-}
-
-byte toByte(json_spirit::mValue const& _v)
-{
- switch (_v.type())
- {
- case json_spirit::str_type: return (byte)stoi(_v.get_str());
- case json_spirit::int_type: return (byte)_v.get_uint64();
- case json_spirit::bool_type: return (byte)_v.get_bool();
- case json_spirit::real_type: return (byte)_v.get_real();
- default: cwarn << "Bad type for scalar: " << _v.type();
- }
- return 0;
-}
-
-bytes importByteArray(std::string const& _str)
-{
- return fromHex(_str.substr(0, 2) == "0x" ? _str.substr(2) : _str, ThrowType::Throw);
-}
-
-bytes importData(json_spirit::mObject& _o)
-{
- bytes data;
- if (_o["data"].type() == json_spirit::str_type)
- data = importByteArray(_o["data"].get_str());
- else
- for (auto const& j: _o["data"].get_array())
- data.push_back(toByte(j));
- return data;
-}
-
-bytes importCode(json_spirit::mObject& _o)
-{
- bytes code;
- if (_o["code"].type() == json_spirit::str_type)
- if (_o["code"].get_str().find_first_of("0x") != 0)
- code = compileLLL(_o["code"].get_str(), false);
- else
- code = fromHex(_o["code"].get_str().substr(2));
- else if (_o["code"].type() == json_spirit::array_type)
- {
- code.clear();
- for (auto const& j: _o["code"].get_array())
- code.push_back(toByte(j));
- }
- return code;
-}
-
-LogEntries importLog(json_spirit::mArray& _a)
-{
- LogEntries logEntries;
- for (auto const& l: _a)
- {
- json_spirit::mObject o = l.get_obj();
- // cant use BOOST_REQUIRE, because this function is used outside boost test (createRandomTest)
- assert(o.count("address") > 0);
- assert(o.count("topics") > 0);
- assert(o.count("data") > 0);
- assert(o.count("bloom") > 0);
- LogEntry log;
- log.address = Address(o["address"].get_str());
- for (auto const& t: o["topics"].get_array())
- log.topics.push_back(h256(t.get_str()));
- log.data = importData(o);
- logEntries.push_back(log);
- }
- return logEntries;
-}
-
-json_spirit::mArray exportLog(eth::LogEntries _logs)
-{
- json_spirit::mArray ret;
- if (_logs.size() == 0) return ret;
- for (LogEntry const& l: _logs)
- {
- json_spirit::mObject o;
- o["address"] = toString(l.address);
- json_spirit::mArray topics;
- for (auto const& t: l.topics)
- topics.push_back(toString(t));
- o["topics"] = topics;
- o["data"] = "0x" + toHex(l.data);
- o["bloom"] = toString(l.bloom());
- ret.push_back(o);
- }
- return ret;
-}
-
-void checkOutput(bytes const& _output, json_spirit::mObject& _o)
-{
- int j = 0;
- if (_o["out"].type() == json_spirit::array_type)
- for (auto const& d: _o["out"].get_array())
- {
- BOOST_CHECK_MESSAGE(_output[j] == toInt(d), "Output byte [" << j << "] different!");
- ++j;
- }
- else if (_o["out"].get_str().find("0x") == 0)
- BOOST_CHECK(_output == fromHex(_o["out"].get_str().substr(2)));
- else
- BOOST_CHECK(_output == fromHex(_o["out"].get_str()));
-}
-
-void checkStorage(map _expectedStore, map _resultStore, Address _expectedAddr)
-{
- for (auto&& expectedStorePair : _expectedStore)
- {
- auto& expectedStoreKey = expectedStorePair.first;
- auto resultStoreIt = _resultStore.find(expectedStoreKey);
- if (resultStoreIt == _resultStore.end())
- BOOST_ERROR(_expectedAddr << ": missing store key " << expectedStoreKey);
- else
- {
- auto& expectedStoreValue = expectedStorePair.second;
- auto& resultStoreValue = resultStoreIt->second;
- BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue);
- }
- }
- BOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size());
- for (auto&& resultStorePair: _resultStore)
- {
- if (!_expectedStore.count(resultStorePair.first))
- BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first);
- }
-}
-
-void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs)
-{
- BOOST_REQUIRE_EQUAL(_resultLogs.size(), _expectedLogs.size());
-
- for (size_t i = 0; i < _resultLogs.size(); ++i)
- {
- BOOST_CHECK_EQUAL(_resultLogs[i].address, _expectedLogs[i].address);
- BOOST_CHECK_EQUAL(_resultLogs[i].topics, _expectedLogs[i].topics);
- BOOST_CHECK(_resultLogs[i].data == _expectedLogs[i].data);
- }
-}
-
-void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates)
-{
- BOOST_REQUIRE_EQUAL(_resultCallCreates.size(), _expectedCallCreates.size());
-
- for (size_t i = 0; i < _resultCallCreates.size(); ++i)
- {
- BOOST_CHECK(_resultCallCreates[i].data() == _expectedCallCreates[i].data());
- BOOST_CHECK(_resultCallCreates[i].receiveAddress() == _expectedCallCreates[i].receiveAddress());
- BOOST_CHECK(_resultCallCreates[i].gas() == _expectedCallCreates[i].gas());
- BOOST_CHECK(_resultCallCreates[i].value() == _expectedCallCreates[i].value());
- }
-}
-
-std::string getTestPath()
-{
- string testPath;
- const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
-
- if (ptestPath == NULL)
- {
- cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
- testPath = "../../../tests";
- }
- else
- testPath = ptestPath;
-
- return testPath;
-}
-
-void userDefinedTest(string testTypeFlag, std::function doTests)
-{
- for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
- {
- string arg = boost::unit_test::framework::master_test_suite().argv[i];
- if (arg == testTypeFlag)
- {
- if (boost::unit_test::framework::master_test_suite().argc <= i + 2)
- {
- cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " \n";
- return;
- }
- string filename = boost::unit_test::framework::master_test_suite().argv[i + 1];
- string testname = boost::unit_test::framework::master_test_suite().argv[i + 2];
- int currentVerbosity = g_logVerbosity;
- g_logVerbosity = 12;
- try
- {
- cnote << "Testing user defined test: " << filename;
- json_spirit::mValue v;
- string s = asString(contents(filename));
- BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
- json_spirit::read_string(s, v);
- json_spirit::mObject oSingleTest;
-
- json_spirit::mObject::const_iterator pos = v.get_obj().find(testname);
- if (pos == v.get_obj().end())
- {
- cnote << "Could not find test: " << testname << " in " << filename << "\n";
- return;
- }
- else
- oSingleTest[pos->first] = pos->second;
-
- json_spirit::mValue v_singleTest(oSingleTest);
- doTests(v_singleTest, false);
- }
- catch (Exception const& _e)
- {
- BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
- g_logVerbosity = currentVerbosity;
- }
- catch (std::exception const& _e)
- {
- BOOST_ERROR("Failed Test with Exception: " << _e.what());
- g_logVerbosity = currentVerbosity;
- }
- g_logVerbosity = currentVerbosity;
- }
- else
- continue;
- }
-}
-
-void executeTests(const string& _name, const string& _testPathAppendix, std::function doTests)
-{
- string testPath = getTestPath();
- testPath += _testPathAppendix;
-
- for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
- {
- string arg = boost::unit_test::framework::master_test_suite().argv[i];
- if (arg == "--filltests")
- {
- try
- {
- cnote << "Populating tests...";
- json_spirit::mValue v;
- boost::filesystem::path p(__FILE__);
- boost::filesystem::path dir = p.parent_path();
- string s = asString(dev::contents(dir.string() + "/" + _name + "Filler.json"));
- BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + dir.string() + "/" + _name + "Filler.json is empty.");
- json_spirit::read_string(s, v);
- doTests(v, true);
- writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true)));
- }
- catch (Exception const& _e)
- {
- BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
- }
- catch (std::exception const& _e)
- {
- BOOST_ERROR("Failed test with Exception: " << _e.what());
- }
- break;
- }
- }
-
- try
- {
- cnote << "Testing ..." << _name;
- json_spirit::mValue v;
- string s = asString(dev::contents(testPath + "/" + _name + ".json"));
- BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testPath + "/" + _name + ".json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
- json_spirit::read_string(s, v);
- doTests(v, false);
- }
- catch (Exception const& _e)
- {
- BOOST_ERROR("Failed test with Exception: " << diagnostic_information(_e));
- }
- catch (std::exception const& _e)
- {
- BOOST_ERROR("Failed test with Exception: " << _e.what());
- }
-}
-
-RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj)
-{
- //Construct Rlp of the given transaction
- RLPStream rlpStream;
- rlpStream.appendList(_tObj.size());
-
- if (_tObj.count("nonce"))
- rlpStream << bigint(_tObj["nonce"].get_str());
-
- if (_tObj.count("gasPrice"))
- rlpStream << bigint(_tObj["gasPrice"].get_str());
-
- if (_tObj.count("gasLimit"))
- rlpStream << bigint(_tObj["gasLimit"].get_str());
-
- if (_tObj.count("to"))
- {
- if (_tObj["to"].get_str().empty())
- rlpStream << "";
- else
- rlpStream << importByteArray(_tObj["to"].get_str());
- }
-
- if (_tObj.count("value"))
- rlpStream << bigint(_tObj["value"].get_str());
-
- if (_tObj.count("data"))
- rlpStream << importData(_tObj);
-
- if (_tObj.count("v"))
- rlpStream << bigint(_tObj["v"].get_str());
-
- if (_tObj.count("r"))
- rlpStream << bigint(_tObj["r"].get_str());
-
- if (_tObj.count("s"))
- rlpStream << bigint(_tObj["s"].get_str());
-
- if (_tObj.count("extrafield"))
- rlpStream << bigint(_tObj["extrafield"].get_str());
-
- return rlpStream;
-}
-
-void processCommandLineOptions()
-{
- auto argc = boost::unit_test::framework::master_test_suite().argc;
- auto argv = boost::unit_test::framework::master_test_suite().argv;
-
- for (auto i = 0; i < argc; ++i)
- {
- if (std::string(argv[i]) == "--jit")
- {
- eth::VMFactory::setKind(eth::VMKind::JIT);
- break;
- }
- }
-}
-
-LastHashes lastHashes(u256 _currentBlockNumber)
-{
- LastHashes ret;
- for (u256 i = 1; i <= 256 && i <= _currentBlockNumber; ++i)
- ret.push_back(sha3(toString(_currentBlockNumber - i)));
- return ret;
-}
-
-} } // namespaces
diff --git a/TestHelper.h b/TestHelper.h
deleted file mode 100644
index c4dde1a60..000000000
--- a/TestHelper.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file TestHelper.h
- * @author Marko Simovic
- * @date 2014
- */
-
-#pragma once
-
-#include
-#include
-#include "JsonSpiritHeaders.h"
-#include
-#include
-
-namespace dev
-{
-namespace eth
-{
-
-class Client;
-
-void mine(Client& c, int numBlocks);
-void connectClients(Client& c1, Client& c2);
-
-}
-
-namespace test
-{
-
-class ImportTest
-{
-public:
- ImportTest(json_spirit::mObject& _o) : m_TestObject(_o) {}
- ImportTest(json_spirit::mObject& _o, bool isFiller);
-
- // imports
- void importEnv(json_spirit::mObject& _o);
- void importState(json_spirit::mObject& _o, eth::State& _state);
- void importTransaction(json_spirit::mObject& _o);
- void exportTest(bytes _output, eth::State& _statePost);
-
- eth::State m_statePre;
- eth::State m_statePost;
- eth::ExtVMFace m_environment;
- eth::Transaction m_transaction;
-
-private:
- json_spirit::mObject& m_TestObject;
-};
-
-// helping functions
-u256 toInt(json_spirit::mValue const& _v);
-byte toByte(json_spirit::mValue const& _v);
-bytes importCode(json_spirit::mObject& _o);
-bytes importData(json_spirit::mObject& _o);
-bytes importByteArray(std::string const& _str);
-eth::LogEntries importLog(json_spirit::mArray& _o);
-json_spirit::mArray exportLog(eth::LogEntries _logs);
-void checkOutput(bytes const& _output, json_spirit::mObject& _o);
-void checkStorage(std::map _expectedStore, std::map _resultStore, Address _expectedAddr);
-void checkLog(eth::LogEntries _resultLogs, eth::LogEntries _expectedLogs);
-void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates);
-
-void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function doTests);
-std::string getTestPath();
-void userDefinedTest(std::string testTypeFlag, std::function doTests);
-RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj);
-void processCommandLineOptions();
-eth::LastHashes lastHashes(u256 _currentBlockNumber);
-
-template
-void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
-{
- for (auto& resultPair : _resultAddrs)
- {
- auto& resultAddr = resultPair.first;
- auto expectedAddrIt = _expectedAddrs.find(resultAddr);
- if (expectedAddrIt == _expectedAddrs.end())
- BOOST_ERROR("Missing result address " << resultAddr);
- }
- BOOST_CHECK(_expectedAddrs == _resultAddrs);
-}
-
-}
-}
diff --git a/TrieHash.cpp b/TrieHash.cpp
deleted file mode 100644
index ee4f2e87d..000000000
--- a/TrieHash.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file TrieHash.cpp
- * @author Gav Wood
- * @date 2014
- */
-
-#include "TrieHash.h"
-
-#include
-#include
-#include
-using namespace std;
-using namespace dev;
-using namespace dev::eth;
-
-namespace dev
-{
-
-/*/
-#define APPEND_CHILD appendData
-/*/
-#define APPEND_CHILD appendRaw
-/**/
-
-#define ENABLE_DEBUG_PRINT 0
-
-#if ENABLE_DEBUG_PRINT
-bool g_hashDebug = false;
-#endif
-
-void hash256aux(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream& _rlp);
-
-void hash256rlp(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream& _rlp)
-{
-#if ENABLE_DEBUG_PRINT
- static std::string s_indent;
- if (_preLen)
- s_indent += " ";
-#endif
-
- if (_begin == _end)
- _rlp << ""; // NULL
- else if (std::next(_begin) == _end)
- {
- // only one left - terminate with the pair.
- _rlp.appendList(2) << hexPrefixEncode(_begin->first, true, _preLen) << _begin->second;
-#if ENABLE_DEBUG_PRINT
- if (g_hashDebug)
- std::cerr << s_indent << toHex(bytesConstRef(_begin->first.data() + _preLen, _begin->first.size() - _preLen), 1) << ": " << _begin->second << " = " << sha3(_rlp.out()) << std::endl;
-#endif
- }
- else
- {
- // find the number of common prefix nibbles shared
- // i.e. the minimum number of nibbles shared at the beginning between the first hex string and each successive.
- unsigned sharedPre = (unsigned)-1;
- unsigned c = 0;
- for (auto i = std::next(_begin); i != _end && sharedPre; ++i, ++c)
- {
- unsigned x = std::min(sharedPre, std::min((unsigned)_begin->first.size(), (unsigned)i->first.size()));
- unsigned shared = _preLen;
- for (; shared < x && _begin->first[shared] == i->first[shared]; ++shared) {}
- sharedPre = std::min(shared, sharedPre);
- }
- if (sharedPre > _preLen)
- {
- // if they all have the same next nibble, we also want a pair.
-#if ENABLE_DEBUG_PRINT
- if (g_hashDebug)
- std::cerr << s_indent << toHex(bytesConstRef(_begin->first.data() + _preLen, sharedPre), 1) << ": " << std::endl;
-#endif
- _rlp.appendList(2) << hexPrefixEncode(_begin->first, false, _preLen, (int)sharedPre);
- hash256aux(_s, _begin, _end, (unsigned)sharedPre, _rlp);
-#if ENABLE_DEBUG_PRINT
- if (g_hashDebug)
- std::cerr << s_indent << "= " << hex << sha3(_rlp.out()) << dec << std::endl;
-#endif
- }
- else
- {
- // otherwise enumerate all 16+1 entries.
- _rlp.appendList(17);
- auto b = _begin;
- if (_preLen == b->first.size())
- {
-#if ENABLE_DEBUG_PRINT
- if (g_hashDebug)
- std::cerr << s_indent << "@: " << b->second << std::endl;
-#endif
- ++b;
- }
- for (auto i = 0; i < 16; ++i)
- {
- auto n = b;
- for (; n != _end && n->first[_preLen] == i; ++n) {}
- if (b == n)
- _rlp << "";
- else
- {
-#if ENABLE_DEBUG_PRINT
- if (g_hashDebug)
- std::cerr << s_indent << std::hex << i << ": " << std::dec << std::endl;
-#endif
- hash256aux(_s, b, n, _preLen + 1, _rlp);
- }
- b = n;
- }
- if (_preLen == _begin->first.size())
- _rlp << _begin->second;
- else
- _rlp << "";
-
-#if ENABLE_DEBUG_PRINT
- if (g_hashDebug)
- std::cerr << s_indent << "= " << hex << sha3(_rlp.out()) << dec << std::endl;
-#endif
- }
- }
-#if ENABLE_DEBUG_PRINT
- if (_preLen)
- s_indent.resize(s_indent.size() - 2);
-#endif
-}
-
-void hash256aux(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream& _rlp)
-{
- RLPStream rlp;
- hash256rlp(_s, _begin, _end, _preLen, rlp);
- if (rlp.out().size() < 32)
- {
- // RECURSIVE RLP
-#if ENABLE_DEBUG_PRINT
- cerr << "[INLINE: " << dec << rlp.out().size() << " < 32]" << endl;
-#endif
- _rlp.APPEND_CHILD(rlp.out());
- }
- else
- {
-#if ENABLE_DEBUG_PRINT
- cerr << "[HASH: " << dec << rlp.out().size() << " >= 32]" << endl;
-#endif
- _rlp << sha3(rlp.out());
- }
-}
-
-h256 hash256(StringMap const& _s)
-{
- // build patricia tree.
- if (_s.empty())
- return sha3(rlp(""));
- HexMap hexMap;
- for (auto i = _s.rbegin(); i != _s.rend(); ++i)
- hexMap[asNibbles(i->first)] = i->second;
- RLPStream s;
- hash256rlp(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s);
- return sha3(s.out());
-}
-
-bytes rlp256(StringMap const& _s)
-{
- // build patricia tree.
- if (_s.empty())
- return rlp("");
- HexMap hexMap;
- for (auto i = _s.rbegin(); i != _s.rend(); ++i)
- hexMap[asNibbles(i->first)] = i->second;
- RLPStream s;
- hash256aux(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s);
- return s.out();
-}
-
-h256 hash256(u256Map const& _s)
-{
- // build patricia tree.
- if (_s.empty())
- return sha3(rlp(""));
- HexMap hexMap;
- for (auto i = _s.rbegin(); i != _s.rend(); ++i)
- hexMap[asNibbles(toBigEndianString(i->first))] = asString(rlp(i->second));
- RLPStream s;
- hash256rlp(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s);
- return sha3(s.out());
-}
-
-}
diff --git a/TrieHash.h b/TrieHash.h
deleted file mode 100644
index be1d84480..000000000
--- a/TrieHash.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file TrieHash.h
- * @author Gav Wood
- * @date 2014
- */
-
-#pragma once
-
-#include
-#include
-
-namespace dev
-{
-
-bytes rlp256(StringMap const& _s);
-h256 hash256(StringMap const& _s);
-h256 hash256(u256Map const& _s);
-
-}
diff --git a/blInvalidHeaderTestFiller.json b/blInvalidHeaderTestFiller.json
deleted file mode 100644
index 482eafc56..000000000
--- a/blInvalidHeaderTestFiller.json
+++ /dev/null
@@ -1,687 +0,0 @@
-{
- "log1_wrongBlockNumber" : {
- "blockHeader" : {
- "number" : "2"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "log1_wrongBloom" : {
- "blockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongCoinbase" : {
- "blockHeader" : {
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongDifficulty" : {
- "blockHeader" : {
- "difficulty" : "10000"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "DifferentExtraData" : {
- "blockHeader" : {
- "extraData" : "42"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongGasLimit" : {
- "blockHeader" : {
- "gasLimit" : "100000"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongGasUsed" : {
- "blockHeader" : {
- "gasUsed" : "0"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongNumber" : {
- "blockHeader" : {
- "number" : "0"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongParentHash" : {
- "blockHeader" : {
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongReceiptTrie" : {
- "blockHeader" : {
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongStateRoot" : {
- "blockHeader" : {
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongTimestamp" : {
- "blockHeader" : {
- "timestamp" : "0x54c98c80"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongTransactionsTrie" : {
- "blockHeader" : {
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "wrongUncleHash" : {
- "blockHeader" : {
- "uncleHash" : "0x0dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- }
-}
diff --git a/blValidBlockTestFiller.json b/blValidBlockTestFiller.json
deleted file mode 100644
index 8099c0dd6..000000000
--- a/blValidBlockTestFiller.json
+++ /dev/null
@@ -1,381 +0,0 @@
-{
- "diffTooLowToChange" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "1023",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "850",
- "gasPrice" : "1",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "10"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "diff1024" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "1024",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "850",
- "gasPrice" : "1",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "10"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "gasPrice0" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "850",
- "gasPrice" : "0",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "10"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "gasLimitTooHigh" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "1000000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "850",
- "gasPrice" : "0",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "10"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "SimpleTx" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "500",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "10"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "txOrder" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "500",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "7000000000"
- },
- {
- "data" : "",
- "gasLimit" : "500",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "8000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "txEqualValue" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "500",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- },
- {
- "data" : "",
- "gasLimit" : "500",
- "gasPrice" : "9",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ]
- },
-
- "log1_correct" : {
- "genesisBlockHeader" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "10000",
- "extraData" : "42",
- "gasLimit" : "100000",
- "gasUsed" : "0",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "0",
- "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
- "balance" : "10000000000",
- "nonce" : "0",
- "code" : "",
- "storage": {}
- },
- "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
- "balance" : "100",
- "nonce" : "0",
- "code" : "{ (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (LOG1 0 32 0) }",
- "storage": {}
- }
- },
- "transactions" : [
- {
- "data" : "",
- "gasLimit" : "5000",
- "gasPrice" : "10",
- "nonce" : "0",
- "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
- "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
- "value" : "5000000000"
- }
- ],
- "uncleHeaders" : [
- ],
-
- "firstBlockTest" : {
- "block" : {
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
- "difficulty" : "023101",
- "extraData" : "42",
- "gasLimit" : "0x0dddb6",
- "gasUsed" : "100",
- "nonce" : "0x498e88f5c14b0b60d6e14ce9c6cc958cbe16a1df8dd90210e50d2d77562a348d",
- "number" : "62",
- "parentHash" : "0xefb4db878627027c81b3bb1c7dd3a18dae3914a49cdd24a3e40ab3bbfbb240c5",
- "receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
- "timestamp" : "0x54c98c81",
- "transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
- },
- "pre" : {
- },
- "transactions" : [
- {
- "data" : "0x60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b56",
- "gasLimit" : "0x0f3e6f",
- "gasPrice" : "0x09184e72a000",
- "nonce" : "0",
- "r" : "0xd4287e915ebac7a8af390560fa53c8f0b7f13802ba0393d7afa5823c2560ca89",
- "s" : "0xae75db31a34f7e386ad459646de98ec3a1c88cc91b11620b4ffd86871f579942",
- "to" : "",
- "v" : "0x1b",
- "value" : ""
- }
- ],
- }
-
- }
-}
-
diff --git a/block.cpp b/block.cpp
deleted file mode 100644
index ce165bc42..000000000
--- a/block.cpp
+++ /dev/null
@@ -1,509 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file block.cpp
- * @author Christoph Jentzsch
- * @date 2015
- * block test functions.
- */
-
-#include
-#include
-#include "TestHelper.h"
-
-using namespace std;
-using namespace json_spirit;
-using namespace dev;
-using namespace dev::eth;
-
-namespace dev { namespace test {
-
-bytes createBlockRLPFromFields(mObject& _tObj)
-{
- RLPStream rlpStream;
- rlpStream.appendList(_tObj.size());
-
- if (_tObj.count("parentHash"))
- rlpStream << importByteArray(_tObj["parentHash"].get_str());
-
- if (_tObj.count("uncleHash"))
- rlpStream << importByteArray(_tObj["uncleHash"].get_str());
-
- if (_tObj.count("coinbase"))
- rlpStream << importByteArray(_tObj["coinbase"].get_str());
-
- if (_tObj.count("stateRoot"))
- rlpStream << importByteArray(_tObj["stateRoot"].get_str());
-
- if (_tObj.count("transactionsTrie"))
- rlpStream << importByteArray(_tObj["transactionsTrie"].get_str());
-
- if (_tObj.count("receiptTrie"))
- rlpStream << importByteArray(_tObj["receiptTrie"].get_str());
-
- if (_tObj.count("bloom"))
- rlpStream << importByteArray(_tObj["bloom"].get_str());
-
- if (_tObj.count("difficulty"))
- rlpStream << bigint(_tObj["difficulty"].get_str());
-
- if (_tObj.count("number"))
- rlpStream << bigint(_tObj["number"].get_str());
-
- if (_tObj.count("gasLimit"))
- rlpStream << bigint(_tObj["gasLimit"].get_str());
-
- if (_tObj.count("gasUsed"))
- rlpStream << bigint(_tObj["gasUsed"].get_str());
-
- if (_tObj.count("timestamp"))
- rlpStream << bigint(_tObj["timestamp"].get_str());
-
- if (_tObj.count("extraData"))
- rlpStream << importByteArray(_tObj["extraData"].get_str());
-
- if (_tObj.count("nonce"))
- rlpStream << importByteArray(_tObj["nonce"].get_str());
-
- return rlpStream.out();
-}
-
-void doBlockTests(json_spirit::mValue& _v, bool _fillin)
-{
- for (auto& i: _v.get_obj())
- {
- cerr << i.first << endl;
- mObject& o = i.second.get_obj();
-
- BOOST_REQUIRE(o.count("genesisBlockHeader"));
- BlockInfo blockFromFields;
- try
- {
- // construct genesis block
- const bytes c_blockRLP = createBlockRLPFromFields(o["genesisBlockHeader"].get_obj());
- const RLP c_bRLP(c_blockRLP);
- blockFromFields.populateFromHeader(c_bRLP, false);
- }
- catch (Exception const& _e)
- {
- cnote << "block population did throw an exception: " << diagnostic_information(_e);
- BOOST_ERROR("Failed block population with Exception: " << _e.what());
- continue;
- }
- catch (std::exception const& _e)
- {
- BOOST_ERROR("Failed block population with Exception: " << _e.what());
- continue;
- }
- catch(...)
- {
- cnote << "block population did throw an unknown exception\n";
- continue;
- }
-
- BOOST_REQUIRE(o.count("pre"));
-
- ImportTest importer(o["pre"].get_obj());
- State state(Address(), OverlayDB(), BaseState::Empty);
- importer.importState(o["pre"].get_obj(), state);
- state.commit();
-
- if (_fillin)
- blockFromFields.stateRoot = state.rootHash();
- else
- BOOST_CHECK_MESSAGE(blockFromFields.stateRoot == state.rootHash(), "root hash does not match");
-
- if (_fillin)
- {
- // find new valid nonce
- ProofOfWork pow;
- MineInfo ret;
- while (!ProofOfWork::verify(blockFromFields.headerHash(WithoutNonce), blockFromFields.nonce, blockFromFields.difficulty))
- tie(ret, blockFromFields.nonce) = pow.mine(blockFromFields.headerHash(WithoutNonce), blockFromFields.difficulty, 1000, true, true);
-
- //update genesis block in json file
- o["genesisBlockHeader"].get_obj()["stateRoot"] = toString(blockFromFields.stateRoot);
- o["genesisBlockHeader"].get_obj()["nonce"] = toString(blockFromFields.nonce);
- }
-
- // create new "genesis" block
- RLPStream rlpStream;
- blockFromFields.streamRLP(rlpStream, WithNonce);
-
- RLPStream block(3);
- block.appendRaw(rlpStream.out());
- block.appendRaw(RLPEmptyList);
- block.appendRaw(RLPEmptyList);
-
- blockFromFields.verifyInternals(&block.out());
-
- // construct blockchain
- BlockChain bc(block.out(), string(), true);
-
- if (_fillin)
- {
- BOOST_REQUIRE(o.count("transactions"));
-
- TransactionQueue txs;
-
- for (auto const& txObj: o["transactions"].get_array())
- {
- mObject tx = txObj.get_obj();
- importer.importTransaction(tx);
- if (!txs.attemptImport(importer.m_transaction.rlp()))
- cnote << "failed importing transaction\n";
- }
-
- try
- {
- state.sync(bc);
- state.sync(bc,txs);
- state.commitToMine(bc);
- MineInfo info;
- for (info.completed = false; !info.completed; info = state.mine()) {}
- state.completeMine();
- }
- catch (Exception const& _e)
- {
- cnote << "state sync or mining did throw an exception: " << diagnostic_information(_e);
- return;
- }
- catch (std::exception const& _e)
- {
- cnote << "state sync or mining did throw an exception: " << _e.what();
- return;
- }
-
- // write valid txs
- mArray txArray;
- Transactions txList;
- for (auto const& txi: txs.transactions())
- {
- Transaction tx(txi.second, CheckSignature::Sender);
- txList.push_back(tx);
- mObject txObject;
- txObject["nonce"] = toString(tx.nonce());
- txObject["data"] = toHex(tx.data());
- txObject["gasLimit"] = toString(tx.gas());
- txObject["gasPrice"] = toString(tx.gasPrice());
- txObject["r"] = "0x" + toString(tx.signature().r);
- txObject["s"] = "0x" + toString(tx.signature().s);
- txObject["v"] = to_string(tx.signature().v + 27);
- txObject["to"] = toString(tx.receiveAddress());
- txObject["value"] = toString(tx.value());
-
- txArray.push_back(txObject);
- }
-
- o["transactions"] = txArray;
- o["rlp"] = "0x" + toHex(state.blockData());
-
- BlockInfo current_BlockHeader = state.info();
-
- // overwrite blockheader with (possible wrong) data from "blockheader" in filler;
-
- if (o.count("blockHeader"))
- {
- if (o["blockHeader"].get_obj().size() != 14)
- {
-
- BlockInfo tmp = current_BlockHeader;
-
- if (o["blockHeader"].get_obj().count("parentHash"))
- tmp.parentHash = h256(o["blockHeader"].get_obj()["parentHash"].get_str());
-
- if (o["blockHeader"].get_obj().count("uncleHash"))
- tmp.sha3Uncles = h256(o["blockHeader"].get_obj()["uncleHash"].get_str());
-
- if (o["blockHeader"].get_obj().count("coinbase"))
- tmp.coinbaseAddress = Address(o["blockHeader"].get_obj()["coinbase"].get_str());
-
- if (o["blockHeader"].get_obj().count("stateRoot"))
- tmp.stateRoot = h256(o["blockHeader"].get_obj()["stateRoot"].get_str());
-
- if (o["blockHeader"].get_obj().count("transactionsTrie"))
- tmp.transactionsRoot = h256(o["blockHeader"].get_obj()["transactionsTrie"].get_str());
-
- if (o["blockHeader"].get_obj().count("receiptTrie"))
- tmp.receiptsRoot = h256(o["blockHeader"].get_obj()["receiptTrie"].get_str());
-
- if (o["blockHeader"].get_obj().count("bloom"))
- tmp.logBloom = LogBloom(o["blockHeader"].get_obj()["bloom"].get_str());
-
- if (o["blockHeader"].get_obj().count("difficulty"))
- tmp.difficulty = toInt(o["blockHeader"].get_obj()["difficulty"]);
-
- if (o["blockHeader"].get_obj().count("number"))
- tmp.number = toInt(o["blockHeader"].get_obj()["number"]);
-
- if (o["blockHeader"].get_obj().count("gasLimit"))
- tmp.gasLimit = toInt(o["blockHeader"].get_obj()["gasLimit"]);
-
- if (o["blockHeader"].get_obj().count("gasUsed"))
- tmp.gasUsed = toInt(o["blockHeader"].get_obj()["gasUsed"]);
-
- if (o["blockHeader"].get_obj().count("timestamp"))
- tmp.timestamp = toInt(o["blockHeader"].get_obj()["timestamp"]);
-
- if (o["blockHeader"].get_obj().count("extraData"))
- tmp.extraData = importByteArray(o["blockHeader"].get_obj()["extraData"].get_str());
-
- // find new valid nonce
-
- if (tmp != current_BlockHeader)
- {
- current_BlockHeader = tmp;
- cout << "new header!\n";
- ProofOfWork pow;
- MineInfo ret;
- while (!ProofOfWork::verify(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.nonce, current_BlockHeader.difficulty))
- tie(ret, current_BlockHeader.nonce) = pow.mine(current_BlockHeader.headerHash(WithoutNonce), current_BlockHeader.difficulty, 10000, true, true);
- }
- }
- else
- {
- // take the blockheader as is
- const bytes c_blockRLP = createBlockRLPFromFields(o["blockHeader"].get_obj());
- const RLP c_bRLP(c_blockRLP);
- current_BlockHeader.populateFromHeader(c_bRLP, false);
- }
- }
-
- // write block header
-
- mObject oBlockHeader;
- oBlockHeader["parentHash"] = toString(current_BlockHeader.parentHash);
- oBlockHeader["uncleHash"] = toString(current_BlockHeader.sha3Uncles);
- oBlockHeader["coinbase"] = toString(current_BlockHeader.coinbaseAddress);
- oBlockHeader["stateRoot"] = toString(current_BlockHeader.stateRoot);
- oBlockHeader["transactionsTrie"] = toString(current_BlockHeader.transactionsRoot);
- oBlockHeader["receiptTrie"] = toString(current_BlockHeader.receiptsRoot);
- oBlockHeader["bloom"] = toString(current_BlockHeader.logBloom);
- oBlockHeader["difficulty"] = toString(current_BlockHeader.difficulty);
- oBlockHeader["number"] = toString(current_BlockHeader.number);
- oBlockHeader["gasLimit"] = toString(current_BlockHeader.gasLimit);
- oBlockHeader["gasUsed"] = toString(current_BlockHeader.gasUsed);
- oBlockHeader["timestamp"] = toString(current_BlockHeader.timestamp);
- oBlockHeader["extraData"] = toHex(current_BlockHeader.extraData);
- oBlockHeader["nonce"] = toString(current_BlockHeader.nonce);
-
- o["blockHeader"] = oBlockHeader;
-
- // write uncle list
- mArray aUncleList; // as of now, our parent is always the genesis block, so we can not have uncles.
- o["uncleHeaders"] = aUncleList;
-
- //txs:
-
- RLPStream txStream;
- txStream.appendList(txList.size());
- for (unsigned i = 0; i < txList.size(); ++i)
- {
- RLPStream txrlp;
- txList[i].streamRLP(txrlp);
- txStream.appendRaw(txrlp.out());
- }
-
- RLPStream rlpStream2;
- current_BlockHeader.streamRLP(rlpStream2, WithNonce);
-
- RLPStream block2(3);
- block2.appendRaw(rlpStream2.out());
- block2.appendRaw(txStream.out());
- block2.appendRaw(RLPEmptyList);
-
- o["rlp"] = "0x" + toHex(block2.out());
-
- if (sha3(RLP(state.blockData())[0].data()) != sha3(RLP(block2.out())[0].data()))
- cnote << "block header mismatch\n";
-
- if (sha3(RLP(state.blockData())[1].data()) != sha3(RLP(block2.out())[1].data()))
- cnote << "txs mismatch\n";
-
- if (sha3(RLP(state.blockData())[2].data()) != sha3(RLP(block2.out())[2].data()))
- cnote << "uncle list mismatch\n";
-
- try
- {
- ImportTest importerTmp(o["pre"].get_obj());
- State stateTmp(Address(), OverlayDB(), BaseState::Empty);
- importerTmp.importState(o["pre"].get_obj(), stateTmp);
- stateTmp.commit();
- BlockChain bcTmp(block.out(), getDataDir() + "/tmpBlockChain.bc", true);
- stateTmp.sync(bcTmp);
- bc.import(block2.out(), stateTmp.db());
- stateTmp.sync(bcTmp);
- }
- // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given
- catch (...)
- {
- cnote << "block is invalid!\n";
- o.erase(o.find("blockHeader"));
- o.erase(o.find("uncleHeaders"));
- o.erase(o.find("transactions"));
- }
- }
-
- else
- {
- bytes blockRLP;
- try
- {
- state.sync(bc);
- blockRLP = importByteArray(o["rlp"].get_str());
- bc.import(blockRLP, state.db());
- state.sync(bc);
- }
- // if exception is thrown, RLP is invalid and no blockHeader, Transaction list, or Uncle list should be given
- catch (Exception const& _e)
- {
- cnote << "state sync or block import did throw an exception: " << diagnostic_information(_e);
- BOOST_CHECK(o.count("blockHeader") == 0);
- BOOST_CHECK(o.count("transactions") == 0);
- BOOST_CHECK(o.count("uncleHeaders") == 0);
- continue;
- }
- catch (std::exception const& _e)
- {
- cnote << "state sync or block import did throw an exception: " << _e.what();
- BOOST_CHECK(o.count("blockHeader") == 0);
- BOOST_CHECK(o.count("transactions") == 0);
- BOOST_CHECK(o.count("uncleHeaders") == 0);
- continue;
- }
- catch(...)
- {
- cnote << "state sync or block import did throw an exception\n";
- BOOST_CHECK(o.count("blockHeader") == 0);
- BOOST_CHECK(o.count("transactions") == 0);
- BOOST_CHECK(o.count("uncleHeaders") == 0);
- continue;
- }
-
- BOOST_REQUIRE(o.count("blockHeader"));
-
- mObject tObj = o["blockHeader"].get_obj();
- BlockInfo blockHeaderFromFields;
- const bytes c_rlpBytesBlockHeader = createBlockRLPFromFields(tObj);
- const RLP c_blockHeaderRLP(c_rlpBytesBlockHeader);
- blockHeaderFromFields.populateFromHeader(c_blockHeaderRLP, false);
-
- BlockInfo blockFromRlp = bc.info();
-
- //Check the fields restored from RLP to original fields
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.headerHash(WithNonce) == blockFromRlp.headerHash(WithNonce), "hash in given RLP not matching the block hash!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.parentHash == blockFromRlp.parentHash, "parentHash in given RLP not matching the block parentHash!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.sha3Uncles == blockFromRlp.sha3Uncles, "sha3Uncles in given RLP not matching the block sha3Uncles!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.coinbaseAddress == blockFromRlp.coinbaseAddress,"coinbaseAddress in given RLP not matching the block coinbaseAddress!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.stateRoot == blockFromRlp.stateRoot, "stateRoot in given RLP not matching the block stateRoot!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.transactionsRoot == blockFromRlp.transactionsRoot, "transactionsRoot in given RLP not matching the block transactionsRoot!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.receiptsRoot == blockFromRlp.receiptsRoot, "receiptsRoot in given RLP not matching the block receiptsRoot!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.logBloom == blockFromRlp.logBloom, "logBloom in given RLP not matching the block logBloom!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.difficulty == blockFromRlp.difficulty, "difficulty in given RLP not matching the block difficulty!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.number == blockFromRlp.number, "number in given RLP not matching the block number!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasLimit == blockFromRlp.gasLimit,"gasLimit in given RLP not matching the block gasLimit!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.gasUsed == blockFromRlp.gasUsed, "gasUsed in given RLP not matching the block gasUsed!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.timestamp == blockFromRlp.timestamp, "timestamp in given RLP not matching the block timestamp!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.extraData == blockFromRlp.extraData, "extraData in given RLP not matching the block extraData!");
- BOOST_CHECK_MESSAGE(blockHeaderFromFields.nonce == blockFromRlp.nonce, "nonce in given RLP not matching the block nonce!");
-
- BOOST_CHECK_MESSAGE(blockHeaderFromFields == blockFromRlp, "However, blockHeaderFromFields != blockFromRlp!");
-
- //Check transaction list
-
- Transactions txsFromField;
-
- for (auto const& txObj: o["transactions"].get_array())
- {
- mObject tx = txObj.get_obj();
-
- BOOST_REQUIRE(tx.count("nonce"));
- BOOST_REQUIRE(tx.count("gasPrice"));
- BOOST_REQUIRE(tx.count("gasLimit"));
- BOOST_REQUIRE(tx.count("to"));
- BOOST_REQUIRE(tx.count("value"));
- BOOST_REQUIRE(tx.count("v"));
- BOOST_REQUIRE(tx.count("r"));
- BOOST_REQUIRE(tx.count("s"));
- BOOST_REQUIRE(tx.count("data"));
-
- try
- {
- Transaction t(createRLPStreamFromTransactionFields(tx).out(), CheckSignature::Sender);
- txsFromField.push_back(t);
- }
- catch (Exception const& _e)
- {
- BOOST_ERROR("Failed transaction constructor with Exception: " << diagnostic_information(_e));
- }
- catch (exception const& _e)
- {
- cnote << _e.what();
- }
- }
-
- Transactions txsFromRlp;
- RLP root(blockRLP);
- for (auto const& tr: root[1])
- {
- Transaction tx(tr.data(), CheckSignature::Sender);
- txsFromRlp.push_back(tx);
- }
-
- BOOST_CHECK_MESSAGE(txsFromRlp.size() == txsFromField.size(), "transaction list size does not match");
-
- for (size_t i = 0; i < txsFromField.size(); ++i)
- {
- BOOST_CHECK_MESSAGE(txsFromField[i].data() == txsFromRlp[i].data(), "transaction data in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].gas() == txsFromRlp[i].gas(), "transaction gasLimit in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].gasPrice() == txsFromRlp[i].gasPrice(), "transaction gasPrice in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].nonce() == txsFromRlp[i].nonce(), "transaction nonce in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].signature().r == txsFromRlp[i].signature().r, "transaction r in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].signature().s == txsFromRlp[i].signature().s, "transaction s in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].signature().v == txsFromRlp[i].signature().v, "transaction v in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].receiveAddress() == txsFromRlp[i].receiveAddress(), "transaction receiveAddress in rlp and in field do not match");
- BOOST_CHECK_MESSAGE(txsFromField[i].value() == txsFromRlp[i].value(), "transaction receiveAddress in rlp and in field do not match");
-
- BOOST_CHECK_MESSAGE(txsFromField[i] == txsFromRlp[i], "transactions in rlp and in transaction field do not match");
- }
-
- // check uncle list
- BOOST_CHECK_MESSAGE((o["uncleList"].type() == json_spirit::null_type ? 0 : o["uncleList"].get_array().size()) == 0, "Uncle list is not empty, but the genesis block can not have uncles");
- }
- }
-}
-
-} }// Namespace Close
-
-
-BOOST_AUTO_TEST_SUITE(BlockTests)
-
-BOOST_AUTO_TEST_CASE(blValidBlockTest)
-{
- dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests);
-}
-
-BOOST_AUTO_TEST_CASE(blInvalidHeaderTest)
-{
- dev::test::executeTests("blInvalidHeaderTest", "/BlockTests", dev::test::doBlockTests);
-}
-
-BOOST_AUTO_TEST_CASE(userDefinedFileBl)
-{
- dev::test::userDefinedTest("--bltest", dev::test::doBlockTests);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/boostTest.cpp b/boostTest.cpp
deleted file mode 100644
index 1523a7a11..000000000
--- a/boostTest.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file boostTest.cpp
- * @author Marko Simovic
- * @date 2014
- * Stub for generating main boost.test module.
- */
-
-#define BOOST_TEST_MODULE EthereumTests
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-#define BOOST_DISABLE_WIN32 //disables SEH warning
-#include
-#pragma GCC diagnostic pop
diff --git a/checkRandomTest.cpp b/checkRandomTest.cpp
deleted file mode 100644
index e3442d438..000000000
--- a/checkRandomTest.cpp
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file checkRandomTest.cpp
- * @author Christoph Jentzsch
- * @date 2015
- * Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation.
- */
-
-#include
-#include
-#include
-#include
-#include "vm.h"
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-
-using namespace std;
-using namespace json_spirit;
-using namespace dev::test;
-using namespace dev;
-
-bool doVMTest(mValue& v);
-
-int main(int argc, char *argv[])
-{
- g_logVerbosity = 0;
- bool ret = false;
-
- try
- {
- mValue v;
- string s;
- for (int i = 1; i < argc; ++i)
- s += argv[i];
- if (asserts(s.length() > 0))
- {
- cout << "Content of argument is empty\n";
- return 1;
- }
- read_string(s, v);
- ret = doVMTest(v);
- }
- catch (Exception const& _e)
- {
- cout << "Failed test with Exception: " << diagnostic_information(_e) << endl;
- ret = false;
- }
- catch (std::exception const& _e)
- {
- cout << "Failed test with Exception: " << _e.what() << endl;
- ret = false;
- }
- return ret;
-}
-
-bool doVMTest(mValue& v)
-{
- eth::VMFactory::setKind(eth::VMKind::JIT);
-
- for (auto& i: v.get_obj())
- {
- cnote << i.first;
- mObject& o = i.second.get_obj();
-
- assert(o.count("env") > 0);
- assert(o.count("pre") > 0);
- assert(o.count("exec") > 0);
-
- FakeExtVM fev;
- fev.importEnv(o["env"].get_obj());
- fev.importState(o["pre"].get_obj());
-
- fev.importExec(o["exec"].get_obj());
- if (fev.code.empty())
- {
- fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
- fev.code = fev.thisTxCode;
- }
-
- bytes output;
- u256 gas;
- bool vmExceptionOccured = false;
- try
- {
- auto vm = eth::VMFactory::create(fev.gas);
- output = vm->go(fev, fev.simpleTrace()).toBytes();
- gas = vm->gas();
- }
- catch (eth::VMException)
- {
- cnote << "Safe VM Exception";
- vmExceptionOccured = true;
- }
- catch (Exception const& _e)
- {
- cnote << "VM did throw an exception: " << diagnostic_information(_e);
- cnote << "Failed VM Test with Exception: " << _e.what();
- return 1;
- }
- catch (std::exception const& _e)
- {
- cnote << "VM did throw an exception: " << _e.what();
- cnote << "Failed VM Test with Exception: " << _e.what();
- return 1;
- }
-
- // delete null entries in storage for the sake of comparison
- for (auto &a: fev.addresses)
- {
- vector keystoDelete;
- for (auto &s: get<2>(a.second))
- {
- if (s.second == 0)
- keystoDelete.push_back(s.first);
- }
- for (auto const key: keystoDelete )
- {
- get<2>(a.second).erase(key);
- }
- }
-
- if (o.count("post") > 0) // No exceptions expected
- {
- if (asserts(!vmExceptionOccured) || asserts(o.count("post") > 0) || asserts(o.count("callcreates") > 0) || asserts(o.count("out") > 0) || asserts(o.count("gas") > 0) || asserts(o.count("logs") > 0))
- return 1;
-
- dev::test::FakeExtVM test;
- test.importState(o["post"].get_obj());
- test.importCallCreates(o["callcreates"].get_array());
- test.sub.logs = importLog(o["logs"].get_array());
-
- //checkOutput(output, o);
- int j = 0;
- if (o["out"].type() == array_type)
- for (auto const& d: o["out"].get_array())
- {
- if (asserts(output[j] == toInt(d)))
- {
- cout << "Output byte [" << j << "] different!";
- return 1;
- }
- ++j;
- }
- else if (o["out"].get_str().find("0x") == 0)
- {
- if (asserts(output == fromHex(o["out"].get_str().substr(2))))
- return 1;
- }
- else
- {
- if (asserts(output == fromHex(o["out"].get_str())))
- return 1;
- }
-
- if (asserts(toInt(o["gas"]) == gas))
- return 1;
-
- auto& expectedAddrs = test.addresses;
- auto& resultAddrs = fev.addresses;
- for (auto&& expectedPair : expectedAddrs)
- {
- auto& expectedAddr = expectedPair.first;
- auto resultAddrIt = resultAddrs.find(expectedAddr);
- if (resultAddrIt == resultAddrs.end())
- {
- cout << "Missing expected address " << expectedAddr;
- return 1;
- }
- else
- {
- auto& expectedState = expectedPair.second;
- auto& resultState = resultAddrIt->second;
- if (asserts(std::get<0>(expectedState) == std::get<0>(resultState)))
- {
- cout << expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState);
- return 1;
- }
- if (asserts(std::get<1>(expectedState) == std::get<1>(resultState)))
- {
- cout << expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState);
- return 1;
- }
- if (asserts(std::get<3>(expectedState) == std::get<3>(resultState)))
- {
- cout << expectedAddr << ": incorrect code";
- return 1;
- }
-
- //checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr);
- for (auto&& expectedStorePair : std::get<2>(expectedState))
- {
- auto& expectedStoreKey = expectedStorePair.first;
- auto resultStoreIt = std::get<2>(resultState).find(expectedStoreKey);
- if (resultStoreIt == std::get<2>(resultState).end())
- {
- cout << expectedAddr << ": missing store key " << expectedStoreKey << endl;
- return 1;
- }
- else
- {
- auto& expectedStoreValue = expectedStorePair.second;
- auto& resultStoreValue = resultStoreIt->second;
- if (asserts(expectedStoreValue == resultStoreValue))
- {
- cout << expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue << endl;
- return 1;
- }
- }
- }
- if (assertsEqual(std::get<2>(resultState).size(), std::get<2>(expectedState).size()))
- return 1;
- for (auto&& resultStorePair: std::get<2>(resultState))
- {
- if (!std::get<2>(expectedState).count(resultStorePair.first))
- {
- cout << expectedAddr << ": unexpected store key " << resultStorePair.first << endl;
- return 1;
- }
- }
- }
- }
-
- //checkAddresses, bytes> > >(test.addresses, fev.addresses);
- for (auto& resultPair : fev.addresses)
- {
- auto& resultAddr = resultPair.first;
- auto expectedAddrIt = test.addresses.find(resultAddr);
- if (expectedAddrIt == test.addresses.end())
- {
- cout << "Missing result address " << resultAddr << endl;
- return 1;
- }
- }
- if (asserts(test.addresses == fev.addresses))
- return 1;
-
- if (asserts(test.callcreates == fev.callcreates))
- return 1;
-
- //checkCallCreates(fev.callcreates, test.callcreates);
- {
- if (assertsEqual(test.callcreates.size(), fev.callcreates.size()))
- return 1;
-
- for (size_t i = 0; i < test.callcreates.size(); ++i)
- {
- if (asserts(test.callcreates[i].data() == fev.callcreates[i].data()))
- return 1;
- if (asserts(test.callcreates[i].receiveAddress() == fev.callcreates[i].receiveAddress()))
- return 1;
- if (asserts(test.callcreates[i].gas() == fev.callcreates[i].gas()))
- return 1;
- if (asserts(test.callcreates[i].value() == fev.callcreates[i].value()))
- return 1;
- }
- }
-
- //checkLog(fev.sub.logs, test.sub.logs);
- {
- if (assertsEqual(fev.sub.logs.size(), test.sub.logs.size()))
- return 1;
-
- for (size_t i = 0; i < fev.sub.logs.size(); ++i)
- {
- if (assertsEqual(fev.sub.logs[i].address, test.sub.logs[i].address))
- return 1;
- if (assertsEqual(fev.sub.logs[i].topics, test.sub.logs[i].topics))
- return 1;
- if (asserts(fev.sub.logs[i].data == test.sub.logs[i].data))
- return 1;
- }
- }
-
- }
- else // Exception expected
- {
- if (asserts(vmExceptionOccured))
- return 1;
- }
- }
- // test passed
- return 0;
-}
-
diff --git a/commonjs.cpp b/commonjs.cpp
deleted file mode 100644
index 041a14f68..000000000
--- a/commonjs.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file commonjs.cpp
- * @author Marek Kotewicz
- * @date 2014
- */
-
-#include
-#include
-#include
-
-BOOST_AUTO_TEST_SUITE(commonjs)
-using namespace std;
-using namespace dev;
-using namespace dev::eth;
-
-BOOST_AUTO_TEST_CASE(jsToPublic)
-{
- cnote << "Testing jsToPublic...";
- KeyPair kp = KeyPair::create();
- string string = toJS(kp.pub());
- Public pub = dev::jsToPublic(string);
- BOOST_CHECK_EQUAL(kp.pub(), pub);
-}
-
-BOOST_AUTO_TEST_CASE(jsToAddress)
-{
- cnote << "Testing jsToPublic...";
- KeyPair kp = KeyPair::create();
- string string = toJS(kp.address());
- Address address = dev::eth::jsToAddress(string);
- BOOST_CHECK_EQUAL(kp.address(), address);
-}
-
-BOOST_AUTO_TEST_CASE(jsToSecret)
-{
- cnote << "Testing jsToPublic...";
- KeyPair kp = KeyPair::create();
- string string = toJS(kp.secret());
- Secret secret = dev::jsToSecret(string);
- BOOST_CHECK_EQUAL(kp.secret(), secret);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/createRandomTest.cpp b/createRandomTest.cpp
deleted file mode 100644
index fa5ed7bd3..000000000
--- a/createRandomTest.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file createRandomTest.cpp
- * @author Christoph Jentzsch
- * @date 2014
- * Creating a random virtual machine test.
- */
-
-#include
-#include
-#include
-#include
-#include
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "vm.h"
-
-using namespace std;
-using namespace json_spirit;
-using namespace dev;
-
-void doMyTests(json_spirit::mValue& v);
-
-int main(int argc, char *argv[])
-{
- g_logVerbosity = 0;
-
- // create random code
-
- boost::random::mt19937 gen;
-
- auto now = chrono::steady_clock::now().time_since_epoch();
- auto timeSinceEpoch = chrono::duration_cast(now).count();
- gen.seed(static_cast(timeSinceEpoch));
- boost::random::uniform_int_distribution<> lengthOfCodeDist(2, 16);
- boost::random::uniform_int_distribution<> opcodeDist(0, 255);
- boost::random::uniform_int_distribution<> BlockInfoOpcodeDist(0x40, 0x45);
- boost::random::variate_generator > randGen(gen, opcodeDist);
- boost::random::variate_generator > randGenBlockInfoOpcode(gen, BlockInfoOpcodeDist);
-
- int lengthOfCode = lengthOfCodeDist(gen);
- string randomCode;
-
- for (int i = 0; i < lengthOfCode; ++i)
- {
- if (i < 8 && (randGen() < 192))
- {
- randomCode += toHex(toCompactBigEndian((uint8_t)randGenBlockInfoOpcode()));
- continue;
- }
-
- uint8_t opcode = randGen();
- // disregard all invalid commands, except of one (0x0c)
- if ((dev::eth::isValidInstruction(dev::eth::Instruction(opcode)) || (randGen() > 250)))
- randomCode += toHex(toCompactBigEndian(opcode));
- else
- i--;
- }
-
- const string s =\
-"{\n\
- \"randomVMtest\": {\n\
- \"env\" : {\n\
- \"previousHash\" : \"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6\",\n\
- \"currentNumber\" : \"300\",\n\
- \"currentGasLimit\" : \"1000000\",\n\
- \"currentDifficulty\" : \"115792089237316195423570985008687907853269984665640564039457584007913129639935\",\n\
- \"currentTimestamp\" : 2,\n\
- \"currentCoinbase\" : \"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba\"\n\
- },\n\
- \"pre\" : {\n\
- \"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6\" : {\n\
- \"balance\" : \"1000000000000000000\",\n\
- \"nonce\" : 0,\n\
- \"code\" : \"random\",\n\
- \"storage\": {}\n\
- }\n\
- },\n\
- \"exec\" : {\n\
- \"address\" : \"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6\",\n\
- \"origin\" : \"cd1722f3947def4cf144679da39c4c32bdc35681\",\n\
- \"caller\" : \"cd1722f3947def4cf144679da39c4c32bdc35681\",\n\
- \"value\" : \"1000000000000000000\",\n\
- \"data\" : \"\",\n\
- \"gasPrice\" : \"100000000000000\",\n\
- \"gas\" : \"10000\"\n\
- }\n\
- }\n\
-}";
-
- mValue v;
- read_string(s, v);
-
- // insert new random code
- v.get_obj().find("randomVMtest")->second.get_obj().find("pre")->second.get_obj().begin()->second.get_obj()["code"] = "0x" + randomCode + (randGen() > 128 ? "55" : "");
-
- // execute code in vm
- doMyTests(v);
-
- // stream to output for further handling by the bash script
- cout << json_spirit::write_string(v, true);
-
- return 0;
-}
-
-void doMyTests(json_spirit::mValue& v)
-{
- eth::VMFactory::setKind(eth::VMKind::Interpreter);
-
- for (auto& i: v.get_obj())
- {
- cnote << i.first;
- mObject& o = i.second.get_obj();
-
- assert(o.count("env") > 0);
- assert(o.count("pre") > 0);
- assert(o.count("exec") > 0);
-
- dev::test::FakeExtVM fev;
- fev.importEnv(o["env"].get_obj());
- fev.importState(o["pre"].get_obj());
-
- o["pre"] = mValue(fev.exportState());
-
- fev.importExec(o["exec"].get_obj());
- if (fev.code.empty())
- {
- fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress));
- fev.code = fev.thisTxCode;
- }
-
- bytes output;
- auto vm = eth::VMFactory::create(fev.gas);
-
- u256 gas;
- bool vmExceptionOccured = false;
- try
- {
- output = vm->go(fev, fev.simpleTrace()).toBytes();
- gas = vm->gas();
- }
- catch (eth::VMException const& _e)
- {
- cnote << "VM did throw an exception: " << diagnostic_information(_e);
- vmExceptionOccured = true;
- }
- catch (Exception const& _e)
- {
- cnote << "VM did throw an exception: " << diagnostic_information(_e);
- }
- catch (std::exception const& _e)
- {
- cnote << "VM did throw an exception: " << _e.what();
- }
-
- // delete null entries in storage for the sake of comparison
-
- for (auto &a: fev.addresses)
- {
- vector keystoDelete;
- for (auto &s: get<2>(a.second))
- {
- if (s.second == 0)
- keystoDelete.push_back(s.first);
- }
- for (auto const key: keystoDelete )
- {
- get<2>(a.second).erase(key);
- }
- }
-
- o["env"] = mValue(fev.exportEnv());
- o["exec"] = mValue(fev.exportExec());
- if (!vmExceptionOccured)
- {
- o["post"] = mValue(fev.exportState());
- o["callcreates"] = fev.exportCallCreates();
- o["out"] = "0x" + toHex(output);
- fev.push(o, "gas", gas);
- o["logs"] = test::exportLog(fev.sub.logs);
- }
- }
-}
diff --git a/crypto.cpp b/crypto.cpp
deleted file mode 100644
index 291893f59..000000000
--- a/crypto.cpp
+++ /dev/null
@@ -1,559 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file crypto.cpp
- * @author Gav Wood
- * @date 2014
- * Crypto test functions.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include