@@ -9,7 +9,7 @@ const VALIDATOR_ROLE: felt252 = selector!("VALIDATOR_ROLE");
99const POOL_CREATOR : ContractAddress = 123. try_into (). unwrap ();
1010const USER_ONE : ContractAddress = ' User1' . try_into (). unwrap ();
1111const ONE_STRK : u256 = 1_000_000_000_000_000_000 ;
12- use super :: test_utils :: {approve_tokens_for_payment, create_default_pool, deploy_predifi};
12+ use super :: test_utils :: {approve_tokens_for_payment, create_default_pool, deploy_predifi, mint_tokens_for };
1313
1414/// @notice Gas benchmarking tests for optimized storage operations
1515/// @dev These tests measure gas consumption of optimized functions to ensure efficiency
@@ -30,6 +30,7 @@ fn test_vote_function_gas_optimization() {
3030
3131 // Setup user with tokens
3232 start_cheat_caller_address (erc20_address , USER_ONE );
33+ mint_tokens_for (USER_ONE , erc20_address , ONE_STRK * 1000 );
3334 approve_tokens_for_payment (contract . contract_address, erc20_address , ONE_STRK * 1000 );
3435 stop_cheat_caller_address (erc20_address );
3536
@@ -39,12 +40,12 @@ fn test_vote_function_gas_optimization() {
3940 start_cheat_caller_address (contract . contract_address, USER_ONE );
4041
4142 // Execute vote function (without gas metering since it's not available in this version)
42- contract . vote (pool_id , ' Team A' , ONE_STRK );
43+ contract . vote (pool_id , ' Team A' , 1000 );
4344
44- // Verify the vote was successful by checking pool state
45+ // Verify the vote was successful by checking pool state
4546 let pool = contract . get_pool (pool_id );
46- assert (pool . totalBetCount == 1 , ' Vote should have been recorded' );
47- assert (pool . totalStakeOption1 == ONE_STRK , ' Stake should be recorded correctly ' );
47+ assert (pool . totalBetCount == 1 , ' Vote not recorded' );
48+ assert (pool . totalStakeOption1 == 1000 , ' Stake incorrect ' );
4849}
4950
5051#[test]
@@ -63,17 +64,18 @@ fn test_stake_function_gas_optimization() {
6364
6465 // Setup user with tokens
6566 start_cheat_caller_address (erc20_address , USER_ONE );
67+ mint_tokens_for (USER_ONE , erc20_address , ONE_STRK * 1000 );
6668 approve_tokens_for_payment (contract . contract_address, erc20_address , ONE_STRK * 1000 );
6769 stop_cheat_caller_address (erc20_address );
6870
6971 start_cheat_caller_address (contract . contract_address, USER_ONE );
7072
7173 // Execute stake function
72- contract . stake (pool_id , ONE_STRK * 200 );
74+ contract . stake (pool_id , 200_000_000_000_000_000_000 );
7375
74- // Verify the stake was successful
76+ // Verify the stake was successful
7577 let user_stake = contract . get_user_stake (pool_id , USER_ONE );
76- assert (user_stake . amount == ONE_STRK * 200 , ' Stake should be recorded correctly ' );
78+ assert (user_stake . amount == 200_000_000_000_000_000_000 , ' Stake amount wrong ' );
7779}
7880
7981#[test]
@@ -130,12 +132,13 @@ fn test_emergency_withdraw_gas_optimization() {
130132
131133 // Setup user with tokens and make them participate
132134 start_cheat_caller_address (erc20_address , USER_ONE );
135+ mint_tokens_for (USER_ONE , erc20_address , ONE_STRK * 1000 );
133136 approve_tokens_for_payment (contract . contract_address, erc20_address , ONE_STRK * 1000 );
134137 stop_cheat_caller_address (erc20_address );
135138
136139 start_cheat_block_timestamp (contract . contract_address, 1710000001 );
137140 start_cheat_caller_address (contract . contract_address, USER_ONE );
138- contract . vote (pool_id , ' Team A' , ONE_STRK );
141+ contract . vote (pool_id , ' Team A' , 1000 );
139142
140143 // Simulate emergency state (this would normally be done by admin)
141144 // For testing purposes, we'll assume emergency state is set
@@ -161,20 +164,21 @@ fn test_multiple_votes_gas_comparison() {
161164
162165 // Setup user with tokens
163166 start_cheat_caller_address (erc20_address , USER_ONE );
167+ mint_tokens_for (USER_ONE , erc20_address , ONE_STRK * 10000 );
164168 approve_tokens_for_payment (contract . contract_address, erc20_address , ONE_STRK * 10000 );
165169 stop_cheat_caller_address (erc20_address );
166170
167171 start_cheat_block_timestamp (contract . contract_address, 1710000001 );
168172 start_cheat_caller_address (contract . contract_address, USER_ONE );
169173
170174 // Execute multiple votes to test cumulative gas efficiency
171- contract . vote (pool_id , ' Team A' , ONE_STRK );
172- contract . vote (pool_id , ' Team B' , ONE_STRK * 2 );
173- contract . vote (pool_id , ' Team A' , ONE_STRK * 3 );
175+ contract . vote (pool_id , ' Team A' , 1000 );
176+ contract . vote (pool_id , ' Team B' , 2000 );
177+ contract . vote (pool_id , ' Team A' , 3000 );
174178
175179 // Verify final state
176180 let pool = contract . get_pool (pool_id );
177181 assert (pool . totalBetCount == 3 , ' Should have 3 bets' );
178- assert (pool . totalStakeOption1 == ONE_STRK + ONE_STRK * 3 , ' Option 1 stake should be correct ' );
179- assert (pool . totalStakeOption2 == ONE_STRK * 2 , ' Option 2 stake should be correct ' );
182+ assert (pool . totalStakeOption1 == 1000 + 3000 , ' Option1 stake wrong ' );
183+ assert (pool . totalStakeOption2 == 2000 , ' Option2 stake wrong ' );
180184}
0 commit comments