Skip to content

Commit

Permalink
feat(contracts): add new forwarder contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
gianchandania committed Dec 26, 2023
1 parent bf7a20a commit deed33c
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions test/forwarderV4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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'"
);
}
});
Expand All @@ -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'"
);
}
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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[])',
])
};

Expand Down

0 comments on commit deed33c

Please sign in to comment.