Created
October 9, 2024 14:33
-
-
Save Maar-io/c9a66526aab19c20b1ce57c5d2da5ebb to your computer and use it in GitHub Desktop.
Quick check for devnet. But it can be run on any OP network. Place file in proper folder and change l1 addresses. RPCs are set for devnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
// Place this script in the optimism/packages/contracts-bedrock/scripts directory | |
// start with: forge script checkL1.s.sol | |
pragma solidity ^0.8.0; | |
import 'forge-std/Script.sol'; | |
contract CheckDevnet is Script { | |
// L1 addresses specific to deployment. Change these to match your deployment | |
address constant BATCHER = 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC; | |
address constant L2OutputOracleProxy = 0x59b670e9fA9D0A427751Af201D676719a970857b; | |
// common addresses | |
address constant DEV_ACCOUNT = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8; | |
uint256 DEV_PRIVATE_KEY = 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d; | |
string constant L1_RPC_URL = 'http://127.0.0.1:8545'; | |
string constant L2_RPC_URL = 'http://127.0.0.1:9545'; | |
function run() external { | |
uint256 forkId = vm.createFork(L1_RPC_URL); | |
vm.selectFork(forkId); | |
vm.startBroadcast(DEV_PRIVATE_KEY); | |
console.log('L1:'); | |
lastBlock(); | |
latestOracleBlock(); | |
checkBatcherTxCount(); | |
vm.stopBroadcast(); | |
uint256 L2fork = vm.createFork(L2_RPC_URL); | |
vm.selectFork(L2fork); | |
vm.startBroadcast(DEV_PRIVATE_KEY); | |
console.log('-------------------'); | |
console.log('L2:'); | |
unsafeBlock(); | |
safeBlock(); | |
finalizedBlock(); | |
sendTxAndVerifyBalance(); | |
vm.stopBroadcast(); | |
} | |
function lastBlock() public view { | |
// Check the latest block number | |
if (block.number > 0) { | |
console.log(unicode'✅ Latest l1 Block Number:', block.number); | |
} else { | |
console.log(unicode'❌ Latest l1 Block Number is ', block.number); | |
} | |
} | |
function latestOracleBlock() public { | |
// Call the contract to get the latest block number | |
(bool success, bytes memory data) = L2OutputOracleProxy.call( | |
abi.encodeWithSignature('latestBlockNumber()') | |
); | |
if (!success) { | |
// Decode the revert reason if available | |
if (data.length > 0) { | |
string memory revertReason = abi.decode(data, (string)); | |
console.log('Call to contract failed with reason:', revertReason); | |
} else { | |
console.log('Call to contract failed with unknown reason'); | |
} | |
revert('Call to contract failed'); | |
} | |
uint256 contractLatestBlockNumber = abi.decode(data, (uint256)); | |
if (contractLatestBlockNumber > 0) { | |
console.log( | |
unicode'✅ Latest proposed L2 block:', | |
contractLatestBlockNumber | |
); | |
} else { | |
console.log( | |
unicode'❌ Latest proposed L2 block is ', | |
contractLatestBlockNumber | |
); | |
} | |
} | |
function checkBatcherTxCount() public view { | |
// Get the transaction count for the batcher address | |
uint256 txCount = vm.getNonce(BATCHER); | |
if (txCount > 1) { | |
console.log(unicode"✅ Batcher has more than 1 transaction:", txCount); | |
} else { | |
console.log(unicode"❌ Batcher has 1 or fewer transactions:", txCount); | |
} | |
} | |
function unsafeBlock() public view { | |
// Check the latest block number | |
if (block.number > 0) { | |
console.log(unicode"✅ Latest unsafe l2 Block Number:", block.number); | |
} else { | |
console.log(unicode"❌ Latest l2 Block Number is ", block.number); | |
} | |
} | |
function safeBlock() public { | |
bytes memory result = vm.rpc("eth_getBlockByNumber", "[\"safe\", false]"); | |
(uint256 safeBlockNumber) = abi.decode(result, (uint256)); | |
console.log(unicode"✅ Safe head block number:", safeBlockNumber); | |
} | |
function finalizedBlock() public { | |
bytes memory result = vm.rpc("eth_getBlockByNumber", "[\"finalized\", false]"); | |
(uint256 finalizedBlockNumber) = abi.decode(result, (uint256)); | |
console.log(unicode"✅ Finalized head block number:", finalizedBlockNumber); | |
} | |
function sendTxAndVerifyBalance() public { | |
address recipient = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266; | |
uint256 amount = 0.1 ether; | |
// Get initial balances | |
uint256 initialSenderBalance = DEV_ACCOUNT.balance; | |
uint256 initialRecipientBalance = recipient.balance; | |
// Send transaction | |
(bool success, ) = recipient.call{value: amount}(""); | |
require(success, "Transaction failed"); | |
// Get final balances | |
uint256 finalSenderBalance = DEV_ACCOUNT.balance; | |
uint256 finalRecipientBalance = recipient.balance; | |
// Verify balances | |
require(finalSenderBalance == initialSenderBalance - amount, "Sender balance verification failed"); | |
require(finalRecipientBalance == initialRecipientBalance + amount, "Recipient balance verification failed"); | |
console.log(unicode"✅ L2 Transaction successful and balances verified"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment