From 3128ec2ca5d30aaca78aae457642214f3f52e31f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 16:20:05 +0000 Subject: Add blockNumber and blockTimestamp to ExecutionFramework --- test/ExecutionFramework.cpp | 8 ++++++++ test/ExecutionFramework.h | 2 ++ test/RPCSession.cpp | 1 + test/RPCSession.h | 1 + 4 files changed, 12 insertions(+) (limited to 'test') diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index ddcd9cb6..70139642 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -82,6 +82,8 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 m_rpc.test_mineBlocks(1); RPCSession::TransactionReceipt receipt(m_rpc.eth_getTransactionReceipt(txHash)); + m_blockNumber = u256(receipt.blockNumber); + if (_isCreation) { m_contractAddress = Address(receipt.contractAddress); @@ -129,6 +131,12 @@ size_t ExecutionFramework::currentTimestamp() return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); } +size_t ExecutionFramework::blockTimestamp(u256 _number) +{ + auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {toString(_number), "false"}); + return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); +} + Address ExecutionFramework::account(size_t _i) { return Address(m_rpc.accountCreateIfNotExists(_i)); diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index 733fd56d..76d0fd8c 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -262,6 +262,7 @@ protected: void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0); void sendEther(Address const& _to, u256 const& _value); size_t currentTimestamp(); + size_t blockTimestamp(u256 number); /// @returns the (potentially newly created) _ith address. Address account(size_t _i); @@ -284,6 +285,7 @@ protected: bool m_showMessages = false; Address m_sender; Address m_contractAddress; + u256 m_blockNumber; u256 const m_gasPrice = 100 * szabo; u256 const m_gas = 100000000; bytes m_output; diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index b3451528..a58355d0 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -138,6 +138,7 @@ RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string cons BOOST_REQUIRE(!result.isNull()); receipt.gasUsed = result["gasUsed"].asString(); receipt.contractAddress = result["contractAddress"].asString(); + receipt.blockNumber = result["blockNumber"].asString(); for (auto const& log: result["logs"]) { LogEntry entry; diff --git a/test/RPCSession.h b/test/RPCSession.h index f1aee6a8..b2e8a309 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -92,6 +92,7 @@ public: std::string gasUsed; std::string contractAddress; std::vector logEntries; + std::string blockNumber; }; static RPCSession& instance(std::string const& _path); -- cgit v1.2.3 From 4cf44f1b41fe021653a6f45c72c19253dd352459 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 16:20:25 +0000 Subject: Do not use modifyTimestamp where not needed --- test/libsolidity/SolidityEndToEndTest.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 4924b55d..3c2e939c 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1482,9 +1482,12 @@ BOOST_AUTO_TEST_CASE(now) } } )"; - m_rpc.test_modifyTimestamp(0x776347e2); compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 0x776347e3)); + u256 startBlock = m_blockNumber; + auto ret = callContractFunction("someInfo()"); + u256 endBlock = m_blockNumber; + BOOST_CHECK(startBlock != endBlock); + BOOST_CHECK(ret == encodeArgs(true, blockTimestamp(endBlock))); } BOOST_AUTO_TEST_CASE(type_conversions_cleanup) -- cgit v1.2.3 From 702ee20a0179afe607383554ee89b0f863e14f63 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 18:41:51 +0000 Subject: Create getBlockByNumber RPC method --- test/ExecutionFramework.cpp | 4 ++-- test/RPCSession.cpp | 10 ++++++++-- test/RPCSession.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index 70139642..f4e5fcef 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -127,13 +127,13 @@ void ExecutionFramework::sendEther(Address const& _to, u256 const& _value) size_t ExecutionFramework::currentTimestamp() { - auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {"\"latest\"", "false"}); + auto latestBlock = m_rpc.eth_getBlockByNumber("latest", false); return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); } size_t ExecutionFramework::blockTimestamp(u256 _number) { - auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {toString(_number), "false"}); + auto latestBlock = m_rpc.eth_getBlockByNumber(toString(_number), false); return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); } diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index a58355d0..c27e73d4 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -131,6 +131,12 @@ string RPCSession::eth_getCode(string const& _address, string const& _blockNumbe return rpcCall("eth_getCode", { quote(_address), quote(_blockNumber) }).asString(); } +Json::Value RPCSession::eth_getBlockByNumber(string const& _blockNumber, bool _fullObjects) +{ + // NOTE: to_string() converts bool to 0 or 1 + return rpcCall("eth_getBlockByNumber", { quote(_blockNumber), _fullObjects ? "true" : "false" }); +} + RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string const& _transactionHash) { TransactionReceipt receipt; @@ -290,9 +296,9 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector const& request += "],\"id\":" + to_string(m_rpcSequence) + "}"; ++m_rpcSequence; - //cout << "Request: " << request << endl; + // cout << "Request: " << request << endl; string reply = m_ipcSocket.sendRequest(request); - //cout << "Reply: " << reply << endl; + // cout << "Reply: " << reply << endl; Json::Value result; BOOST_REQUIRE(Json::Reader().parse(reply, result, false)); diff --git a/test/RPCSession.h b/test/RPCSession.h index b2e8a309..105ba378 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -98,6 +98,7 @@ public: static RPCSession& instance(std::string const& _path); std::string eth_getCode(std::string const& _address, std::string const& _blockNumber); + Json::Value eth_getBlockByNumber(std::string const& _blockNumber, bool _fullObjects); std::string eth_call(TransactionData const& _td, std::string const& _blockNumber); TransactionReceipt eth_getTransactionReceipt(std::string const& _transactionHash); std::string eth_sendTransaction(TransactionData const& _transactionData); -- cgit v1.2.3 From a82acba49ae68a960f33a2938f3d3560bf65441c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 13:26:11 +0000 Subject: Compare start/end timestamp --- test/libsolidity/SolidityEndToEndTest.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3c2e939c..53b61450 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1484,10 +1484,13 @@ BOOST_AUTO_TEST_CASE(now) )"; compileAndRun(sourceCode); u256 startBlock = m_blockNumber; + size_t startTime = blockTimestamp(startBlock); auto ret = callContractFunction("someInfo()"); u256 endBlock = m_blockNumber; + size_t endTime = blockTimestamp(endBlock); BOOST_CHECK(startBlock != endBlock); - BOOST_CHECK(ret == encodeArgs(true, blockTimestamp(endBlock))); + BOOST_CHECK(startTime != endTime); + BOOST_CHECK(ret == encodeArgs(true, endTime)); } BOOST_AUTO_TEST_CASE(type_conversions_cleanup) -- cgit v1.2.3