mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1676 from ethereum/test-modifytimestamp
Add blockTimestamp and do not rely on mining time (soltest)
This commit is contained in:
commit
e2349f9d5d
@ -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);
|
||||
@ -125,7 +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.eth_getBlockByNumber(toString(_number), false);
|
||||
return size_t(u256(latestBlock.get("timestamp", "invalid").asString()));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
@ -138,6 +144,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;
|
||||
@ -289,9 +296,9 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector<string> 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));
|
||||
|
@ -92,11 +92,13 @@ public:
|
||||
std::string gasUsed;
|
||||
std::string contractAddress;
|
||||
std::vector<LogEntry> logEntries;
|
||||
std::string blockNumber;
|
||||
};
|
||||
|
||||
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);
|
||||
|
@ -1482,9 +1482,15 @@ BOOST_AUTO_TEST_CASE(now)
|
||||
}
|
||||
}
|
||||
)";
|
||||
m_rpc.test_modifyTimestamp(0x776347e2);
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 0x776347e3));
|
||||
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(startTime != endTime);
|
||||
BOOST_CHECK(ret == encodeArgs(true, endTime));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_conversions_cleanup)
|
||||
|
Loading…
Reference in New Issue
Block a user