Skip to content

Commit

Permalink
fix: Fix event checks in test cases (#824)
Browse files Browse the repository at this point in the history
* fix: Fix event emission checks in tests chai matchers

* fix await emit in tests

* fix: await emit

Co-authored-by: Lukas <lukasstrassel@googlemail.com>
Co-authored-by: Andrei Kozlov <kyzia.ru@gmail.com>
  • Loading branch information
3 people authored Mar 13, 2023
1 parent 2437c56 commit 29ff9b9
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 121 deletions.
26 changes: 11 additions & 15 deletions test-suites/aave-oracle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ makeSuite('AaveOracle', (testEnv: TestEnv) => {
expect(priorSourcesPrices).to.eql(['0']);

// Add asset source
expect(
await aaveOracle
await expect(
aaveOracle
.connect(poolAdmin.signer)
.setAssetSources([mockToken.address], [mockAggregator.address])
)
Expand All @@ -69,10 +69,8 @@ makeSuite('AaveOracle', (testEnv: TestEnv) => {
expect(daiSource).to.be.not.eq(ZERO_ADDRESS);

// Update DAI source
expect(
await aaveOracle
.connect(poolAdmin.signer)
.setAssetSources([dai.address], [mockAggregator.address])
await expect(
aaveOracle.connect(poolAdmin.signer).setAssetSources([dai.address], [mockAggregator.address])
)
.to.emit(aaveOracle, 'AssetSourceUpdated')
.withArgs(dai.address, mockAggregator.address);
Expand Down Expand Up @@ -113,10 +111,8 @@ makeSuite('AaveOracle', (testEnv: TestEnv) => {
const { poolAdmin, aaveOracle, weth } = testEnv;

// Add asset source for BASE_CURRENCY address
expect(
await aaveOracle
.connect(poolAdmin.signer)
.setAssetSources([weth.address], [mockAggregator.address])
await expect(
aaveOracle.connect(poolAdmin.signer).setAssetSources([weth.address], [mockAggregator.address])
)
.to.emit(aaveOracle, 'AssetSourceUpdated')
.withArgs(weth.address, mockAggregator.address);
Expand Down Expand Up @@ -149,8 +145,8 @@ makeSuite('AaveOracle', (testEnv: TestEnv) => {
expect(await aaveOracle.getSourceOfAsset(mockToken.address)).to.be.eq(ZERO_ADDRESS);

// Add asset source
expect(
await aaveOracle
await expect(
aaveOracle
.connect(poolAdmin.signer)
.setAssetSources([mockToken.address], [zeroPriceMockAgg.address])
)
Expand All @@ -173,8 +169,8 @@ makeSuite('AaveOracle', (testEnv: TestEnv) => {
expect(await aaveOracle.getSourceOfAsset(mockToken.address)).to.be.eq(ZERO_ADDRESS);

// Add asset source
expect(
await aaveOracle
await expect(
aaveOracle
.connect(poolAdmin.signer)
.setAssetSources([mockToken.address], [zeroPriceMockAgg.address])
)
Expand All @@ -191,7 +187,7 @@ makeSuite('AaveOracle', (testEnv: TestEnv) => {
expect(await aaveOracle.getFallbackOracle()).to.be.eq(oracle.address);

// Update oracle source
expect(await aaveOracle.connect(poolAdmin.signer).setFallbackOracle(ONE_ADDRESS))
await expect(aaveOracle.connect(poolAdmin.signer).setFallbackOracle(ONE_ADDRESS))
.to.emit(aaveOracle, 'FallbackOracleUpdated')
.withArgs(ONE_ADDRESS);

Expand Down
2 changes: 1 addition & 1 deletion test-suites/aave-protocol-data-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ makeSuite('AaveProtocolDataProvider: Edge cases', (testEnv: TestEnv) => {
const oldPoolImpl = await getProxyImplementation(addressesProvider.address, poolProxyAddress);

// Update the addressesProvider with a mock pool
expect(await addressesProvider.connect(poolAdmin.signer).setPoolImpl(mockPool.address))
await expect(addressesProvider.connect(poolAdmin.signer).setPoolImpl(mockPool.address))
.to.emit(addressesProvider, 'PoolUpdated')
.withArgs(oldPoolImpl, mockPool.address);

Expand Down
14 changes: 7 additions & 7 deletions test-suites/addresses-provider-registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {

const providersBefore = await registry.getAddressesProvidersList();

expect(
await registry.registerAddressesProvider(
await expect(
registry.registerAddressesProvider(
NEW_ADDRESSES_PROVIDER_ADDRESS,
NEW_ADDRESSES_PROVIDER_ID_2
)
Expand Down Expand Up @@ -72,7 +72,7 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
const { users, registry } = testEnv;

// Simulating an addresses provider using the users[2] wallet address
expect(await registry.registerAddressesProvider(users[2].address, NEW_ADDRESSES_PROVIDER_ID_3))
await expect(registry.registerAddressesProvider(users[2].address, NEW_ADDRESSES_PROVIDER_ID_3))
.to.emit(registry, 'AddressesProviderRegistered')
.withArgs(users[2].address, NEW_ADDRESSES_PROVIDER_ID_3);

Expand All @@ -97,7 +97,7 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
await registry.getAddressesProviderIdByAddress(NEW_ADDRESSES_PROVIDER_ADDRESS)
).to.be.equal(NEW_ADDRESSES_PROVIDER_ID_2);

expect(await registry.unregisterAddressesProvider(NEW_ADDRESSES_PROVIDER_ADDRESS))
await expect(registry.unregisterAddressesProvider(NEW_ADDRESSES_PROVIDER_ADDRESS))
.to.emit(registry, 'AddressesProviderUnregistered')
.withArgs(NEW_ADDRESSES_PROVIDER_ADDRESS, NEW_ADDRESSES_PROVIDER_ID_2);

Expand Down Expand Up @@ -177,8 +177,8 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {

const providersBefore = await registry.getAddressesProvidersList();

expect(
await registry.registerAddressesProvider(
await expect(
registry.registerAddressesProvider(
NEW_ADDRESSES_PROVIDER_ADDRESS,
NEW_ADDRESSES_PROVIDER_ID_2
)
Expand Down Expand Up @@ -212,7 +212,7 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
const providerToRemove = providersBefore[providersBefore.length - 1];
const providerToRemoveId = await registry.getAddressesProviderIdByAddress(providerToRemove);

expect(await registry.unregisterAddressesProvider(providerToRemove))
await expect(registry.unregisterAddressesProvider(providerToRemove))
.to.emit(registry, 'AddressesProviderUnregistered')
.withArgs(providerToRemove, providerToRemoveId);

Expand Down
2 changes: 1 addition & 1 deletion test-suites/atoken-delegation-aware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ makeSuite('AToken: DelegationAwareAToken', (testEnv: TestEnv) => {
it('Delegates to user 2', async () => {
const { users } = testEnv;

expect(await delegationAToken.delegateUnderlyingTo(users[2].address))
await expect(delegationAToken.delegateUnderlyingTo(users[2].address))
.to.emit(delegationAToken, 'DelegateUnderlyingTo')
.withArgs(users[2].address);

Expand Down
12 changes: 6 additions & 6 deletions test-suites/atoken-edge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ makeSuite('AToken: Edge cases', (testEnv: TestEnv) => {

it('approve() with a ZERO_ADDRESS spender', async () => {
const { users, aDai } = testEnv;
expect(await aDai.connect(users[0].signer).approve(ZERO_ADDRESS, MAX_UINT_AMOUNT))
await expect(aDai.connect(users[0].signer).approve(ZERO_ADDRESS, MAX_UINT_AMOUNT))
.to.emit(aDai, 'Approval')
.withArgs(users[0].address, ZERO_ADDRESS, MAX_UINT_AMOUNT);
});
Expand Down Expand Up @@ -105,14 +105,14 @@ makeSuite('AToken: Edge cases', (testEnv: TestEnv) => {

it('transfer() with a ZERO_ADDRESS recipient', async () => {
const { users, aDai } = testEnv;
expect(await aDai.connect(users[1].signer).transfer(ZERO_ADDRESS, 0))
await expect(aDai.connect(users[1].signer).transfer(ZERO_ADDRESS, 0))
.to.emit(aDai, 'Transfer')
.withArgs(users[1].address, ZERO_ADDRESS, 0);
});

it('transfer() with a ZERO_ADDRESS origin', async () => {
const { users, aDai } = testEnv;
expect(await aDai.connect(users[1].signer).transferFrom(ZERO_ADDRESS, users[1].address, 0))
await expect(aDai.connect(users[1].signer).transferFrom(ZERO_ADDRESS, users[1].address, 0))
.to.emit(aDai, 'Transfer')
.withArgs(ZERO_ADDRESS, users[1].address, 0);
});
Expand Down Expand Up @@ -141,7 +141,7 @@ makeSuite('AToken: Edge cases', (testEnv: TestEnv) => {
const poolSigner = await hre.ethers.getSigner(pool.address);

const mintingAmount = await convertToCurrencyDecimals(aDai.address, '100');
expect(
await expect(
aDai
.connect(poolSigner)
.mint(ZERO_ADDRESS, ZERO_ADDRESS, mintingAmount, utils.parseUnits('1', 27))
Expand Down Expand Up @@ -174,8 +174,8 @@ makeSuite('AToken: Edge cases', (testEnv: TestEnv) => {
const poolSigner = await hre.ethers.getSigner(pool.address);

const burnAmount = await convertToCurrencyDecimals(aDai.address, '100');
expect(
await aDai
await expect(
aDai
.connect(poolSigner)
.burn(ZERO_ADDRESS, users[0].address, burnAmount, utils.parseUnits('1', 27))
)
Expand Down
14 changes: 7 additions & 7 deletions test-suites/atoken-transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {

expect(await aDai.getPreviousIndex(users[0].address)).to.be.gt(0);

expect(await aDai.connect(users[0].signer).transfer(users[0].address, amountDAItoDeposit))
await expect(aDai.connect(users[0].signer).transfer(users[0].address, amountDAItoDeposit))
.to.emit(aDai, 'Transfer')
.withArgs(users[0].address, users[0].address, amountDAItoDeposit);

Expand Down Expand Up @@ -71,7 +71,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {

expect(await pool.connect(users[0].signer).setUserUseReserveAsCollateral(dai.address, false));

expect(await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit))
await expect(aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit))
.to.emit(aDai, 'Transfer')
.withArgs(users[0].address, users[1].address, amountDAItoDeposit);

Expand Down Expand Up @@ -112,7 +112,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
);

expect(await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoTransfer))
await expect(aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoTransfer))
.to.emit(aDai, 'Transfer')
.withArgs(users[0].address, users[1].address, amountDAItoTransfer);
expect(await aDai.balanceOf(users[0].address)).to.be.eq(
Expand All @@ -124,7 +124,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
INVALID_TO_BALANCE_AFTER_TRANSFER
);

expect(await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoTransfer))
await expect(aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoTransfer))
.to.emit(aDai, 'Transfer')
.withArgs(users[0].address, users[1].address, amountDAItoTransfer);
expect(await aDai.balanceOf(users[0].address)).to.be.eq(
Expand All @@ -136,7 +136,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
INVALID_TO_BALANCE_AFTER_TRANSFER
);

expect(await aDai.connect(users[0].signer).transfer(users[1].address, 0))
await expect(aDai.connect(users[0].signer).transfer(users[1].address, 0))
.to.emit(aDai, 'Transfer')
.withArgs(users[0].address, users[1].address, 0);
expect(await aDai.balanceOf(users[0].address)).to.be.eq(
Expand Down Expand Up @@ -168,7 +168,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
.deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
);

expect(await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit))
await expect(aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit))
.to.emit(aDai, 'Transfer')
.withArgs(users[0].address, users[1].address, amountDAItoDeposit);

Expand Down Expand Up @@ -232,7 +232,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {

const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '100');

expect(await aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer))
await expect(aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer))
.to.emit(aDai, 'Transfer')
.withArgs(users[1].address, users[0].address, aDAItoTransfer);

Expand Down
22 changes: 11 additions & 11 deletions test-suites/configurator-borrow-cap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ makeSuite('PoolConfigurator: Borrow Cap', (testEnv: TestEnv) => {
const { borrowCap: daiOldBorrowCap } = await helpersContract.getReserveCaps(dai.address);

const newCap = 10;
expect(await configurator.setBorrowCap(usdc.address, newCap))
await expect(configurator.setBorrowCap(usdc.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(usdc.address, daiOldBorrowCap, newCap);
expect(await configurator.setBorrowCap(dai.address, newCap))
await expect(configurator.setBorrowCap(dai.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(dai.address, usdcOldBorrowCap, newCap);

Expand Down Expand Up @@ -179,10 +179,10 @@ makeSuite('PoolConfigurator: Borrow Cap', (testEnv: TestEnv) => {
const { borrowCap: usdcOldBorrowCap } = await helpersContract.getReserveCaps(usdc.address);
const { borrowCap: daiOldBorrowCap } = await helpersContract.getReserveCaps(dai.address);

expect(await configurator.setBorrowCap(usdc.address, newCap))
await expect(configurator.setBorrowCap(usdc.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(usdc.address, usdcOldBorrowCap, newCap);
expect(await configurator.setBorrowCap(dai.address, newCap))
await expect(configurator.setBorrowCap(dai.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(dai.address, daiOldBorrowCap, newCap);

Expand Down Expand Up @@ -224,7 +224,7 @@ makeSuite('PoolConfigurator: Borrow Cap', (testEnv: TestEnv) => {
const { borrowCap: wethOldBorrowCap } = await helpersContract.getReserveCaps(weth.address);

const newCap = 2;
expect(await configurator.setBorrowCap(weth.address, newCap))
await expect(configurator.setBorrowCap(weth.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(weth.address, wethOldBorrowCap, newCap);

Expand Down Expand Up @@ -307,10 +307,10 @@ makeSuite('PoolConfigurator: Borrow Cap', (testEnv: TestEnv) => {
const { borrowCap: daiOldBorrowCap } = await helpersContract.getReserveCaps(dai.address);

const newCap = '1000';
expect(await configurator.setBorrowCap(usdc.address, newCap))
await expect(configurator.setBorrowCap(usdc.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(usdc.address, usdcOldBorrowCap, newCap);
expect(await configurator.setBorrowCap(dai.address, newCap))
await expect(configurator.setBorrowCap(dai.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(dai.address, daiOldBorrowCap, newCap);

Expand Down Expand Up @@ -353,10 +353,10 @@ makeSuite('PoolConfigurator: Borrow Cap', (testEnv: TestEnv) => {
const { borrowCap: daiOldBorrowCap } = await helpersContract.getReserveCaps(dai.address);

const newCap = '200';
expect(await configurator.setBorrowCap(usdc.address, newCap))
await expect(configurator.setBorrowCap(usdc.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(usdc.address, usdcOldBorrowCap, newCap);
expect(await configurator.setBorrowCap(dai.address, newCap))
await expect(configurator.setBorrowCap(dai.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(dai.address, daiOldBorrowCap, newCap);

Expand Down Expand Up @@ -399,10 +399,10 @@ makeSuite('PoolConfigurator: Borrow Cap', (testEnv: TestEnv) => {
const { borrowCap: daiOldBorrowCap } = await helpersContract.getReserveCaps(dai.address);

const newCap = MAX_BORROW_CAP;
expect(await configurator.setBorrowCap(usdc.address, newCap))
await expect(configurator.setBorrowCap(usdc.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(usdc.address, usdcOldBorrowCap, newCap);
expect(await configurator.setBorrowCap(dai.address, newCap))
await expect(configurator.setBorrowCap(dai.address, newCap))
.to.emit(configurator, 'BorrowCapChanged')
.withArgs(dai.address, daiOldBorrowCap, newCap);

Expand Down
8 changes: 4 additions & 4 deletions test-suites/configurator-liquidation-protocol-fee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ makeSuite('PoolConfigurator: Liquidation Protocol Fee', (testEnv: TestEnv) => {

const liquidationProtocolFee = 1000;

expect(await configurator.setLiquidationProtocolFee(usdc.address, liquidationProtocolFee))
await expect(configurator.setLiquidationProtocolFee(usdc.address, liquidationProtocolFee))
.to.emit(configurator, 'LiquidationProtocolFeeChanged')
.withArgs(usdc.address, oldUsdcLiquidationProtocolFee, liquidationProtocolFee);
expect(await configurator.setLiquidationProtocolFee(dai.address, liquidationProtocolFee))
await expect(configurator.setLiquidationProtocolFee(dai.address, liquidationProtocolFee))
.to.emit(configurator, 'LiquidationProtocolFeeChanged')
.withArgs(dai.address, oldDaiLiquidationProtocolFee, liquidationProtocolFee);

Expand All @@ -72,10 +72,10 @@ makeSuite('PoolConfigurator: Liquidation Protocol Fee', (testEnv: TestEnv) => {

const liquidationProtocolFee = 10000;

expect(await configurator.setLiquidationProtocolFee(usdc.address, liquidationProtocolFee))
await expect(configurator.setLiquidationProtocolFee(usdc.address, liquidationProtocolFee))
.to.emit(configurator, 'LiquidationProtocolFeeChanged')
.withArgs(usdc.address, oldUsdcLiquidationProtocolFee, liquidationProtocolFee);
expect(await configurator.setLiquidationProtocolFee(dai.address, liquidationProtocolFee))
await expect(configurator.setLiquidationProtocolFee(dai.address, liquidationProtocolFee))
.to.emit(configurator, 'LiquidationProtocolFeeChanged')
.withArgs(dai.address, oldDaiLiquidationProtocolFee, liquidationProtocolFee);

Expand Down
Loading

0 comments on commit 29ff9b9

Please sign in to comment.