Improve ERC4626 event coverage (#4072)

This commit is contained in:
Hadrien Croubois
2023-02-23 21:06:47 +01:00
committed by GitHub
parent 9d06a1b64b
commit a6b8366980

View File

@ -66,6 +66,13 @@ contract('ERC4626', function (accounts) {
to: recipient, to: recipient,
value: parseShare(1), value: parseShare(1),
}); });
await expectEvent.inTransaction(tx, this.vault, 'Deposit', {
sender: holder,
owner: recipient,
assets: parseToken(1),
shares: parseShare(1),
});
}); });
it('mint', async function () { it('mint', async function () {
@ -85,6 +92,13 @@ contract('ERC4626', function (accounts) {
to: recipient, to: recipient,
value: parseShare(1), value: parseShare(1),
}); });
await expectEvent.inTransaction(tx, this.vault, 'Deposit', {
sender: holder,
owner: recipient,
assets: parseToken(1),
shares: parseShare(1),
});
}); });
it('withdraw', async function () { it('withdraw', async function () {
@ -104,6 +118,14 @@ contract('ERC4626', function (accounts) {
to: constants.ZERO_ADDRESS, to: constants.ZERO_ADDRESS,
value: '0', value: '0',
}); });
await expectEvent.inTransaction(tx, this.vault, 'Withdraw', {
sender: holder,
receiver: recipient,
owner: holder,
assets: '0',
shares: '0',
});
}); });
it('redeem', async function () { it('redeem', async function () {
@ -123,6 +145,14 @@ contract('ERC4626', function (accounts) {
to: constants.ZERO_ADDRESS, to: constants.ZERO_ADDRESS,
value: '0', value: '0',
}); });
await expectEvent.inTransaction(tx, this.vault, 'Withdraw', {
sender: holder,
receiver: recipient,
owner: holder,
assets: '0',
shares: '0',
});
}); });
}); });
@ -171,6 +201,13 @@ contract('ERC4626', function (accounts) {
to: recipient, to: recipient,
value: expectedShares, value: expectedShares,
}); });
await expectEvent.inTransaction(tx, this.vault, 'Deposit', {
sender: holder,
owner: recipient,
assets: depositAssets,
shares: expectedShares,
});
}); });
/** /**
@ -207,6 +244,13 @@ contract('ERC4626', function (accounts) {
to: recipient, to: recipient,
value: mintShares, value: mintShares,
}); });
await expectEvent.inTransaction(tx, this.vault, 'Deposit', {
sender: holder,
owner: recipient,
assets: expectedAssets,
shares: mintShares,
});
}); });
it('withdraw', async function () { it('withdraw', async function () {
@ -226,6 +270,14 @@ contract('ERC4626', function (accounts) {
to: constants.ZERO_ADDRESS, to: constants.ZERO_ADDRESS,
value: '0', value: '0',
}); });
await expectEvent.inTransaction(tx, this.vault, 'Withdraw', {
sender: holder,
receiver: recipient,
owner: holder,
assets: '0',
shares: '0',
});
}); });
it('redeem', async function () { it('redeem', async function () {
@ -245,6 +297,14 @@ contract('ERC4626', function (accounts) {
to: constants.ZERO_ADDRESS, to: constants.ZERO_ADDRESS,
value: '0', value: '0',
}); });
await expectEvent.inTransaction(tx, this.vault, 'Withdraw', {
sender: holder,
receiver: recipient,
owner: holder,
assets: '0',
shares: '0',
});
}); });
}); });
@ -292,6 +352,13 @@ contract('ERC4626', function (accounts) {
to: recipient, to: recipient,
value: expectedShares, value: expectedShares,
}); });
await expectEvent.inTransaction(tx, this.vault, 'Deposit', {
sender: holder,
owner: recipient,
assets: depositAssets,
shares: expectedShares,
});
}); });
/** /**
@ -326,6 +393,13 @@ contract('ERC4626', function (accounts) {
to: recipient, to: recipient,
value: mintShares, value: mintShares,
}); });
await expectEvent.inTransaction(tx, this.vault, 'Deposit', {
sender: holder,
owner: recipient,
assets: expectedAssets,
shares: mintShares,
});
}); });
it('withdraw', async function () { it('withdraw', async function () {
@ -351,6 +425,14 @@ contract('ERC4626', function (accounts) {
to: constants.ZERO_ADDRESS, to: constants.ZERO_ADDRESS,
value: expectedShares, value: expectedShares,
}); });
await expectEvent.inTransaction(tx, this.vault, 'Withdraw', {
sender: holder,
receiver: recipient,
owner: holder,
assets: withdrawAssets,
shares: expectedShares,
});
}); });
it('withdraw with approval', async function () { it('withdraw with approval', async function () {
@ -363,21 +445,35 @@ contract('ERC4626', function (accounts) {
}); });
it('redeem', async function () { it('redeem', async function () {
expect(await this.vault.maxRedeem(holder)).to.be.bignumber.equal(parseShare(100)); const effectiveAssets = await this.vault.totalAssets().then(x => x.add(virtualAssets));
expect(await this.vault.previewRedeem(parseShare(100))).to.be.bignumber.equal(parseToken(1)); const effectiveShares = await this.vault.totalSupply().then(x => x.add(virtualShares));
const { tx } = await this.vault.redeem(parseShare(100), recipient, holder, { from: holder }); const redeemShares = parseShare(100);
const expectedAssets = redeemShares.mul(effectiveAssets).div(effectiveShares);
expect(await this.vault.maxRedeem(holder)).to.be.bignumber.equal(redeemShares);
expect(await this.vault.previewRedeem(redeemShares)).to.be.bignumber.equal(expectedAssets);
const { tx } = await this.vault.redeem(redeemShares, recipient, holder, { from: holder });
await expectEvent.inTransaction(tx, this.token, 'Transfer', { await expectEvent.inTransaction(tx, this.token, 'Transfer', {
from: this.vault.address, from: this.vault.address,
to: recipient, to: recipient,
value: parseToken(1), value: expectedAssets,
}); });
await expectEvent.inTransaction(tx, this.vault, 'Transfer', { await expectEvent.inTransaction(tx, this.vault, 'Transfer', {
from: holder, from: holder,
to: constants.ZERO_ADDRESS, to: constants.ZERO_ADDRESS,
value: parseShare(100), value: redeemShares,
});
await expectEvent.inTransaction(tx, this.vault, 'Withdraw', {
sender: holder,
receiver: recipient,
owner: holder,
assets: expectedAssets,
shares: redeemShares,
}); });
}); });