Skip to content

bug: (staking-pool) edge case bug - contract account with low balance #99

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

Open
luciotato opened this issue Sep 7, 2020 · 1 comment · May be fixed by #100
Open

bug: (staking-pool) edge case bug - contract account with low balance #99

luciotato opened this issue Sep 7, 2020 · 1 comment · May be fixed by #100

Comments

@luciotato
Copy link

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

    }

@luciotato luciotato linked a pull request Sep 7, 2020 that will close this issue
@luciotato luciotato changed the title edge case bug - contract account with low balance bug: (staking-pool) edge case bug - contract account with low balance Sep 7, 2020
@evgenykuzyakov
Copy link
Collaborator

It's not an issue for the production, because the minimum amount of NEAR the account can have is 0.01 due to state staking: https://nomicon.io/Economics/README.html#state-stake

Still it's good to address it, so proceed with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants