diff --git a/test/forwarderV4.js b/test/forwarderV4.js index e8eed1a..6a6e54c 100644 --- a/test/forwarderV4.js +++ b/test/forwarderV4.js @@ -14,6 +14,7 @@ const ERC721 = artifacts.require('./MockERC721'); const ERC1155 = artifacts.require('./MockERC1155'); const AlwaysFalseERC165 = artifacts.require('./AlwaysFalseERC165.sol'); const ReentryForwarder = artifacts.require('./ReentryForwarder'); +const Tether = artifacts.require('./TetherToken.sol'); const createForwarder = async (creator, parent, feeAddress) => { const forwarderContract = await ForwarderV4.new([], { from: creator }); @@ -83,9 +84,18 @@ const FORWARDER_DEPOSITED_EVENT = 'ForwarderDeposited'; describe('ForwarderV4', function () { let accounts; + let tetherTokenContract; before(async () => { await hre.network.provider.send('hardhat_reset'); accounts = await web3.eth.getAccounts(); + + tetherTokenContract = await Tether.new('1000000', 'USDT', 'USDT', 6, { + from: accounts[0] + }); + const tetherBalance = await tetherTokenContract.balanceOf.call( + accounts[0] + ); + tetherBalance.toString().should.eql('1000000'); }); it('Basic forwarding test', async function () { @@ -201,7 +211,7 @@ describe('ForwarderV4', function () { } catch (err) { assertVMException( err, - "VM Exception while processing transaction: reverted with reason string 'Invalid address'" + "VM Exception while processing transaction: reverted with reason string 'Invalid fee address'" ); } }); @@ -215,7 +225,7 @@ describe('ForwarderV4', function () { } catch (err) { assertVMException( err, - "VM Exception while processing transaction: reverted with reason string 'Invalid address'" + "VM Exception while processing transaction: reverted with reason string 'Invalid parent address'" ); } }); @@ -280,6 +290,37 @@ describe('ForwarderV4', function () { ); }); + it('should batch flush erc20 tokens back to parent address when caller is allowed address', async () => { + const baseAddress = accounts[0]; + const feeAddress = accounts[2]; + const forwarder = await createForwarder( + baseAddress, + baseAddress, + feeAddress + ); + await tetherTokenContract.transfer(forwarder.address, 100, { + from: accounts[0] + }); + const balance = await tetherTokenContract.balanceOf.call(accounts[0]); + balance.should.eql(web3.utils.toBN(1000000 - 100)); + + const forwarderContractStartTokens = + await tetherTokenContract.balanceOf.call(forwarder.address); + forwarderContractStartTokens.should.eql(web3.utils.toBN(100)); + + await forwarder.batchFlushERC20Tokens( + [tetherTokenContract.address], + { from: feeAddress } + ); + + const forwarderAccountEndTokens = + await tetherTokenContract.balanceOf.call(forwarder.address); + forwarderAccountEndTokens.should.eql(web3.utils.toBN(0)); + + const balanceAtEnd = await tetherTokenContract.balanceOf.call(accounts[0]); + balanceAtEnd.should.eql(web3.utils.toBN(1000000)); + }); + describe('NFT Support', function () { let token721; let tokenId = 0; @@ -699,13 +740,14 @@ describe('ForwarderV4', function () { 'onERC1155Received(address,address,uint256,uint256,bytes)', 'onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)' ]), - IForwarder: makeInterfaceId.ERC165([ + IForwarderV4: makeInterfaceId.ERC165([ 'setAutoFlush721(bool)', 'setAutoFlush1155(bool)', 'flushTokens(address)', 'flushERC721Token(address,uint256)', 'flushERC1155Tokens(address,uint256)', - 'batchFlushERC1155Tokens(address,uint256[])' + 'batchFlushERC1155Tokens(address,uint256[])', + 'batchFlushERC20Tokens(address[])', ]) };