Skip to content

Commit

Permalink
Merge branch 'master' into java-types
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Mar 22, 2021
2 parents 95b16bb + bfe3cf1 commit 1122076
Show file tree
Hide file tree
Showing 37 changed files with 1,415 additions and 435 deletions.
25 changes: 15 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
SplitEmptyFunction: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
# AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
# BeforeLambdaBody: true
# BeforeWhile: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
ColumnLimit: 100
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ project(evmc)
set(PROJECT_VERSION 7.5.0-alpha.0)

cable_configure_compiler(NO_STACK_PROTECTION)
if(CABLE_COMPILER_GNULIKE)
# TODO: Resolve issues or remove "result optional storage" and enable -Wcast-align.
add_compile_options(-Wmissing-declarations)
cable_add_cxx_compiler_flag_if_supported(-Wfinal-dtor-non-final-class)
cable_add_cxx_compiler_flag_if_supported(-Wnewline-eof)
cable_add_cxx_compiler_flag_if_supported(-Wsuggest-destructor-override)
cable_add_cxx_compiler_flag_if_supported(-Wunreachable-code-break)
cable_add_cxx_compiler_flag_if_supported(-Wduplicated-cond)
cable_add_cxx_compiler_flag_if_supported(-Wduplicate-enum)
cable_add_cxx_compiler_flag_if_supported(-Wlogical-op)
endif()
if(CABLE_COMPILER_CLANG)
set(CMAKE_C_FLAGS_COVERAGE "-fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-instr-generate -fcoverage-mapping")
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ WARN_LOGFILE =
INPUT = \
include/evmc/ \
docs/ \
examples/example_vm/example_vm.c
examples/example_vm/example_vm.cpp
INPUT_ENCODING = UTF-8
FILE_PATTERNS =
RECURSIVE = NO
Expand Down
16 changes: 8 additions & 8 deletions bindings/go/evmc/evmc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2018-2020 The EVMC Authors.
// Licensed under the Apache License, Version 2.0.

//go:generate gcc -shared ../../../examples/example_vm/example_vm.c -I../../../include -o example_vm.so
//go:generate g++ -shared ../../../examples/example_vm/example_vm.cpp -I../../../include -o example_vm.so

package evmc

Expand Down Expand Up @@ -41,21 +41,21 @@ func TestLoadConfigure(t *testing.T) {
}
}

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

addr := Address{}
h := 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 bytes.Compare(output, []byte("")) != 0 {
t.Errorf("execution unexpected output: %x", output)
}
if gasLeft != 99 {
t.Error("execution gas left is incorrect")
if gasLeft != 999 {
t.Errorf("execution gas left is incorrect: %d", gasLeft)
}
if err != Failure {
t.Error("execution returned unexpected error")
if err != nil {
t.Errorf("execution returned unexpected error: %v", err)
}
}
32 changes: 20 additions & 12 deletions bindings/go/evmc/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,57 @@ func (host *testHostContext) Call(kind CallKind,
return output, gas, Address{}, nil
}

func TestGetTxContext(t *testing.T) {
func TestGetBlockNumberFromTxContext(t *testing.T) {
// Yul: mstore(0, number()) return(0, msize())
code := []byte("\x43\x60\x00\x52\x59\x60\x00\xf3")

vm, _ := Load(modulePath)
defer vm.Destroy()

host := &testHostContext{}
code := []byte("\x43\x60\x00\x52\x59\x60\x00\xf3")

addr := Address{}
h := Hash{}
output, gasLeft, err := vm.Execute(host, Byzantium, Call, false, 1, 100, addr, addr, nil, h, code, h)

if len(output) != 20 {
if len(output) != 32 {
t.Errorf("unexpected output size: %d", len(output))
}
if bytes.Compare(output[0:3], []byte("42\x00")) != 0 {
t.Errorf("execution unexpected output: %s", output)

// Should return value 42 (0x2a) as defined in GetTxContext().
expectedOutput := []byte("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2a")
if bytes.Compare(output, expectedOutput) != 0 {
t.Errorf("execution unexpected output: %x", output)
}
if gasLeft != 50 {
if gasLeft != 94 {
t.Errorf("execution gas left is incorrect: %d", gasLeft)
}
if err != nil {
t.Error("execution returned unexpected error")
t.Errorf("execution returned unexpected error: %v", err)
}
}

func TestCall(t *testing.T) {
// pseudo-Yul: call(0, 0, 0, 0, 0, 0, 34) return(0, msize())
code := []byte("\x60\x22\x60\x00\x80\x80\x80\x80\x80\xf1\x59\x60\x00\xf3")

vm, _ := Load(modulePath)
defer vm.Destroy()

host := &testHostContext{}
code := []byte("\x60\x00\x80\x80\x80\x80\x80\x80\xf1")

addr := Address{}
h := Hash{}
output, gasLeft, err := vm.Execute(host, Byzantium, Call, false, 1, 100, addr, addr, nil, h, code, h)

if len(output) != 34 {
t.Errorf("execution unexpected output length: %d", len(output))
}
if bytes.Compare(output, []byte("output from testHostContext.Call()")) != 0 {
t.Errorf("execution unexpected output: %s", output)
}
if gasLeft != 99 {
if gasLeft != 89 {
t.Errorf("execution gas left is incorrect: %d", gasLeft)
}
if err != nil {
t.Error("execution returned unexpected error")
t.Errorf("execution returned unexpected error: %v", err)
}
}
12 changes: 6 additions & 6 deletions bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void testExecute_returnAddress() throws Exception {
result.getInt(); // padding
long gasLeft = result.getLong();
assert (statusCode == 0);
assert (gasLeft == 0);
assert (gasLeft == 199994);
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ void testExecute_counter() throws Exception {
result.getInt(); // padding
long gasLeft = result.getLong();
assert (statusCode == 0);
assert (gasLeft == 0);
assert (gasLeft == 199994);
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ void testExecute_returnBlockNumber() throws Exception {
result.getInt(); // padding
long gasLeft = result.getLong();
assert (statusCode == 0);
assert (gasLeft == gas / 2);
assert (gasLeft == 199994);
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ void testExecute_saveReturnBlockNumber() throws Exception {
result.getInt(); // padding
long gasLeft = result.getLong();
assert (statusCode == 0);
assert (gasLeft == gas / 2);
assert (gasLeft == 199991);
}
}

Expand Down Expand Up @@ -216,7 +216,7 @@ void testExecute_makeCall() throws Exception {
result.getInt(); // padding
long gasLeft = result.getLong();
assert (statusCode == 0);
assert (gasLeft == 0); // gas - gas / 64);
assert (gasLeft == 199992);
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ void testExecute_EVMC_CREATE() throws Exception {
result.getInt(); // padding
long gasLeft = result.getLong();
assert (statusCode == 0);
assert (gasLeft == gas / 10);
assert (gasLeft == 199999);
}
}

Expand Down
4 changes: 0 additions & 4 deletions bindings/rust/evmc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use std::path::PathBuf;
fn gen_bindings() {
let bindings = bindgen::Builder::default()
.header("evmc.h")
// See https://github.com/rust-lang-nursery/rust-bindgen/issues/947
.trust_clang_mangling(false)
.generate_comments(true)
// https://github.com/rust-lang-nursery/rust-bindgen/issues/947#issuecomment-327100002
.layout_tests(false)
// do not generate an empty enum for EVMC_ABI_VERSION
.constified_enum("")
// generate Rust enums for each evmc enum
Expand Down
3 changes: 2 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ jobs:
command: |
# Convert to relative paths
sed -i 's|$(pwd)/||' ~/build/evmc.lcov
sudo pip3 install --upgrade --quiet --no-cache-dir codecov
codecov --file ~/build/evmc.lcov -X gcov
Expand Down Expand Up @@ -276,7 +277,7 @@ jobs:
go get -v $(grep -o 'github.com/ethereum/evmc/v.*' ../../go.mod)@$V
go mod tidy -v
go mod graph
gcc -shared -I../../include ../../examples/example_vm/example_vm.c -o example-vm.so
g++ -shared -I../../include ../../examples/example_vm/example_vm.cpp -o example-vm.so
go test -v
go mod graph
Expand Down
8 changes: 8 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ hunter_config(
SHA1 152b849610d91a9dfa1401293f43230c2e0c33f8
CMAKE_ARGS BUILD_GMOCK=OFF gtest_force_shared_crt=ON CMAKE_CXX_FLAGS=${gtest_cxx_flags}
)

hunter_config(
CLI11
VERSION 1.9.1
URL https://github.com/CLIUtils/CLI11/archive/v1.9.1.tar.gz
SHA1 8c32b19a5301726f1bf0b910a91a05d4291deadc
CMAKE_ARGS CLI11_BUILD_DOCS=OFF CLI11_BUILD_TESTS=OFF CLI11_BUILD_EXAMPLES=OFF CLI11_SINGLE_FILE=OFF
)
2 changes: 1 addition & 1 deletion docs/VM_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## An example

You can start with [the example implementation of EVMC VM interface in C](@ref example_vm.c).
You can start with [the example implementation of EVMC VM interface in C++](@ref example_vm.cpp).

## VM instance

Expand Down
5 changes: 3 additions & 2 deletions examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class ExampleHost : public evmc::Host

public:
ExampleHost() = default;
explicit ExampleHost(evmc_tx_context& _tx_context) noexcept : tx_context{_tx_context} {};
explicit ExampleHost(evmc_tx_context& _tx_context) noexcept : tx_context{_tx_context} {}
ExampleHost(evmc_tx_context& _tx_context, evmc::accounts& _accounts) noexcept
: accounts{_accounts}, tx_context{_tx_context} {};
: accounts{_accounts}, tx_context{_tx_context}
{}

bool account_exists(const evmc::address& addr) const noexcept final
{
Expand Down
8 changes: 5 additions & 3 deletions examples/example_vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# Copyright 2019-2020 The EVMC Authors.
# Licensed under the Apache License, Version 2.0.

add_library(example-vm SHARED example_vm.c example_vm.h)
add_library(example-vm SHARED example_vm.cpp example_vm.h)
add_library(evmc::example-vm ALIAS example-vm)
target_compile_features(example-vm PRIVATE cxx_std_11)
target_link_libraries(example-vm PRIVATE evmc::evmc)

add_library(example-vm-static STATIC example_vm.c example_vm.h)
add_library(example-vm-static STATIC example_vm.cpp example_vm.h)
add_library(evmc::example-vm-static ALIAS example-vm-static)
target_compile_features(example-vm-static PRIVATE cxx_std_11)
target_link_libraries(example-vm-static PRIVATE evmc::evmc)

set_source_files_properties(example_vm.c PROPERTIES
set_source_files_properties(example_vm.cpp PROPERTIES
COMPILE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}")

if(EVMC_INSTALL)
Expand Down
Loading

0 comments on commit 1122076

Please sign in to comment.