Skip to content

Commit

Permalink
change to dynamic impl, bugfixes, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Dec 3, 2024
1 parent e5b7db9 commit 4b8e7d0
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,8 @@ where
.argument(&token_ticker)
.argument(&token_type_name);

if token_type_name == "META" {
if token_type != EsdtTokenType::DynamicNFT && token_type != EsdtTokenType::DynamicSFT {
tx = tx.argument(&num_decimals);
} else {
assert!(
num_decimals == 0usize,
"only META tokens accept number of decimals > 0"
);
}

tx.original_result()
Expand Down Expand Up @@ -285,13 +280,8 @@ where
.argument(&token_ticker)
.argument(&token_type_name);

if token_type_name == "META" {
if token_type != EsdtTokenType::DynamicNFT && token_type != EsdtTokenType::DynamicSFT {
tx = tx.argument(&num_decimals);
} else {
assert!(
num_decimals == 0usize,
"only META tokens accept number of decimals > 0"
);
}

tx.original_result()
Expand Down Expand Up @@ -649,6 +639,19 @@ where
append_token_property_arguments(&mut tx.data, property_arguments);
tx.original_result()
}

/// Changes token to dynamic.
/// Does not work for: FungibleESDT, NonFungibleESDT, NonFungibleESDTv2.
pub fn change_to_dynamic<Arg0: ProxyArg<TokenIdentifier<Env::Api>>>(
self,
token_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("changeToDynamic")
.argument(&token_id)
.original_result()
}
}

const TRUE_STR: &str = "true";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,17 @@ where
EsdtTokenType::Invalid => "",
};

ContractCallWithEgld::new(esdt_system_sc_address, endpoint, issue_cost)
.argument(&token_display_name)
.argument(&token_ticker)
.argument(&token_type_name)
.argument(&num_decimals)
let mut contract_call =
ContractCallWithEgld::new(esdt_system_sc_address, endpoint, issue_cost)
.argument(&token_display_name)
.argument(&token_ticker)
.argument(&token_type_name);

if token_type != EsdtTokenType::DynamicNFT {
contract_call = contract_call.argument(&num_decimals);
}

contract_call
}

/// Issues dynamic ESDT tokens
Expand Down Expand Up @@ -245,13 +251,8 @@ where
contract_call.proxy_arg(token_ticker);
contract_call.proxy_arg(&token_type_name);

if token_type_name == "META" {
if token_type != EsdtTokenType::DynamicNFT {
contract_call.proxy_arg(&num_decimals);
} else {
assert!(
num_decimals == 0usize,
"only META tokens accept number of decimals > 0"
);
}

contract_call
Expand Down
14 changes: 14 additions & 0 deletions tools/interactor-system-func-calls/src/system_sc_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,20 @@ impl SysFuncCallsInteract {
.await;
}

pub async fn change_to_dynamic(&mut self, token_id: &[u8]) {
println!("Changing the following token {token_id:?} to dynamic...");

self.interactor
.tx()
.from(&self.wallet_address)
.to(ESDTSystemSCAddress)
.gas(100_000_000u64)
.typed(ESDTSystemSCProxy)
.change_to_dynamic(TokenIdentifier::from(token_id))
.run()
.await;
}

pub async fn mint_sft(
&mut self,
token_id: &[u8],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ async fn cs_builtin_func_tokens_test() {
)
.await;

// issue dynamic META with all roles
let _ = interact
.issue_token_all_roles(
RustBigUint::from(ISSUE_COST),
b"TESTNFT",
b"TEST",
0usize,
EsdtTokenType::DynamicMeta,
)
.await;

// issue dynamic SFT with all roles
let _ = interact
.issue_token_all_roles(
RustBigUint::from(ISSUE_COST),
b"TESTNFT",
b"TEST",
0usize,
EsdtTokenType::DynamicSFT,
)
.await;

// issue dynamic NFT with all roles
let dynamic_nft_token_id = interact
.issue_token_all_roles(
Expand Down Expand Up @@ -126,3 +148,48 @@ async fn cs_builtin_func_tokens_test() {

println!("Metadata recreated for {dynamic_nft_token_id:?} with nonce {nonce:?}. A new token has been created.");
}

#[tokio::test]
#[ignore = "run on demand"]
async fn change_to_dynamic_test() {
let mut interact = SysFuncCallsInteract::init(Config::load_config()).await;

// issue NFT with all roles
let _ = interact
.issue_token_all_roles(
RustBigUint::from(ISSUE_COST),
b"TESTNFT",
b"TEST",
0usize,
EsdtTokenType::NonFungible,
)
.await;

// issue META token with all roles
let meta_token_id = interact
.issue_token_all_roles(
RustBigUint::from(ISSUE_COST),
b"TESTNFT",
b"TEST",
18usize,
EsdtTokenType::Meta,
)
.await;

// change META to dynamic
interact.change_to_dynamic(meta_token_id.as_bytes()).await;

// issue SFT token with all roles
let sft_token_id = interact
.issue_token_all_roles(
RustBigUint::from(ISSUE_COST),
b"TESTNFT",
b"TEST",
18usize,
EsdtTokenType::SemiFungible,
)
.await;

// change SFT to dynamic
interact.change_to_dynamic(sft_token_id.as_bytes()).await;
}

0 comments on commit 4b8e7d0

Please sign in to comment.