mod context;
mod external;
mod mocked_blockchain;
mod receipt;
pub(crate) use self::external::SdkExternal;
pub use self::mocked_blockchain::MockedBlockchain;
pub use self::receipt::{Receipt, VmAction};
pub use context::VmContextBuilder;
use core::cell::RefCell;
pub use near_primitives_core::runtime::fees::RuntimeFeesConfig;
pub use near_vm_logic::{VMConfig, VMContext};
thread_local! {
static BLOCKCHAIN_INTERFACE: RefCell<MockedBlockchain>
= RefCell::new(MockedBlockchain::default());
}
#[macro_export]
macro_rules! testing_env {
($context:expr, $config:expr, $fee_config:expr, $validators:expr, $promise_results:expr $(,)?) => {
$crate::mock::set_mocked_blockchain($crate::mock::MockedBlockchain::new(
$context,
$config,
$fee_config,
$promise_results,
$crate::mock::with_mocked_blockchain(|b| ::core::mem::take(b.storage_mut())),
$validators,
None,
));
};
($context:expr, $config:expr, $fee_config:expr, $validators:expr $(,)?) => {
testing_env!(
$context,
$config,
$fee_config,
$validators,
Default::default()
);
};
($context:expr, $config:expr, $fee_config:expr $(,)?) => {
testing_env!($context, $config, $fee_config, Default::default());
};
($context:expr) => {
testing_env!($context, Default::default(), Default::default());
};
}
pub fn set_mocked_blockchain(blockchain_interface: MockedBlockchain) {
crate::mock::with_mocked_blockchain(|b| {
*b = blockchain_interface;
})
}
pub fn new_context(context: VMContext) {
with_mocked_blockchain(|b| {
let storage = core::mem::take(b.storage_mut());
*b = MockedBlockchain::new(
context,
Default::default(),
Default::default(),
vec![],
storage,
Default::default(),
None,
)
});
}
pub fn with_mocked_blockchain<F, R>(f: F) -> R
where
F: FnOnce(&mut MockedBlockchain) -> R,
{
BLOCKCHAIN_INTERFACE.with(|b| f(&mut b.borrow_mut()))
}