Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions creator-keys/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,48 @@ fn test_transfer_keys_insufficient_balance_reverts() {
assert_eq!(result, Err(Ok(ContractError::InsufficientBalance)));
}

#[test]
fn test_transfer_keys_balance_updates_correctly() {
let env = Env::default();
env.mock_all_auths();
let contract_id = env.register(CreatorKeysContract, ());
let client = CreatorKeysContractClient::new(&env, &contract_id);
let admin = Address::generate(&env);
let creator = Address::generate(&env);
let sender = Address::generate(&env);
let recipient = Address::generate(&env);

client.set_key_price(&admin, &100i128);
client.register_creator(
&crate::RegisterCreatorParams {
creator: creator.clone(),
handle: String::from_str(&env, "alice"),
},
&None,
&None,
&None,
&None,
&None
);

// Seed sender with 10 keys
for _ in 0..10 {
client.buy_key(&creator, &sender, &100i128, &None);
}

// Transfer 4 keys to recipient
client.transfer_keys(&creator, &sender, &recipient, &4);

// Assert sender balance is 6 (10 - 4)
assert_eq!(client.get_key_balance(&creator, &sender), 6);

// Assert recipient balance is 4
assert_eq!(client.get_key_balance(&creator, &recipient), 4);

// Assert total supply is unchanged (still 10)
assert_eq!(client.get_total_key_supply(&creator), 10);
}

// --- Max supply cap tests (#394) ---

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"void",
"void",
"void",
"void",
"void"
]
}
Expand Down Expand Up @@ -178,7 +179,52 @@
},
"ext": "v0"
},
4095
6311520
]
],
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "CreatorTtlLiveUntil"
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
},
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "CreatorTtlLiveUntil"
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
},
"durability": "persistent",
"val": {
"u32": 6311520
}
}
},
"ext": "v0"
},
6311520
]
],
[
Expand Down Expand Up @@ -223,7 +269,7 @@
},
"ext": "v0"
},
4095
6311520
]
],
[
Expand Down Expand Up @@ -265,7 +311,7 @@
},
"ext": "v0"
},
4095
6311520
]
],
[
Expand Down
Loading
Loading