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

feat: Improving test coverage of SCs #240

Merged
merged 16 commits into from
Mar 5, 2024

Conversation

Raid5594
Copy link
Collaborator

What ❔

Add tests for contracts or simply factor existing tests, so that they are included in coverage report.

Why ❔

Increase overall coverage of smart contracts in the repo

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

}

function getTotalPriorityTxs() external view returns (uint256) {
return priorityQueue.getTotalPriorityTxs();
return PriorityQueue.getTotalPriorityTxs(priorityQueue);
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

foundry-rs/foundry#3128

using for patterns are ignored by coverage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also wanted to ask why the PriorityQueue folder is missing from tests in this branch, but is available in the main.

Shall I add it back or maybe the base is not correct?

Copy link
Member

Choose a reason for hiding this comment

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

You should add back, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It moved to state-transition folder, so all good, missed it :)

Copy link
Member

@vladbochok vladbochok left a comment

Choose a reason for hiding this comment

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

Please make sure no dev-contracts/tests/artifacts contracts in yarn coverage:foundry

Comment on lines 8 to 9
// add this to be excluded from coverage report
function test() internal virtual {}
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed in order to PriorityQueue.sol to be in coverage

Comment on lines 8 to 9
// add this to be excluded from coverage report
function test() internal virtual {}
Copy link
Member

Choose a reason for hiding this comment

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

Same here

uint256 chainId = block.chainid;
Diamond.DiamondCutData memory initialDiamondCutData = getDiamondCutData(diamondInit);

vm.expectRevert(bytes("StateTransition: only bridgehub"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't seem that coverage captured modifier's revert, researching how to make it work


vm.expectRevert(bytes("StateTransition: only bridgehub"));

chainContractAddress.createNewChain(chainId, baseToken, sharedBridge, admin, abi.encode(initialDiamondCutData));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will probably move new chain creation to a function, as it's been reused in multiple places

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

vm.startPrank(governor);
}

function getAdminSelectors() private view returns (bytes4[] memory) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will move selector getters to Utils

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@vladbochok vladbochok left a comment

Choose a reason for hiding this comment

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

It looks good! Just nits that you mentioned in the PR already and what I left and then we can merge

l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol Outdated Show resolved Hide resolved
import {DiamondProxy} from "solpp/state-transition/chain-deps/DiamondProxy.sol";

contract createNewChainTest is StateTransitionManagerTest {
function testRevertWhenInitialDiamondCutHashMismatch() public {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think convention is test_RevertWhen_

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


// Call fails as storage is frozen
vm.expectRevert(bytes.concat("q1"));
isChainFrozen = gettersFacet.isDiamondStorageFrozen();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it the case that this getter can't return true? (as the call reverts with the error described above)

@vladbochok vladbochok merged commit 39c5451 into kl-factory Mar 5, 2024
6 of 9 checks passed
@vladbochok vladbochok deleted the ra/improving-test-coverage branch March 5, 2024 20:18
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.

2 participants