From b683d02f117d43d21d50e07787d69ee7ac445ef0 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 31 Oct 2014 13:54:24 +0100 Subject: [PATCH 1/3] # This is a combination of 2 commits. # The first commit's message is: Merge pull request #454 from jorisbontje/423-dockerfile update Dockerfile with cryptopp and jsonrpc dependencies, fixes #423 Cleaned up jsonrpc test # This is the 2nd commit message: Forgot the #if --- test/jsonrpc.cpp | 54 +++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/test/jsonrpc.cpp b/test/jsonrpc.cpp index 033339ec2..793d6a6e3 100644 --- a/test/jsonrpc.cpp +++ b/test/jsonrpc.cpp @@ -36,8 +36,6 @@ #include "TestHelper.h" #include "webthreestubclient.h" -BOOST_AUTO_TEST_SUITE(jsonrpc) - using namespace std; using namespace dev; using namespace dev::eth; @@ -46,35 +44,34 @@ namespace js = json_spirit; namespace jsonrpc_tests { -string name = "Ethereum(++) tests"; -string dbPath; -auto s = set{"eth", "shh"}; -dev::p2p::NetworkPreferences np(30303, std::string(), false); -dev::WebThreeDirect web3(name, dbPath, true, s, np); - -unique_ptr jsonrpcServer; -unique_ptr jsonrpcClient; - struct JsonrpcFixture { - JsonrpcFixture() + JsonrpcFixture():web3(name, dbPath, true, set{"eth", "shh"}, dev::p2p::NetworkPreferences(30303, std::string(), false)) { cnote << "setup jsonrpc"; + name = "Ethereum(++) tests"; web3.setIdealPeerCount(5); web3.ethereum()->setForceMining(true); jsonrpcServer = unique_ptr(new WebThreeStubServer(new jsonrpc::CorsHttpServer(8080), web3, {})); jsonrpcServer->setIdentities({}); jsonrpcServer->StartListening(); - + jsonrpcClient = unique_ptr(new WebThreeStubClient(new jsonrpc::HttpClient("http://localhost:8080"))); } ~JsonrpcFixture() { cnote << "teardown jsonrpc"; } + + string name; + string dbPath; + unique_ptr jsonrpcServer; + unique_ptr jsonrpcClient; + dev::WebThreeDirect web3; + }; -BOOST_GLOBAL_FIXTURE(JsonrpcFixture) +BOOST_FIXTURE_TEST_SUITE(jsonrpc, JsonrpcFixture) BOOST_AUTO_TEST_CASE(jsonrpc_defaultBlock) { @@ -97,7 +94,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isListening) web3.startNetwork(); bool listeningOn = jsonrpcClient->listening(); BOOST_CHECK_EQUAL(listeningOn, web3.isNetworkStarted()); - + web3.stopNetwork(); bool listeningOff = jsonrpcClient->listening(); BOOST_CHECK_EQUAL(listeningOff, web3.isNetworkStarted()); @@ -159,7 +156,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setListening) jsonrpcClient->setListening(true); BOOST_CHECK_EQUAL(web3.isNetworkStarted(), true); - + jsonrpcClient->setListening(false); BOOST_CHECK_EQUAL(web3.isNetworkStarted(), false); } @@ -189,7 +186,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact) cnote << "Testing jsonrpc transact..."; string coinbase = jsonrpcClient->coinbase(); BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3.ethereum()->address()); - + dev::KeyPair key = KeyPair::create(); auto address = key.address(); auto receiver = KeyPair::create(); @@ -198,28 +195,28 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact) coinbase = jsonrpcClient->coinbase(); BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3.ethereum()->address()); BOOST_CHECK_EQUAL(jsToAddress(coinbase), address); - + jsonrpcServer->setAccounts({key}); auto balance = web3.ethereum()->balanceAt(address, 0); string balanceString = jsonrpcClient->balanceAt(toJS(address)); double countAt = jsonrpcClient->countAt(toJS(address)); - + BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address)); BOOST_CHECK_EQUAL(countAt, 0); BOOST_CHECK_EQUAL(toJS(balance), balanceString); BOOST_CHECK_EQUAL(jsToDecimal(balanceString), "0"); - + dev::eth::mine(*(web3.ethereum()), 1); balance = web3.ethereum()->balanceAt(address, 0); balanceString = jsonrpcClient->balanceAt(toJS(address)); - + BOOST_CHECK_EQUAL(toJS(balance), balanceString); BOOST_CHECK_EQUAL(jsToDecimal(balanceString), "1500000000000000000"); - + auto txAmount = balance / 2u; auto gasPrice = 10 * dev::eth::szabo; auto gas = dev::eth::c_txGas; - + Json::Value t; t["from"] = toJS(address); t["value"] = jsToDecimal(toJS(txAmount)); @@ -227,24 +224,21 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact) t["data"] = toJS(bytes()); t["gas"] = toJS(gas); t["gasPrice"] = toJS(gasPrice); - + jsonrpcClient->transact(t); jsonrpcServer->setAccounts({}); dev::eth::mine(*(web3.ethereum()), 1); - + countAt = jsonrpcClient->countAt(toJS(address)); auto balance2 = web3.ethereum()->balanceAt(receiver.address()); string balanceString2 = jsonrpcClient->balanceAt(toJS(receiver.address())); - + BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address)); BOOST_CHECK_EQUAL(countAt, 1); BOOST_CHECK_EQUAL(toJS(balance2), balanceString2); BOOST_CHECK_EQUAL(jsToDecimal(balanceString2), "750000000000000000"); BOOST_CHECK_EQUAL(txAmount, balance2); } - + BOOST_AUTO_TEST_SUITE_END() } - -BOOST_AUTO_TEST_SUITE_END() - #endif From aeb353a4d0d1ba4c794920e1257e98864b78fe83 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Tue, 4 Nov 2014 13:43:13 +0100 Subject: [PATCH 2/3] Merge pull request #454 from jorisbontje/423-dockerfile update Dockerfile with cryptopp and jsonrpc dependencies, fixes #423 Cleaned up jsonrpc test Forgot the #if Undo jsonrpc test changes --- test/jsonrpc.cpp | 54 +++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/test/jsonrpc.cpp b/test/jsonrpc.cpp index 793d6a6e3..033339ec2 100644 --- a/test/jsonrpc.cpp +++ b/test/jsonrpc.cpp @@ -36,6 +36,8 @@ #include "TestHelper.h" #include "webthreestubclient.h" +BOOST_AUTO_TEST_SUITE(jsonrpc) + using namespace std; using namespace dev; using namespace dev::eth; @@ -44,34 +46,35 @@ namespace js = json_spirit; namespace jsonrpc_tests { +string name = "Ethereum(++) tests"; +string dbPath; +auto s = set{"eth", "shh"}; +dev::p2p::NetworkPreferences np(30303, std::string(), false); +dev::WebThreeDirect web3(name, dbPath, true, s, np); + +unique_ptr jsonrpcServer; +unique_ptr jsonrpcClient; + struct JsonrpcFixture { - JsonrpcFixture():web3(name, dbPath, true, set{"eth", "shh"}, dev::p2p::NetworkPreferences(30303, std::string(), false)) + JsonrpcFixture() { cnote << "setup jsonrpc"; - name = "Ethereum(++) tests"; web3.setIdealPeerCount(5); web3.ethereum()->setForceMining(true); jsonrpcServer = unique_ptr(new WebThreeStubServer(new jsonrpc::CorsHttpServer(8080), web3, {})); jsonrpcServer->setIdentities({}); jsonrpcServer->StartListening(); - + jsonrpcClient = unique_ptr(new WebThreeStubClient(new jsonrpc::HttpClient("http://localhost:8080"))); } ~JsonrpcFixture() { cnote << "teardown jsonrpc"; } - - string name; - string dbPath; - unique_ptr jsonrpcServer; - unique_ptr jsonrpcClient; - dev::WebThreeDirect web3; - }; -BOOST_FIXTURE_TEST_SUITE(jsonrpc, JsonrpcFixture) +BOOST_GLOBAL_FIXTURE(JsonrpcFixture) BOOST_AUTO_TEST_CASE(jsonrpc_defaultBlock) { @@ -94,7 +97,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isListening) web3.startNetwork(); bool listeningOn = jsonrpcClient->listening(); BOOST_CHECK_EQUAL(listeningOn, web3.isNetworkStarted()); - + web3.stopNetwork(); bool listeningOff = jsonrpcClient->listening(); BOOST_CHECK_EQUAL(listeningOff, web3.isNetworkStarted()); @@ -156,7 +159,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setListening) jsonrpcClient->setListening(true); BOOST_CHECK_EQUAL(web3.isNetworkStarted(), true); - + jsonrpcClient->setListening(false); BOOST_CHECK_EQUAL(web3.isNetworkStarted(), false); } @@ -186,7 +189,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact) cnote << "Testing jsonrpc transact..."; string coinbase = jsonrpcClient->coinbase(); BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3.ethereum()->address()); - + dev::KeyPair key = KeyPair::create(); auto address = key.address(); auto receiver = KeyPair::create(); @@ -195,28 +198,28 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact) coinbase = jsonrpcClient->coinbase(); BOOST_CHECK_EQUAL(jsToAddress(coinbase), web3.ethereum()->address()); BOOST_CHECK_EQUAL(jsToAddress(coinbase), address); - + jsonrpcServer->setAccounts({key}); auto balance = web3.ethereum()->balanceAt(address, 0); string balanceString = jsonrpcClient->balanceAt(toJS(address)); double countAt = jsonrpcClient->countAt(toJS(address)); - + BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address)); BOOST_CHECK_EQUAL(countAt, 0); BOOST_CHECK_EQUAL(toJS(balance), balanceString); BOOST_CHECK_EQUAL(jsToDecimal(balanceString), "0"); - + dev::eth::mine(*(web3.ethereum()), 1); balance = web3.ethereum()->balanceAt(address, 0); balanceString = jsonrpcClient->balanceAt(toJS(address)); - + BOOST_CHECK_EQUAL(toJS(balance), balanceString); BOOST_CHECK_EQUAL(jsToDecimal(balanceString), "1500000000000000000"); - + auto txAmount = balance / 2u; auto gasPrice = 10 * dev::eth::szabo; auto gas = dev::eth::c_txGas; - + Json::Value t; t["from"] = toJS(address); t["value"] = jsToDecimal(toJS(txAmount)); @@ -224,21 +227,24 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact) t["data"] = toJS(bytes()); t["gas"] = toJS(gas); t["gasPrice"] = toJS(gasPrice); - + jsonrpcClient->transact(t); jsonrpcServer->setAccounts({}); dev::eth::mine(*(web3.ethereum()), 1); - + countAt = jsonrpcClient->countAt(toJS(address)); auto balance2 = web3.ethereum()->balanceAt(receiver.address()); string balanceString2 = jsonrpcClient->balanceAt(toJS(receiver.address())); - + BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address)); BOOST_CHECK_EQUAL(countAt, 1); BOOST_CHECK_EQUAL(toJS(balance2), balanceString2); BOOST_CHECK_EQUAL(jsToDecimal(balanceString2), "750000000000000000"); BOOST_CHECK_EQUAL(txAmount, balance2); } - BOOST_AUTO_TEST_SUITE_END() + } + +BOOST_AUTO_TEST_SUITE_END() + #endif From 8c1202c76f9be1e052ec38bfbc8f8a72d4cc7503 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Tue, 4 Nov 2014 13:39:49 +0100 Subject: [PATCH 3/3] bugfix jumps after push --- libevm/VM.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libevm/VM.h b/libevm/VM.h index c76a45e33..8bf3854f3 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -104,7 +104,7 @@ template dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con { int in = _ext.code[i] - (unsigned)Instruction::PUSH1 + 1; u256 p = 0; - for (; in--; i++) + for (i++; in--; i++) p = (p << 8) | _ext.getCode(i); if ((_ext.getCode(i) == (byte)Instruction::JUMP || _ext.getCode(i) == (byte)Instruction::JUMPI) && !(_ext.getCode(p) == (byte)Instruction::JUMP || _ext.getCode(p) == (byte)Instruction::JUMPI)) if (p >= _ext.code.size()) @@ -112,6 +112,7 @@ template dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con else implicit.insert(p); else {} + i--; } for (unsigned i = 0; i < _ext.code.size(); i += instructionInfo((Instruction)_ext.getCode(i)).additional + 1) if (implicit.count(i))