mirror of
https://github.com/status-im/evmc.git
synced 2025-02-23 08:28:15 +00:00
go: Add unit test for Execute()
This commit is contained in:
parent
65d68faed2
commit
0a0bb0b92e
@ -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:
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user