From e4b54df48513e46f1338b509b48f6d5707d628dd Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:04:32 -0700 Subject: [PATCH] resolve all build warnings --- src/Test.sol | 2 +- src/protocols/Builder/Session.sol | 6 ++++-- src/protocols/Builder/Types.sol | 10 ++++++---- test/Gateway.t.sol | 1 + test/Transactions.t.sol | 8 ++++---- test/crypto/Secp256k1.t.sol | 2 +- test/protocols/Builder/Session.t.sol | 14 ++++++++------ test/protocols/Builder/Types.t.sol | 4 ++-- test/protocols/Bundle.t.sol | 4 ++-- test/protocols/MevShare.t.sol | 2 +- 10 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/Test.sol b/src/Test.sol index d6becb2..e71de7c 100644 --- a/src/Test.sol +++ b/src/Test.sol @@ -24,7 +24,7 @@ contract SuaveEnabled is Test { inputs[0] = "suave-geth"; inputs[1] = "version"; - try vm.ffi(inputs) returns (bytes memory response) { + try vm.ffi(inputs) returns (bytes memory) { // TODO: validate versions } catch (bytes memory reason) { revert(detectErrorMessage(reason)); diff --git a/src/protocols/Builder/Session.sol b/src/protocols/Builder/Session.sol index b7128f2..115d693 100644 --- a/src/protocols/Builder/Session.sol +++ b/src/protocols/Builder/Session.sol @@ -40,15 +40,17 @@ contract Session is Test { callImpl("buildBlock", input); } - function bid(string memory blsPubKey) public returns (JSONParserLib.Item memory) { + function bid(string memory blsPubKey) public returns (JSONParserLib.Item memory output) { bytes memory input = abi.encodePacked(session, ',"0x', blsPubKey, '"'); - JSONParserLib.Item memory output = callImpl("bid", input); + output = callImpl("bid", input); console.log("-- bid output --"); console.log(output.value()); // retrieve the root to sign bytes memory root = HexStrings.fromHexString(HexStrings.stripQuotesAndPrefix(output.at('"root"').value())); + // TODO: do something with this root + root; // suppress warning } function doCall(address target, bytes memory data) public returns (bytes memory) { diff --git a/src/protocols/Builder/Types.sol b/src/protocols/Builder/Types.sol index 5a3c8b4..6264d84 100644 --- a/src/protocols/Builder/Types.sol +++ b/src/protocols/Builder/Types.sol @@ -44,7 +44,7 @@ library Types { } // encodeBuildBlockArgs encodes BuildBlockArgs to json - function encodeBuildBlockArgs(BuildBlockArgs memory args) internal returns (bytes memory) { + function encodeBuildBlockArgs(BuildBlockArgs memory args) internal pure returns (bytes memory) { bytes memory body = abi.encodePacked( '{"slot":"', LibString.toMinimalHexString(args.slot), @@ -88,7 +88,7 @@ library Types { } // encodeWithdrawals encodes Withdrawal array to json - function encodeWithdrawals(Withdrawal[] memory withdrawals) internal returns (bytes memory) { + function encodeWithdrawals(Withdrawal[] memory withdrawals) internal pure returns (bytes memory) { bytes memory result = abi.encodePacked("["); for (uint64 i = 0; i < withdrawals.length; i++) { result = abi.encodePacked(result, i > 0 ? "," : "", encodeWithdrawal(withdrawals[i])); @@ -97,7 +97,7 @@ library Types { } // encodeWithdrawal encodes Withdrawal to json - function encodeWithdrawal(Withdrawal memory withdrawal) internal returns (bytes memory) { + function encodeWithdrawal(Withdrawal memory withdrawal) internal pure returns (bytes memory) { return abi.encodePacked( '{"index":', LibString.toHexString(withdrawal.index), @@ -114,13 +114,14 @@ library Types { function decodeSimulateTransactionResult(string memory input) internal + pure returns (SimulateTransactionResult memory result) { JSONParserLib.Item memory item = input.parse(); return decodeSimulateTransactionResult(item); } - function decodeSimulatedLog(JSONParserLib.Item memory item) internal returns (SimulatedLog memory log) { + function decodeSimulatedLog(JSONParserLib.Item memory item) internal pure returns (SimulatedLog memory log) { log.data = fromHexString(_stripQuotesAndPrefix(item.at('"data"').value())); log.addr = bytesToAddress(fromHexString(_stripQuotesAndPrefix(item.at('"addr"').value()))); @@ -133,6 +134,7 @@ library Types { function decodeSimulateTransactionResult(JSONParserLib.Item memory item) internal + pure returns (SimulateTransactionResult memory result) { if (compareStrings(item.at('"success"').value(), "true")) { diff --git a/test/Gateway.t.sol b/test/Gateway.t.sol index dc1a554..56e995c 100644 --- a/test/Gateway.t.sol +++ b/test/Gateway.t.sol @@ -21,6 +21,7 @@ contract TestGateway is Test, SuaveEnabled { } catch { vm.skip(true); } + revert("this code path should never be reached in normal circumstances"); } } diff --git a/test/Transactions.t.sol b/test/Transactions.t.sol index 2dec288..dbde7f1 100644 --- a/test/Transactions.t.sol +++ b/test/Transactions.t.sol @@ -9,7 +9,7 @@ import "./Fixtures.sol"; contract TestTransactions is Test, SuaveEnabled { using Transactions for *; - function testEIP155TransactionRLPEncoding() public { + function testEIP155TransactionRLPEncoding() public view { Transactions.EIP155 memory txnWithToAddress = Transactions.EIP155({ to: address(0x095E7BAea6a6c7c4c2DfeB977eFac326aF552d87), gas: 50000, @@ -53,7 +53,7 @@ contract TestTransactions is Test, SuaveEnabled { Fixtures.validate("txn_155_contract_creation.json", string(txnJSON)); } - function testEIP1559TransactionRLPEncoding() public { + function testEIP1559TransactionRLPEncoding() public pure { Transactions.EIP1559 memory txnWithToAddress = Transactions.EIP1559({ to: address(0xaea46A60368A7bD060eec7DF8CBa43b7EF41Ad85), gas: 64744, @@ -101,7 +101,7 @@ contract TestTransactions is Test, SuaveEnabled { _testEIP1559Transaction(txnWithoutToAddress, expected); } - function _testEIP155Transaction(Transactions.EIP155 memory legacyTxn, bytes memory expectedRlp) public { + function _testEIP155Transaction(Transactions.EIP155 memory legacyTxn, bytes memory expectedRlp) public pure { bytes memory rlp = Transactions.encodeRLP(legacyTxn); assertEq0(rlp, expectedRlp); @@ -112,7 +112,7 @@ contract TestTransactions is Test, SuaveEnabled { assertEq0(rlp1, expectedRlp); } - function _testEIP1559Transaction(Transactions.EIP1559 memory eip1559Txn, bytes memory expectedRlp) public { + function _testEIP1559Transaction(Transactions.EIP1559 memory eip1559Txn, bytes memory expectedRlp) public pure { bytes memory rlp = Transactions.encodeRLP(eip1559Txn); assertEq0(rlp, expectedRlp); diff --git a/test/crypto/Secp256k1.t.sol b/test/crypto/Secp256k1.t.sol index 17af2ad..3471a53 100644 --- a/test/crypto/Secp256k1.t.sol +++ b/test/crypto/Secp256k1.t.sol @@ -8,7 +8,7 @@ import "src/Context.sol"; import "src/crypto/Secp256k1.sol"; contract TestSecp256K1 is Test, SuaveEnabled { - function testRecoverAddress() public { + function testRecoverAddress() public pure { string memory signingKey = "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"; address expected = 0x71562b71999873DB5b286dF957af199Ec94617F7; diff --git a/test/protocols/Builder/Session.t.sol b/test/protocols/Builder/Session.t.sol index d15ed87..577c1da 100644 --- a/test/protocols/Builder/Session.t.sol +++ b/test/protocols/Builder/Session.t.sol @@ -20,8 +20,12 @@ contract Example { contract SuaveBuilderSessionTest is Test, SuaveEnabled { string constant signingKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; string constant execNodeEndpoint = "http://localhost:8545"; + // pair of bls private and public keys + string constant blsPrivKey = "68a84428e388a5de81fa54f6f91a34d28f09692262c0ee4da81935a4e832ae19"; + string constant blsPubKey = + "b6b973370f9684a2bc0b89f873b772b01269277196e84b69fe8ebad8908e777c09cdfad9d4a2f849e12ecd12ba9dce20"; - function getBlockBuildArgs() public returns (Types.BuildBlockArgs memory) { + function getBlockBuildArgs() public pure returns (Types.BuildBlockArgs memory) { Types.BuildBlockArgs memory args; args.slot = 1; args.proposerPubkey = hex"1234"; @@ -87,17 +91,13 @@ contract SuaveBuilderSessionTest is Test, SuaveEnabled { // send a valid transaction Transactions.EIP155 memory response = getValidTxn(); Types.SimulateTransactionResult memory result = session.addTransaction(response); + assertEq(result.success, true); // build the block session.buildBlock(); } function testBuilderAPI_BidBuiltBlock() public { - // pair of bls private and public keys - string memory blsPrivKey = "68a84428e388a5de81fa54f6f91a34d28f09692262c0ee4da81935a4e832ae19"; - string memory blsPubKey = - "b6b973370f9684a2bc0b89f873b772b01269277196e84b69fe8ebad8908e777c09cdfad9d4a2f849e12ecd12ba9dce20"; - Types.BuildBlockArgs memory args = getBlockBuildArgs(); Session session = new Session(getBuilderSessionURL()); @@ -106,6 +106,7 @@ contract SuaveBuilderSessionTest is Test, SuaveEnabled { // send a valid transaction Transactions.EIP155 memory response = getValidTxn(); Types.SimulateTransactionResult memory result = session.addTransaction(response); + assertEq(result.success, true); // build the block session.buildBlock(); @@ -121,5 +122,6 @@ contract SuaveBuilderSessionTest is Test, SuaveEnabled { } catch { vm.skip(true); } + revert("this code path should never be reached in normal circumstances"); } } diff --git a/test/protocols/Builder/Types.t.sol b/test/protocols/Builder/Types.t.sol index 191e60c..d4b7d82 100644 --- a/test/protocols/Builder/Types.t.sol +++ b/test/protocols/Builder/Types.t.sol @@ -7,7 +7,7 @@ import "src/suavelib/Suave.sol"; import "../../Fixtures.sol"; contract SuaveBuilderTypesTest is Test { - function testSuaveBuilderTypes_Encode_BuildblockArgs() public { + function testSuaveBuilderTypes_Encode_BuildblockArgs() public view { Types.BuildBlockArgs memory args; args.slot = 1; args.proposerPubkey = hex"1234"; @@ -23,7 +23,7 @@ contract SuaveBuilderTypesTest is Test { Fixtures.validate("suave_builder_builderArgs.json", string(encode)); } - function testSuaveBuilderTypes_Decode_SimulateTransactionResult() public { + function testSuaveBuilderTypes_Decode_SimulateTransactionResult() public view { string memory test = Fixtures.readFixture("suave_builder_simulateTransactionResult_failed.json"); Types.SimulateTransactionResult memory result = Types.decodeSimulateTransactionResult(test); assertEq(result.success, false); diff --git a/test/protocols/Bundle.t.sol b/test/protocols/Bundle.t.sol index bbf3a09..159ed81 100644 --- a/test/protocols/Bundle.t.sol +++ b/test/protocols/Bundle.t.sol @@ -9,7 +9,7 @@ import "solady/src/utils/LibString.sol"; contract EthSendBundle is Test { using LibString for *; - function testEthSendBundleEncode() public { + function testEthSendBundleEncode() public pure { Bundle.BundleObj memory bundle; bundle.blockNumber = 1; bundle.txns = new bytes[](1); @@ -41,7 +41,7 @@ contract EthSendBundle is Test { ); } - function testBundleDecode() public { + function testBundleDecode() public pure { string memory json = "{" '"blockNumber": "0xdead",' '"minTimestamp": 1625072400,' '"maxTimestamp": 1625076000,' '"txs": [' '"0xdeadbeef",' '"0xc0ffee",' '"0x00aabb"' "]" "}"; diff --git a/test/protocols/MevShare.t.sol b/test/protocols/MevShare.t.sol index 2a6cdc5..cd2bb88 100644 --- a/test/protocols/MevShare.t.sol +++ b/test/protocols/MevShare.t.sol @@ -6,7 +6,7 @@ import "src/protocols/MevShare.sol"; import "src/suavelib/Suave.sol"; contract MevShareTest is Test { - function testEncodeMevShare() public { + function testEncodeMevShare() public pure { MevShare.Bundle memory bundle; bundle.inclusionBlock = 1;