Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
imp: linted all
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Nov 5, 2024
1 parent d498d4f commit d816b8b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
7 changes: 4 additions & 3 deletions contracts/src/SP1ICS07Tendermint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ contract SP1ICS07Tendermint is
revert UnknownZkAlgorithm(uint8(clientState.zkAlgorithm));
}

require(clientState.trustingPeriod <= clientState.unbondingPeriod, TrustingPeriodTooLong(
clientState.trustingPeriod, clientState.unbondingPeriod
));
require(
clientState.trustingPeriod <= clientState.unbondingPeriod,
TrustingPeriodTooLong(clientState.trustingPeriod, clientState.unbondingPeriod)
);
}

/// @inheritdoc ISP1ICS07Tendermint
Expand Down
1 change: 0 additions & 1 deletion contracts/src/msgs/IMisbehaviourMsgs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.28;

import { IICS07TendermintMsgs } from "./IICS07TendermintMsgs.sol";
import { ISP1Msgs } from "./ISP1Msgs.sol";

/// @title Misbehaviour Program Messages
/// @author gjermundgaraba
Expand Down
1 change: 0 additions & 1 deletion contracts/src/msgs/ISP1Msgs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ interface ISP1Msgs {
Groth16,
Plonk
}

}
1 change: 0 additions & 1 deletion contracts/src/msgs/IUpdateClientMsgs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.28;

import { IICS07TendermintMsgs } from "./IICS07TendermintMsgs.sol";
import { ISP1Msgs } from "./ISP1Msgs.sol";

/// @title Update Client Program Messages
/// @author srdtrk
Expand Down
21 changes: 17 additions & 4 deletions contracts/test/Misbehaviour.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.28;

// solhint-disable-next-line no-global-import
import "forge-std/console.sol";
import { SP1ICS07Tendermint } from "../src/SP1ICS07Tendermint.sol";
import { SP1ICS07TendermintTest } from "./SP1ICS07TendermintTest.sol";
import { IMisbehaviourMsgs } from "../src/msgs/IMisbehaviourMsgs.sol";
import { SP1Verifier } from "@sp1-contracts/v3.0.0/SP1VerifierPlonk.sol";
Expand Down Expand Up @@ -107,7 +106,9 @@ contract SP1ICS07MisbehaviourTest is SP1ICS07TendermintTest {
badOutput.clientState.chainId = "bad-chain-id";
badSubmitMsg.sp1Proof.publicValues = abi.encode(badOutput);
submitMsgBz = abi.encode(badSubmitMsg);
vm.expectRevert(abi.encodeWithSelector(ChainIdMismatch.selector, output.clientState.chainId, badOutput.clientState.chainId));
vm.expectRevert(
abi.encodeWithSelector(ChainIdMismatch.selector, output.clientState.chainId, badOutput.clientState.chainId)
);
ics07Tendermint.misbehaviour(submitMsgBz);

// trust threshold mismatch
Expand All @@ -116,7 +117,15 @@ contract SP1ICS07MisbehaviourTest is SP1ICS07TendermintTest {
badOutput.clientState.trustLevel = TrustThreshold({ numerator: 1, denominator: 2 });
badSubmitMsg.sp1Proof.publicValues = abi.encode(badOutput);
submitMsgBz = abi.encode(badSubmitMsg);
vm.expectRevert(abi.encodeWithSelector(TrustThresholdMismatch.selector, output.clientState.trustLevel.numerator, output.clientState.trustLevel.denominator, badOutput.clientState.trustLevel.numerator, badOutput.clientState.trustLevel.denominator));
vm.expectRevert(
abi.encodeWithSelector(
TrustThresholdMismatch.selector,
output.clientState.trustLevel.numerator,
output.clientState.trustLevel.denominator,
badOutput.clientState.trustLevel.numerator,
badOutput.clientState.trustLevel.denominator
)
);
ics07Tendermint.misbehaviour(submitMsgBz);

// trusting period mismatch
Expand All @@ -125,7 +134,11 @@ contract SP1ICS07MisbehaviourTest is SP1ICS07TendermintTest {
badOutput.clientState.trustingPeriod = 1;
badSubmitMsg.sp1Proof.publicValues = abi.encode(badOutput);
submitMsgBz = abi.encode(badSubmitMsg);
vm.expectRevert(abi.encodeWithSelector(TrustingPeriodMismatch.selector, output.clientState.trustingPeriod, badOutput.clientState.trustingPeriod));
vm.expectRevert(
abi.encodeWithSelector(
TrustingPeriodMismatch.selector, output.clientState.trustingPeriod, badOutput.clientState.trustingPeriod
)
);
ics07Tendermint.misbehaviour(submitMsgBz);

// invalid proof
Expand Down
7 changes: 5 additions & 2 deletions contracts/test/SP1ICS07TendermintTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { IMisbehaviourMsgs } from "../src/msgs/IMisbehaviourMsgs.sol";
import { SP1ICS07Tendermint } from "../src/SP1ICS07Tendermint.sol";
import { ISP1ICS07TendermintErrors } from "../src/errors/ISP1ICS07TendermintErrors.sol";
import { ISP1Verifier } from "@sp1-contracts/ISP1Verifier.sol";
import { SP1Verifier } from "@sp1-contracts/v3.0.0/SP1VerifierPlonk.sol";
import { SP1MockVerifier } from "@sp1-contracts/SP1MockVerifier.sol";
import { ILightClientMsgs } from "solidity-ibc/msgs/ILightClientMsgs.sol";

Expand Down Expand Up @@ -69,7 +68,11 @@ abstract contract SP1ICS07TendermintTest is
trustedConsensusHash
);
SP1MockVerifier mockVerifier = new SP1MockVerifier();
vm.mockFunction(address(mockIcs07Tendermint.VERIFIER()), address(mockVerifier), abi.encodeWithSelector(ISP1Verifier.verifyProof.selector));
vm.mockFunction(
address(mockIcs07Tendermint.VERIFIER()),
address(mockVerifier),
abi.encodeWithSelector(ISP1Verifier.verifyProof.selector)
);

ClientState memory clientState = mockIcs07Tendermint.getClientState();
assert(keccak256(abi.encode(clientState)) == keccak256(genesisFixture.trustedClientState));
Expand Down
12 changes: 8 additions & 4 deletions contracts/test/UcAndMembership.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract SP1ICS07UpdateClientAndMembershipTest is MembershipTest {
function test_Valid_UpdateClientAndVerifyMembership() public {
FixtureTestCase[] memory testCases = fixtureTestCases();

for (uint i = 0; i < testCases.length; i++) {
for (uint256 i = 0; i < testCases.length; i++) {
setUpUcAndMemTestWithFixtures(testCases[i].fileName);

UcAndMembershipOutput memory output = abi.decode(proof.sp1Proof.publicValues, (UcAndMembershipOutput));
Expand All @@ -51,7 +51,9 @@ contract SP1ICS07UpdateClientAndMembershipTest is MembershipTest {
// run verify
ics07Tendermint.membership(membershipMsg);

console.log("UpdateClientAndVerifyMembership-", testCases[i].name, "gas used: ", vm.lastCallGas().gasTotalUsed);
console.log(
"UpdateClientAndVerifyMembership-", testCases[i].name, "gas used: ", vm.lastCallGas().gasTotalUsed
);

ClientState memory clientState = ics07Tendermint.getClientState();
assert(clientState.latestHeight.revisionHeight == output.updateClientOutput.newHeight.revisionHeight);
Expand All @@ -67,7 +69,7 @@ contract SP1ICS07UpdateClientAndMembershipTest is MembershipTest {
function test_Valid_UpdateClientAndVerifyNonMembership() public {
FixtureTestCase[] memory testCases = fixtureTestCases();

for (uint i = 0; i < testCases.length; i++) {
for (uint256 i = 0; i < testCases.length; i++) {
setUpUcAndMemTestWithFixtures(testCases[i].fileName);

UcAndMembershipOutput memory output = abi.decode(proof.sp1Proof.publicValues, (UcAndMembershipOutput));
Expand All @@ -84,7 +86,9 @@ contract SP1ICS07UpdateClientAndMembershipTest is MembershipTest {
// run verify
ics07Tendermint.membership(nonMembershipMsg);

console.log("UpdateClientAndVerifyNonMembership-", testCases[i].name ,"gas used: ", vm.lastCallGas().gasTotalUsed);
console.log(
"UpdateClientAndVerifyNonMembership-", testCases[i].name, "gas used: ", vm.lastCallGas().gasTotalUsed
);

ClientState memory clientState = ics07Tendermint.getClientState();
assert(clientState.latestHeight.revisionHeight == output.updateClientOutput.newHeight.revisionHeight);
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/UpdateClient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract SP1ICS07UpdateClientTest is SP1ICS07TendermintTest {
function test_ValidUpdateClient() public {
FixtureTestCase[] memory testCases = fixtureTestCases();

for (uint i = 0; i < testCases.length; i++) {
for (uint256 i = 0; i < testCases.length; i++) {
setUpTestWithFixture(testCases[i].fileName);

// set a correct timestamp
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ lint-fix:
cargo fmt --all
cargo clippy --fix --allow-dirty --allow-staged
@echo "Fixing the Solidity code..."
forge fmt && bun solhint -w 0 -c .solhint.json 'contracts/**/*.sol' && bun natspec-smells --enforceInheritdoc false --include 'contracts/src/**/*.sol'
forge fmt && bun solhint -w 0 -c .solhint.json 'contracts/**/*.sol'
@echo "Fixing the Go code..."
cd e2e/interchaintestv8 && golangci-lint run --fix

Expand Down

0 comments on commit d816b8b

Please sign in to comment.