Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: add LoadAndConfigure method #404

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning].

## [6.3.1] - unreleased

### Added

- Added `LoadAndConfigure` method to the Go API.
[[#404](https://github.com/ethereum/evmc/pull/404)]

### Fixed

- In C++ API the `get_balance()` method now returns expected `evmc::uint256be`
instead of `evmc_uint256be`.
[[#403](https://github.com/ethereum/evmc/pull/403)]


## [6.3.0] - 2019-08-12

### Added
Expand Down
20 changes: 20 additions & 0 deletions bindings/go/evmc/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ func Load(filename string) (instance *Instance, err error) {
return instance, err
}

func LoadAndConfigure(config string) (instance *Instance, err error) {
cconfig := C.CString(config)
var loaderErr C.enum_evmc_loader_error_code
handle := C.evmc_load_and_configure(cconfig, &loaderErr)
C.free(unsafe.Pointer(cconfig))

if loaderErr == C.EVMC_LOADER_SUCCESS {
instance = &Instance{handle}
} else {
errMsg := C.evmc_last_error_msg()
if errMsg != nil {
err = fmt.Errorf("EVMC loading error: %s", C.GoString(errMsg))
} else {
err = fmt.Errorf("EVMC loading error %d", int(loaderErr))
}
}

return instance, err
}

func (instance *Instance) Destroy() {
C.evmc_destroy(instance.handle)
}
Expand Down
14 changes: 14 additions & 0 deletions bindings/go/evmc/evmc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ func TestLoad(t *testing.T) {
}
}

func TestLoadConfigure(t *testing.T) {
i, err := LoadAndConfigure(modulePath)
if err != nil {
t.Fatal(err.Error())
}
defer i.Destroy()
if i.Name() != "example_vm" {
t.Fatalf("name is %s", i.Name())
}
if i.Version()[0] < '0' || i.Version()[0] > '9' {
t.Fatalf("version number is weird: %s", i.Version())
}
}

func TestExecute(t *testing.T) {
vm, _ := Load(modulePath)
defer vm.Destroy()
Expand Down