Skip to content

Commit

Permalink
update lastSnapshotId when staking
Browse files Browse the repository at this point in the history
  • Loading branch information
pblivin0x committed Jun 12, 2024
1 parent fc4b6aa commit 09abd4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/staking/PrtStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ contract PrtStakingPool is Ownable, ERC20Snapshot, ReentrancyGuard {
function stake(uint256 _amount) external nonReentrant {
require(_amount > 0, "Cannot stake 0");
prt.transferFrom(msg.sender, address(this), _amount);
lastSnapshotId[msg.sender] = getCurrentId();
super._mint(msg.sender, _amount);
}

Expand Down
25 changes: 25 additions & 0 deletions test/staking/prtStakingPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ describe.only("PrtStakingPool", () => {
).to.be.revertedWith("Transfers not allowed");
});

describe("when the snapshot id is greater than 0", async () => {
beforeEach(async () => {
const amount = ether(1);

await prt.connect(owner.wallet).approve(prtStakingPool.address, amount);
await prtStakingPool.connect(owner.wallet).stake(amount);

await setToken.connect(owner.wallet).transfer(feeSplitExtension.address, amount);
await setToken.connect(feeSplitExtension.wallet).approve(prtStakingPool.address, amount);

await prtStakingPool.connect(feeSplitExtension.wallet).accrue(amount);
});

it("should increment the last claimed id for the staker", async () => {
const lastSnapshotIdBefore = await prtStakingPool.lastSnapshotId(bob.address);
expect(lastSnapshotIdBefore).to.eq(0);

await subject();

const lastSnapshotIdAfter = await prtStakingPool.lastSnapshotId(bob.address);
expect(lastSnapshotIdAfter).to.eq(1);
expect(lastSnapshotIdAfter).to.eq(lastSnapshotIdBefore.add(1));
});
});

describe("when the amount is 0", async () => {
beforeEach(async () => {
subjectAmount = ZERO;
Expand Down

0 comments on commit 09abd4f

Please sign in to comment.