Skip to content

Commit

Permalink
Fix deprecated expectEvent.inLogs OpenZeppelin#3332 (OpenZeppelin#3333)
Browse files Browse the repository at this point in the history
  • Loading branch information
niccolopetti authored Apr 23, 2022
1 parent 5a75065 commit d4e6236
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 136 deletions.
12 changes: 6 additions & 6 deletions test/finance/PaymentSplitter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ contract('PaymentSplitter', function (accounts) {
// distribute to payees

const tracker1 = await balance.tracker(payee1);
const { logs: logs1 } = await this.contract.release(payee1);
const receipt1 = await this.contract.release(payee1);
const profit1 = await tracker1.delta();
expect(profit1).to.be.bignumber.equal(ether('0.20'));
expectEvent.inLogs(logs1, 'PaymentReleased', { to: payee1, amount: profit1 });
expectEvent(receipt1, 'PaymentReleased', { to: payee1, amount: profit1 });

const tracker2 = await balance.tracker(payee2);
const { logs: logs2 } = await this.contract.release(payee2);
const receipt2 = await this.contract.release(payee2);
const profit2 = await tracker2.delta();
expect(profit2).to.be.bignumber.equal(ether('0.10'));
expectEvent.inLogs(logs2, 'PaymentReleased', { to: payee2, amount: profit2 });
expectEvent(receipt2, 'PaymentReleased', { to: payee2, amount: profit2 });

const tracker3 = await balance.tracker(payee3);
const { logs: logs3 } = await this.contract.release(payee3);
const receipt3 = await this.contract.release(payee3);
const profit3 = await tracker3.delta();
expect(profit3).to.be.bignumber.equal(ether('0.70'));
expectEvent.inLogs(logs3, 'PaymentReleased', { to: payee3, amount: profit3 });
expectEvent(receipt3, 'PaymentReleased', { to: payee3, amount: profit3 });

// end balance should be zero
expect(await balance.current(this.contract.address)).to.be.bignumber.equal('0');
Expand Down
4 changes: 2 additions & 2 deletions test/governance/utils/Votes.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ function shouldBehaveLikeVotes () {
}),
));

const { logs } = await this.votes.delegateBySig(this.account1Delegatee, nonce, MAX_UINT256, v, r, s);
const { args } = logs.find(({ event }) => event === 'DelegateChanged');
const receipt = await this.votes.delegateBySig(this.account1Delegatee, nonce, MAX_UINT256, v, r, s);
const { args } = receipt.logs.find(({ event }) => event === 'DelegateChanged');
expect(args.delegator).to.not.be.equal(delegatorAddress);
expect(args.fromDelegate).to.be.equal(ZERO_ADDRESS);
expect(args.toDelegate).to.be.equal(this.account1Delegatee);
Expand Down
8 changes: 4 additions & 4 deletions test/security/Pausable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ contract('Pausable', function (accounts) {

context('when paused', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.pausable.pause({ from: pauser }));
(this.receipt = await this.pausable.pause({ from: pauser }));
});

it('emits a Paused event', function () {
expectEvent.inLogs(this.logs, 'Paused', { account: pauser });
expectEvent(this.receipt, 'Paused', { account: pauser });
});

it('cannot perform normal process in pause', async function () {
Expand All @@ -60,11 +60,11 @@ contract('Pausable', function (accounts) {

context('when unpaused', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.pausable.unpause({ from: pauser }));
(this.receipt = await this.pausable.unpause({ from: pauser }));
});

it('emits an Unpaused event', function () {
expectEvent.inLogs(this.logs, 'Unpaused', { account: pauser });
expectEvent(this.receipt, 'Unpaused', { account: pauser });
});

it('should resume allowing normal process', async function () {
Expand Down
28 changes: 14 additions & 14 deletions test/token/ERC1155/ERC1155.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
});

describe('setApprovalForAll', function () {
let logs;
let receipt;
beforeEach(async function () {
({ logs } = await this.token.setApprovalForAll(proxy, true, { from: multiTokenHolder }));
(receipt = await this.token.setApprovalForAll(proxy, true, { from: multiTokenHolder }));
});

it('sets approval status which can be queried via isApprovedForAll', async function () {
expect(await this.token.isApprovedForAll(multiTokenHolder, proxy)).to.be.equal(true);
});

it('emits an ApprovalForAll log', function () {
expectEvent.inLogs(logs, 'ApprovalForAll', { account: multiTokenHolder, operator: proxy, approved: true });
expectEvent(receipt, 'ApprovalForAll', { account: multiTokenHolder, operator: proxy, approved: true });
});

it('can unset approval for an operator', async function () {
Expand Down Expand Up @@ -247,7 +247,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
});

it('emits a TransferSingle log', function () {
expectEvent.inLogs(this.transferLogs, 'TransferSingle', {
expectEvent(this.transferLogs, 'TransferSingle', {
operator,
from,
to: this.toWhom,
Expand All @@ -260,7 +260,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
context('when called by the multiTokenHolder', async function () {
beforeEach(async function () {
this.toWhom = recipient;
({ logs: this.transferLogs } =
(this.transferLogs =
await this.token.safeTransferFrom(multiTokenHolder, recipient, firstTokenId, firstAmount, '0x', {
from: multiTokenHolder,
}));
Expand Down Expand Up @@ -302,7 +302,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
beforeEach(async function () {
this.toWhom = recipient;
await this.token.setApprovalForAll(proxy, true, { from: multiTokenHolder });
({ logs: this.transferLogs } =
(this.transferLogs =
await this.token.safeTransferFrom(multiTokenHolder, recipient, firstTokenId, firstAmount, '0x', {
from: proxy,
}));
Expand Down Expand Up @@ -344,7 +344,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
'0x',
{ from: multiTokenHolder },
);
({ logs: this.transferLogs } = this.transferReceipt);
(this.transferLogs = this.transferReceipt);
});

transferWasSuccessful.call(this, {
Expand Down Expand Up @@ -377,7 +377,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
data,
{ from: multiTokenHolder },
);
({ logs: this.transferLogs } = this.transferReceipt);
(this.transferLogs = this.transferReceipt);
});

transferWasSuccessful.call(this, {
Expand Down Expand Up @@ -525,7 +525,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
});

it('emits a TransferBatch log', function () {
expectEvent.inLogs(this.transferLogs, 'TransferBatch', {
expectEvent(this.transferLogs, 'TransferBatch', {
operator,
from,
to: this.toWhom,
Expand All @@ -538,7 +538,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
context('when called by the multiTokenHolder', async function () {
beforeEach(async function () {
this.toWhom = recipient;
({ logs: this.transferLogs } =
(this.transferLogs =
await this.token.safeBatchTransferFrom(
multiTokenHolder, recipient,
[firstTokenId, secondTokenId],
Expand Down Expand Up @@ -578,7 +578,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
beforeEach(async function () {
this.toWhom = recipient;
await this.token.setApprovalForAll(proxy, true, { from: multiTokenHolder });
({ logs: this.transferLogs } =
(this.transferLogs =
await this.token.safeBatchTransferFrom(
multiTokenHolder, recipient,
[firstTokenId, secondTokenId],
Expand Down Expand Up @@ -620,7 +620,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
[firstAmount, secondAmount],
'0x', { from: multiTokenHolder },
);
({ logs: this.transferLogs } = this.transferReceipt);
(this.transferLogs = this.transferReceipt);
});

batchTransferWasSuccessful.call(this, {
Expand Down Expand Up @@ -651,7 +651,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
[firstAmount, secondAmount],
data, { from: multiTokenHolder },
);
({ logs: this.transferLogs } = this.transferReceipt);
(this.transferLogs = this.transferReceipt);
});

batchTransferWasSuccessful.call(this, {
Expand Down Expand Up @@ -729,7 +729,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
[firstAmount, secondAmount],
'0x', { from: multiTokenHolder },
);
({ logs: this.transferLogs } = this.transferReceipt);
(this.transferLogs = this.transferReceipt);
});

batchTransferWasSuccessful.call(this, {
Expand Down
16 changes: 8 additions & 8 deletions test/token/ERC1155/ERC1155.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ contract('ERC1155', function (accounts) {

context('with minted tokens', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.token.mint(tokenHolder, tokenId, mintAmount, data, { from: operator }));
(this.receipt = await this.token.mint(tokenHolder, tokenId, mintAmount, data, { from: operator }));
});

it('emits a TransferSingle event', function () {
expectEvent.inLogs(this.logs, 'TransferSingle', {
expectEvent(this.receipt, 'TransferSingle', {
operator,
from: ZERO_ADDRESS,
to: tokenHolder,
Expand Down Expand Up @@ -79,7 +79,7 @@ contract('ERC1155', function (accounts) {

context('with minted batch of tokens', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.token.mintBatch(
(this.receipt = await this.token.mintBatch(
tokenBatchHolder,
tokenBatchIds,
mintAmounts,
Expand All @@ -89,7 +89,7 @@ contract('ERC1155', function (accounts) {
});

it('emits a TransferBatch event', function () {
expectEvent.inLogs(this.logs, 'TransferBatch', {
expectEvent(this.receipt, 'TransferBatch', {
operator,
from: ZERO_ADDRESS,
to: tokenBatchHolder,
Expand Down Expand Up @@ -142,7 +142,7 @@ contract('ERC1155', function (accounts) {
context('with minted-then-burnt tokens', function () {
beforeEach(async function () {
await this.token.mint(tokenHolder, tokenId, mintAmount, data);
({ logs: this.logs } = await this.token.burn(
(this.receipt = await this.token.burn(
tokenHolder,
tokenId,
burnAmount,
Expand All @@ -151,7 +151,7 @@ contract('ERC1155', function (accounts) {
});

it('emits a TransferSingle event', function () {
expectEvent.inLogs(this.logs, 'TransferSingle', {
expectEvent(this.receipt, 'TransferSingle', {
operator,
from: tokenHolder,
to: ZERO_ADDRESS,
Expand Down Expand Up @@ -199,7 +199,7 @@ contract('ERC1155', function (accounts) {
context('with minted-then-burnt tokens', function () {
beforeEach(async function () {
await this.token.mintBatch(tokenBatchHolder, tokenBatchIds, mintAmounts, data);
({ logs: this.logs } = await this.token.burnBatch(
(this.receipt = await this.token.burnBatch(
tokenBatchHolder,
tokenBatchIds,
burnAmounts,
Expand All @@ -208,7 +208,7 @@ contract('ERC1155', function (accounts) {
});

it('emits a TransferBatch event', function () {
expectEvent.inLogs(this.logs, 'TransferBatch', {
expectEvent(this.receipt, 'TransferBatch', {
operator,
from: tokenBatchHolder,
to: ZERO_ADDRESS,
Expand Down
9 changes: 4 additions & 5 deletions test/token/ERC20/extensions/ERC20Burnable.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {

function shouldBurn (amount) {
beforeEach(async function () {
({ logs: this.logs } = await this.token.burn(amount, { from: owner }));
(this.receipt = await this.token.burn(amount, { from: owner }));
});

it('burns the requested amount', async function () {
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal(initialBalance.sub(amount));
});

it('emits a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
expectEvent(this.receipt, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
value: amount,
Expand Down Expand Up @@ -59,8 +59,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {

beforeEach(async function () {
await this.token.approve(burner, originalAllowance, { from: owner });
const { logs } = await this.token.burnFrom(owner, amount, { from: burner });
this.logs = logs;
this.receipt = await this.token.burnFrom(owner, amount, { from: burner });
});

it('burns the requested amount', async function () {
Expand All @@ -72,7 +71,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
});

it('emits a transfer event', async function () {
expectEvent.inLogs(this.logs, 'Transfer', {
expectEvent(this.receipt, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
value: amount,
Expand Down
32 changes: 16 additions & 16 deletions test/token/ERC20/extensions/ERC20Snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ contract('ERC20Snapshot', function (accounts) {

describe('snapshot', function () {
it('emits a snapshot event', async function () {
const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot');
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot');
});

it('creates increasing snapshots ids, starting from 1', async function () {
for (const id of ['1', '2', '3', '4', '5']) {
const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id });
}
});
});
Expand All @@ -42,8 +42,8 @@ contract('ERC20Snapshot', function (accounts) {
beforeEach(async function () {
this.initialSnapshotId = new BN('1');

const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id: this.initialSnapshotId });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id: this.initialSnapshotId });
});

context('with no supply changes after the snapshot', function () {
Expand All @@ -66,8 +66,8 @@ contract('ERC20Snapshot', function (accounts) {
beforeEach(async function () {
this.secondSnapshotId = new BN('2');

const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id: this.secondSnapshotId });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id: this.secondSnapshotId });
});

it('snapshots return the supply before and after the changes', async function () {
Expand All @@ -84,8 +84,8 @@ contract('ERC20Snapshot', function (accounts) {
this.secondSnapshotIds = ['2', '3', '4'];

for (const id of this.secondSnapshotIds) {
const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id });
}
});

Expand Down Expand Up @@ -116,8 +116,8 @@ contract('ERC20Snapshot', function (accounts) {
beforeEach(async function () {
this.initialSnapshotId = new BN('1');

const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id: this.initialSnapshotId });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id: this.initialSnapshotId });
});

context('with no balance changes after the snapshot', function () {
Expand Down Expand Up @@ -147,8 +147,8 @@ contract('ERC20Snapshot', function (accounts) {
beforeEach(async function () {
this.secondSnapshotId = new BN('2');

const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id: this.secondSnapshotId });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id: this.secondSnapshotId });
});

it('snapshots return the balances before and after the changes', async function () {
Expand All @@ -174,8 +174,8 @@ contract('ERC20Snapshot', function (accounts) {
this.secondSnapshotIds = ['2', '3', '4'];

for (const id of this.secondSnapshotIds) {
const { logs } = await this.token.snapshot();
expectEvent.inLogs(logs, 'Snapshot', { id });
const receipt = await this.token.snapshot();
expectEvent(receipt, 'Snapshot', { id });
}
});

Expand Down
4 changes: 2 additions & 2 deletions test/token/ERC20/extensions/ERC20Votes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ contract('ERC20Votes', function (accounts) {
}),
));

const { logs } = await this.token.delegateBySig(holderDelegatee, nonce, MAX_UINT256, v, r, s);
const { args } = logs.find(({ event }) => event == 'DelegateChanged');
const receipt = await this.token.delegateBySig(holderDelegatee, nonce, MAX_UINT256, v, r, s);
const { args } = receipt.logs.find(({ event }) => event == 'DelegateChanged');
expect(args.delegator).to.not.be.equal(delegatorAddress);
expect(args.fromDelegate).to.be.equal(ZERO_ADDRESS);
expect(args.toDelegate).to.be.equal(holderDelegatee);
Expand Down
4 changes: 2 additions & 2 deletions test/token/ERC20/extensions/ERC20VotesComp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ contract('ERC20VotesComp', function (accounts) {
}),
));

const { logs } = await this.token.delegateBySig(holderDelegatee, nonce, MAX_UINT256, v, r, s);
const { args } = logs.find(({ event }) => event == 'DelegateChanged');
const receipt = await this.token.delegateBySig(holderDelegatee, nonce, MAX_UINT256, v, r, s);
const { args } = receipt.logs.find(({ event }) => event == 'DelegateChanged');
expect(args.delegator).to.not.be.equal(delegatorAddress);
expect(args.fromDelegate).to.be.equal(ZERO_ADDRESS);
expect(args.toDelegate).to.be.equal(holderDelegatee);
Expand Down
Loading

0 comments on commit d4e6236

Please sign in to comment.