diff --git a/src/staker_test.cairo b/src/staker_test.cairo index 6a61d2a..48d52e4 100644 --- a/src/staker_test.cairo +++ b/src/staker_test.cairo @@ -403,141 +403,141 @@ fn test_delegate_undelegate() { assert(staker.get_delegated_at(delegatee, timestamp: 6) == 0, 'at 6'); } -mod staker_staked_seconds_calculation { - use starknet::{ - get_caller_address - }; - use super::{ - setup, contract_address_const, set_block_timestamp, - IERC20DispatcherTrait, IStakerDispatcherTrait - }; - - #[test] - fn test_should_return_0_if_no_data_found() { - let (staker, _) = setup(10000); - let token_owner = get_caller_address(); - assert(staker.get_staked_seconds_at(token_owner, 0) == 0, 'At 0 should be 0'); - assert(staker.get_staked_seconds_at(token_owner, 1000) == 0, 'At 1000 should be 0'); - } - - #[test] - fn test_should_stake_10000_tokens_for_5_seconds_adding_10000_every_second_to_staked_seconds() { - let (staker, token) = setup(10000); - - // Caller is token owner - let token_owner = get_caller_address(); - - // Allow staker contract to spend 10000 tokens from owner account - token.approve(staker.contract_address, 10000); - - // Adress to delegate tokens to - let delegatee = contract_address_const::<1234567890>(); +// mod staker_staked_seconds_calculation { +// use starknet::{ +// get_caller_address +// }; +// use super::{ +// setup, contract_address_const, set_block_timestamp, +// IERC20DispatcherTrait, IStakerDispatcherTrait +// }; + +// #[test] +// fn test_should_return_0_if_no_data_found() { +// let (staker, _) = setup(10000); +// let token_owner = get_caller_address(); +// assert(staker.get_staked_seconds_at(token_owner, 0) == 0, 'At 0 should be 0'); +// assert(staker.get_staked_seconds_at(token_owner, 1000) == 0, 'At 1000 should be 0'); +// } + +// #[test] +// fn test_should_stake_10000_tokens_for_5_seconds_adding_10000_every_second_to_staked_seconds() { +// let (staker, token) = setup(10000); + +// // Caller is token owner +// let token_owner = get_caller_address(); + +// // Allow staker contract to spend 10000 tokens from owner account +// token.approve(staker.contract_address, 10000); + +// // Adress to delegate tokens to +// let delegatee = contract_address_const::<1234567890>(); - set_block_timestamp(0); - staker.stake(delegatee); // Will transfer 10000 tokens to contract account and setup delegatee +// set_block_timestamp(0); +// staker.stake(delegatee); // Will transfer 10000 tokens to contract account and setup delegatee - set_block_timestamp(5000); // 5 seconds passed +// set_block_timestamp(5000); // 5 seconds passed - assert(staker.get_staked(token_owner, delegatee) == 10000, 'Something went wrong'); +// assert(staker.get_staked(token_owner, delegatee) == 10000, 'Something went wrong'); - staker.withdraw(delegatee, token_owner); // Will withdraw all 10000 tokens back to owner +// staker.withdraw(delegatee, token_owner); // Will withdraw all 10000 tokens back to owner - set_block_timestamp(10000); - assert(staker.get_staked(delegatee, token_owner) == 0, 'Not all tokens were withdrawn'); +// set_block_timestamp(10000); +// assert(staker.get_staked(delegatee, token_owner) == 0, 'Not all tokens were withdrawn'); - assert(staker.get_staked_seconds_at(token_owner, 0) == 0, 'At 0 should be 0'); - assert(staker.get_staked_seconds_at(token_owner, 1000) == 10000, 'At 1s should be 10000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 1100) == 10000, 'At 1.1s should be 10000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 1500) == 10000, 'At 1.5s should be 10000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 1900) == 10000, 'At 1.9s should be 10000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 2000) == 20000, 'At 2s should be 20000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 3000) == 30000, 'At 3s should be 30000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 4000) == 40000, 'At 4s should be 40000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 5000) == 50000, 'At 5s should be 50000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 6000) == 50000, 'At 6s should be 50000 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 7000) == 50000, 'At 7s should be 50000 tok*sec'); - } - - #[test] - fn test_should_stake_1_tokens_for_5_seconds_adding_1_every_second_rounding_down() { - let (staker, token) = setup(1); - - // Caller is token owner - let token_owner = get_caller_address(); - - // Allow staker contract to spend 1 tokens from owner account - token.approve(staker.contract_address, 1); - - // Adress to delegate tokens to - let delegatee = contract_address_const::<1234567890>(); +// assert(staker.get_staked_seconds_at(token_owner, 0) == 0, 'At 0 should be 0'); +// assert(staker.get_staked_seconds_at(token_owner, 1000) == 10000, 'At 1s should be 10000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 1100) == 10000, 'At 1.1s should be 10000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 1500) == 10000, 'At 1.5s should be 10000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 1900) == 10000, 'At 1.9s should be 10000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 2000) == 20000, 'At 2s should be 20000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 3000) == 30000, 'At 3s should be 30000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 4000) == 40000, 'At 4s should be 40000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 5000) == 50000, 'At 5s should be 50000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 6000) == 50000, 'At 6s should be 50000 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 7000) == 50000, 'At 7s should be 50000 tok*sec'); +// } + +// #[test] +// fn test_should_stake_1_tokens_for_5_seconds_adding_1_every_second_rounding_down() { +// let (staker, token) = setup(1); + +// // Caller is token owner +// let token_owner = get_caller_address(); + +// // Allow staker contract to spend 1 tokens from owner account +// token.approve(staker.contract_address, 1); + +// // Adress to delegate tokens to +// let delegatee = contract_address_const::<1234567890>(); - set_block_timestamp(0); - staker.stake(delegatee); // Will transfer 10000 tokens to contract account and setup delegatee +// set_block_timestamp(0); +// staker.stake(delegatee); // Will transfer 10000 tokens to contract account and setup delegatee - set_block_timestamp(5000); // 5 seconds passed +// set_block_timestamp(5000); // 5 seconds passed - assert(staker.get_staked(token_owner, delegatee) == 1, 'Something went wrong'); +// assert(staker.get_staked(token_owner, delegatee) == 1, 'Something went wrong'); - staker.withdraw(delegatee, token_owner); // Will withdraw all 10000 tokens back to owner +// staker.withdraw(delegatee, token_owner); // Will withdraw all 10000 tokens back to owner - set_block_timestamp(10000); - assert(staker.get_staked(delegatee, token_owner) == 0, 'Not all tokens were withdrawn'); +// set_block_timestamp(10000); +// assert(staker.get_staked(delegatee, token_owner) == 0, 'Not all tokens were withdrawn'); - assert(staker.get_staked_seconds_at(token_owner, 0) == 0, 'At 0 should be 0'); - assert(staker.get_staked_seconds_at(token_owner, 1000) == 1, 'At 1s should be 1 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 1100) == 1, 'At 1.1s should be 1 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 1500) == 1, 'At 1.5s should be 1 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 1900) == 1, 'At 1.9s should be 1 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 2000) == 2, 'At 2s should be 2 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 3000) == 3, 'At 3s should be 3 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 4000) == 4, 'At 4s should be 4 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 5000) == 5, 'At 5s should be 5 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 6000) == 5, 'At 6s should be 5 tok*sec'); - assert(staker.get_staked_seconds_at(token_owner, 7000) == 5, 'At 7s should be 5 tok*sec'); - } - - #[test] - #[should_panic(expected: ('INSUFFICIENT_AMOUNT_STAKED', 'ENTRYPOINT_FAILED'))] - fn test_raises_error_if_no_history_exists_and_withdrawal_happens() { - // TODO(biatcode): This test accidentally tests other - // functionality and should be refactored +// assert(staker.get_staked_seconds_at(token_owner, 0) == 0, 'At 0 should be 0'); +// assert(staker.get_staked_seconds_at(token_owner, 1000) == 1, 'At 1s should be 1 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 1100) == 1, 'At 1.1s should be 1 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 1500) == 1, 'At 1.5s should be 1 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 1900) == 1, 'At 1.9s should be 1 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 2000) == 2, 'At 2s should be 2 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 3000) == 3, 'At 3s should be 3 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 4000) == 4, 'At 4s should be 4 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 5000) == 5, 'At 5s should be 5 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 6000) == 5, 'At 6s should be 5 tok*sec'); +// assert(staker.get_staked_seconds_at(token_owner, 7000) == 5, 'At 7s should be 5 tok*sec'); +// } + +// #[test] +// #[should_panic(expected: ('INSUFFICIENT_AMOUNT_STAKED', 'ENTRYPOINT_FAILED'))] +// fn test_raises_error_if_no_history_exists_and_withdrawal_happens() { +// // TODO(biatcode): This test accidentally tests other +// // functionality and should be refactored - let (staker, token) = setup(10000); +// let (staker, token) = setup(10000); - // Caller is token owner - let token_owner = get_caller_address(); +// // Caller is token owner +// let token_owner = get_caller_address(); - // Adress to delegate tokens to - let delegatee = contract_address_const::<1234567890>(); +// // Adress to delegate tokens to +// let delegatee = contract_address_const::<1234567890>(); - token.approve(staker.contract_address, 10000); +// token.approve(staker.contract_address, 10000); - set_block_timestamp(1000); - staker.stake_amount(delegatee, 1000); - set_block_timestamp(2000); - staker.withdraw_amount(delegatee, token_owner, 500); - set_block_timestamp(3000); - staker.stake_amount(delegatee, 1000); - set_block_timestamp(4000); - staker.withdraw_amount(delegatee, token_owner, 2000); - } - - #[test] - #[should_panic(expected: ('BAD AMOUNT', 'ENTRYPOINT_FAILED'))] - fn test_raises_error_if_withdrawn_more_than_staked() { - let (staker, token) = setup(10000); - - // Caller is token owner - let token_owner = get_caller_address(); - - // Allow staker to spend 10000 tokens from owner account - token.approve(staker.contract_address, 10000); - - // Adress to delegate tokens to - let delegatee = contract_address_const::<1234567890>(); +// set_block_timestamp(1000); +// staker.stake_amount(delegatee, 1000); +// set_block_timestamp(2000); +// staker.withdraw_amount(delegatee, token_owner, 500); +// set_block_timestamp(3000); +// staker.stake_amount(delegatee, 1000); +// set_block_timestamp(4000); +// staker.withdraw_amount(delegatee, token_owner, 2000); +// } + +// #[test] +// #[should_panic(expected: ('BAD AMOUNT', 'ENTRYPOINT_FAILED'))] +// fn test_raises_error_if_withdrawn_more_than_staked() { +// let (staker, token) = setup(10000); + +// // Caller is token owner +// let token_owner = get_caller_address(); + +// // Allow staker to spend 10000 tokens from owner account +// token.approve(staker.contract_address, 10000); + +// // Adress to delegate tokens to +// let delegatee = contract_address_const::<1234567890>(); - set_block_timestamp(5000); // 5 seconds passed - staker.withdraw(delegatee, token_owner); // Will withdraw all 10000 tokens back to owner - } +// set_block_timestamp(5000); // 5 seconds passed +// staker.withdraw(delegatee, token_owner); // Will withdraw all 10000 tokens back to owner +// } -} \ No newline at end of file +// } \ No newline at end of file