-
Notifications
You must be signed in to change notification settings - Fork 99
Nnennaokoye/acbu smart contract #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Junman140
merged 5 commits into
Pi-Defi-world:dev
from
nnennaokoye:nnennaokoye/acbu-smart-contract
Jun 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4a8607
Fix #336: Add paginated get_user_lots to prevent return value size li…
nnennaokoye ef0fbdc
Fix #337: Add rate limiting to verify_reserves to prevent spam and le…
nnennaokoye 91a9f27
Fix #354: Add unit tests for pure functions in shared crate
nnennaokoye 17c33f7
Fix #358: Add initialization check helper for multiple contracts
nnennaokoye 740540a
pr fix
nnennaokoye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #![cfg(test)] | ||
|
|
||
| use shared::{calculate_amount_after_fee, calculate_fee, calculate_deviation, BASIS_POINTS}; | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_zero_fee_rate() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 0i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_zero_amount() { | ||
| let amount = 0i128; | ||
| let fee_rate = 300i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_1_percent() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 100i128; | ||
| let expected = 100_000i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_3_percent() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 300i128; | ||
| let expected = 300_000i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_10_percent() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 1_000i128; | ||
| let expected = 1_000_000i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_100_percent() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = BASIS_POINTS; | ||
| let expected = 10_000_000i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_large_amount() { | ||
| let amount = 1_000_000_000_000i128; | ||
| let fee_rate = 300i128; | ||
| let expected = 30_000_000_000i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_fee_small_amount() { | ||
| let amount = 1i128; | ||
| let fee_rate = 300i128; | ||
| assert_eq!(calculate_fee(amount, fee_rate), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_amount_after_fee_basic() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 300i128; | ||
| let fee = 300_000i128; | ||
| let expected = 9_700_000i128; | ||
| assert_eq!(calculate_amount_after_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_amount_after_fee_zero_fee() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 0i128; | ||
| assert_eq!(calculate_amount_after_fee(amount, fee_rate), amount); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_amount_after_fee_zero_amount() { | ||
| let amount = 0i128; | ||
| let fee_rate = 300i128; | ||
| assert_eq!(calculate_amount_after_fee(amount, fee_rate), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_amount_after_fee_high_fee() { | ||
| let amount = 10_000_000i128; | ||
| let fee_rate = 5_000i128; | ||
| let expected = 5_000_000i128; | ||
| assert_eq!(calculate_amount_after_fee(amount, fee_rate), expected); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_equal_values() { | ||
| let value1 = 100i128; | ||
| let value2 = 100i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_value1_greater() { | ||
| let value1 = 150i128; | ||
| let value2 = 100i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 5_000); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_value2_greater() { | ||
| let value1 = 100i128; | ||
| let value2 = 150i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 3_333); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_small_deviation() { | ||
| let value1 = 101i128; | ||
| let value2 = 100i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 100); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_large_deviation() { | ||
| let value1 = 200i128; | ||
| let value2 = 100i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 10_000); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_zero_divisor() { | ||
| let value1 = 100i128; | ||
| let value2 = 0i128; | ||
| assert_eq!(calculate_deviation(value1, value2), i128::MAX); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_both_zero() { | ||
| let value1 = 0i128; | ||
| let value2 = 0i128; | ||
| assert_eq!(calculate_deviation(value1, value2), i128::MAX); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_negative_value1() { | ||
| let value1 = -100i128; | ||
| let value2 = 100i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 20_000); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_calculate_deviation_7decimal_rates() { | ||
| let value1 = 1_050_000i128; | ||
| let value2 = 1_000_000i128; | ||
| assert_eq!(calculate_deviation(value1, value2), 500); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.