Skip to content

Commit 928dd99

Browse files
Refactor cross-contract calls examples (#91)
* Refactor `cross-contract-calls-advanced` * Format `cross-contract-calls`
1 parent 407eddc commit 928dd99

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

cross-contract-calls-advanced/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "cross-contract-calls"
2+
name = "cross-contract-calls-advanced"
33
version = "6.0.0-beta.1"
44
authors = ["Use Ink <[email protected]>"]
55
edition = "2024"

cross-contract-calls-advanced/e2e_tests.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::cross_contract_calls::*;
1+
use super::cross_contract_calls_advanced::*;
22
use ink_e2e::ContractsBackend;
33

44
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
@@ -18,14 +18,18 @@ async fn instantiate_with_insufficient_storage_deposit_limit<Client: E2EBackend>
1818
const PROOF_SIZE_LIMIT: u64 = 100_000_000_000;
1919
let storage_deposit_limit = ink::U256::from(100_000_000_000_000u64);
2020

21-
let mut constructor = CrossContractCallsRef::new_with_limits(
21+
let mut constructor = CrossContractCallsAdvancedRef::new_with_limits(
2222
other_contract_code.code_hash,
2323
REF_TIME_LIMIT,
2424
PROOF_SIZE_LIMIT,
2525
storage_deposit_limit,
2626
);
2727
let call_result = client
28-
.instantiate("cross-contract-calls", &ink_e2e::alice(), &mut constructor)
28+
.instantiate(
29+
"cross-contract-calls-advanced",
30+
&ink_e2e::alice(),
31+
&mut constructor,
32+
)
2933
.dry_run()
3034
.await?;
3135

@@ -55,14 +59,18 @@ async fn instantiate_with_sufficient_limits<Client: E2EBackend>(
5559
// `pallet-revive`. but they should throw an error about `StorageLimitExhausted`.
5660
let storage_deposit_limit = ink::U256::from(100_000_000_000_000u64);
5761

58-
let mut constructor = CrossContractCallsRef::new_with_limits(
62+
let mut constructor = CrossContractCallsAdvancedRef::new_with_limits(
5963
other_contract_code.code_hash,
6064
REF_TIME_LIMIT,
6165
PROOF_SIZE_LIMIT,
6266
storage_deposit_limit,
6367
);
6468
let contract = client
65-
.instantiate("cross-contract-calls", &ink_e2e::alice(), &mut constructor)
69+
.instantiate(
70+
"cross-contract-calls-advanced",
71+
&ink_e2e::alice(),
72+
&mut constructor,
73+
)
6674
.submit()
6775
.await;
6876

@@ -81,9 +89,13 @@ async fn instantiate_no_limits<Client: E2EBackend>(mut client: Client) -> E2ERes
8189
.expect("other_contract upload failed");
8290

8391
let mut constructor =
84-
CrossContractCallsRef::new_no_limits(other_contract_code.code_hash);
92+
CrossContractCallsAdvancedRef::new_no_limits(other_contract_code.code_hash);
8593
let contract = client
86-
.instantiate("cross-contract-calls", &ink_e2e::alice(), &mut constructor)
94+
.instantiate(
95+
"cross-contract-calls-advanced",
96+
&ink_e2e::alice(),
97+
&mut constructor,
98+
)
8799
.submit()
88100
.await;
89101

@@ -102,13 +114,17 @@ async fn flip_and_get<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
102114
.expect("other_contract upload failed");
103115

104116
let mut constructor =
105-
CrossContractCallsRef::new_no_limits(other_contract_code.code_hash);
117+
CrossContractCallsAdvancedRef::new_no_limits(other_contract_code.code_hash);
106118
let contract = client
107-
.instantiate("cross-contract-calls", &ink_e2e::alice(), &mut constructor)
119+
.instantiate(
120+
"cross-contract-calls-advanced",
121+
&ink_e2e::alice(),
122+
&mut constructor,
123+
)
108124
.submit()
109125
.await
110126
.expect("cross-contract-calls instantiate failed");
111-
let mut call_builder = contract.call_builder::<CrossContractCalls>();
127+
let mut call_builder = contract.call_builder::<CrossContractCallsAdvanced>();
112128

113129
const REF_TIME_LIMIT: u64 = 500_000_000;
114130
const PROOF_SIZE_LIMIT: u64 = 100_000;

cross-contract-calls-advanced/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#![cfg_attr(not(feature = "std"), no_std, no_main)]
22

33
#[ink::contract]
4-
mod cross_contract_calls {
4+
mod cross_contract_calls_advanced {
55
use ink::codegen::TraitCallBuilder;
66
use other_contract::OtherContractRef;
77

88
#[ink(storage)]
9-
pub struct CrossContractCalls {
9+
pub struct CrossContractCallsAdvanced {
1010
other_contract: OtherContractRef,
1111
}
1212

13-
impl CrossContractCalls {
13+
impl CrossContractCallsAdvanced {
1414
/// Initializes the contract by instantiating the code at the given code hash via
1515
/// `instantiate` host function with the supplied weight and storage
1616
/// limits.

cross-contract-calls/e2e_tests.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::cross_contract_calls::*;
2-
use other_contract::OtherContractRef;
32
use ink_e2e::ContractsBackend;
3+
use other_contract::OtherContractRef;
44

55
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
66

@@ -15,8 +15,7 @@ async fn instantiate_no_limits<Client: E2EBackend>(mut client: Client) -> E2ERes
1515
.expect("other-contract instantiate failed");
1616

1717
// when
18-
let mut constructor =
19-
CrossContractCallsRef::new(other_contract.addr);
18+
let mut constructor = CrossContractCallsRef::new(other_contract.addr);
2019
let contract = client
2120
.instantiate("cross-contract-calls", &ink_e2e::alice(), &mut constructor)
2221
.submit()
@@ -38,8 +37,7 @@ async fn flip_and_get<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
3837
.await
3938
.expect("other-contract instantiate failed");
4039

41-
let mut constructor =
42-
CrossContractCallsRef::new(other_contract.addr);
40+
let mut constructor = CrossContractCallsRef::new(other_contract.addr);
4341
let contract = client
4442
.instantiate("cross-contract-calls", &ink_e2e::alice(), &mut constructor)
4543
.submit()

cross-contract-calls/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ mod cross_contract_calls {
1717
pub fn new(other_contract_address: ink::Address) -> Self {
1818
// Note: In the future, this will be replaced by:
1919
// let other_contract = OtherContractRef::from(other_contract_address);
20-
let other_contract = ink::env::call::FromAddr::from_addr(other_contract_address);
20+
let other_contract =
21+
ink::env::call::FromAddr::from_addr(other_contract_address);
2122
Self { other_contract }
2223
}
2324

0 commit comments

Comments
 (0)