Skip to content

Commit

Permalink
fix hardhat test
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0Louis committed Sep 19, 2023
1 parent dd0b873 commit 67852e6
Showing 1 changed file with 68 additions and 9 deletions.
77 changes: 68 additions & 9 deletions test/StableJoeStaking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ describe("Stable Joe Staking", function () {
this.StableJoeStakingCF,
[
this.rewardToken.address,
this.joe.address,
this.penaltyCollector.address,
ethers.utils.parseEther("0.03"),
]
],
{
unsafeAllow: ["constructor", "state-variable-immutable"],
constructorArgs: [this.joe.address]
}
);

await this.joe
Expand Down Expand Up @@ -196,13 +199,18 @@ describe("Stable Joe Staking", function () {
).to.be.equal(ethers.utils.parseEther("1"));

// Making sure that `pendingReward` still return the accurate tokens even after updating pools
await this.stableJoeStaking.updateReward(this.rewardToken.address);
await this.stableJoeStaking.connect(this.alice).deposit("1");

expect(
await this.rewardToken.balanceOf(this.alice.address)
).to.be.equal(ethers.utils.parseEther("1"));

expect(
await this.stableJoeStaking.pendingReward(
this.alice.address,
this.rewardToken.address
)
).to.be.equal(ethers.utils.parseEther("1"));
).to.be.equal(ethers.utils.parseEther("0"));

await this.rewardToken
.connect(this.joeMaker)
Expand All @@ -215,16 +223,21 @@ describe("Stable Joe Staking", function () {
this.alice.address,
this.rewardToken.address
)
).to.be.equal(ethers.utils.parseEther("2"));
).to.be.equal(ethers.utils.parseEther("1"));

// Making sure that `pendingReward` still return the accurate tokens even after updating pools
await this.stableJoeStaking.updateReward(this.rewardToken.address);
await this.stableJoeStaking.connect(this.alice).deposit("1");

expect(
await this.rewardToken.balanceOf(this.alice.address)
).to.be.equal(ethers.utils.parseEther("2"));

expect(
await this.stableJoeStaking.pendingReward(
this.alice.address,
this.rewardToken.address
)
).to.be.equal(ethers.utils.parseEther("2"));
).to.be.equal(ethers.utils.parseEther("0"));
});

it("should allow deposits and withdraws of multiple users and distribute rewards accordingly", async function () {
Expand All @@ -241,8 +254,6 @@ describe("Stable Joe Staking", function () {
await this.rewardToken
.connect(this.joeMaker)
.transfer(this.stableJoeStaking.address, ethers.utils.parseEther("6"));
await this.stableJoeStaking.updateReward(this.rewardToken.address);
await increase(86400);

await this.stableJoeStaking
.connect(this.alice)
Expand Down Expand Up @@ -705,6 +716,54 @@ describe("Stable Joe Staking", function () {
expect(userInfo[0]).to.be.equal(0);
expect(userInfo[1]).to.be.equal(0);
});

it("should allow owner to sweep stuck tokens that are not rewards", async function () {
await this.stableJoeStaking
.connect(this.alice)
.deposit(ethers.utils.parseEther("300"));
expect(await this.joe.balanceOf(this.alice.address)).to.be.equal(
ethers.utils.parseEther("700")
);
expect(
await this.joe.balanceOf(this.stableJoeStaking.address)
).to.be.equal(ethers.utils.parseEther("291"));

const stuckToken = await this.JoeTokenCF.deploy();
await stuckToken.mint(
this.stableJoeStaking.address,
ethers.utils.parseEther("100")
); // We send 100 Tokens to sJoe's address

await this.stableJoeStaking.connect(this.dev).sweep(
stuckToken.address,
this.dev.address
);

expect(await stuckToken.balanceOf(this.dev.address)).to.be.equal(
ethers.utils.parseEther("100")
);
expect(await stuckToken.balanceOf(this.stableJoeStaking.address)).to.be.equal(
0
);

// Should fail for joe
await expect(
this.stableJoeStaking.connect(this.dev).sweep(
this.joe.address,
this.dev.address
)
).to.be.revertedWith("StableJoeStaking: token can't be swept");

// Should fail if stuckToken is added as a reward token
await this.stableJoeStaking.connect(this.dev).addRewardToken(stuckToken.address);

await expect(
this.stableJoeStaking.connect(this.dev).sweep(
stuckToken.address,
this.dev.address
)
).to.be.revertedWith("StableJoeStaking: token can't be swept");
});
});

after(async function () {
Expand Down

0 comments on commit 67852e6

Please sign in to comment.