diff --git a/contract-testing/CHANGELOG.md b/contract-testing/CHANGELOG.md index 84e022fa..46364be3 100644 --- a/contract-testing/CHANGELOG.md +++ b/contract-testing/CHANGELOG.md @@ -5,6 +5,7 @@ - Integrate protocol version 7 cost semantics. - The `ContractInvokeSuccess` and `ContractInvokeError` have additional fields that record where parts of the energy was allocated during execution. +- Add support for loading the contract under test with the `module_load_output` function. The module path is exposed by `cargo-concordium` through the `CARGO_CONCORDIUM_TEST_MODULE_OUTPUT_PATH` environment variable. ## 4.2.0 diff --git a/contract-testing/src/constants.rs b/contract-testing/src/constants.rs index f6fb7cd8..568a1ba1 100644 --- a/contract-testing/src/constants.rs +++ b/contract-testing/src/constants.rs @@ -75,3 +75,8 @@ pub(crate) const INITIALIZE_CONTRACT_INSTANCE_CREATE_COST: Energy = Energy { pub(crate) const UPDATE_CONTRACT_INSTANCE_BASE_COST: Energy = Energy { energy: 300, }; + +/// The name of the environment variable that holds the path to the contract +/// module file. To load the module, use the +/// [`module_load_output`](crate::module_load_output) function. +pub const CONTRACT_MODULE_OUTPUT_PATH_ENV_VAR: &str = "CARGO_CONCORDIUM_TEST_MODULE_OUTPUT_PATH"; diff --git a/contract-testing/src/impls.rs b/contract-testing/src/impls.rs index 827c6d80..8b318895 100644 --- a/contract-testing/src/impls.rs +++ b/contract-testing/src/impls.rs @@ -2,6 +2,7 @@ use crate::{ constants, invocation::{ChangeSet, EntrypointInvocationHandler, TestConfigurationError}, types::*, + CONTRACT_MODULE_OUTPUT_PATH_ENV_VAR, }; use anyhow::anyhow; use concordium_rust_sdk::{ @@ -37,6 +38,7 @@ use sdk::{ }; use std::{ collections::{BTreeMap, BTreeSet}, + env, future::Future, path::Path, sync::Arc, @@ -2058,6 +2060,15 @@ pub fn module_load_v1(module_path: impl AsRef) -> Result Result { + let module_path = env::var(CONTRACT_MODULE_OUTPUT_PATH_ENV_VAR)?; + let module = module_load_v1(module_path)?; + Ok(module) +} + impl Signer { /// Create a signer which always signs with one key. pub const fn with_one_key() -> Self { diff --git a/contract-testing/src/lib.rs b/contract-testing/src/lib.rs index cd4d4fb1..4673c11a 100644 --- a/contract-testing/src/lib.rs +++ b/contract-testing/src/lib.rs @@ -83,13 +83,13 @@ //! - deployment.transaction_fee //! - initialization.transaction_fee //! - update.transaction_fee)); -//! //! ``` mod constants; mod impls; mod invocation; mod types; -pub use impls::{is_debug_enabled, module_load_v1, module_load_v1_raw}; +pub use constants::CONTRACT_MODULE_OUTPUT_PATH_ENV_VAR; +pub use impls::{is_debug_enabled, module_load_output, module_load_v1, module_load_v1_raw}; pub use types::*; // Re-export types. diff --git a/contract-testing/src/types.rs b/contract-testing/src/types.rs index 327cc7ce..1c2c7d34 100644 --- a/contract-testing/src/types.rs +++ b/contract-testing/src/types.rs @@ -27,6 +27,7 @@ use concordium_rust_sdk::{ }; use std::{ collections::{BTreeMap, BTreeSet}, + env, path::PathBuf, sync::Arc, }; @@ -325,6 +326,17 @@ pub enum ModuleLoadErrorKind { UnsupportedModuleVersion(WasmVersion), } +#[derive(Debug, Error)] +pub enum OutputModuleLoadError { + #[error( + "Module path environment variable was not set or invalid. Please ensure that \ + cargo-concordium is up-to-date. Details: {0}" + )] + MissingEnvVar(#[from] env::VarError), + #[error("{0}")] + ModuleLoad(#[from] ModuleLoadError), +} + /// The error produced when trying to read a smart contract /// module from a file. #[derive(Debug, Error)]