From 4f9d8188596af48c8268971de161b928ebb8a2bf Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 11 May 2024 15:59:26 +0800 Subject: [PATCH 1/3] feat: add .gitmodules --- .gitmodules | 9 +++++++++ lib/forge-std | 1 + lib/foundry-huff | 1 + lib/openzeppelin-contracts | 1 + 4 files changed, 12 insertions(+) create mode 100644 .gitmodules create mode 160000 lib/forge-std create mode 160000 lib/foundry-huff create mode 160000 lib/openzeppelin-contracts diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2458e60 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "lib/foundry-huff"] + path = lib/foundry-huff + url = https://github.com/huff-language/foundry-huff +[submodule "lib/forge-std"] + path = lib/forge-std + url = https://github.com/foundry-rs/forge-std +[submodule "lib/openzeppelin-contracts"] + path = lib/openzeppelin-contracts + url = https://github.com/OpenZeppelin/openzeppelin-contracts diff --git a/lib/forge-std b/lib/forge-std new file mode 160000 index 0000000..978ac6f --- /dev/null +++ b/lib/forge-std @@ -0,0 +1 @@ +Subproject commit 978ac6fadb62f5f0b723c996f64be52eddba6801 diff --git a/lib/foundry-huff b/lib/foundry-huff new file mode 160000 index 0000000..7d1ce15 --- /dev/null +++ b/lib/foundry-huff @@ -0,0 +1 @@ +Subproject commit 7d1ce15ccf92bd68458c7e28e0ae847b64b4fc74 diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts new file mode 160000 index 0000000..dbb6104 --- /dev/null +++ b/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit dbb6104ce834628e473d2173bbc9d47f81a9eec3 From fd280ac12896e98d3e00f6ad95da85cea6d8e1f4 Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 11 May 2024 16:19:09 +0800 Subject: [PATCH 2/3] test: check balances --- test/BatchTransferTest.t.sol | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/BatchTransferTest.t.sol b/test/BatchTransferTest.t.sol index a1de2f3..958216f 100644 --- a/test/BatchTransferTest.t.sol +++ b/test/BatchTransferTest.t.sol @@ -5,6 +5,7 @@ import "foundry-huff/HuffDeployer.sol"; import "forge-std/Test.sol"; import "forge-std/console.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract BatchTransferTest is Test { IBatchTransfer iBatch; @@ -27,7 +28,7 @@ contract BatchTransferTest is Test { iBatch = IBatchTransfer(HuffDeployer.deploy("BatchTransfer")); disperse = new Disperse(); - for(uint i; i < 1000; i++){ + for(uint i = 1; i < 1000; i++){ recipients.push(address(uint160(address0)+uint160(i))); amounts.push(i); total += i; @@ -51,12 +52,22 @@ contract BatchTransferTest is Test { vm.prank(address0); //console.log(address0.balance); iBatch.batchTransferETH{value: total}(recipients, amounts); + + // check balance + for (uint256 i = 0; i < recipients.length; i++){ + assertEq(recipients[i].balance, amounts[i]); + } } function testBatchTransferERC20() public { vm.prank(address0); //console.log(address0.balance); iBatch.batchTransferERC20(address(token0), total, recipients, amounts); + + // check balance + for (uint256 i = 0; i < recipients.length; i++){ + assertEq(IERC20(token0).balanceOf(recipients[i]), amounts[i]); + } } function testDisperseDeploy() public { @@ -136,4 +147,4 @@ contract Disperse { for (uint256 i = 0; i < recipients.length; i++) require(token.transferFrom(msg.sender, recipients[i], values[i])); } -} \ No newline at end of file +} From 2b89b9934f19548ec514bd3701395737eca75393 Mon Sep 17 00:00:00 2001 From: Albert Date: Sat, 11 May 2024 16:34:18 +0800 Subject: [PATCH 3/3] test: check balances --- test/BatchTransferTest.t.sol | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/BatchTransferTest.t.sol b/test/BatchTransferTest.t.sol index 958216f..128f4c1 100644 --- a/test/BatchTransferTest.t.sol +++ b/test/BatchTransferTest.t.sol @@ -57,17 +57,22 @@ contract BatchTransferTest is Test { for (uint256 i = 0; i < recipients.length; i++){ assertEq(recipients[i].balance, amounts[i]); } + assertEq(address0.balance, 1000 ether - total); } function testBatchTransferERC20() public { + uint256 balanceBefore = IERC20(token0).balanceOf(address0); + vm.prank(address0); - //console.log(address0.balance); iBatch.batchTransferERC20(address(token0), total, recipients, amounts); // check balance for (uint256 i = 0; i < recipients.length; i++){ assertEq(IERC20(token0).balanceOf(recipients[i]), amounts[i]); } + + uint256 balanceAfter = IERC20(token0).balanceOf(address0); + assertEq(balanceAfter, balanceBefore - total); } function testDisperseDeploy() public {