Skip to content

Commit

Permalink
multi-contract conditional compilation via cargo features
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Mar 16, 2023
1 parent eb656dd commit bf6dc3d
Show file tree
Hide file tree
Showing 17 changed files with 464 additions and 15 deletions.
3 changes: 3 additions & 0 deletions contracts/feature-tests/multi-contract-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
[lib]
path = "src/multi_contract_features.rs"

[features]
example_feature = []

[dependencies.multiversx-sc]
version = "0.39.5"
path = "../../../framework/base"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ add-unlabelled = true
# name is optional, if missing this ^^^ id will be used
external-view = true
add-labels = ["mcs-external-view"]

[contracts.multi-contract-example-feature]
add-unlabelled = true
features = ["example_feature"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"steps": [
{
"step": "setState",
"accounts": {
"sc:mcf": {
"code": "file:../output/multi-contract-features.wasm"
},
"sc:mcf-example-feature": {
"code": "file:../output/multi-contract-example-feature.wasm"
},
"address:owner": {}
}
},
{
"step": "scQuery",
"id": "example_feature_message",
"tx": {
"to": "sc:mcf-example-feature",
"function": "example_feature_message"
},
"expect": {
"out": [
"str:example-feature on"
]
}
},
{
"step": "scQuery",
"id": "example_feature_message",
"tx": {
"to": "sc:mcf",
"function": "example_feature_message"
},
"expect": {
"out": [
"str:example-feature off"
]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ pub trait MultiContractFeatures {
fn sample_value_external_set(&self, sample_value: BigUint) {
self.sample_value().set(sample_value);
}

#[view]
fn example_feature_message(&self) -> &'static str {
example_feature_message()
}
}

#[cfg(feature = "example_feature")]
fn example_feature_message() -> &'static str {
"example-feature on"
}

#[cfg(not(feature = "example_feature"))]
fn example_feature_message() -> &'static str {
"example-feature off"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#[test]
fn external_pure_go() {
multiversx_sc_scenario::run_go("scenarios/external-pure.scen.json");
fn mcf_example_feature_go() {
multiversx_sc_scenario::run_go("scenarios/mcf-example-feature.scen.json");
}

#[test]
fn external_get_go() {
multiversx_sc_scenario::run_go("scenarios/external-get.scen.json");
fn mcf_external_pure_go() {
multiversx_sc_scenario::run_go("scenarios/mcf-external-pure.scen.json");
}

#[test]
fn mcf_external_get_go() {
multiversx_sc_scenario::run_go("scenarios/mcf-external-get.scen.json");
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ fn world() -> ScenarioWorld {
}

#[test]
fn external_pure_rs() {
multiversx_sc_scenario::run_rs("scenarios/external-pure.scen.json", world());
#[ignore] // not supported
fn mcf_example_feature_rs() {
multiversx_sc_scenario::run_rs("scenarios/mcf-example-feature.scen.json", world());
}

#[test]
fn external_get_rs() {
multiversx_sc_scenario::run_rs("scenarios/external-get.scen.json", world());
fn mcf_external_pure_rs() {
multiversx_sc_scenario::run_rs("scenarios/mcf-external-pure.scen.json", world());
}

#[test]
fn mcf_external_get_rs() {
multiversx_sc_scenario::run_rs("scenarios/mcf-external-get.scen.json", world());
}

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

Loading

0 comments on commit bf6dc3d

Please sign in to comment.