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

chore: Test the main contract #100

Merged
merged 12 commits into from
Mar 30, 2022
Merged

chore: Test the main contract #100

merged 12 commits into from
Mar 30, 2022

Conversation

evan-forbes
Copy link
Member

This PR starts the tests for the main contracts.

While this is a decent start, I'm not sure we can close #98 as this is still far from appropriate coverage percentage imho. I didn't originally set out to close #98, only do complete enough to help me debug the relayer. We still need to test expected failures, nil signatures, and a few other edge cases.

@evan-forbes evan-forbes requested a review from adlerjohn as a code owner March 25, 2022 06:21
@evan-forbes evan-forbes self-assigned this Mar 25, 2022
Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

LGTM.
Thanks for adding the checkpoint test :D

@@ -1,3 +1,6 @@
[submodule "ethereum/solidity/lib/ds-test"]
path = ethereum/solidity/lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "ethereum/solidity/lib/openzeppelin-contracts"]
Copy link
Member

Choose a reason for hiding this comment

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

I wonder how were we able to run tests before without having this set here :D

Copy link
Member

Choose a reason for hiding this comment

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

Ah, so forge build doesn't actually error if it can't find an import... forge test does, but given that the QGB contract itself was not tested prior to this PR, then of course there would be no error.

This is of course one of the many examples to Solidity tooling being extremely immature. In the future we should examine using Sway and relaying directly to a Fuel execution layer.

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

I'm not a solidity expert but this LGTM. Can we reject PRs without unit tests in the future? They should be part of any feature introduced.

@adlerjohn adlerjohn changed the title Test the main contract chore: Test the main contract Mar 25, 2022
ethereum/solidity/src/test/QuantumGravityBridge.t.sol Outdated Show resolved Hide resolved
ethereum/solidity/src/test/QuantumGravityBridge.t.sol Outdated Show resolved Hide resolved
ethereum/solidity/src/test/QuantumGravityBridge.t.sol Outdated Show resolved Hide resolved
ethereum/solidity/src/test/QuantumGravityBridge.t.sol Outdated Show resolved Hide resolved
Comment on lines +85 to +100
function computeValidatorSetHash(Validator[] memory _validators) private pure returns (bytes32) {
return keccak256(abi.encode(_validators));
}

function domainSeparateValidatorSetHash(
bytes32 _bridge_id,
uint256 _nonce,
uint256 _powerThreshold,
bytes32 _validatorSetHash
) private pure returns (bytes32) {
bytes32 c = keccak256(
abi.encode(_bridge_id, VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, _nonce, _powerThreshold, _validatorSetHash)
);

return c;
}
Copy link
Member

Choose a reason for hiding this comment

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

Rather than re-implementing these (which is hard to maintain), you could instead make a mock contract that wraps QGB and simply exposes internal methods and public, then call that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried, but couldn't get the mocks to work. per the docs

Private functions and state variables are only visible for the contract they are defined in and not in derived contracts.

does this mean that we can't use them in a mock contract? I could still be doing something wrong

Copy link
Member Author

Choose a reason for hiding this comment

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

this won't compile

contract ExposedQuantumGravityBridge is QuantumGravityBridge {
    function _computeValidatorSetHash(Validator[] memory _validators) public pure returns (bytes32) {
        return computeValidatorSetHash(_validators);
    }

    function _domainSeparateValidatorSetHash(
        bytes32 _bridge_id,
        uint256 _nonce,
        uint256 _powerThreshold,
        bytes32 _validatorSetHash
    ) public pure returns (bytes32) {
        return domainSeparateValidatorSetHash(_bridge_id, _nonce, _powerThreshold, _validatorSetHash);
    }
}

evan-forbes and others added 4 commits March 29, 2022 17:31
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
@evan-forbes evan-forbes merged commit 6b6efce into master Mar 30, 2022
@evan-forbes evan-forbes deleted the evan/main-contract-tests branch March 30, 2022 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add tests for QGB itself
4 participants