Implement recommendations from 5.0 audit Phase 1A (#4398)
Co-authored-by: Francisco Giordano <fg@frang.io> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -15,7 +15,7 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
const symbol = 'MTKN';
|
||||
|
||||
const initialSupply = new BN(100);
|
||||
const loanAmount = new BN(10000000000000);
|
||||
const loanValue = new BN(10000000000000);
|
||||
|
||||
beforeEach(async function () {
|
||||
this.token = await ERC20FlashMintMock.new(name, symbol);
|
||||
@ -34,11 +34,11 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
|
||||
describe('flashFee', function () {
|
||||
it('token match', async function () {
|
||||
expect(await this.token.flashFee(this.token.address, loanAmount)).to.be.bignumber.equal('0');
|
||||
expect(await this.token.flashFee(this.token.address, loanValue)).to.be.bignumber.equal('0');
|
||||
});
|
||||
|
||||
it('token mismatch', async function () {
|
||||
await expectRevertCustomError(this.token.flashFee(ZERO_ADDRESS, loanAmount), 'ERC3156UnsupportedToken', [
|
||||
await expectRevertCustomError(this.token.flashFee(ZERO_ADDRESS, loanValue), 'ERC3156UnsupportedToken', [
|
||||
ZERO_ADDRESS,
|
||||
]);
|
||||
});
|
||||
@ -53,26 +53,26 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
describe('flashLoan', function () {
|
||||
it('success', async function () {
|
||||
const receiver = await ERC3156FlashBorrowerMock.new(true, true);
|
||||
const { tx } = await this.token.flashLoan(receiver.address, this.token.address, loanAmount, '0x');
|
||||
const { tx } = await this.token.flashLoan(receiver.address, this.token.address, loanValue, '0x');
|
||||
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: ZERO_ADDRESS,
|
||||
to: receiver.address,
|
||||
value: loanAmount,
|
||||
value: loanValue,
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: receiver.address,
|
||||
to: ZERO_ADDRESS,
|
||||
value: loanAmount,
|
||||
value: loanValue,
|
||||
});
|
||||
await expectEvent.inTransaction(tx, receiver, 'BalanceOf', {
|
||||
token: this.token.address,
|
||||
account: receiver.address,
|
||||
value: loanAmount,
|
||||
value: loanValue,
|
||||
});
|
||||
await expectEvent.inTransaction(tx, receiver, 'TotalSupply', {
|
||||
token: this.token.address,
|
||||
value: initialSupply.add(loanAmount),
|
||||
value: initialSupply.add(loanValue),
|
||||
});
|
||||
|
||||
expect(await this.token.totalSupply()).to.be.bignumber.equal(initialSupply);
|
||||
@ -83,7 +83,7 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
it('missing return value', async function () {
|
||||
const receiver = await ERC3156FlashBorrowerMock.new(false, true);
|
||||
await expectRevertCustomError(
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanAmount, '0x'),
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanValue, '0x'),
|
||||
'ERC3156InvalidReceiver',
|
||||
[receiver.address],
|
||||
);
|
||||
@ -92,9 +92,9 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
it('missing approval', async function () {
|
||||
const receiver = await ERC3156FlashBorrowerMock.new(true, false);
|
||||
await expectRevertCustomError(
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanAmount, '0x'),
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanValue, '0x'),
|
||||
'ERC20InsufficientAllowance',
|
||||
[this.token.address, 0, loanAmount],
|
||||
[this.token.address, 0, loanValue],
|
||||
);
|
||||
});
|
||||
|
||||
@ -102,9 +102,9 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
const receiver = await ERC3156FlashBorrowerMock.new(true, true);
|
||||
const data = this.token.contract.methods.transfer(other, 10).encodeABI();
|
||||
await expectRevertCustomError(
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanAmount, data),
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanValue, data),
|
||||
'ERC20InsufficientBalance',
|
||||
[receiver.address, loanAmount - 10, loanAmount],
|
||||
[receiver.address, loanValue - 10, loanValue],
|
||||
);
|
||||
});
|
||||
|
||||
@ -130,29 +130,29 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
expect(await this.token.balanceOf(this.receiver.address)).to.be.bignumber.equal(receiverInitialBalance);
|
||||
|
||||
await this.token.setFlashFee(flashFee);
|
||||
expect(await this.token.flashFee(this.token.address, loanAmount)).to.be.bignumber.equal(flashFee);
|
||||
expect(await this.token.flashFee(this.token.address, loanValue)).to.be.bignumber.equal(flashFee);
|
||||
});
|
||||
|
||||
it('default flash fee receiver', async function () {
|
||||
const { tx } = await this.token.flashLoan(this.receiver.address, this.token.address, loanAmount, '0x');
|
||||
const { tx } = await this.token.flashLoan(this.receiver.address, this.token.address, loanValue, '0x');
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: ZERO_ADDRESS,
|
||||
to: this.receiver.address,
|
||||
value: loanAmount,
|
||||
value: loanValue,
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: this.receiver.address,
|
||||
to: ZERO_ADDRESS,
|
||||
value: loanAmount.add(flashFee),
|
||||
value: loanValue.add(flashFee),
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.receiver, 'BalanceOf', {
|
||||
token: this.token.address,
|
||||
account: this.receiver.address,
|
||||
value: receiverInitialBalance.add(loanAmount),
|
||||
value: receiverInitialBalance.add(loanValue),
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.receiver, 'TotalSupply', {
|
||||
token: this.token.address,
|
||||
value: initialSupply.add(receiverInitialBalance).add(loanAmount),
|
||||
value: initialSupply.add(receiverInitialBalance).add(loanValue),
|
||||
});
|
||||
|
||||
expect(await this.token.totalSupply()).to.be.bignumber.equal(
|
||||
@ -172,16 +172,16 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
|
||||
expect(await this.token.balanceOf(flashFeeReceiverAddress)).to.be.bignumber.equal('0');
|
||||
|
||||
const { tx } = await this.token.flashLoan(this.receiver.address, this.token.address, loanAmount, '0x');
|
||||
const { tx } = await this.token.flashLoan(this.receiver.address, this.token.address, loanValue, '0x');
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: ZERO_ADDRESS,
|
||||
to: this.receiver.address,
|
||||
value: loanAmount,
|
||||
value: loanValue,
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: this.receiver.address,
|
||||
to: ZERO_ADDRESS,
|
||||
value: loanAmount,
|
||||
value: loanValue,
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.token, 'Transfer', {
|
||||
from: this.receiver.address,
|
||||
@ -191,11 +191,11 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
await expectEvent.inTransaction(tx, this.receiver, 'BalanceOf', {
|
||||
token: this.token.address,
|
||||
account: this.receiver.address,
|
||||
value: receiverInitialBalance.add(loanAmount),
|
||||
value: receiverInitialBalance.add(loanValue),
|
||||
});
|
||||
await expectEvent.inTransaction(tx, this.receiver, 'TotalSupply', {
|
||||
token: this.token.address,
|
||||
value: initialSupply.add(receiverInitialBalance).add(loanAmount),
|
||||
value: initialSupply.add(receiverInitialBalance).add(loanValue),
|
||||
});
|
||||
|
||||
expect(await this.token.totalSupply()).to.be.bignumber.equal(initialSupply.add(receiverInitialBalance));
|
||||
|
||||
Reference in New Issue
Block a user