-
Notifications
You must be signed in to change notification settings - Fork 140
Open
Description
If the staking pool is created on an account with balance = 1_000_000_000_000, then total_stake_shares is 0, and several view functions start to panic
Note: I'm preparing a PR to handle this edge case
To reproduce, add this unit test: (the 4th parameter is the account initial balance)
#[test]
fn test_low_staked_balance() {
let mut emulator = Emulator::new(
owner(),
"KuTCtARNzxZQ3YvXDeLjx83FDqxv2SdQTSbiq876zR7".to_string(),
zero_fee(),
STAKE_SHARE_PRICE_GUARANTEE_FUND, //account initial balance, minimum, edge case
);
//bob deposits 1M
let deposit_amount = ntoy(1_000_000);
emulator.update_context(bob(), deposit_amount);
emulator.contract.deposit();
emulator.amount += deposit_amount;
//bob wants to know how much unstaked balance he has
emulator.update_context(bob(), 0);
assert_eq!(
emulator.contract.get_account_unstaked_balance(bob()).0,
deposit_amount
);
//panic!
//thread 'tests::test_low_staked_balance' panicked at 'The total number of stake shares can't be 0', src/internal.rs:297:9
}
Metadata
Metadata
Assignees
Labels
No labels