From 933f7fc1109add40f8f9aa947b618e5e28b25a4e Mon Sep 17 00:00:00 2001 From: gordons Date: Fri, 31 Jan 2025 17:56:54 +0100 Subject: [PATCH 1/3] test --- .github/workflows/test_contract.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_contract.yml b/.github/workflows/test_contract.yml index 0fb2a15..b6f56ed 100644 --- a/.github/workflows/test_contract.yml +++ b/.github/workflows/test_contract.yml @@ -1,6 +1,13 @@ name: Test -on: [push, pull_request] +on: + push: + branches: + - main # or the branch you want to monitor for commits + pull_request: + branches: + - main # or the branch for which you want PR testing + # Optional: Add on: [commit] to test specifically on commit permissions: read-all jobs: From e6052a82fa111b2dde63f5622e55f1992559c9b8 Mon Sep 17 00:00:00 2001 From: gordons Date: Fri, 31 Jan 2025 18:07:11 +0100 Subject: [PATCH 2/3] a comment --- tests/test_weaver_contract.cairo | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_weaver_contract.cairo b/tests/test_weaver_contract.cairo index dbc1458..d0d677f 100644 --- a/tests/test_weaver_contract.cairo +++ b/tests/test_weaver_contract.cairo @@ -308,4 +308,6 @@ fn test_mint_task_already_exists() { weaver_contract.mint(task_id); stop_cheat_caller_address(weaver_contract_address); -} \ No newline at end of file +} + +// This is a comment \ No newline at end of file From 7a5f14f1186cdf594e62a5c32a8f162b66f2a5a2 Mon Sep 17 00:00:00 2001 From: gordons Date: Fri, 31 Jan 2025 18:25:44 +0100 Subject: [PATCH 3/3] test nft mint after test completed edgecase --- tests/test_weaver_contract.cairo | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/test_weaver_contract.cairo b/tests/test_weaver_contract.cairo index d0d677f..b5d0811 100644 --- a/tests/test_weaver_contract.cairo +++ b/tests/test_weaver_contract.cairo @@ -282,6 +282,66 @@ fn test_mint_nft_task_not_completed_should_panic() { println!("Mint function did not panic!"); } +#[test] +fn test_mint_nft_after_task_completed() { + // Set up the contracts + let (weaver_contract_address, nft_address) = __setup__(); + let weaver_contract = IWeaverDispatcher { contract_address: weaver_contract_address }; + let nft_dispatcher = IWeaverNFTDispatcher { contract_address: nft_address }; + + // Define the user address + let user: ContractAddress = USER(); + + // Start the contract as the user + start_cheat_caller_address(weaver_contract_address, user); + + // Register the user + let details: ByteArray = "Test User"; + weaver_contract.register_User(details); + + // Verify user registration + let is_registered = weaver_contract.get_register_user(user); + assert!(is_registered.Details == "Test User", "User should be registered"); + + // Register the protocol + let protocol_name: ByteArray = "Weaver Protocol"; + weaver_contract.protocol_register(protocol_name); + + // Verify protocol registration + let protocol_info = weaver_contract.get_registered_protocols(user); + assert!(protocol_info.protocol_name == "Weaver Protocol", "Protocol should be registered"); + + // Define the task ID to mint + let task_id = 1; + + // Retrieve and mark the task as completed + let mut task_info = weaver_contract.get_task_info(task_id); + task_info.is_completed = true; + + // Ensure task is completed + assert!(task_info.is_completed, "Task should be completed"); + + // Now, mint the NFT for the task + weaver_contract.mint(task_id); + + // Get the minted token ID for the user + let minted_token_id = nft_dispatcher.get_user_token_id(user); + assert!(minted_token_id > 0, "NFT NOT Minted!"); + + // Ensure that the minted token ID matches the last minted ID + let last_minted_id = nft_dispatcher.get_last_minted_id(); + assert_eq!(minted_token_id, last_minted_id, "Minted token ID should match the last minted ID"); + + // Ensure the mint timestamp is correct + let mint_timestamp = nft_dispatcher.get_token_mint_timestamp(minted_token_id); + let current_block_timestamp = get_block_timestamp(); + assert_eq!(mint_timestamp, current_block_timestamp, "Mint timestamp does not match"); + + // Stop the contract after the test + stop_cheat_caller_address(weaver_contract_address); +} + + #[test] #[should_panic(expected: 'TASK_ALREADY_EXISTS')] fn test_mint_task_already_exists() {