Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 10 additions & 0 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions executor/wasm/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use casper_execution_engine::engine_state::{EngineConfig, ExecutionEngineV1};
use casper_executor_wasm_interface::{
executor::{
ExecuteRequest, ExecuteRequestBuilder, ExecuteWithProviderError, ExecuteWithProviderResult,
Executor,
},
install::{
InstallContractError, InstallContractRequest, InstallContractRequestBuilder,
InstallContractResult, InstallContractWithProviderResult,
InstallContractWithProviderResult,
},
};
use casper_storage::{
Expand Down
162 changes: 162 additions & 0 deletions executor/wasm/tests/collections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use std::{env, path::PathBuf, sync::Arc};

use casper_execution_engine::engine_state::{EngineConfig, ExecutionEngineV1};
use casper_executor_wasm::{
testing::{
base_execute_builder, base_install_request_builder, make_address_generator,
make_global_state_with_genesis, read_wasm, run_create_contract, run_wasm_session,
},
ExecutorConfigBuilder, ExecutorKind, ExecutorV2,
};

use casper_executor_wasm::{chainspec_config, chainspec_config::ChainspecConfig};
use casper_executor_wasm_interface::executor::ExecutionKind;
use casper_storage::global_state::state::CommitProvider;
use once_cell::sync::Lazy;

/// Symlink to chainspec.
pub static CHAINSPEC_SYMLINK: Lazy<PathBuf> = Lazy::new(|| {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../resources/local/")
.join(chainspec_config::CHAINSPEC_NAME)
});

#[test]
fn should_run_test_suite() {
let chainspec_config = ChainspecConfig::from_chainspec_path(&*CHAINSPEC_SYMLINK)
.expect("must get chainspec config");
let storage_costs = chainspec_config.storage_costs;
let mint_costs = chainspec_config.system_costs_config.mint_costs().clone();
let auction_costs = chainspec_config.system_costs_config.auction_costs().clone();
let v1_config = EngineConfig::from(chainspec_config.clone());
let execution_engine_v1 = ExecutionEngineV1::new(v1_config);
let wasm_v2_config = *chainspec_config.wasm_config.v2();
let memory_limit = wasm_v2_config.max_memory();
let message_limits = chainspec_config.wasm_config.messages_limits();
let executor_config = ExecutorConfigBuilder::default()
.with_memory_limit(memory_limit)
.with_executor_kind(ExecutorKind::Compiled)
.with_wasm_config(wasm_v2_config)
.with_storage_costs(storage_costs)
.with_mint_costs(mint_costs)
.with_auction_costs(auction_costs)
.with_baseline_motes_amount(chainspec_config.core_config.baseline_motes_amount)
.with_message_limits(message_limits)
.build()
.expect("Should build");
let mut executor = ExecutorV2::new(executor_config, execution_engine_v1);

let (global_state, mut state_root_hash, _tempdir) = make_global_state_with_genesis();

let address_generator = make_address_generator();

let vm2_collections_test = read_wasm("vm2_collections_test.wasm");

let install_request = base_install_request_builder(&chainspec_config)
.with_wasm_bytes(vm2_collections_test.wasm)
.with_bundle_data(vm2_collections_test.meta.expect("should have bundle data"))
.with_shared_address_generator(Arc::clone(&address_generator))
.with_transferred_value(0)
.with_entry_point("new".to_string())
.build()
.expect("should build");

let create_result = run_create_contract(
&mut executor,
&global_state,
state_root_hash,
install_request,
);

let contract_address = *create_result.smart_contract_addr();
state_root_hash = global_state
.commit_effects(state_root_hash, create_result.effects().clone())
.expect("Should commit");

let run_method = base_execute_builder(&chainspec_config)
.with_shared_address_generator(Arc::clone(&address_generator))
.with_transferred_value(0)
.with_execution_kind(ExecutionKind::Stored {
address: contract_address,
entry_point: "assertions".to_owned(),
})
.build()
.expect("should build");
let res = run_wasm_session(&mut executor, &global_state, state_root_hash, run_method);
assert!(res.is_ok());
if let Ok(res) = res {
assert!(res.host_error.is_none());
}
}

#[test]
fn inserting_into_non_existing_vec_index_fails() {
let chainspec_config = ChainspecConfig::from_chainspec_path(&*CHAINSPEC_SYMLINK)
.expect("must get chainspec config");
let storage_costs = chainspec_config.storage_costs;
let mint_costs = chainspec_config.system_costs_config.mint_costs().clone();
let auction_costs = chainspec_config.system_costs_config.auction_costs().clone();
let v1_config = EngineConfig::from(chainspec_config.clone());
let execution_engine_v1 = ExecutionEngineV1::new(v1_config);
let wasm_v2_config = *chainspec_config.wasm_config.v2();
let memory_limit = wasm_v2_config.max_memory();
let message_limits = chainspec_config.wasm_config.messages_limits();
let executor_config = ExecutorConfigBuilder::default()
.with_memory_limit(memory_limit)
.with_executor_kind(ExecutorKind::Compiled)
.with_wasm_config(wasm_v2_config)
.with_storage_costs(storage_costs)
.with_mint_costs(mint_costs)
.with_auction_costs(auction_costs)
.with_baseline_motes_amount(chainspec_config.core_config.baseline_motes_amount)
.with_message_limits(message_limits)
.build()
.expect("Should build");
let mut executor = ExecutorV2::new(executor_config, execution_engine_v1);

let (global_state, mut state_root_hash, _tempdir) = make_global_state_with_genesis();

let address_generator = make_address_generator();

let vm2_collections_test = read_wasm("vm2_collections_test.wasm");

let install_request = base_install_request_builder(&chainspec_config)
.with_wasm_bytes(vm2_collections_test.wasm)
.with_bundle_data(vm2_collections_test.meta.expect("should have bundle data"))
.with_shared_address_generator(Arc::clone(&address_generator))
.with_transferred_value(0)
.with_entry_point("new".to_string())
.build()
.expect("should build");

let create_result = run_create_contract(
&mut executor,
&global_state,
state_root_hash,
install_request,
);

let contract_address = *create_result.smart_contract_addr();
state_root_hash = global_state
.commit_effects(state_root_hash, create_result.effects().clone())
.expect("Should commit");

let run_method = base_execute_builder(&chainspec_config)
.with_shared_address_generator(Arc::clone(&address_generator))
.with_transferred_value(0)
.with_execution_kind(ExecutionKind::Stored {
address: contract_address,
entry_point: "test_remove_invalid_index_prepare".to_owned(),
})
.build()
.expect("should build");
let res = run_wasm_session(&mut executor, &global_state, state_root_hash, run_method);
assert!(res.is_ok());

if let Ok(res) = res {
assert!(matches!(
res.host_error,
Some(casper_executor_wasm_common::error::CallError::NotCallable)
));
}
}
2 changes: 2 additions & 0 deletions executor/wasm_host/src/host/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ pub(crate) fn host_env_balance<S: GlobalStateReader + 'static>(
))
}

/// Please note that the returning EnvInfo structure
/// cannot hold any data that can change in course of one wasm execution.
pub(crate) fn host_env_info<S: GlobalStateReader + 'static>(
caller: &mut impl Caller<Context = Context<S>>,
) -> VMResult<(Option<Bytes>, u32)> {
Expand Down
Loading