Skip to content

Commit

Permalink
Merge pull request #1509 from oasisprotocol/kostko/fix/evm-incorrect-…
Browse files Browse the repository at this point in the history
…trim-output
  • Loading branch information
kostko authored Sep 24, 2023
2 parents e57d909 + 320223f commit c35d047
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion runtime-sdk/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<Cfg: Config> Module<Cfg> {
) -> (evm::ExitReason, Vec<u8>),
C: TxContext,
{
let is_query = ctx.is_check_only();
let is_query = ctx.is_check_only() || ctx.is_simulation();
let cfg = Cfg::evm_config(estimate_gas);
let gas_limit: u64 = <C::Runtime as Runtime>::Core::remaining_tx_gas(ctx);
let gas_price: primitive_types::U256 = ctx.tx_auth_info().fee.gas_price().into();
Expand Down
21 changes: 20 additions & 1 deletion runtime-sdk/modules/evm/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use oasis_runtime_sdk::{
use crate::{
derive_caller,
mock::{decode_reverted, decode_reverted_raw, load_contract_bytecode, EvmSigner, QueryOptions},
state,
types::{self, H160},
Config, Genesis, Module as EVMModule,
};
Expand Down Expand Up @@ -1074,4 +1073,24 @@ fn test_return_value_limits() {
} else {
panic!("call should revert");
}

// Make sure that in query context, the return value is not trimmed.
let mut ctx =
mock.create_ctx_for_runtime::<EVMRuntime<EVMConfig>>(context::Mode::CheckTx, true);

let result = signer
.query_evm_opts(
&mut ctx,
contract_address,
"testSuccess",
&[],
&[],
Default::default(),
)
.expect("query should succeed");

assert_eq!(result.len(), 1120, "result should not be trimmed");
// Actual payload is ABI-encoded so the raw result starts at offset 64.
assert_eq!(result[64], 0xFF, "result should be correct");
assert_eq!(result[1023], 0x42, "result should be correct");
}

0 comments on commit c35d047

Please sign in to comment.