Skip to content

Commit

Permalink
Merge branch 'master' into fix/reentrancy
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Nov 24, 2022
2 parents dc0ea03 + 76b0cd2 commit 689a22c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/erc20-pods",
"version": "0.0.8",
"version": "0.0.9",
"description": "ERC20 extension enabling external smart contract based Pods to track balances of those users who opted-in to these Pods",
"repository": {
"type": "git",
Expand Down
27 changes: 26 additions & 1 deletion test/ERC20Pods.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const { ether } = require('@1inch/solidity-utils');
const { expect, ether } = require('@1inch/solidity-utils');
const { ethers } = require('hardhat');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { shouldBehaveLikeERC20Pods } = require('./behaviors/ERC20Pods.behavior');

const POD_LIMITS = 10;

describe('ERC20Pods', function () {
let wallet1;

before(async function () {
[wallet1] = await ethers.getSigners();
});

async function initContracts () {
const ERC20PodsMock = await ethers.getContractFactory('ERC20PodsMock');
const erc20Pods = await ERC20PodsMock.deploy('ERC20PodsMock', 'EPM', POD_LIMITS);
Expand All @@ -22,5 +29,23 @@ describe('ERC20Pods', function () {
return { erc20Pods, pods, amount };
};

async function initWrongPodAndMint () {
const { erc20Pods, amount } = await initContracts();
await erc20Pods.mint(wallet1.address, amount);
const WrongPodMock = await ethers.getContractFactory('WrongPodMock');
const wrongPod = await WrongPodMock.deploy('WrongPodMock', 'WPM', erc20Pods.address);
await wrongPod.deployed();
return { erc20Pods, wrongPod, amount };
};

shouldBehaveLikeERC20Pods(initContracts);

it('should not fail when updateBalance returns gas bomb @skip-on-coverage', async function () {
const { erc20Pods, wrongPod } = await loadFixture(initWrongPodAndMint);
await wrongPod.setReturnGasBomb(true);
const tx = await erc20Pods.addPod(wrongPod.address);
const receipt = await tx.wait();
expect(receipt.gasUsed).to.be.lt(272123); // 272123 with solidity instead of assembly
expect(await erc20Pods.pods(wallet1.address)).to.have.deep.equals([wrongPod.address]);
});
});
9 changes: 0 additions & 9 deletions test/behaviors/ERC20Pods.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,6 @@ function shouldBehaveLikeERC20Pods (initContracts) {
await erc20Pods.addPod(wrongPod.address);
expect(await erc20Pods.pods(wallet1.address)).to.have.deep.equals([wrongPod.address]);
});

it('should not fail when updateBalance returns gas bomb @skip-on-coverage', async function () {
const { erc20Pods, wrongPod } = await loadFixture(initWrongPodAndMint);
await wrongPod.setReturnGasBomb(true);
const tx = await erc20Pods.addPod(wrongPod.address);
const receipt = await tx.wait();
expect(receipt.gasUsed).to.be.lt(272123); // 272123 with solidity instead of assembly
expect(await erc20Pods.pods(wallet1.address)).to.have.deep.equals([wrongPod.address]);
});
});

describe('_afterTokenTransfer', function () {
Expand Down

0 comments on commit 689a22c

Please sign in to comment.