Skip to content

Commit

Permalink
update on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Wang committed Nov 8, 2023
1 parent 2c72dff commit 499dce8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions test/supply-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,37 @@ describe('supplyFrom', function () {
await wait(cometAsB.allow(charlie.address, true));
await expect(cometAsC.supplyFrom(bob.address, alice.address, COMP.address, 7)).to.be.revertedWith("custom error 'Paused()'");
});

it('block re-entrancy', async () => {
const { comet, tokens, users: [alice, bob] } = await makeProtocol({
assets: {
USDC: {
decimals: 6
},
EVIL: {
decimals: 6,
initialPrice: 2,
factory: await ethers.getContractFactory('EvilToken') as EvilToken__factory,
supplyCap: 250e6
}
}
});
const { EVIL } = <{ EVIL: EvilToken }>tokens;

const attack = Object.assign({}, await EVIL.getAttack(), {
attackType: ReentryAttack.SupplyFrom,
source: alice.address,
destination: bob.address,
asset: EVIL.address,
amount: 75e6,
maxCalls: 1
});
await EVIL.setAttack(attack);

await comet.connect(alice).allow(EVIL.address, true);
await wait(EVIL.connect(alice).approve(comet.address, 75e6));
await EVIL.allocateTo(alice.address, 75e6);
await comet.connect(alice).supplyTo(bob.address, EVIL.address, 75e6);
expect(await comet.collateralBalanceOf(bob.address, EVIL.address)).to.be.revertedWith("custom error 'TransferInFailed()'");
});

Check failure on line 697 in test/supply-test.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected indentation of 2 spaces but found 0
});
2 changes: 1 addition & 1 deletion test/withdraw-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ describe('withdraw', function () {
expect(await USDC.balanceOf(bob.address)).to.eq(0);
});

it('is not broken by malicious reentrancy withdrawFrom', async () => {
it('block malicious reentrancy withdrawFrom', async () => {
const { comet, tokens, users: [alice, bob] } = await makeProtocol({
assets: {
USDC: {
Expand Down

0 comments on commit 499dce8

Please sign in to comment.