Skip to content

Commit

Permalink
🧪 update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkac committed Dec 6, 2024
1 parent ad75d54 commit f291543
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 172 deletions.
61 changes: 31 additions & 30 deletions tests/test_merkle_tree.cairo
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
use starknet::{ContractAddress, contract_address_const};
use snforge_std as snf;
use snforge_std::{
ContractClassTrait, spy_events, EventSpy, start_cheat_caller_address, stop_cheat_caller_address,
EventSpyAssertionsTrait
};
use snforge_std::{start_cheat_caller_address};

// Contracts
use carbon_v3::components::offsetter::interface::{
IOffsetHandlerDispatcher, IOffsetHandlerDispatcherTrait
};
use carbon_v3::components::offsetter::OffsetComponent;

/// Utils for testing purposes
use super::tests_lib::{default_setup_and_deploy, deploy_offsetter};

/// Utils to import mock data
use super::tests_lib::{
MERKLE_ROOT_FIRST_WAVE, MERKLE_ROOT_SECOND_WAVE, get_bob_first_wave_allocation,
get_bob_second_wave_allocation, get_alice_second_wave_allocation, get_john_multiple_allocations
MERKLE_ROOT_FIRST_WAVE, get_bob_first_wave_allocation, get_bob_second_wave_allocation,
get_alice_second_wave_allocation, get_john_multiple_allocations
};

#[test]
Expand Down Expand Up @@ -66,7 +61,7 @@ fn test_bob_claims_single_allocation() {
start_cheat_caller_address(offsetter_address, bob_address);
assert_eq!(contract.get_merkle_root(), root);

assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, proof));
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, proof));
}

#[test]
Expand All @@ -81,9 +76,9 @@ fn test_claim_with_invalid_address() {
start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
let invalid_address = contract_address_const::<'DUMMY'>();
assert!(!contract.check_claimed(invalid_address, timestamp, amount, id));
assert!(!contract.check_claimed(invalid_address, timestamp, amount, 1, id));

assert!(!contract.confirm_for_merkle_tree(invalid_address, amount, timestamp, id, proof));
assert!(!contract.confirm_for_merkle_tree(invalid_address, amount, timestamp, 1, id, proof));
}

#[test]
Expand All @@ -98,9 +93,11 @@ fn test_claim_with_invalid_amount() {
start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
let invalid_amount = 0;
assert!(!contract.check_claimed(bob_address, timestamp, invalid_amount, id));
assert!(!contract.check_claimed(bob_address, timestamp, invalid_amount, 1, id));

assert!(!contract.confirm_for_merkle_tree(bob_address, invalid_amount, timestamp, id, proof));
assert!(
!contract.confirm_for_merkle_tree(bob_address, invalid_amount, timestamp, 1, id, proof)
);
}

#[test]
Expand All @@ -115,9 +112,11 @@ fn test_claim_with_invalid_timestamp() {
start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
let invalid_timestamp = 0;
assert!(!contract.check_claimed(bob_address, invalid_timestamp, amount, id));
assert!(!contract.check_claimed(bob_address, invalid_timestamp, amount, 1, id));

assert!(!contract.confirm_for_merkle_tree(bob_address, amount, invalid_timestamp, id, proof));
assert!(
!contract.confirm_for_merkle_tree(bob_address, amount, invalid_timestamp, 1, id, proof)
);
}

#[test]
Expand All @@ -132,9 +131,11 @@ fn test_claim_with_invalid_proof() {
start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
let invalid_proof: Array<felt252> = array![0x123, 0x1];
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));

assert!(!contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, invalid_proof));
assert!(
!contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, invalid_proof)
);
}

#[test]
Expand All @@ -149,13 +150,13 @@ fn test_claim_after_root_update() {

start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));

let (new_root, _, _, _, _, new_proof) = get_bob_second_wave_allocation();
contract.set_merkle_root(new_root);
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));

assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, new_proof));
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, new_proof));
}

#[test]
Expand All @@ -170,17 +171,17 @@ fn test_alice_claims_in_second_wave() {

start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));

assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, proof));
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, proof));

let (new_root, alice_address, amount, timestamp, id, proof) =
get_alice_second_wave_allocation();
start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(new_root);
assert!(!contract.check_claimed(alice_address, timestamp, amount, id));
assert!(!contract.check_claimed(alice_address, timestamp, amount, 1, id));

assert!(contract.confirm_for_merkle_tree(alice_address, amount, timestamp, id, proof));
assert!(contract.confirm_for_merkle_tree(alice_address, amount, timestamp, 1, id, proof));
}

#[test]
Expand Down Expand Up @@ -217,15 +218,15 @@ fn test_john_claims_multiple_allocations() {

start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(root);
assert!(!contract.check_claimed(john_address, timestamp1, amount1, id_1));
assert!(!contract.check_claimed(john_address, timestamp2, amount2, id_2));
assert!(!contract.check_claimed(john_address, timestamp3, amount3, id_3));
assert!(!contract.check_claimed(john_address, timestamp1, amount1, 1, id_1));
assert!(!contract.check_claimed(john_address, timestamp2, amount2, 1, id_2));
assert!(!contract.check_claimed(john_address, timestamp3, amount3, 1, id_3));

assert!(contract.confirm_for_merkle_tree(john_address, amount1, timestamp1, id_1, proof1));
assert!(contract.confirm_for_merkle_tree(john_address, amount2, timestamp2, id_2, proof2));
assert!(contract.confirm_for_merkle_tree(john_address, amount1, timestamp1, 1, id_1, proof1));
assert!(contract.confirm_for_merkle_tree(john_address, amount2, timestamp2, 1, id_2, proof2));

start_cheat_caller_address(offsetter_address, owner_address);
contract.set_merkle_root(new_root);

assert!(contract.confirm_for_merkle_tree(john_address, amount4, timestamp4, id_4, proof4));
assert!(contract.confirm_for_merkle_tree(john_address, amount4, timestamp4, 1, id_4, proof4));
}
32 changes: 14 additions & 18 deletions tests/test_mint.cairo
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
use core::num::traits::Zero;

// Starknet deps

use starknet::{ContractAddress, contract_address_const};

// External deps

use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use openzeppelin::token::erc20::interface::ERC20ABIDispatcherTrait;
use openzeppelin::token::erc1155::ERC1155Component;

use snforge_std as snf;
use snforge_std::{
ContractClassTrait, DeclareResultTrait, test_address, spy_events, EventSpy, CheatSpan,
start_cheat_caller_address, stop_cheat_caller_address, EventSpyAssertionsTrait
ContractClassTrait, DeclareResultTrait, spy_events, start_cheat_caller_address,
stop_cheat_caller_address, EventSpyAssertionsTrait
};

// Components

use carbon_v3::components::vintage::interface::{IVintageDispatcher, IVintageDispatcherTrait};
use carbon_v3::components::vintage::VintageComponent;
use carbon_v3::components::minter::interface::{IMintDispatcher, IMintDispatcherTrait};
use carbon_v3::components::minter::MintComponent;
use carbon_v3::components::minter::mint::MintComponent;

// Contracts

use carbon_v3::contracts::project::{
Project, IExternalDispatcher as IProjectDispatcher,
IExternalDispatcherTrait as IProjectDispatcherTrait
IExternalDispatcher as IProjectDispatcher, IExternalDispatcherTrait as IProjectDispatcherTrait
};
use carbon_v3::contracts::minter::Minter;
use carbon_v3::mock::usdcarb::USDCarb;

// Utils for testing purposes

use super::tests_lib::{
get_mock_absorptions, equals_with_error, deploy_project, setup_project,
default_setup_and_deploy, deploy_offsetter, deploy_erc20, deploy_minter, buy_utils,
helper_get_token_ids, helper_sum_balance, DEFAULT_REMAINING_MINTABLE_CC,
helper_check_vintage_balances, get_mock_absorptions_times_2, helper_expected_transfer_event,
helper_expected_transfer_single_events, helper_get_cc_amounts
default_setup_and_deploy, deploy_erc20, deploy_minter, buy_utils, helper_get_token_ids,
helper_sum_balance, helper_check_vintage_balances, get_mock_absorptions_times_2,
helper_expected_transfer_single_events, DEFAULT_REMAINING_MINTABLE_CC
};

// Constants

use carbon_v3::models::constants::{MULTIPLIER_TONS_TO_MGRAMS};
use carbon_v3::constants::MULTIPLIER_TONS_TO_MGRAMS;

const PROJECT_CARBON: u256 = 42;

// Signers
Expand Down Expand Up @@ -267,7 +263,7 @@ fn test_public_buy() {
// };

let expected_events = helper_expected_transfer_single_events(
project_address, minter_address, Zeroable::zero(), user_address, token_ids, cc_to_buy
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
);
spy.assert_emitted(@expected_events);

Expand Down Expand Up @@ -313,7 +309,7 @@ fn test_minimal_buy() {
let token_ids = helper_get_token_ids(project_address);

let expected_events = helper_expected_transfer_single_events(
project_address, minter_address, Zeroable::zero(), user_address, token_ids, cc_to_buy
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
);
spy.assert_emitted(@expected_events);
}
Expand Down Expand Up @@ -356,7 +352,7 @@ fn test_minimal_buy_error() {
let token_ids = helper_get_token_ids(project_address);

let expected_events = helper_expected_transfer_single_events(
project_address, minter_address, Zeroable::zero(), user_address, token_ids, cc_to_buy
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
);
spy.assert_emitted(@expected_events);
}
Expand Down
Loading

0 comments on commit f291543

Please sign in to comment.