diff options
author | chriseth <c@ethdev.com> | 2016-06-18 08:08:20 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-06-29 05:18:55 +0800 |
commit | e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d (patch) | |
tree | 3e950203ff1b0cb53f81447f1350feb3add0da27 /test/libsolidity | |
parent | 007132a78e5d97e0476e1153b14f0ae63f458b04 (diff) | |
download | dexon-solidity-e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d.tar.gz dexon-solidity-e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d.tar.zst dexon-solidity-e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d.zip |
Fix some more tests.
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 17 | ||||
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.cpp | 29 | ||||
-rw-r--r-- | test/libsolidity/SolidityExecutionFramework.h | 5 |
3 files changed, 40 insertions, 11 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8689d61e..8dcc878e 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1325,10 +1325,10 @@ BOOST_AUTO_TEST_CASE(blockchain) " blockNumber = block.number;\n" " }\n" "}\n"; - m_envInfo.setAuthor(Address(0x123)); - m_envInfo.setNumber(7); + BOOST_CHECK(m_rpc.rpcCall("miner_setEtherbase", {"\"0x1212121212121212121212121212121212121212\""}).asBool() == true); + m_rpc.test_mineBlocks(5); compileAndRun(sourceCode, 27); - BOOST_CHECK(callContractFunctionWithValue("someInfo()", 28) == encodeArgs(28, 0x123, 7)); + BOOST_CHECK(callContractFunctionWithValue("someInfo()", 28) == encodeArgs(28, u256("0x1212121212121212121212121212121212121212"), 7)); } BOOST_AUTO_TEST_CASE(msg_sig) @@ -1368,9 +1368,9 @@ BOOST_AUTO_TEST_CASE(now) " val = now;\n" " }\n" "}\n"; - m_envInfo.setTimestamp(9); + m_rpc.test_modifyTimestamp(0x776347e2); compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 9)); + BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 0x776347e3)); } BOOST_AUTO_TEST_CASE(type_conversions_cleanup) @@ -2462,8 +2462,7 @@ BOOST_AUTO_TEST_CASE(use_std_lib) contract Icarus is mortal { } )"; m_addStandardSources = true; - u256 amount(130); - u160 address(23); + u256 amount(130 * eth::ether); compileAndRun(sourceCode, amount, "Icarus"); u256 balanceBefore = balanceAt(m_sender); BOOST_CHECK(callContractFunction("kill()") == bytes()); @@ -2567,7 +2566,7 @@ BOOST_AUTO_TEST_CASE(event) 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,bytes32,uint256)"))); - BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender)); + BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender, h256::AlignRight)); BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(id)); } } @@ -2624,7 +2623,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous_with_topics) BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK(m_logs[0].data == encodeArgs("abc")); BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 4); - BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(m_sender)); + BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(m_sender, h256::AlignRight)); BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(id)); BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(value)); BOOST_CHECK_EQUAL(m_logs[0].topics[3], h256(2)); diff --git a/test/libsolidity/SolidityExecutionFramework.cpp b/test/libsolidity/SolidityExecutionFramework.cpp index abb564db..efd3a8b8 100644 --- a/test/libsolidity/SolidityExecutionFramework.cpp +++ b/test/libsolidity/SolidityExecutionFramework.cpp @@ -45,7 +45,8 @@ string getIPCSocketPath() } } if (ipcPath.empty()) - ipcPath = getenv("ETH_TEST_IPC"); + if (auto path = getenv("ETH_TEST_IPC")) + ipcPath = path; if (ipcPath.empty()) BOOST_FAIL("ERROR: ipcPath not set! (use --ipc <path>)"); return ipcPath; @@ -86,7 +87,6 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 m_contractAddress = Address(receipt.contractAddress); BOOST_REQUIRE(m_contractAddress); string code = m_rpc.eth_getCode(receipt.contractAddress, "latest"); - BOOST_REQUIRE(code.size() > 2); m_output = fromHex(code, WhenError::Throw); } @@ -103,6 +103,31 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 } } +void ExecutionFramework::sendEther(Address const& _to, u256 const& _value) +{ + RPCSession::TransactionData d; + d.data = "0x"; + d.from = "0x" + toString(m_sender); + d.gas = toHex(m_gas, HexPrefix::Add); + d.gasPrice = toHex(m_gasPrice, HexPrefix::Add); + d.value = toHex(_value, HexPrefix::Add); + d.to = dev::toString(_to); + + string txHash = m_rpc.eth_sendTransaction(d); + m_rpc.test_mineBlocks(1); +} + +size_t ExecutionFramework::currentTimestamp() +{ + auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {"\"latest\"", "false"}); + return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); +} + +Address ExecutionFramework::account(size_t _i) +{ + return Address(m_rpc.accountCreateIfNotExists(_i)); +} + bool ExecutionFramework::addressHasCode(Address const& _addr) { string code = m_rpc.eth_getCode(toString(_addr), "latest"); diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index 42b22c82..f06aeff7 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -250,6 +250,11 @@ private: protected: void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0); + void sendEther(Address const& _to, u256 const& _value); + size_t currentTimestamp(); + + /// @returns the (potentially newly created) _ith address. + Address account(size_t _i); u256 balanceAt(Address const& _addr); bool storageEmpty(Address const& _addr); |