From bb6fcfe3f939fe81c12d6c772f4b84c3ca9cffc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 5 Dec 2014 17:00:29 +0100 Subject: [PATCH 01/11] Use safe pointers in Executive --- vm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/vm.cpp b/vm.cpp index d7bc0612a..67102dcd2 100644 --- a/vm.cpp +++ b/vm.cpp @@ -21,6 +21,7 @@ */ #include +#include #include "vm.h" using namespace std; From bf8ea705b8f7b33b1bd2cd90f6637b0b3014f8db Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Dec 2014 18:46:18 +0100 Subject: [PATCH 02/11] String types. --- solidityEndToEndTest.cpp | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 3c2bb0814..940ccac63 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -482,6 +482,34 @@ BOOST_AUTO_TEST_CASE(small_signed_types) testSolidityAgainstCpp(0, 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); + bytes expectation(32, 0); + expectation[0] = byte('a'); + expectation[1] = byte('b'); + expectation[2] = byte('c'); + expectation[3] = byte(0); + expectation[4] = byte(0xff); + expectation[5] = byte('_'); + expectation[6] = byte('_'); + BOOST_CHECK(callContractFunction(0, bytes()) == expectation); + expectation = bytes(17, 0); + expectation[0] = 0; + expectation[1] = 2; + expectation[16] = 1; + BOOST_CHECK(callContractFunction(1, bytes({0x00, 0x02, 0x01})) == expectation); +} + BOOST_AUTO_TEST_CASE(state_smoke_test) { char const* sourceCode = "contract test {\n" @@ -1060,6 +1088,34 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars) BOOST_REQUIRE(callContractFunction(0, a, b) == toBigEndian(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 helperAddress = m_contractAddress; + compileAndRun(sourceCode, 0, "Main"); + BOOST_REQUIRE(callContractFunction(2, helperAddress) == bytes()); + BOOST_REQUIRE(callContractFunction(1, helperAddress) == toBigEndian(helperAddress)); + BOOST_CHECK(callContractFunction(0, bytes({0, 'a', 1})) == bytes({0, 'a', 0, 0, 0})); +} + BOOST_AUTO_TEST_SUITE_END() } From 1a76615a87d64cefe45066bf574dcce52e547f33 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 10 Dec 2014 17:15:10 +0100 Subject: [PATCH 03/11] Tests for empty and too long strings. --- solidityNameAndTypeResolution.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/solidityNameAndTypeResolution.cpp b/solidityNameAndTypeResolution.cpp index 783972296..7357471cc 100644 --- a/solidityNameAndTypeResolution.cpp +++ b/solidityNameAndTypeResolution.cpp @@ -226,6 +226,22 @@ BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } +BOOST_AUTO_TEST_CASE(empty_string_literal) +{ + char const* text = "contract test {\n" + " function f() { var x = \"\"; }" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + +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" From c1ffbbe79729b25da0d0231cd81fe2ab60519448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 10 Dec 2014 17:41:53 +0100 Subject: [PATCH 04/11] VMFactory - a new way of creating VMs --- createRandomTest.cpp | 8 ++++---- vm.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/createRandomTest.cpp b/createRandomTest.cpp index caeeb6b67..a11688457 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include "vm.h" using namespace std; @@ -142,14 +142,14 @@ void doMyTests(json_spirit::mValue& v) } bytes output; - eth::VM vm(fev.gas); + auto vm = eth::VMFactory::create(fev.gas); u256 gas; bool vmExceptionOccured = false; try { - output = vm.go(fev, fev.simpleTrace()).toBytes(); - gas = vm.gas(); + output = vm->go(fev, fev.simpleTrace()).toBytes(); + gas = vm->gas(); } catch (eth::VMException const& _e) { diff --git a/vm.cpp b/vm.cpp index 45034b716..02cee0a05 100644 --- a/vm.cpp +++ b/vm.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "vm.h" using namespace std; @@ -298,14 +299,14 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) } bytes output; - VM vm(fev.gas); + auto vm = eth::VMFactory::create(fev.gas); u256 gas; bool vmExceptionOccured = false; try { - output = vm.go(fev, fev.simpleTrace()).toBytes(); - gas = vm.gas(); + output = vm->go(fev, fev.simpleTrace()).toBytes(); + gas = vm->gas(); } catch (VMException const& _e) { From 6dcb545cc8a88679d46ab9667beb52e7874df128 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 11 Dec 2014 14:19:11 +0100 Subject: [PATCH 05/11] Support empty strings. --- solidityEndToEndTest.cpp | 14 ++++++++++++++ solidityNameAndTypeResolution.cpp | 8 -------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 940ccac63..5523ded39 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -510,6 +510,20 @@ BOOST_AUTO_TEST_CASE(strings) BOOST_CHECK(callContractFunction(1, bytes({0x00, 0x02, 0x01})) == expectation); } +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(0, bytes({0x02})) == bytes({0x00, 0x02, 'a', 'b', 'c', 0x00})); +} + BOOST_AUTO_TEST_CASE(state_smoke_test) { char const* sourceCode = "contract test {\n" diff --git a/solidityNameAndTypeResolution.cpp b/solidityNameAndTypeResolution.cpp index 7357471cc..03eaebb3a 100644 --- a/solidityNameAndTypeResolution.cpp +++ b/solidityNameAndTypeResolution.cpp @@ -226,14 +226,6 @@ BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } -BOOST_AUTO_TEST_CASE(empty_string_literal) -{ - char const* text = "contract test {\n" - " function f() { var x = \"\"; }" - "}\n"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); -} - BOOST_AUTO_TEST_CASE(large_string_literal) { char const* text = "contract test {\n" From 1d879a9bb451943add6bb2bd68cad3c79e6aa50e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 11 Dec 2014 20:07:07 +0100 Subject: [PATCH 06/11] Remove extraneous old stuff for PoC-7. Fix gas remaining issue. --- vm.cpp | 7 ++++--- vm.h | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/vm.cpp b/vm.cpp index 5c270f789..8fe378cef 100644 --- a/vm.cpp +++ b/vm.cpp @@ -241,10 +241,11 @@ void FakeExtVM::importCallCreates(mArray& _callcreates) eth::OnOpFunc FakeExtVM::simpleTrace() { - return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt) + + return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, dev::eth::VM* voidVM, dev::eth::ExtVMFace const* voidExt) { - FakeExtVM const& ext = *(FakeExtVM const*)voidExt; - eth::VM& vm = *(eth::VM*)voidVM; + FakeExtVM const& ext = *static_cast(voidExt); + eth::VM& vm = *voidVM; std::ostringstream o; o << std::endl << " STACK" << std::endl; diff --git a/vm.h b/vm.h index a52a02e31..3d4b88d54 100644 --- a/vm.h +++ b/vm.h @@ -80,9 +80,6 @@ public: bytes thisTxData; bytes thisTxCode; u256 gas; - -private: - eth::Manifest m_ms; }; From 6e390ba059115d919db631c73cec403cd796b3cc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 11 Dec 2014 21:46:06 +0100 Subject: [PATCH 07/11] Fix genesis test. Refactor/cleaning. --- genesis.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genesis.cpp b/genesis.cpp index 6839d42e2..2cd9221a8 100644 --- a/genesis.cpp +++ b/genesis.cpp @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(genesis_tests) BOOST_CHECK_EQUAL(BlockChain::genesis().stateRoot, h256(o["genesis_state_root"].get_str())); BOOST_CHECK_EQUAL(toHex(BlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str()))); - BOOST_CHECK_EQUAL(sha3(BlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); + BOOST_CHECK_EQUAL(BlockInfo::headerHash(BlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str())); } BOOST_AUTO_TEST_SUITE_END() From 98722ae8e842f54ff1dd67756cfeae7177431665 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 11 Dec 2014 22:52:20 +0100 Subject: [PATCH 08/11] Whisper test fix. --- whisperTopic.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 493b37bc2..941c790e5 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_SUITE(whisper) BOOST_AUTO_TEST_CASE(topic) { - g_logVerbosity = 0; + g_logVerbosity = 20; bool started = false; unsigned result = 0; @@ -40,16 +40,16 @@ BOOST_AUTO_TEST_CASE(topic) { setThreadName("other"); - Host ph("Test", NetworkPreferences(30303, "", false, true)); + Host ph("Test", NetworkPreferences(50303, "", false, true)); auto wh = ph.registerCapability(new WhisperHost()); ph.start(); started = true; /// Only interested in odd packets - auto w = wh->installWatch(BuildTopicMask()("odd")); + auto w = wh->installWatch(BuildTopicMask("odd")); - for (int i = 0, last = 0; i < 100 && last < 81; ++i) + for (int i = 0, last = 0; i < 200 && last < 81; ++i) { for (auto i: wh->checkWatch(w)) { @@ -65,10 +65,12 @@ BOOST_AUTO_TEST_CASE(topic) while (!started) this_thread::sleep_for(chrono::milliseconds(50)); - Host ph("Test", NetworkPreferences(30300, "", false, true)); + Host ph("Test", NetworkPreferences(50300, "", false, true)); auto wh = ph.registerCapability(new WhisperHost()); + this_thread::sleep_for(chrono::milliseconds(500)); ph.start(); - ph.connect("127.0.0.1", 30303); + this_thread::sleep_for(chrono::milliseconds(500)); + ph.connect("127.0.0.1", 50303); KeyPair us = KeyPair::create(); for (int i = 0; i < 10; ++i) @@ -78,6 +80,8 @@ BOOST_AUTO_TEST_CASE(topic) } listener.join(); + g_logVerbosity = 0; + BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81); } From c9ccbe2562c35ecb957dc52f72dfc9c9555335e5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 13:35:05 +0100 Subject: [PATCH 09/11] Reduce verbosity. --- whisperTopic.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 941c790e5..1c8e74837 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -32,7 +32,8 @@ BOOST_AUTO_TEST_SUITE(whisper) BOOST_AUTO_TEST_CASE(topic) { - g_logVerbosity = 20; + cnote << "Testing Whisper..."; + g_logVerbosity = 0; bool started = false; unsigned result = 0; From 73a2647474251168cde3febc6708eaa4d751e19d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 15:31:24 +0100 Subject: [PATCH 10/11] Fix tests. --- jsonrpc.cpp | 2 +- trie.cpp | 7 +++---- whisperTopic.cpp | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/jsonrpc.cpp b/jsonrpc.cpp index d17c5a594..20ffc6d54 100644 --- a/jsonrpc.cpp +++ b/jsonrpc.cpp @@ -19,7 +19,7 @@ * @date 2014 */ -#if ETH_JSONRPC +#if ETH_JSONRPC && 0 #include #include diff --git a/trie.cpp b/trie.cpp index 67f706917..3f072a6d1 100644 --- a/trie.cpp +++ b/trie.cpp @@ -59,8 +59,8 @@ BOOST_AUTO_TEST_CASE(trie_tests) cnote << "Testing Trie..."; js::mValue v; - string s = asString(contents(testPath + "/trietest.json")); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?"); + string s = asString(contents(testPath + "/trieanyorder.json")); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trieanyorder.json' is empty. Have you cloned the 'tests' repo branch develop?"); js::read_string(s, v); for (auto& i: v.get_obj()) { @@ -88,12 +88,11 @@ BOOST_AUTO_TEST_CASE(trie_tests) BOOST_REQUIRE(t.check(true)); } BOOST_REQUIRE(!o["root"].is_null()); - BOOST_CHECK_EQUAL(o["root"].get_str(), toHex(t.root().asArray())); + BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray())); } } } - inline h256 stringMapHash256(StringMap const& _s) { return hash256(_s); diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 1c8e74837..c5e59332d 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_SUITE(whisper) BOOST_AUTO_TEST_CASE(topic) { cnote << "Testing Whisper..."; - g_logVerbosity = 0; +// g_logVerbosity = 0; bool started = false; unsigned result = 0; @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(topic) } listener.join(); - g_logVerbosity = 0; +// g_logVerbosity = 0; BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81); } From 696b5b3a493d7e9c8bee455bed24bdfcfe3a1fb0 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 15:44:18 +0100 Subject: [PATCH 11/11] Minor warning fix. --- solidityOptimizerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidityOptimizerTest.cpp b/solidityOptimizerTest.cpp index f8d3b552c..b689fe54e 100644 --- a/solidityOptimizerTest.cpp +++ b/solidityOptimizerTest.cpp @@ -48,7 +48,7 @@ public: m_optimize = true; bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName); int sizeDiff = nonOptimizedBytecode.size() - optimizedBytecode.size(); - BOOST_CHECK_MESSAGE(sizeDiff >= _expectedSizeDecrease, "Bytecode did only shrink by " + BOOST_CHECK_MESSAGE(sizeDiff >= (int)_expectedSizeDecrease, "Bytecode did only shrink by " + boost::lexical_cast(sizeDiff) + " bytes, expected: " + boost::lexical_cast(_expectedSizeDecrease)); m_optimizedContract = m_contractAddress;