Skip to content

Commit 7241e0c

Browse files
committed
test: add rescue-funds tests
1 parent cfba1b9 commit 7241e0c

File tree

3 files changed

+53
-35
lines changed

3 files changed

+53
-35
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
contract ForceSend {
5+
function forceSend(address payable recipient) public payable {
6+
selfdestruct(recipient);
7+
}
8+
}

packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -254,39 +254,23 @@ describe('contract: ERC20SingleRequestProxy', () => {
254254
).to.be.reverted;
255255
});
256256

257-
// it('should work with USDT-like non-standard ERC20 tokens', async () => {
258-
// const usdtProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy(
259-
// user2Addr,
260-
// usdtFake.address,
261-
// feeRecipientAddr,
262-
// feeAmount,
263-
// paymentReference,
264-
// erc20FeeProxy.address,
265-
// );
266-
267-
// const paymentAmount = BN.from(100).mul(USDT_DECIMAL);
268-
// const totalAmount = paymentAmount.add(feeAmount);
269-
270-
// await usdtFake.transfer(usdtProxy.address, totalAmount);
271-
272-
// const usdtProxyBalanceBefore = await usdtFake.balanceOf(usdtProxy.address);
273-
// expect(usdtProxyBalanceBefore).to.equal(totalAmount);
274-
275-
// await expect(
276-
// user1.sendTransaction({
277-
// to: usdtProxy.address,
278-
// value: 0,
279-
// }),
280-
// )
281-
// .to.emit(erc20FeeProxy, 'TransferWithReferenceAndFee')
282-
// .withArgs(usdtFake.address, user2Addr, paymentAmount, paymentReference, feeAmount, feeRecipientAddr);
283-
284-
// const usdtProxyBalanceAfter = await usdtFake.balanceOf(usdtProxy.address);
285-
// const user2BalanceAfter = await usdtFake.balanceOf(user2Addr);
286-
// const feeRecipientBalanceAfter = await usdtFake.balanceOf(feeRecipientAddr);
287-
288-
// expect(usdtProxyBalanceAfter).to.equal(0);
289-
// expect(user2BalanceAfter).to.equal(paymentAmount);
290-
// expect(feeRecipientBalanceAfter).to.equal(feeAmount);
291-
// });
257+
it('should rescue ERC20 tokens', async () => {
258+
const rescueAmount = BN.from(100).mul(BASE_DECIMAL);
259+
260+
// Transfer tokens directly to the contract
261+
await testToken.transfer(erc20SingleRequestProxy.address, rescueAmount);
262+
263+
const contractBalanceBefore = await testToken.balanceOf(erc20SingleRequestProxy.address);
264+
expect(contractBalanceBefore).to.equal(rescueAmount);
265+
266+
const payeeBalanceBefore = await testToken.balanceOf(user2Addr);
267+
268+
await erc20SingleRequestProxy.rescueFunds();
269+
270+
const contractBalanceAfter = await testToken.balanceOf(erc20SingleRequestProxy.address);
271+
expect(contractBalanceAfter).to.equal(0);
272+
273+
const payeeBalanceAfter = await testToken.balanceOf(user2Addr);
274+
expect(payeeBalanceAfter.sub(payeeBalanceBefore)).to.equal(rescueAmount);
275+
});
292276
});

packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,30 @@ describe('contract : EthereumSingleRequestProxy', () => {
114114
expect(await ethers.provider.getBalance(newEthereumSingleRequestProxy.address)).to.equal(0);
115115
expect(await ethers.provider.getBalance(mockEthereumFeeProxy.address)).to.equal(0);
116116
});
117+
118+
it('should rescue funds', async () => {
119+
const paymentAmount = ethers.utils.parseEther('1');
120+
const totalAmount = paymentAmount.add(feeAmount);
121+
122+
const ForceSendFactory = await ethers.getContractFactory('ForceSend');
123+
const forceSend = await ForceSendFactory.deploy();
124+
await forceSend.deployed();
125+
126+
await forceSend.forceSend(ethereumSingleRequestProxy.address, { value: totalAmount });
127+
128+
const balanceAfterForceSend = await ethers.provider.getBalance(
129+
ethereumSingleRequestProxy.address,
130+
);
131+
expect(balanceAfterForceSend).to.be.gt(0);
132+
expect(balanceAfterForceSend).to.equal(totalAmount);
133+
134+
const initialPayeeBalance = await ethers.provider.getBalance(payeeAddress);
135+
136+
await ethereumSingleRequestProxy.rescueFunds();
137+
138+
expect(await ethers.provider.getBalance(ethereumSingleRequestProxy.address)).to.equal(0);
139+
140+
const finalPayeeBalance = await ethers.provider.getBalance(payeeAddress);
141+
expect(finalPayeeBalance.sub(initialPayeeBalance)).to.equal(balanceAfterForceSend);
142+
});
117143
});

0 commit comments

Comments
 (0)