From 0a0bb0b92e38315a9daa129b834ca719fcfdce24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 12 Mar 2019 14:30:04 +0100 Subject: [PATCH] go: Add unit test for Execute() --- appveyor.yml | 2 +- bindings/go/evmc/evmc_test.go | 27 +++++++++++++++++++++++++-- examples/example_vm.c | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5d88fab..8ecc172 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -48,7 +48,7 @@ build_script: go build ./bindings/go/evmc go generate ./bindings/go/evmc - go test ./bindings/go/evmc + go test -v ./bindings/go/evmc } after_build: diff --git a/bindings/go/evmc/evmc_test.go b/bindings/go/evmc/evmc_test.go index 93bd224..88cbcf9 100644 --- a/bindings/go/evmc/evmc_test.go +++ b/bindings/go/evmc/evmc_test.go @@ -7,12 +7,16 @@ package evmc import ( + "bytes" "testing" + + "github.com/ethereum/go-ethereum/common" ) +var modulePath = "./example_vm.so" + func TestLoad(t *testing.T) { - path := "./example_vm.so" - i, err := Load(path) + i, err := Load(modulePath) if err != nil { t.Fatal(err.Error()) } @@ -24,3 +28,22 @@ func TestLoad(t *testing.T) { t.Fatalf("version number is weird: %s", i.Version()) } } + +func TestExecute(t *testing.T) { + vm, _ := Load(modulePath) + defer vm.Destroy() + + addr := common.Address{} + h := common.Hash{} + output, gasLeft, err := vm.Execute(nil, Byzantium, Call, false, 1, 999, addr, addr, nil, h, nil, h) + + if bytes.Compare(output, []byte("Welcome to Byzantium!")) != 0 { + t.Errorf("execution unexpected output: %s", output) + } + if gasLeft != 99 { + t.Error("execution gas left is incorrect") + } + if err != Failure { + t.Error("execution returned unexpected error") + } +} diff --git a/examples/example_vm.c b/examples/example_vm.c index a13bab9..5f0f483 100644 --- a/examples/example_vm.c +++ b/examples/example_vm.c @@ -91,6 +91,7 @@ static struct evmc_result execute(struct evmc_instance* instance, ret.output_data = (const uint8_t*)error; ret.output_size = strlen(error); ret.status_code = EVMC_FAILURE; + ret.gas_left = msg->gas / 10; ret.release = NULL; // We don't need to release the constant messages. return ret; }