Skip to content

Commit 7a5f14f

Browse files
committed
test nft mint after test completed edgecase
1 parent e6052a8 commit 7a5f14f

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/test_weaver_contract.cairo

+60
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,66 @@ fn test_mint_nft_task_not_completed_should_panic() {
282282
println!("Mint function did not panic!");
283283
}
284284

285+
#[test]
286+
fn test_mint_nft_after_task_completed() {
287+
// Set up the contracts
288+
let (weaver_contract_address, nft_address) = __setup__();
289+
let weaver_contract = IWeaverDispatcher { contract_address: weaver_contract_address };
290+
let nft_dispatcher = IWeaverNFTDispatcher { contract_address: nft_address };
291+
292+
// Define the user address
293+
let user: ContractAddress = USER();
294+
295+
// Start the contract as the user
296+
start_cheat_caller_address(weaver_contract_address, user);
297+
298+
// Register the user
299+
let details: ByteArray = "Test User";
300+
weaver_contract.register_User(details);
301+
302+
// Verify user registration
303+
let is_registered = weaver_contract.get_register_user(user);
304+
assert!(is_registered.Details == "Test User", "User should be registered");
305+
306+
// Register the protocol
307+
let protocol_name: ByteArray = "Weaver Protocol";
308+
weaver_contract.protocol_register(protocol_name);
309+
310+
// Verify protocol registration
311+
let protocol_info = weaver_contract.get_registered_protocols(user);
312+
assert!(protocol_info.protocol_name == "Weaver Protocol", "Protocol should be registered");
313+
314+
// Define the task ID to mint
315+
let task_id = 1;
316+
317+
// Retrieve and mark the task as completed
318+
let mut task_info = weaver_contract.get_task_info(task_id);
319+
task_info.is_completed = true;
320+
321+
// Ensure task is completed
322+
assert!(task_info.is_completed, "Task should be completed");
323+
324+
// Now, mint the NFT for the task
325+
weaver_contract.mint(task_id);
326+
327+
// Get the minted token ID for the user
328+
let minted_token_id = nft_dispatcher.get_user_token_id(user);
329+
assert!(minted_token_id > 0, "NFT NOT Minted!");
330+
331+
// Ensure that the minted token ID matches the last minted ID
332+
let last_minted_id = nft_dispatcher.get_last_minted_id();
333+
assert_eq!(minted_token_id, last_minted_id, "Minted token ID should match the last minted ID");
334+
335+
// Ensure the mint timestamp is correct
336+
let mint_timestamp = nft_dispatcher.get_token_mint_timestamp(minted_token_id);
337+
let current_block_timestamp = get_block_timestamp();
338+
assert_eq!(mint_timestamp, current_block_timestamp, "Mint timestamp does not match");
339+
340+
// Stop the contract after the test
341+
stop_cheat_caller_address(weaver_contract_address);
342+
}
343+
344+
285345
#[test]
286346
#[should_panic(expected: 'TASK_ALREADY_EXISTS')]
287347
fn test_mint_task_already_exists() {

0 commit comments

Comments
 (0)