Add tests for AllOrNothing Contract #5
Conversation
- Add `@nomicfoundation/hardhat-foundry` package - Upgrade `hardhat` from `^2.17.0` to `^2.17.3`
- CampaignInfoFactory.ts - SampleCampaign.ts
- `enlistPlatform` function test - `addBytecode` function test - `enlistBytecode` function test
- Update `currentTimeIsLess` to `currentTimeIsGreater`
- Remove redundant paths variable
- update `currentTimeIsGreater` to `currentTimeIsLess`
This reverts commit 2f3e47e.
- _checkIfCurrentTimeIsLess - _checkIfCurrentTimeIsGreater
- Update - protocol percentage - platform percentage - claimRefund - disburseFees - Add - withdraw
- add 2 new backer address
- add new user creation - use contract owner to deploy all the contracts - initialize `campaignInfoFactory` - mint token to the backer - warp realistic block time
- add comment - update protocolFeePercent variable
- use contract owner for minting - add comments
- implement all the helper functions for AllOrNothing test - enlistPlatform - addBytecode - enlistBytecode - createCampaign - deploy - addReward - pledgeOnPreLaunch - pledgeForAReward - pledgeWithoutAReward - claimRefund - disburseFees - withdraw
- Test functions for happy cases:- - test_addReward - test_pledgeOnPreLaunch - test_pledgeForAReward - test_pledgeWithoutAReward - test_claimRefund - test_disburseFees - test_withdraw
There was a problem hiding this comment.
The tests are very well-written and cover the happy paths of the AllOrNothing model.
This PR can be merged as it is.
However, there are some minor suggestions that can be adopted to adhere to the current input formats of the backend repository. These input format changes are very recent and were made while the task of writing test suites was in progress.
There was a problem hiding this comment.
Remove console.sol import as its not used here
| */ | ||
| function createCampaign(bytes32 platformBytes) internal { | ||
|
|
||
| bytes32 identifierHash = keccak256(abi.encodePacked(platformBytes)); |
There was a problem hiding this comment.
The identifierHash could be taken as input, otherwise the argument value of identifierHash and platformBytes would be same (This issue will be referenced to in feature branch later - tldr: platformBytes would be replaced with platformHash)
There was a problem hiding this comment.
Splitting bytes into 2 works fine for AllOrNothing test. However if the codesize of a chunk becomes greater than 20,000 bytes per chunk - then it may fail. See deployInitialize.ts where chunks are created with each of 20,000 bytes, except the last chunk which must be < 20,000
This doesn't need to changed for this test, but keeping this documented here for reference.
| uint256 public constant PROTOCOL_FEE_PERCENT = 20 * 100; | ||
| uint256 public constant TOKEN_MINT_AMOUNT = 1_000_000e18; | ||
| uint256 public constant PLATFORM_FEE_PERCENT = 10 * 100; | ||
| bytes32 public constant PLATFORM_1_BYTES = bytes32(bytes("KickStarter")); |
There was a problem hiding this comment.
keccak256 should be used here instead of converting it to hex (This doesn't impact the tests, and can be merged without changing this)
| return parseBytes32String(val); | ||
| }; | ||
|
|
||
| export const splitByteCodeIntoChunks = (byteCode: string, numberOfChunks: number) => { |
There was a problem hiding this comment.
Splitting bytes into 2 works fine for AllOrNothing test. However if the codesize of a chunk becomes greater than 20,000 bytes per chunk - then it may fail. See deployInitialize.ts where chunks are created with each of 20,000 bytes, except the last chunk which must be < 20,000
This doesn't need to changed for this test, but keeping this documented here for reference.
Both
hardhatandfoundrytests are included for theAllOrNothingcontract.Foundry:
Base.t.sol:- Base test contract with common logic needed by all tests.utils/BytesSplitter.sol:- Bytes Splitter Contract for splitting bytes.utils/Constants.sol:- Abstract Contract for all the constant variables.utils/Defaults.sol:- Contract with default values used throughout the tests.utils/Types.sol:- Here all the user types will be added. Currently, only theUsersstruct variable is included.unit/GlobalParams.t.sol:- Test contract for GlobalParams contract.unit/TestUSD.t.sol:- Test contract for TestUSD contract.integration/AllOrNothing/AllOrNothing.t.sol:- An abstract contract containing common testing logic is needed by all AllOrNothing integration tests. It implements all the helper functions forAllOrNothingtest.integration/AllOrNothing/AllOrNothingFunction.t.sol:- Integration Test contract for AllOrNothing contract. It contains all the happy path test casesCommand:-forge cleanforge testHardhat
AllOrNothing.test.ts:- It contains all the test cases forAllOrNothingcontract.Command:-npx hardhat cleannpx hardhat test