Skip to content

Commit

Permalink
make a test for increased height and withdrawl
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCardinalError committed Nov 6, 2024
1 parent e006ab2 commit 5c56b50
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/Staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const doubled_stakeAmount_0 = '200000000000000000';
const doubled_committedStakeAmount_0 = '8333333333333';
const nonce_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const height_0 = 0;
const height_0_n_1 = 0;

let staker_1: string;
const overlay_1 = '0xa6f955c72d7053f96b91b5470491a0c732b0175af56dcfb7a604b82b16719406';
Expand Down Expand Up @@ -455,6 +456,35 @@ describe('Staking', function () {
expect(await token.balanceOf(staker_0)).to.not.eq(zeroAmount);
});

it('should make stake surplus withdrawal when height increases', async function () {
const staked_before = await sr_staker_0.stakes(staker_0);
const priceOracle = await ethers.getContract('PriceOracle', deployer);

await priceOracle.setPrice(24000);

// We dont need double here as we are adding double amount with another stakeAmount_0
await mintAndApprove(staker_0, stakeRegistry.address, stakeAmount_0);
await sr_staker_0.manageStake(nonce_0, stakeAmount_0, height_0_n_1);
const staked_after = await sr_staker_0.stakes(staker_0);

expect(staked_after.overlay).to.be.eq(overlay_0);
expect(staked_after.potentialStake).to.be.eq(doubled_stakeAmount_0);
expect(staked_before.lastUpdatedBlockNumber).to.be.eq(updatedBlockNumber);

// Check that balance of wallet is 0 in the begining and lower the price
expect(await token.balanceOf(staker_0)).to.be.eq(zeroAmount);

await sr_staker_0.withdrawFromStake();

const effectiveStake = (await sr_staker_0.nodeEffectiveStake(staker_0)).toString();
const tokenBalance = (await token.balanceOf(staker_0)).toString();
const potentialStakeBalance = staked_after.potentialStake.toString();

expect(staked_after.potentialStake.gt(staked_before.potentialStake)).to.be.true;
expect(String(potentialStakeBalance - tokenBalance)).to.be.eq(effectiveStake);
expect(tokenBalance).to.not.eq(zeroAmount);
});

it('should make stake surplus withdrawal and not withdraw again after', async function () {
const staked_before = await sr_staker_0.stakes(staker_0);
const priceOracle = await ethers.getContract('PriceOracle', deployer);
Expand Down

0 comments on commit 5c56b50

Please sign in to comment.