Skip to content

Commit

Permalink
fix: comments from PR, revert hardhat config
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoMelo00 committed Sep 20, 2024
1 parent f91f56d commit 254c27a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
7 changes: 5 additions & 2 deletions contracts/ERC20Splitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ contract ERC20Splitter is ReentrancyGuard {

/// @notice Withdraw all tokens that the caller is entitled to.
/// Tokens are automatically determined based on previous deposits.
/// @param tokenAddresses Array of token addresses (use address(0) for native tokens).
function withdraw(address[] calldata tokenAddresses) external nonReentrant {
uint256 tokenCount = tokenAddresses.length;
require(tokenCount > 0, 'ERC20Splitter: No tokens specified');
Expand All @@ -68,7 +69,7 @@ contract ERC20Splitter is ReentrancyGuard {
uint256 amount = balances[tokenAddress][msg.sender];

if (amount == 0) {
continue;
return;
}

delete balances[tokenAddress][msg.sender];
Expand Down Expand Up @@ -102,7 +103,9 @@ contract ERC20Splitter is ReentrancyGuard {
address[] calldata recipients
) internal {
require(shares.length == recipients.length, 'ERC20Splitter: Shares and recipients length mismatch');
require(amount > 0, 'ERC20Splitter: Amount must be greater than zero');
if(amount == 0 ) {
return;
}

uint256 totalSharePercentage = 0;

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const BASE_CONFIG = {
forking: {
url: POLYGON_PROVIDER_URL,
blockNumber: 55899875,
timeout: 9999900,
timeout: 20000,
},
},
},
Expand Down
22 changes: 6 additions & 16 deletions test/SplitterContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ describe('ERC20Splitter', () => {
expect(await splitter.balances(mockERC20.getAddress(), recipient1.address)).to.equal(ethers.parseEther('100'))
})

it('Should handle deposit when user has no tokens', async () => {
const recipients = [[recipient1.address]]
const shares = [[10000]]
await splitter.connect(owner).deposit([mockERC20.getAddress()], [0], shares, recipients)
})

it('Should deposit four ERC20 tokens and split them between recipients', async () => {
const tokenAmounts = [
ethers.parseEther('100'),
Expand Down Expand Up @@ -238,7 +244,6 @@ describe('ERC20Splitter', () => {
expect(await splitter.balances(mockERC20.getAddress(), recipient2.address)).to.equal(ethers.parseEther('30'))
expect(await splitter.balances(mockERC20.getAddress(), recipient3.address)).to.equal(ethers.parseEther('20'))
})

it('Should deposit native tokens (ETH) and split them between recipients', async () => {
const shares = [[5000, 3000, 2000]]
const recipients = [[recipient1.address, recipient2.address, recipient3.address]]
Expand Down Expand Up @@ -297,21 +302,6 @@ describe('ERC20Splitter', () => {
}),
).to.be.revertedWith('ERC20Splitter: Incorrect native token amount sent')
})
it('Should revert when amount is 0', async () => {
const incorrectMsgValue = ethers.parseEther('1') // Incorrect Ether amount
const correctEtherAmount = ethers.parseEther('2') // Correct Ether amount to be split
const tokenAddresses = [ethers.ZeroAddress] // Using address(0) for Ether
const amounts = [correctEtherAmount] // Amount to split among recipients
const shares = [[5000, 3000, 2000]] // Shares summing up to 100%
const recipients = [[recipient1.address, recipient2.address, recipient3.address]]

await expect(
splitter.connect(owner).deposit(tokenAddresses, [0], shares, recipients, {
value: incorrectMsgValue, // Sending incorrect msg.value
}),
).to.be.revertedWith('ERC20Splitter: Amount must be greater than zero')
})

it('Should revert when tokenAddresses and amounts lengths mismatch', async () => {
const tokenAddresses = [mockERC20.getAddress(), ethers.ZeroAddress]
const amounts = [ethers.parseEther('100')] // Length 1, intentional mismatch
Expand Down

0 comments on commit 254c27a

Please sign in to comment.