From 4893548d362fdafe5bddaf4dabb1d1ec91537485 Mon Sep 17 00:00:00 2001 From: David Racero Date: Tue, 3 Nov 2020 14:06:10 +0100 Subject: [PATCH] Added fallback/receive test --- test/weth-gateway.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/weth-gateway.spec.ts b/test/weth-gateway.spec.ts index ae037ab3..5e478600 100644 --- a/test/weth-gateway.spec.ts +++ b/test/weth-gateway.spec.ts @@ -183,11 +183,12 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => expect(debtBalanceAfterFullRepay).to.be.eq(zero); }); - xit('Should revert if receive function receives Ether', async () => { + it('Should revert if receive or fallback functions receives Ether', async () => { const {users, wethGateway} = testEnv; const user = users[0]; const amount = parseEther('1'); + // Call receiver function (empty data + value) await expect( user.signer.sendTransaction({to: wethGateway.address, value: amount}) ).to.be.revertedWith('Receive not allowed'); @@ -196,9 +197,12 @@ makeSuite('Use native ETH at LendingPool via WETHGateway', (testEnv: TestEnv) => const abiCoder = new BRE.ethers.utils.Interface(fakeABI); const fakeMethodEncoded = abiCoder.encodeFunctionData('wantToCallFallback', []); + // Call fallback function with value await expect( user.signer.sendTransaction({to: wethGateway.address, data: fakeMethodEncoded, value: amount}) - ).to.be.revertedWith('Fallback not allowed'); + ).to.be.reverted; + + // Call fallback function without value await expect(user.signer.sendTransaction({to: wethGateway.address, data: fakeMethodEncoded})).to .be.reverted; });