Skip to content

Add tests for AllOrNothing Contract #5

Merged
rayedsikder merged 56 commits intotest/v3-implementationfrom
test/all-or-nothing
Oct 9, 2023
Merged

Add tests for AllOrNothing Contract #5
rayedsikder merged 56 commits intotest/v3-implementationfrom
test/all-or-nothing

Conversation

@mahabubAlahi
Copy link
Collaborator

@mahabubAlahi mahabubAlahi commented Oct 3, 2023

Both hardhat and foundry tests are included for the AllOrNothing contract.

allornothing2


Foundry:

  • Base.t.sol:- Base test contract with common logic needed by all tests.

    • setUp
    • createUser
  • utils/BytesSplitter.sol:- Bytes Splitter Contract for splitting bytes.

    • splitBytesIntoTwo
  • 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 the Users struct variable is included.

  • unit/GlobalParams.t.sol:- Test contract for GlobalParams contract.

    • test_GetProtocolAdminAddress
    • test_GetTokenAddress
    • test_GetProtocolFeePercent
  • unit/TestUSD.t.sol:- Test contract for TestUSD contract.

    • setUp
    • test_Mint
    • test_TransferFrom
  • 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 for AllOrNothing test.

    • enlistPlatform
    • addBytecode
    • enlistBytecode
    • createCampaign
    • deploy
    • addReward
    • pledgeOnPreLaunch
    • pledgeForAReward
    • pledgeWithoutAReward
    • claimRefund
    • disburseFees
    • withdraw
  • integration/AllOrNothing/AllOrNothingFunction.t.sol:- Integration Test contract for AllOrNothing contract. It contains all the happy path test cases

    • test_addReward
    • test_pledgeOnPreLaunch
    • test_pledgeForAReward
    • test_pledgeWithoutAReward
    • test_claimRefund
    • test_disburseFees
    • test_withdraw
  • Command:-

    • forge clean
    • forge test

Hardhat

  • AllOrNothing.test.ts:- It contains all the test cases for AllOrNothing contract.
    • deployOnceFixture
    • enlistPlatform
    • addBytecode
    • enlistBytecode
    • createCampaign
    • deploy
    • addReward
    • pledgeOnPreLaunch
    • pledgeForAReward
    • pledgeWithoutAReward
    • claimRefund
    • disburseFees
    • withdraw
  • Command:-
    • npx hardhat clean
    • npx hardhat test

mahabubAlahi and others added 30 commits September 19, 2023 16:54
- 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`
rayedsikder and others added 21 commits September 29, 2023 15:55
- Remove redundant paths variable
- update `currentTimeIsGreater` to `currentTimeIsLess`
- _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
@mahabubAlahi mahabubAlahi added the enhancement New feature or request label Oct 3, 2023
@mahabubAlahi mahabubAlahi self-assigned this Oct 3, 2023
@rayedsikder rayedsikder self-requested a review October 9, 2023 11:40
Copy link
Member

@rayedsikder rayedsikder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.sol import as its not used here

*/
function createCampaign(bytes32 platformBytes) internal {

bytes32 identifierHash = keccak256(abi.encodePacked(platformBytes));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants