Skip to content

Commit

Permalink
fix(gtest): Fix execution model for mock wasms in gtest (#4220)
Browse files Browse the repository at this point in the history
  • Loading branch information
techraed authored Sep 4, 2024
1 parent 007cce6 commit d8e0e5b
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 191 deletions.
1 change: 1 addition & 0 deletions core-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ default = ["std"]
std = ["gear-core-backend/std"]
strict = []
mock = []
gtest = []
8 changes: 8 additions & 0 deletions core-processor/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ pub struct ContextChargedForProgram {
pub(crate) gas_allowance_counter: GasAllowanceCounter,
}

impl ContextChargedForProgram {
/// Unwraps into inner data.
#[cfg(feature = "gtest")]
pub fn into_inner(self) -> (IncomingDispatch, ProgramId, GasCounter) {
(self.dispatch, self.destination_id, self.gas_counter)
}
}

pub struct ContextChargedForAllocations(pub(crate) ContextChargedForProgram);

pub(crate) struct ContextData {
Expand Down
4 changes: 2 additions & 2 deletions core-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ mod precharge;
mod processing;

pub use context::{
ContextChargedForCode, ContextChargedForInstrumentation, ProcessExecutionContext,
SystemReservationContext,
ContextChargedForCode, ContextChargedForInstrumentation, ContextChargedForProgram,
ProcessExecutionContext, SystemReservationContext,
};
pub use ext::{
AllocExtError, Ext, FallibleExtError, ProcessorContext, ProcessorExternalities,
Expand Down
2 changes: 1 addition & 1 deletion gtest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rust-version.workspace = true
gear-core.workspace = true
gear-common = { workspace = true, features = ["std"] }
gear-core-errors.workspace = true
core-processor = { workspace = true, features = ["std"] }
core-processor = { workspace = true, features = ["std", "gtest"] }
gear-lazy-pages.workspace = true
gear-lazy-pages-common.workspace = true
gear-lazy-pages-native-interface.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions gtest/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use crate::{
use core_processor::{
common::*,
configs::{BlockConfig, TESTS_MAX_PAGES_NUMBER},
ContextChargedForInstrumentation, Ext,
ContextChargedForInstrumentation, ContextChargedForProgram, Ext,
};
use gear_common::{
auxiliary::{
Expand All @@ -70,7 +70,6 @@ use gear_core::{
},
pages::{num_traits::Zero, GearPage},
};
use gear_core_errors::{ErrorReplyReason, SimpleExecutionError};
use gear_lazy_pages_native_interface::LazyPagesNative;
use hold_bound::HoldBoundBuilder;
use rand::{rngs::StdRng, RngCore, SeedableRng};
Expand Down
Loading

0 comments on commit d8e0e5b

Please sign in to comment.