Skip to content

Commit

Permalink
make nontransferrable, test cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
pblivin0x committed Jun 11, 2024
1 parent ffa3671 commit d30288a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
10 changes: 10 additions & 0 deletions contracts/staking/PrtStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ contract PrtStakingPool is Ownable, ERC20Snapshot, ReentrancyGuard {
FeeSplitExtensionChanged(_feeSplitExtension);
}

/* ========== ERC20 Overrides ========== */

function transfer(address /*recipient*/, uint256 /*amount*/) public override returns (bool) {
revert("Transfers not allowed");
}

function transferFrom(address /*sender*/, address /*recipient*/, uint256 /*amount*/) public override returns (bool) {
revert("Transfers not allowed");
}

/* ========== View Functions ========== */

/**
Expand Down
77 changes: 74 additions & 3 deletions test/staking/prtStakingPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ describe.only("PrtStakingPool", () => {
await expect(subject()).to.emit(prtStakingPool, "Transfer").withArgs(ADDRESS_ZERO, bob.address, subjectAmount);
});

it("should be non-transferrable", async () => {
await subject();

await expect(
prtStakingPool.connect(bob.wallet).transfer(owner.address, subjectAmount)
).to.be.revertedWith("Transfers not allowed");

await prtStakingPool.connect(bob.wallet).approve(owner.address, subjectAmount);
await expect(
prtStakingPool.connect(bob.wallet).transferFrom(bob.address, owner.address, subjectAmount)
).to.be.revertedWith("Transfers not allowed");
});

describe("when the amount is 0", async () => {
beforeEach(async () => {
subjectAmount = ZERO;
Expand Down Expand Up @@ -320,6 +333,10 @@ describe.only("PrtStakingPool", () => {
expect(accrueSnapshotsAfter[accrueSnapshotsAfter.length - 1]).to.eq(subjectAmount);
});

it("should emit the correct PRT Staking Pool Snapshot event", async () => {
await expect(subject()).to.emit(prtStakingPool, "Snapshot").withArgs(1);
});

describe("when the caller is not the FeeSplitExtension", async () => {
beforeEach(async () => {
subjectCaller = await getRandomAccount();
Expand Down Expand Up @@ -386,8 +403,6 @@ describe.only("PrtStakingPool", () => {
await setToken.connect(owner.wallet).transfer(feeSplitExtension.address, snap3Amount);
await setToken.connect(feeSplitExtension.wallet).approve(prtStakingPool.address, snap3Amount);
await prtStakingPool.connect(feeSplitExtension.wallet).accrue(snap3Amount);

subjectCaller = bob;
});

async function subject(caller: Account): Promise<any> {
Expand Down Expand Up @@ -472,7 +487,6 @@ describe.only("PrtStakingPool", () => {
describe("when the rewards have been claimed", async () => {
beforeEach(async () => {
await prtStakingPool.connect(bob.wallet).claim();
subjectCaller = bob;
});

it("should return 0", async () => {
Expand All @@ -481,6 +495,63 @@ describe.only("PrtStakingPool", () => {
});
});

describe("#transfer", async () => {
let subjectAmount: BigNumber;
let subjectCaller: Account;
let subjectReceiver: Account;

beforeEach(async () => {
const amount = ether(1);

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

subjectAmount = amount;
subjectCaller = bob;
subjectReceiver = alice;
});

async function subject(): Promise<any> {
return prtStakingPool.connect(subjectCaller.wallet).transfer(subjectReceiver.address, subjectAmount);
}

it("should revert", async () => {
await expect(subject()).to.be.revertedWith("Transfers not allowed");
});
});

describe("#transferFrom", async () => {
let subjectAmount: BigNumber;
let subjectCaller: Account;
let subjectSender: Account;

beforeEach(async () => {
const amount = ether(1);

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

subjectAmount = amount;
subjectCaller = alice;
subjectSender = bob;
});

async function subject(): Promise<any> {
return prtStakingPool.connect(subjectCaller.wallet).transferFrom(
subjectSender.address,
subjectCaller.address,
subjectAmount
);
}

it("should revert", async () => {
await expect(subject()).to.be.revertedWith("Transfers not allowed");
});
});

describe("#getSnapshotRewards", async () => {
let bobPrtAmount: BigNumber;
let alicePrtAmount: BigNumber;
Expand Down

0 comments on commit d30288a

Please sign in to comment.