I’m working with elrond-wasm version 0.32.0 and running into problems when testing my smart contract. When I try to set the name for an ESDT token, the system keeps returning the token identifier instead of the actual name I specified.
What I’m doing
First, I configure the NFT properties using this approach:
blockchain_wrapper.set_nft_balance_all_properties::<Empty>(
&contract_wrapper.address_ref(),
&WEAPON_TOKEN_ID,
WEAPON_TOKEN_NONCE,
&rust_biguint!(5u64),
&Empty,
0,
Option::Some(&user_address),
Option::Some(WEAPON_TOKEN_NAME),
Option::Some(b""),
&[],
);
Then I try to retrieve the token name:
blockchain_wrapper
.execute_query(&contract_wrapper, |sc| {
let token_data = sc.blockchain().get_esdt_token_data(
&ManagedAddress::from_address(&contract_wrapper.address_ref()),
&TokenIdentifier::from_esdt_bytes(WEAPON_TOKEN_ID),
WEAPON_TOKEN_NONCE,
);
// token_data.name returns WEAPON_TOKEN_ID instead of WEAPON_TOKEN_NAME
assert_eq!(token_data.name, ManagedBuffer::new_from_bytes(WEAPON_TOKEN_NAME));
})
.assert_ok();
The assertion fails because token_data.name contains the token ID rather than the name I set. Is this expected behavior or am I missing something in my test setup?
Full test example
#[test]
fn token_name_assignment_test() {
const WASM_FILE: &'static str = "sc-weapon-nft/output/weapon_nft.wasm";
const WEAPON_TOKEN_ID: &[u8] = b"WEAPON-b2b2b2";
const WEAPON_TOKEN_NAME: &[u8] = b"magic sword";
const WEAPON_TOKEN_NONCE: u64 = 1;
let zero_amount = rust_biguint!(0u64);
let mut blockchain_wrapper = BlockchainStateWrapper::new();
let user_address = blockchain_wrapper.create_user_account(&zero_amount);
let contract_wrapper = blockchain_wrapper.create_sc_account(
&zero_amount,
Some(&user_address),
weapon_nft::contract_obj,
WASM_FILE,
);
// initialize contract
blockchain_wrapper
.execute_tx(&user_address, &contract_wrapper, &zero_amount, |sc| {
let init_result = sc.init(managed_token_id!(MAIN_TOKEN_ID));
assert_eq!(init_result, SCResult::Ok(()));
})
.assert_ok();
blockchain_wrapper.add_mandos_set_account(contract_wrapper.address_ref());
blockchain_wrapper.set_nft_balance_all_properties::<Empty>(
&contract_wrapper.address_ref(),
&WEAPON_TOKEN_ID,
WEAPON_TOKEN_NONCE,
&rust_biguint!(5u64),
&Empty,
0,
Option::Some(&user_address),
Option::Some(WEAPON_TOKEN_NAME),
Option::Some(b""),
&[],
);
blockchain_wrapper
.execute_query(&contract_wrapper, |sc| {
let token_data = sc.blockchain().get_esdt_token_data(
&ManagedAddress::from_address(&contract_wrapper.address_ref()),
&TokenIdentifier::from_esdt_bytes(WEAPON_TOKEN_ID),
WEAPON_TOKEN_NONCE,
);
println!("Retrieved name: {:?}", token_data.name);
assert_eq!(token_data.name, ManagedBuffer::new_from_bytes(WEAPON_TOKEN_NAME));
})
.assert_ok();
}