-
Notifications
You must be signed in to change notification settings - Fork 16
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
Overflow on fraction of duration #370
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed only finance without liability and interest modules
once address the findings , on the next iteration I'll continue with the rest
use crate::fractionable::Fractionable; | ||
assert_eq!( | ||
Coin::<SuperGroupTestC1>::new(30), | ||
Coin::<SuperGroupTestC1>::new(3).safe_mul(&Percent::from_percent(1000)) | ||
Fractionable::<u32>::checked_mul( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[everywhere] not sure we need the extended syntax when calling checked_mul
. More concise and readable is if we call it on the first operand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the original code cannot be compiled?
use crate::fractionable::Fractionable; | ||
assert_eq!( | ||
Coin::<SuperGroupTestC1>::new(30), | ||
Coin::<SuperGroupTestC1>::new(3).safe_mul(&Percent::from_percent(1000)) | ||
Fractionable::<u32>::checked_mul( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the original code cannot be compiled?
.try_into() | ||
.expect("overflow computing a fraction of duration") | ||
let d128: u128 = self.into(); | ||
Fractionable::<Coin<C>>::checked_mul(d128, fraction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified that the direct calling syntax does not work? We did not add more implementations so d128.checked_mul(fraction)
should work fine
Percent::from_permille(self.units().safe_mul(ratio)) | ||
Fractionable::<Units>::checked_mul(self.units(), ratio).map(Self::from_permille) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, I have to clue why the former calling syntax is not applicable anymore
1de3926
to
e91e7a1
Compare
where | ||
A: Fractionable<U>; | ||
A: Fractionable<U> + Display + Clone; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not require Display + Clone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the motivation for that?
f879640
to
b384923
Compare
f2d5176
to
3e867a0
Compare
…mwasm_std::OverflowError
5b81c33
to
2eeda67
Compare
No description provided.