@@ -3,6 +3,7 @@ use snforge_std::{
3
3
DeclareResultTrait , spy_events, EventSpyAssertionsTrait , get_class_hash
4
4
};
5
5
6
+
6
7
use openzeppelin :: token :: erc20 :: interface :: {IERC20Dispatcher , IERC20DispatcherTrait };
7
8
8
9
use starknet :: {ContractAddress , ClassHash , get_block_timestamp};
@@ -13,7 +14,9 @@ use tokengiver::interfaces::ICampaignPool::{
13
14
use tokengiver :: interfaces :: ITokenGiverNft :: {
14
15
ITokenGiverNftDispatcher , ITokenGiverNftDispatcherTrait
15
16
};
16
- use tokengiver :: campaign_pool :: CampaignPools :: {Event , DonationMade , CreateCampaignPool };
17
+ use tokengiver :: campaign_pool :: CampaignPools :: {
18
+ Event , DonationMade , CreateCampaignPool , ApplicationMade
19
+ };
17
20
use token_bound_accounts :: interfaces :: ILockable :: {ILockableDispatcher , ILockableDispatcherTrait };
18
21
19
22
fn REGISTRY_HASH () -> felt252 {
@@ -130,7 +133,7 @@ fn test_create_campaign_pool() {
130
133
131
134
132
135
#[test]
133
- #[fork(" Mainnet " )]
136
+ #[fork(" SEPOLIA_LATEST " )]
134
137
fn test_create_campaign_pool_event_emission () {
135
138
// Get the initial setup
136
139
let (token_giver_address , _ , nft_address ) = __setup__ ();
@@ -172,3 +175,150 @@ fn test_create_campaign_pool_event_emission() {
172
175
);
173
176
// spy.assert_emitted(@array![(token_giver.contract_address, expected_event)]);
174
177
}
178
+ #[test]
179
+ #[fork(" SEPOLIA_LATEST" )]
180
+ fn test_apply_to_campaign_pool_success () {
181
+ // Set up a campaign pool and a campaign
182
+ let (token_giver_address , strk_address , nft_address ) = __setup__ ();
183
+ let token_giver = ICampaignPoolDispatcher { contract_address : token_giver_address };
184
+ let mut spy = spy_events ();
185
+
186
+ // Create the required parameters for campaign pool
187
+ let registry_hash = REGISTRY_HASH ();
188
+ let implementation_hash = IMPLEMENTATION_HASH ();
189
+ let salt : felt252 = SALT ();
190
+ let recipient : ContractAddress = RECIPIENT ();
191
+ let campaign_id : u256 = 10 ;
192
+ let pool_id : u256 = 11 ;
193
+
194
+ // Create campaign pool
195
+ start_cheat_caller_address (token_giver_address , recipient );
196
+ let campaign_pool_address = token_giver
197
+ . create_campaign_pool (registry_hash , implementation_hash , salt , recipient , pool_id );
198
+
199
+ // Create campaign with different salt
200
+ let campaign_salt : felt252 = ' campaign_salt' ;
201
+ let campaign_address = token_giver
202
+ . create_campaign_pool (
203
+ registry_hash , implementation_hash , campaign_salt , recipient , campaign_id
204
+ );
205
+ stop_cheat_caller_address (token_giver_address );
206
+
207
+ // Amount to request
208
+ let amount : u256 = 100 ;
209
+
210
+ // Apply to campaign pool
211
+ start_cheat_caller_address (token_giver_address , recipient );
212
+ token_giver . apply_to_campaign_pool (campaign_address , campaign_pool_address , amount );
213
+ stop_cheat_caller_address (token_giver_address );
214
+
215
+ // Verify application was stored correctly
216
+ start_cheat_caller_address (token_giver_address , recipient );
217
+ let (stored_pool , stored_amount ) = token_giver . get_campaign_application (campaign_address );
218
+ stop_cheat_caller_address (token_giver_address );
219
+
220
+ assert (stored_pool == campaign_pool_address , ' Wrong pool address stored' );
221
+ assert (stored_amount == amount , ' Wrong amount stored' );
222
+
223
+ // Check event emission
224
+ let expected_event = Event :: ApplicationMade (
225
+ ApplicationMade {
226
+ campaign_pool_address : campaign_pool_address ,
227
+ campaign_address : campaign_address ,
228
+ recipient : recipient ,
229
+ amount : amount ,
230
+ block_timestamp : get_block_timestamp (),
231
+ }
232
+ );
233
+
234
+ spy . assert_emitted (@ array! [(token_giver . contract_address, expected_event )]);
235
+ }
236
+
237
+ #[test]
238
+ #[fork(" Mainnet" )]
239
+ #[should_panic(expected: (' TGN: invalid campaign address!' ,))]
240
+ fn test_apply_with_invalid_campaign_address () {
241
+ // Set up a campaign pool
242
+ let (token_giver_address , _ , _ ) = __setup__ ();
243
+ let token_giver = ICampaignPoolDispatcher { contract_address : token_giver_address };
244
+
245
+ let registry_hash = REGISTRY_HASH ();
246
+ let implementation_hash = IMPLEMENTATION_HASH ();
247
+ let salt : felt252 = SALT ();
248
+ let recipient : ContractAddress = RECIPIENT ();
249
+ let pool_id : u256 = 12 ;
250
+
251
+ // Create campaign pool
252
+ start_cheat_caller_address (token_giver_address , recipient );
253
+ let campaign_pool_address = token_giver
254
+ . create_campaign_pool (registry_hash , implementation_hash , salt , recipient , pool_id );
255
+ stop_cheat_caller_address (token_giver_address );
256
+
257
+ // Use an invalid campaign address
258
+ let invalid_campaign_address : ContractAddress = starknet :: contract_address_const :: <0x123 >();
259
+ let amount : u256 = 100 ;
260
+
261
+ // This should panic with "TGN: invalid campaign address!"
262
+ start_cheat_caller_address (token_giver_address , recipient );
263
+ token_giver . apply_to_campaign_pool (invalid_campaign_address , campaign_pool_address , amount );
264
+ stop_cheat_caller_address (token_giver_address );
265
+ }
266
+
267
+ #[test]
268
+ #[fork(" Mainnet" )]
269
+ #[should_panic(expected: (' TGN: invalid pool address!' ,))]
270
+ fn test_apply_with_invalid_pool_address () {
271
+ // Set up a campaign
272
+ let (token_giver_address , _ , _ ) = __setup__ ();
273
+ let token_giver = ICampaignPoolDispatcher { contract_address : token_giver_address };
274
+
275
+ let registry_hash = REGISTRY_HASH ();
276
+ let implementation_hash = IMPLEMENTATION_HASH ();
277
+ let salt : felt252 = SALT ();
278
+ let recipient : ContractAddress = RECIPIENT ();
279
+ let campaign_id : u256 = 13 ;
280
+
281
+ // Create campaign
282
+ start_cheat_caller_address (token_giver_address , recipient );
283
+ let campaign_address = token_giver
284
+ . create_campaign_pool (registry_hash , implementation_hash , salt , recipient , campaign_id );
285
+ stop_cheat_caller_address (token_giver_address );
286
+
287
+ // Use an invalid pool address
288
+ let invalid_pool_address : ContractAddress = starknet :: contract_address_const :: <0x456 >();
289
+ let amount : u256 = 100 ;
290
+
291
+ // This should panic with "TGN: invalid pool address!"
292
+ start_cheat_caller_address (token_giver_address , recipient );
293
+ token_giver . apply_to_campaign_pool (campaign_address , invalid_pool_address , amount );
294
+ stop_cheat_caller_address (token_giver_address );
295
+ }
296
+
297
+ #[test]
298
+ #[fork(" Mainnet" )]
299
+ #[should_panic(expected: (' TGN: invalid amount!' ,))]
300
+ fn test_apply_with_zero_amount () {
301
+ // Set up a campaign pool and a campaign
302
+ let (token_giver_address , _ , _ ) = __setup__ ();
303
+ let token_giver = ICampaignPoolDispatcher { contract_address : token_giver_address };
304
+
305
+ let registry_hash = REGISTRY_HASH ();
306
+ let implementation_hash = IMPLEMENTATION_HASH ();
307
+ let salt1 : felt252 = ' salt1' ;
308
+ let salt2 : felt252 = ' salt2' ;
309
+ let recipient : ContractAddress = RECIPIENT ();
310
+ let campaign_id : u256 = 14 ;
311
+ let pool_id : u256 = 15 ;
312
+
313
+ // Create campaign pool and campaign
314
+ start_cheat_caller_address (token_giver_address , recipient );
315
+ let campaign_pool_address = token_giver
316
+ . create_campaign_pool (registry_hash , implementation_hash , salt1 , recipient , pool_id );
317
+ let campaign_address = token_giver
318
+ . create_campaign_pool (registry_hash , implementation_hash , salt2 , recipient , campaign_id );
319
+
320
+ // Try to apply with zero amount, should fail
321
+ let zero_amount : u256 = 0 ;
322
+ token_giver . apply_to_campaign_pool (campaign_address , campaign_pool_address , zero_amount );
323
+ stop_cheat_caller_address (token_giver_address );
324
+ }
0 commit comments