mirror of https://github.com/status-im/evmc.git
examples: add evmc_tx_context to ExampleHost
This commit is contained in:
parent
bea35ea084
commit
dd065265d9
|
@ -43,7 +43,9 @@ int main(int argc, char* argv[])
|
|||
const evmc_uint256be value = {{1, 0}};
|
||||
const evmc_address addr = {{0, 1, 2}};
|
||||
const int64_t gas = 200000;
|
||||
struct evmc_context* ctx = example_host_create_context();
|
||||
struct evmc_tx_context tx_context;
|
||||
memset(&tx_context, 0, sizeof(tx_context));
|
||||
struct evmc_context* ctx = example_host_create_context(tx_context);
|
||||
struct evmc_message msg;
|
||||
msg.sender = addr;
|
||||
msg.destination = addr;
|
||||
|
|
|
@ -25,8 +25,12 @@ struct account
|
|||
class ExampleHost : public evmc::Host
|
||||
{
|
||||
std::map<evmc::address, account> accounts;
|
||||
evmc_tx_context tx_context{};
|
||||
|
||||
public:
|
||||
ExampleHost() = default;
|
||||
explicit ExampleHost(evmc_tx_context& _tx_context) noexcept : tx_context{_tx_context} {};
|
||||
|
||||
bool account_exists(const evmc::address& addr) noexcept final
|
||||
{
|
||||
return accounts.find(addr) != accounts.end();
|
||||
|
@ -98,7 +102,7 @@ public:
|
|||
return {EVMC_REVERT, msg.gas, msg.input_data, msg.input_size};
|
||||
}
|
||||
|
||||
evmc_tx_context get_tx_context() noexcept final { return {}; }
|
||||
evmc_tx_context get_tx_context() noexcept final { return tx_context; }
|
||||
|
||||
evmc::bytes32 get_block_hash(int64_t number) noexcept final
|
||||
{
|
||||
|
@ -126,9 +130,9 @@ public:
|
|||
|
||||
extern "C" {
|
||||
|
||||
evmc_context* example_host_create_context()
|
||||
evmc_context* example_host_create_context(evmc_tx_context tx_context)
|
||||
{
|
||||
return new ExampleHost;
|
||||
return new ExampleHost(tx_context);
|
||||
}
|
||||
|
||||
void example_host_destroy_context(evmc_context* context)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct evmc_context* example_host_create_context();
|
||||
struct evmc_context* example_host_create_context(struct evmc_tx_context tx_context);
|
||||
|
||||
void example_host_destroy_context(struct evmc_context* context);
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ TEST(cpp, host)
|
|||
{
|
||||
// Use example host to execute all methods from the C++ host wrapper.
|
||||
|
||||
auto* host_context = example_host_create_context();
|
||||
auto* host_context = example_host_create_context(evmc_tx_context{});
|
||||
auto host = evmc::HostContext{host_context};
|
||||
|
||||
const auto a = evmc::address{{{1}}};
|
||||
|
@ -380,7 +380,7 @@ TEST(cpp, host_call)
|
|||
{
|
||||
// Use example host to test Host::call() method.
|
||||
|
||||
auto* host_context = example_host_create_context();
|
||||
auto* host_context = example_host_create_context(evmc_tx_context{});
|
||||
auto host = evmc::HostContext{host_context};
|
||||
|
||||
EXPECT_EQ(host.call({}).gas_left, 0);
|
||||
|
|
|
@ -59,7 +59,7 @@ TEST_F(evmc_vm_test, capabilities)
|
|||
|
||||
TEST_F(evmc_vm_test, execute_call)
|
||||
{
|
||||
evmc_context* context = example_host_create_context();
|
||||
evmc_context* context = example_host_create_context(evmc_tx_context{});
|
||||
evmc_message msg{};
|
||||
std::array<uint8_t, 2> code = {{0xfe, 0x00}};
|
||||
|
||||
|
@ -92,7 +92,7 @@ TEST_F(evmc_vm_test, execute_call)
|
|||
|
||||
TEST_F(evmc_vm_test, execute_create)
|
||||
{
|
||||
evmc_context* context = example_host_create_context();
|
||||
evmc_context* context = example_host_create_context(evmc_tx_context{});
|
||||
evmc_message msg{
|
||||
EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, nullptr, 0, evmc_uint256be{},
|
||||
evmc_bytes32{}};
|
||||
|
|
Loading…
Reference in New Issue