Skip to content

Commit f291543

Browse files
tekkactekkac
authored andcommitted
🧪 update tests
1 parent ad75d54 commit f291543

File tree

7 files changed

+128
-172
lines changed

7 files changed

+128
-172
lines changed

‎tests/test_merkle_tree.cairo‎

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
use starknet::{ContractAddress, contract_address_const};
2-
use snforge_std as snf;
3-
use snforge_std::{
4-
ContractClassTrait, spy_events, EventSpy, start_cheat_caller_address, stop_cheat_caller_address,
5-
EventSpyAssertionsTrait
6-
};
2+
use snforge_std::{start_cheat_caller_address};
73

84
// Contracts
95
use carbon_v3::components::offsetter::interface::{
106
IOffsetHandlerDispatcher, IOffsetHandlerDispatcherTrait
117
};
12-
use carbon_v3::components::offsetter::OffsetComponent;
138

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

1712
/// Utils to import mock data
1813
use super::tests_lib::{
19-
MERKLE_ROOT_FIRST_WAVE, MERKLE_ROOT_SECOND_WAVE, get_bob_first_wave_allocation,
20-
get_bob_second_wave_allocation, get_alice_second_wave_allocation, get_john_multiple_allocations
14+
MERKLE_ROOT_FIRST_WAVE, get_bob_first_wave_allocation, get_bob_second_wave_allocation,
15+
get_alice_second_wave_allocation, get_john_multiple_allocations
2116
};
2217

2318
#[test]
@@ -66,7 +61,7 @@ fn test_bob_claims_single_allocation() {
6661
start_cheat_caller_address(offsetter_address, bob_address);
6762
assert_eq!(contract.get_merkle_root(), root);
6863

69-
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, proof));
64+
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, proof));
7065
}
7166

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

86-
assert!(!contract.confirm_for_merkle_tree(invalid_address, amount, timestamp, id, proof));
81+
assert!(!contract.confirm_for_merkle_tree(invalid_address, amount, timestamp, 1, id, proof));
8782
}
8883

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

103-
assert!(!contract.confirm_for_merkle_tree(bob_address, invalid_amount, timestamp, id, proof));
98+
assert!(
99+
!contract.confirm_for_merkle_tree(bob_address, invalid_amount, timestamp, 1, id, proof)
100+
);
104101
}
105102

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

120-
assert!(!contract.confirm_for_merkle_tree(bob_address, amount, invalid_timestamp, id, proof));
117+
assert!(
118+
!contract.confirm_for_merkle_tree(bob_address, amount, invalid_timestamp, 1, id, proof)
119+
);
121120
}
122121

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

137-
assert!(!contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, invalid_proof));
136+
assert!(
137+
!contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, invalid_proof)
138+
);
138139
}
139140

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

150151
start_cheat_caller_address(offsetter_address, owner_address);
151152
contract.set_merkle_root(root);
152-
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
153+
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));
153154

154155
let (new_root, _, _, _, _, new_proof) = get_bob_second_wave_allocation();
155156
contract.set_merkle_root(new_root);
156-
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
157+
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));
157158

158-
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, new_proof));
159+
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, new_proof));
159160
}
160161

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

171172
start_cheat_caller_address(offsetter_address, owner_address);
172173
contract.set_merkle_root(root);
173-
assert!(!contract.check_claimed(bob_address, timestamp, amount, id));
174+
assert!(!contract.check_claimed(bob_address, timestamp, amount, 1, id));
174175

175-
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, id, proof));
176+
assert!(contract.confirm_for_merkle_tree(bob_address, amount, timestamp, 1, id, proof));
176177

177178
let (new_root, alice_address, amount, timestamp, id, proof) =
178179
get_alice_second_wave_allocation();
179180
start_cheat_caller_address(offsetter_address, owner_address);
180181
contract.set_merkle_root(new_root);
181-
assert!(!contract.check_claimed(alice_address, timestamp, amount, id));
182+
assert!(!contract.check_claimed(alice_address, timestamp, amount, 1, id));
182183

183-
assert!(contract.confirm_for_merkle_tree(alice_address, amount, timestamp, id, proof));
184+
assert!(contract.confirm_for_merkle_tree(alice_address, amount, timestamp, 1, id, proof));
184185
}
185186

186187
#[test]
@@ -217,15 +218,15 @@ fn test_john_claims_multiple_allocations() {
217218

218219
start_cheat_caller_address(offsetter_address, owner_address);
219220
contract.set_merkle_root(root);
220-
assert!(!contract.check_claimed(john_address, timestamp1, amount1, id_1));
221-
assert!(!contract.check_claimed(john_address, timestamp2, amount2, id_2));
222-
assert!(!contract.check_claimed(john_address, timestamp3, amount3, id_3));
221+
assert!(!contract.check_claimed(john_address, timestamp1, amount1, 1, id_1));
222+
assert!(!contract.check_claimed(john_address, timestamp2, amount2, 1, id_2));
223+
assert!(!contract.check_claimed(john_address, timestamp3, amount3, 1, id_3));
223224

224-
assert!(contract.confirm_for_merkle_tree(john_address, amount1, timestamp1, id_1, proof1));
225-
assert!(contract.confirm_for_merkle_tree(john_address, amount2, timestamp2, id_2, proof2));
225+
assert!(contract.confirm_for_merkle_tree(john_address, amount1, timestamp1, 1, id_1, proof1));
226+
assert!(contract.confirm_for_merkle_tree(john_address, amount2, timestamp2, 1, id_2, proof2));
226227

227228
start_cheat_caller_address(offsetter_address, owner_address);
228229
contract.set_merkle_root(new_root);
229230

230-
assert!(contract.confirm_for_merkle_tree(john_address, amount4, timestamp4, id_4, proof4));
231+
assert!(contract.confirm_for_merkle_tree(john_address, amount4, timestamp4, 1, id_4, proof4));
231232
}

‎tests/test_mint.cairo‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,44 @@
1+
use core::num::traits::Zero;
2+
13
// Starknet deps
24

35
use starknet::{ContractAddress, contract_address_const};
46

57
// External deps
68

79
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
8-
use openzeppelin::token::erc20::interface::ERC20ABIDispatcherTrait;
9-
use openzeppelin::token::erc1155::ERC1155Component;
1010

1111
use snforge_std as snf;
1212
use snforge_std::{
13-
ContractClassTrait, DeclareResultTrait, test_address, spy_events, EventSpy, CheatSpan,
14-
start_cheat_caller_address, stop_cheat_caller_address, EventSpyAssertionsTrait
13+
ContractClassTrait, DeclareResultTrait, spy_events, start_cheat_caller_address,
14+
stop_cheat_caller_address, EventSpyAssertionsTrait
1515
};
1616

1717
// Components
1818

1919
use carbon_v3::components::vintage::interface::{IVintageDispatcher, IVintageDispatcherTrait};
20-
use carbon_v3::components::vintage::VintageComponent;
2120
use carbon_v3::components::minter::interface::{IMintDispatcher, IMintDispatcherTrait};
22-
use carbon_v3::components::minter::MintComponent;
21+
use carbon_v3::components::minter::mint::MintComponent;
2322

2423
// Contracts
2524

2625
use carbon_v3::contracts::project::{
27-
Project, IExternalDispatcher as IProjectDispatcher,
28-
IExternalDispatcherTrait as IProjectDispatcherTrait
26+
IExternalDispatcher as IProjectDispatcher, IExternalDispatcherTrait as IProjectDispatcherTrait
2927
};
30-
use carbon_v3::contracts::minter::Minter;
31-
use carbon_v3::mock::usdcarb::USDCarb;
3228

3329
// Utils for testing purposes
3430

3531
use super::tests_lib::{
3632
get_mock_absorptions, equals_with_error, deploy_project, setup_project,
37-
default_setup_and_deploy, deploy_offsetter, deploy_erc20, deploy_minter, buy_utils,
38-
helper_get_token_ids, helper_sum_balance, DEFAULT_REMAINING_MINTABLE_CC,
39-
helper_check_vintage_balances, get_mock_absorptions_times_2, helper_expected_transfer_event,
40-
helper_expected_transfer_single_events, helper_get_cc_amounts
33+
default_setup_and_deploy, deploy_erc20, deploy_minter, buy_utils, helper_get_token_ids,
34+
helper_sum_balance, helper_check_vintage_balances, get_mock_absorptions_times_2,
35+
helper_expected_transfer_single_events, DEFAULT_REMAINING_MINTABLE_CC
4136
};
4237

4338
// Constants
4439

45-
use carbon_v3::models::constants::{MULTIPLIER_TONS_TO_MGRAMS};
40+
use carbon_v3::constants::MULTIPLIER_TONS_TO_MGRAMS;
41+
4642
const PROJECT_CARBON: u256 = 42;
4743

4844
// Signers
@@ -267,7 +263,7 @@ fn test_public_buy() {
267263
// };
268264

269265
let expected_events = helper_expected_transfer_single_events(
270-
project_address, minter_address, Zeroable::zero(), user_address, token_ids, cc_to_buy
266+
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
271267
);
272268
spy.assert_emitted(@expected_events);
273269

@@ -313,7 +309,7 @@ fn test_minimal_buy() {
313309
let token_ids = helper_get_token_ids(project_address);
314310

315311
let expected_events = helper_expected_transfer_single_events(
316-
project_address, minter_address, Zeroable::zero(), user_address, token_ids, cc_to_buy
312+
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
317313
);
318314
spy.assert_emitted(@expected_events);
319315
}
@@ -356,7 +352,7 @@ fn test_minimal_buy_error() {
356352
let token_ids = helper_get_token_ids(project_address);
357353

358354
let expected_events = helper_expected_transfer_single_events(
359-
project_address, minter_address, Zeroable::zero(), user_address, token_ids, cc_to_buy
355+
project_address, minter_address, Zero::zero(), user_address, token_ids, cc_to_buy
360356
);
361357
spy.assert_emitted(@expected_events);
362358
}

0 commit comments

Comments
 (0)