go: Add unit test for Execute()

This commit is contained in:
Paweł Bylica 2019-03-12 14:30:04 +01:00
parent 65d68faed2
commit 0a0bb0b92e
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 27 additions and 3 deletions

View File

@ -48,7 +48,7 @@ build_script:
go build ./bindings/go/evmc go build ./bindings/go/evmc
go generate ./bindings/go/evmc go generate ./bindings/go/evmc
go test ./bindings/go/evmc go test -v ./bindings/go/evmc
} }
after_build: after_build:

View File

@ -7,12 +7,16 @@
package evmc package evmc
import ( import (
"bytes"
"testing" "testing"
"github.com/ethereum/go-ethereum/common"
) )
var modulePath = "./example_vm.so"
func TestLoad(t *testing.T) { func TestLoad(t *testing.T) {
path := "./example_vm.so" i, err := Load(modulePath)
i, err := Load(path)
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
@ -24,3 +28,22 @@ func TestLoad(t *testing.T) {
t.Fatalf("version number is weird: %s", i.Version()) 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")
}
}

View File

@ -91,6 +91,7 @@ static struct evmc_result execute(struct evmc_instance* instance,
ret.output_data = (const uint8_t*)error; ret.output_data = (const uint8_t*)error;
ret.output_size = strlen(error); ret.output_size = strlen(error);
ret.status_code = EVMC_FAILURE; ret.status_code = EVMC_FAILURE;
ret.gas_left = msg->gas / 10;
ret.release = NULL; // We don't need to release the constant messages. ret.release = NULL; // We don't need to release the constant messages.
return ret; return ret;
} }