mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
EVMHost: Reuse tx_context from MockedHost
This commit is contained in:
parent
2683c83ad2
commit
635e2fc9d3
@ -100,6 +100,15 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
|
||||
// 1wei
|
||||
m_state.accounts[address].balance.bytes[31] = 1;
|
||||
}
|
||||
|
||||
// TODO: support short literals in EVMC and use them here
|
||||
tx_context.block_difficulty = convertToEVMC(u256("200000000"));
|
||||
tx_context.block_gas_limit = 20000000;
|
||||
tx_context.block_coinbase = 0x7878787878787878787878787878787878787878_address;
|
||||
tx_context.tx_gas_price = convertToEVMC(u256("3000000000"));
|
||||
tx_context.tx_origin = 0x9292929292929292929292929292929292929292_address;
|
||||
// Mainnet according to EIP-155
|
||||
tx_context.chain_id = convertToEVMC(u256(1));
|
||||
}
|
||||
|
||||
evmc_storage_status EVMHost::set_storage(const evmc::address& _addr, const evmc::bytes32& _key, const evmc::bytes32& _value) noexcept
|
||||
@ -229,22 +238,6 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
|
||||
return result;
|
||||
}
|
||||
|
||||
evmc_tx_context EVMHost::get_tx_context() const noexcept
|
||||
{
|
||||
evmc_tx_context ctx = {};
|
||||
ctx.block_timestamp = m_state.timestamp;
|
||||
ctx.block_number = m_state.blockNumber;
|
||||
ctx.block_coinbase = m_coinbase;
|
||||
// TODO: support short literals in EVMC and use them here
|
||||
ctx.block_difficulty = convertToEVMC(u256("200000000"));
|
||||
ctx.block_gas_limit = 20000000;
|
||||
ctx.tx_gas_price = convertToEVMC(u256("3000000000"));
|
||||
ctx.tx_origin = 0x9292929292929292929292929292929292929292_address;
|
||||
// Mainnet according to EIP-155
|
||||
ctx.chain_id = convertToEVMC(u256(1));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
evmc::bytes32 EVMHost::get_block_hash(int64_t _number) const noexcept
|
||||
{
|
||||
return convertToEVMC(u256("0x3737373737373737373737373737373737373737373737373737373737373737") + _number);
|
||||
|
@ -56,8 +56,6 @@ public:
|
||||
|
||||
struct State
|
||||
{
|
||||
size_t blockNumber;
|
||||
uint64_t timestamp;
|
||||
std::map<evmc::address, Account> accounts;
|
||||
};
|
||||
|
||||
@ -76,8 +74,8 @@ public:
|
||||
void reset() { m_state = State{}; m_currentAddress = {}; }
|
||||
void newBlock()
|
||||
{
|
||||
m_state.blockNumber++;
|
||||
m_state.timestamp += 15;
|
||||
tx_context.block_number++;
|
||||
tx_context.block_timestamp += 15;
|
||||
recorded_logs.clear();
|
||||
}
|
||||
|
||||
@ -142,8 +140,6 @@ public:
|
||||
|
||||
evmc::result call(evmc_message const& _message) noexcept;
|
||||
|
||||
evmc_tx_context get_tx_context() const noexcept;
|
||||
|
||||
evmc::bytes32 get_block_hash(int64_t number) const noexcept;
|
||||
|
||||
static Address convertFromEVMC(evmc::address const& _addr);
|
||||
@ -154,7 +150,6 @@ public:
|
||||
|
||||
State m_state;
|
||||
evmc::address m_currentAddress = {};
|
||||
evmc::address m_coinbase = convertToEVMC(Address("0x7878787878787878787878787878787878787878"));
|
||||
|
||||
private:
|
||||
static evmc::result precompileECRecover(evmc_message const& _message) noexcept;
|
||||
|
@ -89,12 +89,12 @@ std::pair<bool, string> ExecutionFramework::compareAndCreateMessage(
|
||||
|
||||
u256 ExecutionFramework::gasLimit() const
|
||||
{
|
||||
return {m_evmHost->get_tx_context().block_gas_limit};
|
||||
return {m_evmHost->tx_context.block_gas_limit};
|
||||
}
|
||||
|
||||
u256 ExecutionFramework::gasPrice() const
|
||||
{
|
||||
return {EVMHost::convertFromEVMC(m_evmHost->get_tx_context().tx_gas_price)};
|
||||
return {EVMHost::convertFromEVMC(m_evmHost->tx_context.tx_gas_price)};
|
||||
}
|
||||
|
||||
u256 ExecutionFramework::blockHash(u256 const& _number) const
|
||||
@ -104,7 +104,7 @@ u256 ExecutionFramework::blockHash(u256 const& _number) const
|
||||
|
||||
u256 ExecutionFramework::blockNumber() const
|
||||
{
|
||||
return m_evmHost->m_state.blockNumber;
|
||||
return m_evmHost->tx_context.block_number;
|
||||
}
|
||||
|
||||
void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 const& _value)
|
||||
@ -178,7 +178,7 @@ void ExecutionFramework::sendEther(Address const& _addr, u256 const& _amount)
|
||||
|
||||
size_t ExecutionFramework::currentTimestamp()
|
||||
{
|
||||
return m_evmHost->get_tx_context().block_timestamp;
|
||||
return m_evmHost->tx_context.block_timestamp;
|
||||
}
|
||||
|
||||
size_t ExecutionFramework::blockTimestamp(u256 _block)
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev::test;
|
||||
@ -280,8 +279,7 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
size_t const m_biddingTime = size_t(7 * 24 * 3600);
|
||||
size_t const m_renewalInterval = size_t(365 * 24 * 3600);
|
||||
int64_t const m_biddingTime = 7 * 24 * 3600;
|
||||
};
|
||||
|
||||
}
|
||||
@ -417,7 +415,7 @@ BOOST_AUTO_TEST_CASE(auction_simple)
|
||||
BOOST_CHECK_EQUAL(registrar.owner(name), 0);
|
||||
// "wait" until auction end
|
||||
|
||||
m_evmHost->m_state.timestamp += m_biddingTime + 10;
|
||||
m_evmHost->tx_context.block_timestamp += m_biddingTime + 10;
|
||||
// trigger auction again
|
||||
registrar.reserve(name);
|
||||
BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
|
||||
@ -429,7 +427,7 @@ BOOST_AUTO_TEST_CASE(auction_bidding)
|
||||
string name = "x";
|
||||
|
||||
unsigned startTime = 0x776347e2;
|
||||
m_evmHost->m_state.timestamp = startTime;
|
||||
m_evmHost->tx_context.block_timestamp = startTime;
|
||||
|
||||
RegistrarInterface registrar(*this);
|
||||
// initiate auction
|
||||
@ -437,19 +435,19 @@ BOOST_AUTO_TEST_CASE(auction_bidding)
|
||||
registrar.reserve(name);
|
||||
BOOST_CHECK_EQUAL(registrar.owner(name), 0);
|
||||
// overbid self
|
||||
m_evmHost->m_state.timestamp = startTime + m_biddingTime - 10;
|
||||
m_evmHost->tx_context.block_timestamp = startTime + m_biddingTime - 10;
|
||||
registrar.setNextValue(12);
|
||||
registrar.reserve(name);
|
||||
// another bid by someone else
|
||||
sendEther(account(1), 10 * ether);
|
||||
m_sender = account(1);
|
||||
m_evmHost->m_state.timestamp = startTime + 2 * m_biddingTime - 50;
|
||||
m_evmHost->tx_context.block_timestamp = startTime + 2 * m_biddingTime - 50;
|
||||
registrar.setNextValue(13);
|
||||
registrar.reserve(name);
|
||||
BOOST_CHECK_EQUAL(registrar.owner(name), 0);
|
||||
// end auction by first bidder (which is not highest) trying to overbid again (too late)
|
||||
m_sender = account(0);
|
||||
m_evmHost->m_state.timestamp = startTime + 4 * m_biddingTime;
|
||||
m_evmHost->tx_context.block_timestamp = startTime + 4 * m_biddingTime;
|
||||
registrar.setNextValue(20);
|
||||
registrar.reserve(name);
|
||||
BOOST_CHECK_EQUAL(registrar.owner(name), account(1));
|
||||
|
@ -1135,7 +1135,7 @@ BOOST_AUTO_TEST_CASE(blockchain)
|
||||
}
|
||||
}
|
||||
)";
|
||||
m_evmHost->m_coinbase = EVMHost::convertToEVMC(Address("0x1212121212121212121212121212121212121212"));
|
||||
m_evmHost->tx_context.block_coinbase = EVMHost::convertToEVMC(Address("0x1212121212121212121212121212121212121212"));
|
||||
m_evmHost->newBlock();
|
||||
m_evmHost->newBlock();
|
||||
m_evmHost->newBlock();
|
||||
|
Loading…
Reference in New Issue
Block a user