Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sc config update #2 #1239

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion contracts/benchmarks/str-repeat/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ main = "str-repeat"

# the only purpose of this config is to specify the allocator
[contracts.str-repeat]
add-unlabelled = true
allocator = "leaking"
2 changes: 1 addition & 1 deletion contracts/examples/multisig/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ main = "main"

[contracts.main]
name = "multisig"
add-unlabelled = true

[contracts.full]
name = "multisig-full"
Expand All @@ -13,4 +12,5 @@ add-labels = ["multisig-external-view"]
[contracts.view]
name = "multisig-view"
external-view = true
add-unlabelled = false
add-labels = ["multisig-external-view"]
2 changes: 1 addition & 1 deletion contracts/feature-tests/abi-tester/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ main = "main"

[contracts.main]
name = "abi-tester"
add-unlabelled = true

[contracts.external-view]
name = "abi-tester-ev"
external-view = true
add-unlabelled = false
add-labels = ["test-external-view"]
add-endpoints = ["payable_any_token", "label_a"] # labels can be bypassed, endpoints added directly
1 change: 0 additions & 1 deletion contracts/feature-tests/basic-features/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
main = "basic-features"

[contracts.basic-features]
add-unlabelled = true

[contracts.basic-features-storage-bytes]
add-endpoints = ["init", "load_bytes", "store_bytes"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ main = "main"

[contracts.main]
name = "forwarder-queue"
add-unlabelled = true

[contracts.promises]
name = "forwarder-queue-promises"
add-unlabelled = true
add-labels = ["promises-callback"]
features = ["promises"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ main = "forwarder-raw"

[contracts.forwarder-raw]
name = "forwarder-raw"
add-unlabelled = true

[contracts.forwarder-raw-init-async-call]
add-unlabelled = false
add-labels = ["init-async-call"]

[contracts.forwarder-raw-init-sync-call]
add-unlabelled = false
add-labels = ["init-sync-call"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ main = "proxy-test-first"

# the only purpose of this config is to specify the allocator
[contracts.proxy-test-first]
add-unlabelled = true
allocator = "static64k"
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ main = "lottery-erc20"

# the only purpose of this config is to specify the allocator
[contracts.lottery-erc20]
add-unlabelled = true
allocator = "static64k"
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ main = "multi-contract-main"
[contracts.multi-contract-main]
# main contract can have any id and any name
name = "multi-contract-features"
add-unlabelled = true

[contracts.multi-contract-features-view]
# name is optional, if missing this ^^^ id will be used
external-view = true
add-unlabelled = false
add-labels = ["mcs-external-view"]

[contracts.multi-contract-example-feature]
add-unlabelled = true
add-unlabelled = true # optional here, since the default is true
features = ["example_feature"]

[contracts.multi-contract-alt-impl]
add-unlabelled = false
add-labels = ["alt-impl"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ main = "main"

[contracts.main]
name = "panic-message-features"
add-unlabelled = true
panic-message = true
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ main = "rust-testing-framework-tester"

# the only purpose of this config is to specify the allocator
[contracts.rust-testing-framework-tester]
add-unlabelled = true
allocator = "static64k"
2 changes: 1 addition & 1 deletion contracts/feature-tests/use-module/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ main = "main"

[contracts.main]
name = "use-module"
add-unlabelled = true

[contracts.view]
name = "use-module-view"
external-view = true
add-unlabelled = false
add-labels = ["module-external-view"]
27 changes: 21 additions & 6 deletions framework/meta/src/cmd/contract/output_contract/oc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use super::{
};

/// Temporary structure, to help create instances of `OutputContract`. Not publicly exposed.
#[derive(Default)]
struct OutputContractBuilder {
pub contract_id: String,
pub explicit_name: String,
Expand All @@ -25,6 +24,21 @@ struct OutputContractBuilder {
pub settings: OutputContractSettings,
}

impl Default for OutputContractBuilder {
fn default() -> Self {
Self {
contract_id: Default::default(),
explicit_name: Default::default(),
add_unlabelled: true,
add_labels: Default::default(),
add_endpoints: Default::default(),
collected_endpoints: Default::default(),
endpoint_names: Default::default(),
settings: Default::default(),
}
}
}

impl OutputContractBuilder {
fn new(id: String) -> Self {
OutputContractBuilder {
Expand All @@ -43,25 +57,26 @@ impl OutputContractBuilder {
multiversx_sc::external_view_contract::external_view_contract_constructor_abi(),
)
}
let default = OutputContractBuilder::default();
(
contract_id.clone(),
OutputContractBuilder {
contract_id: contract_id.clone(),
explicit_name: cms.name.clone().unwrap_or_default(),
add_unlabelled: cms.add_unlabelled.unwrap_or_default(),
explicit_name: cms.name.clone().unwrap_or(default.explicit_name),
add_unlabelled: cms.add_unlabelled.unwrap_or(default.add_unlabelled),
add_labels: cms.add_labels.iter().cloned().collect(),
add_endpoints: cms.add_endpoints.iter().cloned().collect(),
collected_endpoints,
settings: OutputContractSettings {
external_view: cms.external_view.unwrap_or_default(),
panic_message: cms.panic_message.unwrap_or_default(),
external_view: cms.external_view.unwrap_or(default.settings.external_view),
panic_message: cms.panic_message.unwrap_or(default.settings.panic_message),
check_ei: parse_check_ei(&cms.ei),
allocator: parse_allocator(&cms.allocator),
stack_size: parse_stack_size(&cms.stack_size),
features: cms.features.clone(),
kill_legacy_callback: cms.kill_legacy_callback,
},
..Default::default()
..default
},
)
}
Expand Down
3 changes: 3 additions & 0 deletions framework/meta/src/cmd/contract/output_contract/oc_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ impl std::fmt::Debug for OutputContract {
.field("main", &self.main)
.field("config_name", &self.contract_id)
.field("public_name", &self.contract_name)
.field("num-constructors", &self.abi.constructors.len())
.field("num-endpoints", &self.abi.endpoints.len())
.field("settings", &self.settings)
.finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use oc_parse_stack_size::*;
use crate::ei::EIVersion;

/// Collection of flags, specified in the multicontract config.
#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct OutputContractSettings {
/// External view contracts are just readers of data from another contract.
pub external_view: bool,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Default, Clone, PartialEq, Eq)]
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub enum ContractAllocator {
/// No allocation is allowed. Any attempt causes `signalError` to be thrown.
#[default]
Expand Down
2 changes: 1 addition & 1 deletion framework/meta/src/ei/ei_version.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// The version of the SC environment interface (EI), it deals with the VM hooks available at a certain point in time.
///
/// It is not tied to the version of the VM, hence the different numbering.
#[derive(Clone, Copy, Default, PartialEq, Eq)]
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
pub enum EIVersion {
/// This is not necessarily the first version of the EI,
/// but rather the oldest version when we started keeping track of the EI.
Expand Down
3 changes: 2 additions & 1 deletion framework/meta/tests/multi_contract_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ fn get_serialized_toml() -> MultiContractConfigSerde {

[contracts.secondary-contract]
name = "contract2-name"
add-labels = ["label1", "label2"]
external-view = true
add-unlabelled = false
add-labels = ["label1", "label2"]

[labels-for-contracts]
default = ["main-contract"]
Expand Down
Loading