Migrate ERC20 extensions tests to ethers v6 (#4773)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: ernestognw <ernestognw@gmail.com>
This commit is contained in:
Renan Souza
2023-12-13 19:31:56 -03:00
committed by GitHub
parent 6ba452dea4
commit 88512b23d2
19 changed files with 989 additions and 1334 deletions

View File

@ -6,12 +6,13 @@ const { shouldBehaveLikeERC20 } = require('../ERC20.behavior');
const name = 'My Token';
const symbol = 'MTKN';
const decimals = 9n;
const initialSupply = 100n;
async function fixture() {
const [initialHolder, recipient, anotherAccount] = await ethers.getSigners();
const underlying = await ethers.deployContract('$ERC20DecimalsMock', [name, symbol, 9]);
const underlying = await ethers.deployContract('$ERC20DecimalsMock', [name, symbol, decimals]);
await underlying.$_mint(initialHolder, initialSupply);
const token = await ethers.deployContract('$ERC20Wrapper', [`Wrapped ${name}`, `W${symbol}`, underlying]);
@ -20,9 +21,6 @@ async function fixture() {
}
describe('ERC20Wrapper', function () {
const name = 'My Token';
const symbol = 'MTKN';
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
});
@ -40,7 +38,7 @@ describe('ERC20Wrapper', function () {
});
it('has the same decimals as the underlying token', async function () {
expect(await this.token.decimals()).to.be.equal(9n);
expect(await this.token.decimals()).to.be.equal(decimals);
});
it('decimals default back to 18 if token has no metadata', async function () {
@ -56,13 +54,13 @@ describe('ERC20Wrapper', function () {
describe('deposit', function () {
it('executes with approval', async function () {
await this.underlying.connect(this.initialHolder).approve(this.token, initialSupply);
const tx = await this.token.connect(this.initialHolder).depositFor(this.initialHolder, initialSupply);
await expect(tx)
.to.emit(this.underlying, 'Transfer')
.withArgs(this.initialHolder.address, this.token.target, initialSupply)
.to.emit(this.token, 'Transfer')
.withArgs(ethers.ZeroAddress, this.initialHolder.address, initialSupply);
await expect(tx).to.changeTokenBalances(
this.underlying,
[this.initialHolder, this.token],
@ -79,6 +77,7 @@ describe('ERC20Wrapper', function () {
it('reverts when inssuficient balance', async function () {
await this.underlying.connect(this.initialHolder).approve(this.token, ethers.MaxUint256);
await expect(this.token.connect(this.initialHolder).depositFor(this.initialHolder, ethers.MaxUint256))
.to.be.revertedWithCustomError(this.underlying, 'ERC20InsufficientBalance')
.withArgs(this.initialHolder.address, initialSupply, ethers.MaxUint256);
@ -86,13 +85,13 @@ describe('ERC20Wrapper', function () {
it('deposits to other account', async function () {
await this.underlying.connect(this.initialHolder).approve(this.token, initialSupply);
const tx = await this.token.connect(this.initialHolder).depositFor(this.recipient, initialSupply);
await expect(tx)
.to.emit(this.underlying, 'Transfer')
.withArgs(this.initialHolder.address, this.token.target, initialSupply)
.to.emit(this.token, 'Transfer')
.withArgs(ethers.ZeroAddress, this.recipient.address, initialSupply);
await expect(tx).to.changeTokenBalances(
this.underlying,
[this.initialHolder, this.token],
@ -103,6 +102,7 @@ describe('ERC20Wrapper', function () {
it('reverts minting to the wrapper contract', async function () {
await this.underlying.connect(this.initialHolder).approve(this.token, ethers.MaxUint256);
await expect(this.token.connect(this.initialHolder).depositFor(this.token, ethers.MaxUint256))
.to.be.revertedWithCustomError(this.token, 'ERC20InvalidReceiver')
.withArgs(this.token.target);
@ -130,7 +130,6 @@ describe('ERC20Wrapper', function () {
.withArgs(this.token.target, this.initialHolder.address, value)
.to.emit(this.token, 'Transfer')
.withArgs(this.initialHolder.address, ethers.ZeroAddress, value);
await expect(tx).to.changeTokenBalances(this.underlying, [this.token, this.initialHolder], [-value, value]);
await expect(tx).to.changeTokenBalance(this.token, this.initialHolder, -value);
});
@ -142,7 +141,6 @@ describe('ERC20Wrapper', function () {
.withArgs(this.token.target, this.initialHolder.address, initialSupply)
.to.emit(this.token, 'Transfer')
.withArgs(this.initialHolder.address, ethers.ZeroAddress, initialSupply);
await expect(tx).to.changeTokenBalances(
this.underlying,
[this.token, this.initialHolder],
@ -158,7 +156,6 @@ describe('ERC20Wrapper', function () {
.withArgs(this.token.target, this.recipient.address, initialSupply)
.to.emit(this.token, 'Transfer')
.withArgs(this.initialHolder.address, ethers.ZeroAddress, initialSupply);
await expect(tx).to.changeTokenBalances(
this.underlying,
[this.token, this.initialHolder, this.recipient],
@ -181,7 +178,6 @@ describe('ERC20Wrapper', function () {
const tx = await this.token.$_recover(this.recipient);
await expect(tx).to.emit(this.token, 'Transfer').withArgs(ethers.ZeroAddress, this.recipient.address, 0n);
await expect(tx).to.changeTokenBalance(this.token, this.recipient, 0);
});
@ -192,7 +188,6 @@ describe('ERC20Wrapper', function () {
await expect(tx)
.to.emit(this.token, 'Transfer')
.withArgs(ethers.ZeroAddress, this.recipient.address, initialSupply);
await expect(tx).to.changeTokenBalance(this.token, this.recipient, initialSupply);
});
});