Skip to content

Commit

Permalink
runtime-sdk/modules/evm: Add subcall precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jul 18, 2023
1 parent 563a9f4 commit 1f27002
Show file tree
Hide file tree
Showing 29 changed files with 1,681 additions and 369 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions client-sdk/go/modules/evm/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package evm

import (
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
)

// NewAddressFromEth creates a new address from an Eth-compatible address.
func NewAddressFromEth(ethAddress []byte) types.Address {
return types.NewAddressRaw(types.AddressV0Secp256k1EthContext, ethAddress)
}
20 changes: 20 additions & 0 deletions client-sdk/go/modules/evm/address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package evm

import (
"encoding/hex"
"testing"

"github.com/stretchr/testify/require"
)

func TestNewAddressFromEth(t *testing.T) {
ethAddr, err := hex.DecodeString("Dce075E1C39b1ae0b75D554558b6451A226ffe00")
require.NoError(t, err, "hex.DecodeString")
addr := NewAddressFromEth(ethAddr)
require.Equal(t, addr.String(), "oasis1qrk58a6j2qn065m6p06jgjyt032f7qucy5wqeqpt")

ethAddr, err = hex.DecodeString("709EEbd979328A2B3605A160915DEB26E186abF8")
require.NoError(t, err, "hex.DecodeString")
addr = NewAddressFromEth(ethAddr)
require.Equal(t, addr.String(), "oasis1qqcd0qyda6gtwdrfcqawv3s8cr2kupzw9v967au6")
}
9 changes: 9 additions & 0 deletions runtime-sdk/modules/contracts/src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ fn process_subcalls<Cfg: Config, C: TxContext>(
// preconfigured the amount of available gas.
<C::Runtime as Runtime>::Core::use_tx_gas(ctx, result.gas_used)?;

// Forward any emitted event tags.
ctx.emit_etags(result.state.events);

// Forward any emitted runtime messages.
for (msg, hook) in result.state.messages {
// This should never fail as child context has the right limits configured.
ctx.emit_message(msg, hook)?;
}

// Process replies based on filtering criteria.
let result = result.call_result;
match (reply, result.is_success()) {
Expand Down
9 changes: 6 additions & 3 deletions runtime-sdk/modules/contracts/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ fn test_hello_contract_call() {
"there should only be one denomination"
);

let (etags, messages) = tx_ctx.commit();
let tags = etags.into_tags();
let state = tx_ctx.commit();
let tags = state.events.into_tags();
// Make sure no runtime messages got emitted.
assert!(messages.is_empty(), "no runtime messages should be emitted");
assert!(
state.messages.is_empty(),
"no runtime messages should be emitted"
);
// Make sure a contract event was emitted and is properly formatted.
assert_eq!(tags.len(), 2, "two events should have been emitted");
assert_eq!(tags[0].key, b"accounts\x00\x00\x00\x01"); // accounts.Transfer (code = 1) event
Expand Down
1 change: 1 addition & 0 deletions runtime-sdk/modules/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ uint = "0.9.1"
criterion = "0.5.1"
oasis-runtime-sdk = { path = "../..", features = ["test"] }
rand = "0.7.3"
ethabi = { version = "18.0.0", default-features = false, features = ["std", "full-serde"]}

[[bench]]
name = "criterion_benchmark"
Expand Down
Loading

0 comments on commit 1f27002

Please sign in to comment.