-
Notifications
You must be signed in to change notification settings - Fork 129
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
fix:(staking-pool) edge case #100
base: master
Are you sure you want to change the base?
Conversation
@@ -514,10 +518,11 @@ mod tests { | |||
owner: String, | |||
stake_public_key: String, | |||
reward_fee_fraction: RewardFeeFraction, | |||
initial_balance: Balance, |
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.
add a 4th parameter for testing, initial balance
@@ -183,6 +183,10 @@ impl StakingContract { | |||
"The owner account ID is invalid" | |||
); | |||
let account_balance = env::account_balance(); | |||
assert!( |
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.
avoid total_staked_balance
=0
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.
Realistically, this is impossible, because the storage required for the contract itself covers this.
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.
I see. The contract will stop working way before that.
@@ -183,6 +183,10 @@ impl StakingContract { | |||
"The owner account ID is invalid" | |||
); | |||
let account_balance = env::account_balance(); | |||
assert!( |
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.
Realistically, this is impossible, because the storage required for the contract itself covers this.
@@ -183,6 +183,10 @@ impl StakingContract { | |||
"The owner account ID is invalid" | |||
); | |||
let account_balance = env::account_balance(); | |||
assert!( | |||
account_balance > STAKE_SHARE_PRICE_GUARANTEE_FUND, |
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.
Why this is strictly higher?
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.
because if account_balance == STAKE_SHARE_PRICE_GUARANTEE_FUND
then in the next line total_staked_balance becomes zero. total_staked_balance
is used in several share calculations as denominator, so total_staked_balance==0
leads to div by zero panics. (i.e. fn num_shares_from_staked_amount_rounded_down/up
)
fixes #99