various fixes from comments

This commit is contained in:
jonesmarvin8 2025-12-22 19:51:41 -05:00
parent 5baa759283
commit 072cf5cd0f

View File

@ -77,32 +77,19 @@ fn is_token_standard_valid(standard: u8) -> bool {
matches!( matches!(
standard, standard,
TOKEN_STANDARD_FUNGIBLE_TOKEN TOKEN_STANDARD_FUNGIBLE_TOKEN
| TOKEN_STANDARD_FUNGIBLE_ASSET | TOKEN_STANDARD_FUNGIBLE_ASSET
| TOKEN_STANDARD_NONFUNGIBLE | TOKEN_STANDARD_NONFUNGIBLE
| TOKEN_STANDARD_NONFUNGIBLE_PRINTABLE | TOKEN_STANDARD_NONFUNGIBLE_PRINTABLE
) )
} }
fn is_metadata_type_valid(standard: u8) -> bool { fn is_metadata_type_valid(standard: u8) -> bool {
if standard == METADATA_TYPE_SIMPLE { matches!(standard, METADATA_TYPE_SIMPLE | METADATA_TYPE_EXPANDED)
true
} else if standard == METADATA_TYPE_EXPANDED {
true
} else {
false
}
} }
fn is_token_holding_type_valid(standard: u8) -> bool { fn is_token_holding_type_valid(standard: u8) -> bool {
if standard == TOKEN_HOLDING_STANDARD { matches!(standard, |TOKEN_HOLDING_STANDARD| TOKEN_HOLDING_NFT_MASTER
true | TOKEN_HOLDING_NFT_PRINTED_COPY)
} else if standard == TOKEN_HOLDING_NFT_MASTER {
true
} else if standard == TOKEN_HOLDING_NFT_PRINTED_COPY {
true
} else {
false
}
} }
struct TokenDefinition { struct TokenDefinition {
@ -154,9 +141,9 @@ impl TokenDefinition {
}); });
match account_type { match account_type {
TOKEN_STANDARD_NONFUNGIBLE if total_supply != 1 TOKEN_STANDARD_NONFUNGIBLE if total_supply != 1 => None,
| TOKEN_STANDARD_FUNGIBLE_TOKEN if metadata_id != AccountId::new([0; 32]) => None TOKEN_STANDARD_FUNGIBLE_TOKEN if metadata_id != AccountId::new([0; 32]) => None,
_ => this _ => this,
} }
} }
} }
@ -528,11 +515,7 @@ fn new_definition_with_metadata(
} }
fn valid_total_supply_for_token_standard(total_supply: u128, token_standard: u8) -> bool { fn valid_total_supply_for_token_standard(total_supply: u128, token_standard: u8) -> bool {
if token_standard == TOKEN_STANDARD_NONFUNGIBLE && total_supply != 1 { token_standard != TOKEN_STANDARD_NONFUNGIBLE || total_supply == 1
false
} else {
true
}
} }
fn initialize_account(pre_states: &[AccountWithMetadata]) -> Vec<AccountPostState> { fn initialize_account(pre_states: &[AccountWithMetadata]) -> Vec<AccountPostState> {
@ -619,11 +602,7 @@ fn burn(pre_states: &[AccountWithMetadata], balance_to_burn: u128) -> Vec<Accoun
} }
fn is_mintable(account_type: u8) -> bool { fn is_mintable(account_type: u8) -> bool {
if account_type == TOKEN_STANDARD_NONFUNGIBLE { account_type != TOKEN_STANDARD_NONFUNGIBLE
false
} else {
true
}
} }
fn mint_additional_supply( fn mint_additional_supply(
@ -1529,10 +1508,7 @@ mod tests {
== AccountForTests::definition_account_unclaimed().account == AccountForTests::definition_account_unclaimed().account
); );
assert!( assert!(*holding_account.account() == AccountForTests::holding_account_unclaimed().account);
*holding_account.account()
== AccountForTests::holding_account_unclaimed().account
);
} }
#[should_panic(expected = "Invalid number of input accounts")] #[should_panic(expected = "Invalid number of input accounts")]
@ -1697,13 +1673,11 @@ mod tests {
let [sender_post, recipient_post] = post_states.try_into().ok().unwrap(); let [sender_post, recipient_post] = post_states.try_into().ok().unwrap();
assert!( assert!(
*sender_post.account() *sender_post.account() == AccountForTests::holding_account_init_post_transfer().account
== AccountForTests::holding_account_init_post_transfer().account
); );
assert!( assert!(
*recipient_post.account() *recipient_post.account()
== AccountForTests::holding_account2_init_post_transfer() == AccountForTests::holding_account2_init_post_transfer().account
.account
); );
} }
@ -1738,13 +1712,11 @@ mod tests {
assert!( assert!(
*sender_post.account() *sender_post.account()
== AccountForTests::holding_account_master_nft_post_transfer() == AccountForTests::holding_account_master_nft_post_transfer().account
.account
); );
assert!( assert!(
*recipient_post.account() *recipient_post.account()
== AccountForTests::holding_account_with_master_nft_transferred_to() == AccountForTests::holding_account_with_master_nft_transferred_to().account
.account
); );
} }
@ -1758,23 +1730,18 @@ mod tests {
let [sender_post, recipient_post] = post_states.try_into().ok().unwrap(); let [sender_post, recipient_post] = post_states.try_into().ok().unwrap();
assert!( assert!(
*sender_post.account() *sender_post.account() == AccountForTests::holding_account_init_post_transfer().account
== AccountForTests::holding_account_init_post_transfer()
.account
); );
assert!( assert!(
*recipient_post.account() *recipient_post.account()
== AccountForTests::holding_account2_init_post_transfer() == AccountForTests::holding_account2_init_post_transfer().account
.account
); );
} }
#[test] #[test]
#[should_panic(expected = "Invalid number of accounts")] #[should_panic(expected = "Invalid number of accounts")]
fn test_burn_invalid_number_of_accounts() { fn test_burn_invalid_number_of_accounts() {
let pre_states = vec![ let pre_states = vec![AccountForTests::definition_account_auth()];
AccountForTests::definition_account_auth(),
];
let _post_states = burn(&pre_states, BalanceForTests::burn_success()); let _post_states = burn(&pre_states, BalanceForTests::burn_success());
} }
@ -1829,14 +1796,8 @@ mod tests {
let def_post = post_states[0].clone(); let def_post = post_states[0].clone();
let holding_post = post_states[1].clone(); let holding_post = post_states[1].clone();
assert!( assert!(*def_post.account() == AccountForTests::definition_account_post_burn().account);
*def_post.account() assert!(*holding_post.account() == AccountForTests::holding_account_post_burn().account);
== AccountForTests::definition_account_post_burn().account
);
assert!(
*holding_post.account()
== AccountForTests::holding_account_post_burn().account
);
} }
#[test] #[test]
@ -1908,10 +1869,7 @@ mod tests {
let def_post = post_states[0].clone(); let def_post = post_states[0].clone();
let holding_post = post_states[1].clone(); let holding_post = post_states[1].clone();
assert!( assert!(*def_post.account() == AccountForTests::definition_account_mint().account);
*def_post.account()
== AccountForTests::definition_account_mint().account
);
assert!( assert!(
*holding_post.account() *holding_post.account()
== AccountForTests::holding_account_same_definition_mint().account == AccountForTests::holding_account_same_definition_mint().account
@ -1929,13 +1887,8 @@ mod tests {
let def_post = post_states[0].clone(); let def_post = post_states[0].clone();
let holding_post = post_states[1].clone(); let holding_post = post_states[1].clone();
assert!( assert!(*def_post.account() == AccountForTests::definition_account_mint().account);
*def_post.account() assert!(*holding_post.account() == AccountForTests::init_mint().account);
== AccountForTests::definition_account_mint().account
);
assert!(
*holding_post.account() == AccountForTests::init_mint().account
);
assert!(holding_post.requires_claim() == true); assert!(holding_post.requires_claim() == true);
} }
@ -2346,9 +2299,7 @@ mod tests {
#[should_panic(expected = "Invalid number of accounts")] #[should_panic(expected = "Invalid number of accounts")]
#[test] #[test]
fn test_print_nft_invalid_number_of_accounts_1() { fn test_print_nft_invalid_number_of_accounts_1() {
let pre_states = vec![ let pre_states = vec![AccountForTests::holding_account_master_nft()];
AccountForTests::holding_account_master_nft()
];
let _post_states = print_nft(&pre_states); let _post_states = print_nft(&pre_states);
} }
@ -2425,12 +2376,8 @@ mod tests {
let post_printed = post_states[1].account(); let post_printed = post_states[1].account();
assert!( assert!(
*post_master_nft *post_master_nft == AccountForTests::holding_account_master_nft_after_print().account
== AccountForTests::holding_account_master_nft_after_print().account
);
assert!(
*post_printed
== AccountForTests::holding_account_printed_nft().account
); );
assert!(*post_printed == AccountForTests::holding_account_printed_nft().account);
} }
} }