Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of the Stake table contract (register function) #769

Merged
merged 60 commits into from
Dec 1, 2023

Conversation

philippecamacho
Copy link
Contributor

@philippecamacho philippecamacho commented Nov 20, 2023

Part of #737.

Implements the register function of the Stake Table contract.
To test:

just sol-test

@philippecamacho philippecamacho marked this pull request as draft November 20, 2023 22:52
@philippecamacho philippecamacho requested review from alxiong and removed request for nomaxg and ImJeremyHe November 20, 2023 22:52
@philippecamacho philippecamacho changed the title Implementation of the Stake table contract. Implementation of the Stake table contract (register function) Nov 22, 2023
Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

General comment:
all variables/struct/event, all functions (including those defined in IStakeTable.sol, except constructor) should add code doc.
note that @notice is the general doc, @dev is dev-specific info, I noticed that sometimes we misuse the latter for the former. When in doubt, consult NatSpec.

contracts/src/interfaces/IStakeTable.sol Outdated Show resolved Hide resolved
contracts/src/interfaces/IStakeTable.sol Outdated Show resolved Hide resolved
contracts/rust/src/bin/diff_test.rs Outdated Show resolved Hide resolved
contracts/rust/src/bin/diff_test.rs Outdated Show resolved Hide resolved
contracts/src/StakeTable.sol Outdated Show resolved Hide resolved
contracts/src/StakeTable.sol Outdated Show resolved Hide resolved
contracts/src/StakeTable.sol Show resolved Hide resolved
contracts/src/StakeTable.sol Outdated Show resolved Hide resolved
contracts/test/StakeTable.t.sol Outdated Show resolved Hide resolved
contracts/test/StakeTable.t.sol Outdated Show resolved Hide resolved
@philippecamacho
Copy link
Contributor Author

Two general comments:

  • the order of tests should follow the logic of contract: if contract check StakeType first, then first few test functions should be about fail if it's wrong

Done in ce1ebbf .

  • the order of the test contract (within the same StakeTable.t.sol file) should follow the order of their target function in the implementation: if in StakeTable.sol, the order is regiseter() then deposit() then in the test file, it should be contract StakeTable_register_Test and contract StakeTable_deposit_Test.

Should not we have a different file for each important Stake table contract function like register, deposit etc ...?

whenever there's external/public function with potential user-input, we should add testFuzz on these as much as possible. For example, we never add validity check on blsVK, if we use fuzzing, then it could be that user is passing in an invalid G2/G1 point. which we should also be able to handle.

Yes, added a TODO in the ticket #737.

@philippecamacho
Copy link
Contributor Author

General comment: all variables/struct/event, all functions (including those defined in IStakeTable.sol, except constructor) should add code doc. note that @notice is the general doc, @dev is dev-specific info, I noticed that sometimes we misuse the latter for the former. When in doubt, consult NatSpec.

Done in 3c97955.

.gitmodules Outdated Show resolved Hide resolved
Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

The test code looks so much better and idiosyncratic! it's very easy to read them!! 👍

I left some comments to improve the quality and coverage of the logic that I believe can make our future contract auditor happier.

contracts/test/StakeTable.t.sol Outdated Show resolved Hide resolved
contracts/test/StakeTable.t.sol Outdated Show resolved Hide resolved
contracts/test/StakeTable.t.sol Outdated Show resolved Hide resolved
contracts/test/StakeTable.t.sol Outdated Show resolved Hide resolved
@alxiong
Copy link
Contributor

alxiong commented Nov 30, 2023

the order of the test contract (within the same StakeTable.t.sol file) should follow the order of their target function in the implementation: if in StakeTable.sol, the order is regiseter() then deposit() then in the test file, it should be contract StakeTable_register_Test and contract StakeTable_deposit_Test.

Should not we have a different file for each important Stake table contract function like register, deposit etc ...?

this depends on preferences as the best practice guides (1st point here) says:

For testing MyContract.sol, the test file should be MyContract.t.sol. For testing MyScript.s.sol, the test file should be MyScript.t.sol.

  • If the contract is big and you want to split it over multiple files, group them logically like MyContract.owner.t.sol, MyContract.deposits.t.sol, etc.

So I guess it depends, we can split the file when it's getting big. but for now, for easier location, just keep it in StakeTable.t.sol single file.

@philippecamacho
Copy link
Contributor Author

the order of the test contract (within the same StakeTable.t.sol file) should follow the order of their target function in the implementation: if in StakeTable.sol, the order is regiseter() then deposit() then in the test file, it should be contract StakeTable_register_Test and contract StakeTable_deposit_Test.

Should not we have a different file for each important Stake table contract function like register, deposit etc ...?

this depends on preferences as the best practice guides (1st point here) says:

For testing MyContract.sol, the test file should be MyContract.t.sol. For testing MyScript.s.sol, the test file should be MyScript.t.sol.

  • If the contract is big and you want to split it over multiple files, group them logically like MyContract.owner.t.sol, MyContract.deposits.t.sol, etc.

So I guess it depends, we can split the file when it's getting big. but for now, for easier location, just keep it in StakeTable.t.sol single file.

Sounds good, let us try with a single file for now.

@alxiong alxiong enabled auto-merge (squash) December 1, 2023 04:22
@alxiong alxiong merged commit 06a02b4 into main Dec 1, 2023
8 checks passed
@alxiong alxiong deleted the feat/t737-stake-table-contract-impl branch December 1, 2023 04:33
sveitser pushed a commit that referenced this pull request Feb 4, 2025
Co-authored-by: tbro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants