Skip to content

Commit 8ed1d1c

Browse files
Merge branch 'master' into check-state-partial-keys
2 parents b7cc9cd + 14da70e commit 8ed1d1c

File tree

8 files changed

+166
-52
lines changed

8 files changed

+166
-52
lines changed

contracts/feature-tests/basic-features/interact/src/bf_interact.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl BasicFeaturesInteract {
9696
pub async fn deploy(&mut self) {
9797
self.set_state().await;
9898

99-
let new_address = self
99+
let (new_address, _tx_hash) = self
100100
.interactor
101101
.tx()
102102
.from(&self.wallet_address)
@@ -105,6 +105,7 @@ impl BasicFeaturesInteract {
105105
.init()
106106
.code(CODE_EXPR)
107107
.returns(ReturnsNewBech32Address)
108+
.returns(ReturnsTxHash)
108109
.run()
109110
.await;
110111

@@ -185,7 +186,8 @@ impl BasicFeaturesInteract {
185186
&mut self,
186187
egld: u64,
187188
) -> ManagedDecimal<StaticApi, EgldDecimals> {
188-
self.interactor
189+
let (result, _tx_hash) = self
190+
.interactor
189191
.tx()
190192
.from(&self.wallet_address)
191193
.to(self.state.bf_contract())
@@ -194,8 +196,11 @@ impl BasicFeaturesInteract {
194196
.returns_egld_decimal()
195197
.egld(egld)
196198
.returns(ReturnsResultUnmanaged)
199+
.returns(ReturnsTxHash)
197200
.run()
198-
.await
201+
.await;
202+
203+
result
199204
}
200205

201206
pub async fn echo_managed_option(
@@ -229,7 +234,7 @@ impl BasicFeaturesInteract {
229234
.gas(10_000_000)
230235
.typed(basic_features::basic_features_proxy::BasicFeaturesProxy)
231236
.verify_secp256r1_signature(key, message, signature)
232-
.returns(ReturnsHandledOrError::new())
237+
.returns(ReturnsHandledOrError::new().returns(ReturnsTxHash))
233238
.run()
234239
.await;
235240

framework/base/src/types/interaction/system_proxy/builtin_func_proxy.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ where
301301
new_attributes: &T,
302302
uris: ManagedVec<Env::Api, ManagedBuffer<Env::Api>>,
303303
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
304-
let tx = self
304+
let mut tx = self
305305
.wrapped_tx
306306
.payment(NotPayable)
307307
.raw_call(ESDT_METADATA_RECREATE_FUNC_NAME)
@@ -310,8 +310,18 @@ where
310310
.argument(&name)
311311
.argument(&royalties)
312312
.argument(&hash)
313-
.argument(&new_attributes)
314-
.argument(&uris);
313+
.argument(&new_attributes);
314+
315+
if uris.is_empty() {
316+
// at least one URI is required, so we push an empty one
317+
tx = tx.argument(&Empty);
318+
} else {
319+
// The API function has the last argument as variadic,
320+
// so we top-encode each and send as separate argument
321+
for uri in uris {
322+
tx = tx.argument(&uri);
323+
}
324+
}
315325

316326
tx.original_result()
317327
}
@@ -334,7 +344,7 @@ where
334344
new_attributes: &T,
335345
uris: ManagedVec<Env::Api, ManagedBuffer<Env::Api>>,
336346
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
337-
let tx = self
347+
let mut tx = self
338348
.wrapped_tx
339349
.payment(NotPayable)
340350
.raw_call(ESDT_METADATA_UPDATE_FUNC_NAME)
@@ -343,8 +353,18 @@ where
343353
.argument(&name)
344354
.argument(&royalties)
345355
.argument(&hash)
346-
.argument(&new_attributes)
347-
.argument(&uris);
356+
.argument(&new_attributes);
357+
358+
if uris.is_empty() {
359+
// at least one URI is required, so we push an empty one
360+
tx = tx.argument(&Empty);
361+
} else {
362+
// The API function has the last argument as variadic,
363+
// so we top-encode each and send as separate argument
364+
for uri in uris {
365+
tx = tx.argument(&uri);
366+
}
367+
}
348368

349369
tx.original_result()
350370
}

framework/scenario/src/scenario/model/step/sc_call_step.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,12 @@ impl ScCallStep {
211211
expect.update_from_response(&tx_response)
212212
}
213213
}
214-
tx_response.tx_hash = self
215-
.explicit_tx_hash
216-
.as_ref()
217-
.map(|vm_hash| vm_hash.as_array().into());
214+
if tx_response.tx_hash.is_none() {
215+
tx_response.tx_hash = self
216+
.explicit_tx_hash
217+
.as_ref()
218+
.map(|vm_hash| vm_hash.as_array().into());
219+
}
218220
self.response = Some(tx_response);
219221
}
220222
}

framework/scenario/src/scenario/model/step/sc_deploy_step.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ impl ScDeployStep {
141141
expect.update_from_response(&tx_response)
142142
}
143143
}
144-
tx_response.tx_hash = self
145-
.explicit_tx_hash
146-
.as_ref()
147-
.map(|vm_hash| vm_hash.as_array().into());
144+
if tx_response.tx_hash.is_none() {
145+
tx_response.tx_hash = self
146+
.explicit_tx_hash
147+
.as_ref()
148+
.map(|vm_hash| vm_hash.as_array().into());
149+
}
148150
self.response = Some(tx_response);
149151
}
150152
}

framework/snippets/src/interactor/interactor_sender.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::sdk::{data::transaction::Transaction, wallet::Wallet};
44
use log::debug;
55
use multiversx_sc_scenario::multiversx_sc::types::Address;
66
use multiversx_sdk::data::account::Account;
7-
use multiversx_sdk::gateway::{GatewayAsyncService, GetAccountRequest, GetAccountStorageRequest};
7+
use multiversx_sdk::data::esdt::EsdtBalance;
8+
use multiversx_sdk::gateway::{
9+
GatewayAsyncService, GetAccountEsdtTokensRequest, GetAccountRequest, GetAccountStorageRequest,
10+
};
811

912
use crate::InteractorBase;
1013

@@ -42,6 +45,13 @@ where
4245
.expect("failed to retrieve account")
4346
}
4447

48+
pub async fn get_account_esdt(&self, address: &Address) -> HashMap<String, EsdtBalance> {
49+
self.proxy
50+
.request(GetAccountEsdtTokensRequest::new(address))
51+
.await
52+
.expect("failed to retrieve account")
53+
}
54+
4555
pub(crate) async fn set_nonce_and_sign_tx(
4656
&mut self,
4757
sender_address: &Address,

sdk/core/src/data/esdt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::collections::HashMap;
77
pub struct EsdtBalance {
88
pub token_identifier: String,
99
pub balance: String,
10+
pub uris: Vec<String>,
1011
}
1112

1213
// EsdtBalanceDataholds the esdt balance data

tools/interactor-system-func-calls/src/system_sc_interact.rs

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ mod system_sc_interact_cli;
22
mod system_sc_interact_config;
33
mod system_sc_interact_state;
44

5+
use std::collections::HashMap;
6+
57
use clap::Parser;
68
pub use system_sc_interact_cli::NftDummyAttributes;
79
pub use system_sc_interact_config::Config;
810
use system_sc_interact_state::State;
911

10-
use multiversx_sc_snippets::imports::*;
12+
use multiversx_sc_snippets::{
13+
imports::*,
14+
sdk::{data::esdt::EsdtBalance, utils::base64_decode},
15+
};
1116

1217
pub async fn system_sc_interact_cli() {
1318
env_logger::init();
@@ -131,7 +136,7 @@ pub async fn system_sc_interact_cli() {
131136
creation_epoch: 2u64,
132137
cool_factor: 3u8,
133138
},
134-
Vec::new(),
139+
&Vec::new(),
135140
)
136141
.await;
137142
},
@@ -746,12 +751,12 @@ impl SysFuncCallsInteract {
746751
royalties: u64,
747752
hash: &[u8],
748753
attributes: &T,
749-
uris: Vec<String>,
754+
uris: &[String],
750755
) -> u64 {
751756
println!("Minting NFT...");
752757

753758
let uris = uris
754-
.into_iter()
759+
.iter()
755760
.map(ManagedBuffer::from)
756761
.collect::<ManagedVec<StaticApi, ManagedBuffer<StaticApi>>>();
757762

@@ -860,11 +865,11 @@ impl SysFuncCallsInteract {
860865
.await;
861866
}
862867

863-
pub async fn set_new_uris(&mut self, token_id: &[u8], nonce: u64, new_uris: Vec<String>) {
868+
pub async fn set_new_uris(&mut self, token_id: &[u8], nonce: u64, new_uris: &[String]) {
864869
println!("Setting new uris for token {token_id:?} with nonce {nonce:?}...");
865870

866871
let uris = new_uris
867-
.into_iter()
872+
.iter()
868873
.map(ManagedBuffer::from)
869874
.collect::<ManagedVec<StaticApi, ManagedBuffer<StaticApi>>>();
870875

@@ -917,12 +922,12 @@ impl SysFuncCallsInteract {
917922
royalties: u64,
918923
hash: &[u8],
919924
new_attributes: &T,
920-
uris: Vec<String>,
925+
uris: &[String],
921926
) {
922927
println!("Recreating the token {token_id:?} with nonce {nonce:?} with new attributes...");
923928

924929
let uris = uris
925-
.into_iter()
930+
.iter()
926931
.map(ManagedBuffer::from)
927932
.collect::<ManagedVec<StaticApi, ManagedBuffer<StaticApi>>>();
928933

@@ -946,12 +951,12 @@ impl SysFuncCallsInteract {
946951
royalties: u64,
947952
hash: &[u8],
948953
new_attributes: &T,
949-
uris: Vec<String>,
954+
uris: &[String],
950955
) {
951956
println!("Updating the token {token_id:?} with nonce {nonce:?} with new attributes...");
952957

953958
let uris = uris
954-
.into_iter()
959+
.iter()
955960
.map(ManagedBuffer::from)
956961
.collect::<ManagedVec<StaticApi, ManagedBuffer<StaticApi>>>();
957962

@@ -965,4 +970,47 @@ impl SysFuncCallsInteract {
965970
.run()
966971
.await;
967972
}
973+
974+
pub async fn get_account_esdt_tokens(&mut self) -> HashMap<String, EsdtBalance> {
975+
println!(
976+
"Retrieving ESDT tokens for {}...",
977+
self.wallet_address.to_bech32_str()
978+
);
979+
980+
self.interactor
981+
.get_account_esdt(&self.wallet_address.to_address())
982+
.await
983+
}
984+
985+
pub async fn check_nft_uris(
986+
&mut self,
987+
token_id: &String,
988+
nonce: u64,
989+
expected_uris: &[String],
990+
) {
991+
let esdt_tokens = self.get_account_esdt_tokens().await;
992+
let nft_token_id = if nonce <= 10 {
993+
format!("{}-0{:x}", token_id, nonce)
994+
} else {
995+
format!("{}-{:x}", token_id, nonce)
996+
};
997+
998+
let uris = esdt_tokens
999+
.get(&nft_token_id)
1000+
.expect("nft token not owned by account")
1001+
.uris
1002+
.clone();
1003+
1004+
if expected_uris.is_empty() {
1005+
assert_eq!(1, uris.len());
1006+
assert_eq!(String::new(), uris[0]);
1007+
return;
1008+
}
1009+
1010+
assert_eq!(expected_uris.len(), uris.len());
1011+
for (index, uri) in uris.iter().enumerate() {
1012+
let uri_string = String::from_utf8(base64_decode(uri)).unwrap();
1013+
assert_eq!(expected_uris[index], uri_string);
1014+
}
1015+
}
9681016
}

0 commit comments

Comments
 (0)