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

Removed the need to use Self::Api #1252

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
544 changes: 337 additions & 207 deletions Cargo.lock
100755 → 100644

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [

"framework/base",
"framework/derive",
"framework/imports",
"framework/meta",
"framework/scenario",
"framework/snippets",
Expand Down
10 changes: 9 additions & 1 deletion contracts/benchmarks/large-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ publish = false
[lib]
path = "src/large_storage.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../framework/scenario"
optional = true

[dev-dependencies.large-storage]
path = "."
features = ["debug"]
2 changes: 1 addition & 1 deletion contracts/benchmarks/large-storage/src/large_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ pub trait LargeStorageBenchmark {

#[view(savedStructure)]
#[storage_mapper("savedStructure")]
fn structure(&self) -> SingleValueMapper<Structure<Self::Api>>;
fn structure(&self) -> SingleValueMapper<Structure<CurrentApi>>;
}
10 changes: 9 additions & 1 deletion contracts/benchmarks/mappers/benchmark-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ publish = false
[lib]
path = "src/lib.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../../framework/scenario"
optional = true

[dev-dependencies.benchmark-common]
path = "."
features = ["debug"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub trait BenchmarkCommon {

fn use_index_struct(
&self,
base: &ExampleStruct<Self::Api>,
base: &ExampleStruct<CurrentApi>,
index: usize,
) -> ExampleStruct<Self::Api> {
) -> ExampleStruct<CurrentApi> {
let mut example_struct = base.clone();
example_struct.first_token_nonce = index as u64;
example_struct.second_token_nonce = index as u64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ where
{
pub first_token_id: TokenIdentifier<M>,
pub first_token_nonce: Nonce,
pub first_token_amount: BigUint<M>,
pub first_token_amount: BaseBigUint<M>,
pub second_token_id: TokenIdentifier<M>,
pub second_token_nonce: Nonce,
pub second_token_amount: BigUint<M>,
pub second_token_amount: BaseBigUint<M>,
}

impl<M> PartialEq for ExampleStruct<M>
Expand Down
11 changes: 9 additions & 2 deletions contracts/benchmarks/mappers/linked-list-repeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ publish = false
[lib]
path = "src/linked_list_repeat.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.benchmark-common]
path = "../benchmark-common"


[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../../framework/scenario"
optional = true

[dev-dependencies.linked-list-repeat]
path = "."
features = ["debug"]
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ pub trait LinkedListRepeat: benchmark_common::BenchmarkCommon {
fn bench(&self) -> LinkedListMapper<ManagedBuffer>;

#[endpoint]
fn add_struct(&self, num_repeats: usize, value: ExampleStruct<Self::Api>) {
fn add_struct(&self, num_repeats: usize, value: ExampleStruct<CurrentApi>) {
let mut bench = self.bench_struct();
for i in 0..num_repeats {
bench.push_back(self.use_index_struct(&value, i));
}
}

#[endpoint]
fn count_struct(&self, value: ExampleStruct<Self::Api>) -> usize {
fn count_struct(&self, value: ExampleStruct<CurrentApi>) -> usize {
self.bench_struct()
.iter()
.filter(|item| *item.get_value_as_ref() == value)
Expand All @@ -63,5 +63,5 @@ pub trait LinkedListRepeat: benchmark_common::BenchmarkCommon {

#[view]
#[storage_mapper("bench_struct")]
fn bench_struct(&self) -> LinkedListMapper<ExampleStruct<Self::Api>>;
fn bench_struct(&self) -> LinkedListMapper<ExampleStruct<CurrentApi>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn setup() -> ScenarioWorld {
#[test]
fn linked_list_repeat_blackbox_raw() {
let mut world = setup();
let mut contract = ContractInfo::<linked_list_repeat::Proxy<StaticApi>>::new("sc:llr");
let mut contract = ContractInfo::<StaticApi, linked_list_repeat::Proxy<StaticApi>>::new("sc:llr");

let num_repeats = 5usize;

Expand Down Expand Up @@ -72,15 +72,15 @@ fn linked_list_repeat_blackbox_raw() {
#[test]
fn linked_list_repeat_struct_blackbox_raw() {
let mut world = setup();
let mut contract = ContractInfo::<linked_list_repeat::Proxy<StaticApi>>::new("sc:llr");
let mut contract = ContractInfo::<StaticApi, linked_list_repeat::Proxy<StaticApi>>::new("sc:llr");

let mut example = ExampleStruct {
first_token_id: TokenIdentifier::from_esdt_bytes(b"str:TESTTOK-1234"),
first_token_nonce: 0,
first_token_amount: multiversx_sc::types::BigUint::from(1_000_000_000_000_000_000u64),
first_token_amount: multiversx_sc::types::BaseBigUint::from(1_000_000_000_000_000_000u64),
second_token_id: TokenIdentifier::from_esdt_bytes(b"str:TESTTOK-2345"),
second_token_nonce: 0,
second_token_amount: multiversx_sc::types::BigUint::from(1_000_000_000_000_000_000u64),
second_token_amount: multiversx_sc::types::BaseBigUint::from(1_000_000_000_000_000_000u64),
};
world.sc_call(
ScCallStep::new()
Expand Down
11 changes: 9 additions & 2 deletions contracts/benchmarks/mappers/map-repeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ publish = false
[lib]
path = "src/map_repeat.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.benchmark-common]
path = "../benchmark-common"


[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../../framework/scenario"
optional = true

[dev-dependencies.map-repeat]
path = "."
features = ["debug"]
10 changes: 5 additions & 5 deletions contracts/benchmarks/mappers/map-repeat/src/map_repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub trait MapRepeat: benchmark_common::BenchmarkCommon {
fn add_struct(
&self,
num_repeats: usize,
key: ExampleStruct<Self::Api>,
value: ExampleStruct<Self::Api>,
key: ExampleStruct<CurrentApi>,
value: ExampleStruct<CurrentApi>,
) {
let mut bench = self.bench_struct();
for i in 0..num_repeats {
Expand All @@ -48,19 +48,19 @@ pub trait MapRepeat: benchmark_common::BenchmarkCommon {
}

#[endpoint]
fn count_struct(&self, value: ExampleStruct<Self::Api>) -> usize {
fn count_struct(&self, value: ExampleStruct<CurrentApi>) -> usize {
let bench = self.bench_struct();
bench.iter().filter(|(_, v)| *v == value).count()
}

#[endpoint]
fn remove_struct(&self, num_repeats: usize, key: ExampleStruct<Self::Api>) {
fn remove_struct(&self, num_repeats: usize, key: ExampleStruct<CurrentApi>) {
let mut bench = self.bench_struct();
for i in 1..=num_repeats {
bench.remove(&self.use_index_struct(&key, i));
}
}

#[storage_mapper("bench_struct")]
fn bench_struct(&self) -> MapMapper<ExampleStruct<Self::Api>, ExampleStruct<Self::Api>>;
fn bench_struct(&self) -> MapMapper<ExampleStruct<CurrentApi>, ExampleStruct<CurrentApi>>;
}
11 changes: 9 additions & 2 deletions contracts/benchmarks/mappers/queue-repeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ publish = false
[lib]
path = "src/queue_repeat.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.benchmark-common]
path = "../benchmark-common"


[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../../framework/scenario"
optional = true

[dev-dependencies.queue-repeat]
path = "."
features = ["debug"]
6 changes: 3 additions & 3 deletions contracts/benchmarks/mappers/queue-repeat/src/queue_repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ pub trait QueueRepeat: benchmark_common::BenchmarkCommon {
fn bench(&self) -> QueueMapper<ManagedBuffer>;

#[endpoint]
fn add_struct(&self, num_repeats: usize, value: ExampleStruct<Self::Api>) {
fn add_struct(&self, num_repeats: usize, value: ExampleStruct<CurrentApi>) {
let mut bench = self.bench_struct();
for i in 0..num_repeats {
bench.push_back(self.use_index_struct(&value, i));
}
}

#[endpoint]
fn count_struct(&self, value: ExampleStruct<Self::Api>) -> usize {
fn count_struct(&self, value: ExampleStruct<CurrentApi>) -> usize {
self.bench_struct().iter().filter(|v| *v == value).count()
}

Expand All @@ -57,5 +57,5 @@ pub trait QueueRepeat: benchmark_common::BenchmarkCommon {

#[view]
#[storage_mapper("bench_struct")]
fn bench_struct(&self) -> QueueMapper<ExampleStruct<Self::Api>>;
fn bench_struct(&self) -> QueueMapper<ExampleStruct<CurrentApi>>;
}
11 changes: 9 additions & 2 deletions contracts/benchmarks/mappers/set-repeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ publish = false
[lib]
path = "src/set_repeat.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.benchmark-common]
path = "../benchmark-common"


[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../../framework/scenario"
optional = true

[dev-dependencies.set-repeat]
path = "."
features = ["debug"]
8 changes: 4 additions & 4 deletions contracts/benchmarks/mappers/set-repeat/src/set_repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ pub trait SetRepeat: benchmark_common::BenchmarkCommon {
fn bench(&self) -> SetMapper<ManagedBuffer>;

#[endpoint]
fn add_struct(&self, num_repeats: usize, value: ExampleStruct<Self::Api>) {
fn add_struct(&self, num_repeats: usize, value: ExampleStruct<CurrentApi>) {
let mut bench = self.bench_struct();
for i in 0..num_repeats {
bench.insert(self.use_index_struct(&value, i));
}
}

#[endpoint]
fn count_struct(&self, value: ExampleStruct<Self::Api>) -> usize {
fn count_struct(&self, value: ExampleStruct<CurrentApi>) -> usize {
self.bench_struct().iter().filter(|v| *v == value).count()
}

#[endpoint]
fn remove_struct(&self, num_repeats: usize, value: ExampleStruct<Self::Api>) {
fn remove_struct(&self, num_repeats: usize, value: ExampleStruct<CurrentApi>) {
let mut bench = self.bench_struct();
for i in 1..=num_repeats {
bench.remove(&self.use_index_struct(&value, i));
Expand All @@ -57,5 +57,5 @@ pub trait SetRepeat: benchmark_common::BenchmarkCommon {

#[view]
#[storage_mapper("bench_struct")]
fn bench_struct(&self) -> SetMapper<ExampleStruct<Self::Api>>;
fn bench_struct(&self) -> SetMapper<ExampleStruct<CurrentApi>>;
}
11 changes: 9 additions & 2 deletions contracts/benchmarks/mappers/single-value-repeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ publish = false
[lib]
path = "src/single_value_repeat.rs"

[features]
debug = ["dep:multiversx-sc-scenario"]

[dependencies.benchmark-common]
path = "../benchmark-common"


[dependencies.multiversx-sc]
version = "0.43.5"
path = "../../../../framework/base"

[dev-dependencies.multiversx-sc-scenario]
[dependencies.multiversx-sc-scenario]
version = "0.43.5"
path = "../../../../framework/scenario"
optional = true

[dev-dependencies.single-value-repeat]
path = "."
features = ["debug"]
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub trait SingleValueRepeat: benchmark_common::BenchmarkCommon {
fn add_struct(
&self,
num_repeats: usize,
key: ExampleStruct<Self::Api>,
value: ExampleStruct<Self::Api>,
key: ExampleStruct<CurrentApi>,
value: ExampleStruct<CurrentApi>,
) {
for i in 0..num_repeats {
self.struct_at(&key, i).set(&value);
Expand All @@ -53,32 +53,32 @@ pub trait SingleValueRepeat: benchmark_common::BenchmarkCommon {
fn count_struct(
&self,
num_repeats: usize,
key: ExampleStruct<Self::Api>,
value: ExampleStruct<Self::Api>,
key: ExampleStruct<CurrentApi>,
value: ExampleStruct<CurrentApi>,
) -> usize {
(0..num_repeats)
.filter(|&i| self.struct_at(&key, i).get() == value)
.count()
}

#[endpoint]
fn remove_struct(&self, num_repeats: usize, key: ExampleStruct<Self::Api>) {
fn remove_struct(&self, num_repeats: usize, key: ExampleStruct<CurrentApi>) {
for i in 1..=num_repeats {
self.struct_at(&key, i).clear();
}
}

fn struct_at(
&self,
key: &ExampleStruct<Self::Api>,
key: &ExampleStruct<CurrentApi>,
index: usize,
) -> SingleValueMapper<ExampleStruct<Self::Api>> {
) -> SingleValueMapper<ExampleStruct<CurrentApi>> {
self.bench_struct(self.use_index_struct(key, index))
}

#[storage_mapper("bench_struct")]
fn bench_struct(
&self,
key: ExampleStruct<Self::Api>,
) -> SingleValueMapper<ExampleStruct<Self::Api>>;
key: ExampleStruct<CurrentApi>,
) -> SingleValueMapper<ExampleStruct<CurrentApi>>;
}
Loading