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

Bridgehub Test Coverage Increase #494

Merged

Conversation

neotheprogramist
Copy link
Contributor

What ❔

Increased coverage in bridgehub unit tests, add some cases for two bridges deposit.
Changed order of assert in Bridgehub contract.

Why ❔

Previous tests had low coverage on branches, asserts and types of deposits, theirs permutations.

Checklist

  • overall tests to increase coverage
  • deposit eth using second bridge to non eth base chain
  • deposit nonbase token using second bridge to some erc20 base chain

@neotheprogramist neotheprogramist changed the title Bridgehub test coverage increase + change in bridgehub! Test Coverage Increase + change in bridgehub! Jun 3, 2024
@neotheprogramist neotheprogramist changed the title Test Coverage Increase + change in bridgehub! Bridgehub Test Coverage Increase Jun 3, 2024
@tommysr tommysr force-pushed the bridgehub-test-coverage-increase branch from 159fb4f to f799fa0 Compare June 12, 2024 12:24
@tommysr tommysr force-pushed the bridgehub-test-coverage-increase branch 2 times, most recently from 417a1d6 to 9ea11f4 Compare July 3, 2024 09:50
@tommysr
Copy link

tommysr commented Jul 3, 2024

Coverage: 88.01% (lines) | 88.60% (statements) | 75.98% (branches) | 85.09% (funcs)

secondBridge.acceptOwnership();

sharedBridgeAddress = address(sharedBridge);
secondBridgeAddress = address(secondBridge);
testToken = new TestnetERC20Token("ZKSTT", "ZkSync Test Token", 18);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we aim for tests with tokens that have decimals other than 18, such as 6 (USDC) , cTokens from Compound and WBTC have 8, etc.

Copy link

Choose a reason for hiding this comment

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

Added tokens with different decimals, I've used modifier to choose random token.

Comment on lines 489 to 492
_chainId: 1,
_stateTransitionManager: address(mockSTM),
_baseToken: address(testToken),
_salt: uint256(123),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please fuzz the tests as much as you can. In this case, try and provide the _chainId parameter as a fuzzed number bounded to be between 1 and type(uint48).max and similarly for the _salt parameter.

Copy link

Choose a reason for hiding this comment

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

I've fuzzed chain ids. Can you confirm if salt spans the whole uint256 range?


vm.deal(randomCaller, l2TxnReqDirect.mintValue);
vm.txGasPrice(0.05 ether);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good approximation, but ideally we would this value to be fuzzed as well. You can upper bound the values to be in a realistic range.

Copy link

Choose a reason for hiding this comment

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

Gas is now fuzzed and bounded

@@ -641,8 +879,15 @@ contract ExperimentalBridgeTest is Test {
mockChainContract.setBridgeHubAddress(address(bridgeHub));
assertTrue(mockChainContract.getBridgeHubAddress() == address(bridgeHub));

vm.txGasPrice(0.05 ether);
if (msgValue != mockMintValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can it be if(msgValue < mockMintValue) instead of the strict equality used here?

Copy link

@tommysr tommysr Jul 29, 2024

Choose a reason for hiding this comment

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

Require statement has strict equality, so I guess strict inequality fits here. I've separated success/revert case, moved revert into separate function and used vm.assume to discard equal values.

@tommysr tommysr force-pushed the bridgehub-test-coverage-increase branch from 8ef6604 to be07ab8 Compare July 30, 2024 14:56
@tommysr tommysr force-pushed the bridgehub-test-coverage-increase branch from e8f1972 to ebc08c1 Compare August 14, 2024 12:43
@saxenism saxenism merged commit 118f081 into matter-labs:dev Aug 14, 2024
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants