I am writing tests for my smart contract using elrond-wasm 0.32.0.
My issue is that my smart contract returns the identifier of the ESDT token when I am getting the name.
I am setting my ESDT token's name like so:
blockchain_wrapper.set_nft_balance_all_properties::<Empty>(
&cf_wrapper.address_ref(),
&ITEM_TO_EQUIP_ID,
ITEM_TO_EQUIP_NONCE,
&rust_biguint!(2u64),
&Empty,
0,
Option::Some(&owner_address),
Option::Some(ITEM_TO_EQUIP_NAME),
Option::Some(b""),
&[],
);
Then, I get my ESDT token's name :
blockchain_wrapper
.execute_query(&cf_wrapper, |sc| {
let data = sc.blockchain().get_esdt_token_data(
&ManagedAddress::from_address(&cf_wrapper.address_ref()),
&TokenIdentifier::from_esdt_bytes(ITEM_TO_EQUIP_ID),
ITEM_TO_EQUIP_NONCE,
);
// data.name equals ITEM_TO_EQUIP_ID, so it fail
assert_eq!(data.name, ManagedBuffer::new_from_bytes(ITEM_TO_EQUIP_NAME));
})
.assert_ok();
Did I forget something, or is it a bug?
#[test]
fn set_name_test() {
const WASM_PATH: &'static str = "sc-customize-nft/output/customize_nft.wasm";
const ITEM_TO_EQUIP_ID: &[u8] = b"ITEM-a1a1a1";
const ITEM_TO_EQUIP_NAME: &[u8] = b"item name";
const ITEM_TO_EQUIP_NONCE: u64 = 1;
let rust_zero = rust_biguint!(0u64);
let mut blockchain_wrapper = BlockchainStateWrapper::new();
let owner_address = blockchain_wrapper.create_user_account(&rust_zero);
let cf_wrapper = blockchain_wrapper.create_sc_account(
&rust_zero,
Some(&owner_address),
customize_nft::contract_obj,
WASM_PATH,
);
// deploy contract
blockchain_wrapper
.execute_tx(&owner_address, &cf_wrapper, &rust_zero, |sc| {
let result = sc.init(managed_token_id!(PENGUIN_TOKEN_ID));
assert_eq!(result, SCResult::Ok(()));
})
.assert_ok();
blockchain_wrapper.add_mandos_set_account(cf_wrapper.address_ref());
blockchain_wrapper.set_nft_balance_all_properties::<Empty>(
&cf_wrapper.address_ref(),
&ITEM_TO_EQUIP_ID,
ITEM_TO_EQUIP_NONCE,
&rust_biguint!(2u64),
&Empty,
0,
Option::Some(&owner_address),
Option::Some(ITEM_TO_EQUIP_NAME),
Option::Some(b""),
&[],
);
blockchain_wrapper
.execute_query(&cf_wrapper, |sc| {
let data = sc.blockchain().get_esdt_token_data(
&ManagedAddress::from_address(&cf_wrapper.address_ref()),
&TokenIdentifier::from_esdt_bytes(ITEM_TO_EQUIP_ID),
ITEM_TO_EQUIP_NONCE,
);
println!("Name is {:?}", data.name);
assert_eq!(data.name, ManagedBuffer::new_from_bytes(ITEM_TO_EQUIP_NAME));
})
.assert_ok();
}
I got an answer from an Elrond Developer:
It's a bug in the mock. It's being set properly, but the get_esdt_token_data mock just returns the token ID instead of the name from metadata. Thanks for reporting!