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

Add unit tests to blockchain reader #93

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions cartesi-rollups/contracts/deploy_anvil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,28 @@ INITIAL_HASH=`xxd -p -c32 "${MACHINE_PATH}/hash"`

export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

forge script \
inputbox_script="forge script \
script/InputBox.s.sol \
--fork-url 'http://127.0.0.1:8545' \
--broadcast \
--sig 'run()' \
-vvvv 2>&1"

deploy_inputbox=$(eval $inputbox_script)
inputbox_addresses=$(echo $deploy_inputbox | grep -oP 'new InputBox@(0x[a-fA-F0-9]{40})' | grep -oP '0x[a-fA-F0-9]{40}')
INPUTBOX_ADDRESS=$(echo $inputbox_addresses | cut -d ' ' -f 1)
echo $INPUTBOX_ADDRESS

daveconsensus_script="forge script \
script/DaveConsensus.s.sol \
--fork-url "http://127.0.0.1:8545" \
--fork-url 'http://127.0.0.1:8545' \
--broadcast \
--sig "run(bytes32)" \
"${INITIAL_HASH}" \
-vvvv
--sig 'run(bytes32,address)' \
'$INITIAL_HASH' \
'$INPUTBOX_ADDRESS' \
-vvvv 2>&1"

deploy_daveconsensus=$(eval $daveconsensus_script)
daveconsensus_addresses=$(echo $deploy_daveconsensus | grep -oP 'new DaveConsensus@(0x[a-fA-F0-9]{40})' | grep -oP '0x[a-fA-F0-9]{40}')
DAVECONSENSUS_ADDRESS=$(echo $daveconsensus_addresses | cut -d ' ' -f 1)
echo $DAVECONSENSUS_ADDRESS
6 changes: 2 additions & 4 deletions cartesi-rollups/contracts/script/DaveConsensus.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {Machine} from "prt-contracts/Machine.sol";

import "prt-contracts/tournament/factories/MultiLevelTournamentFactory.sol";
import "prt-contracts/CanonicalConstants.sol";
import "rollups-contracts/inputs/InputBox.sol";
import "rollups-contracts/inputs/IInputBox.sol";
import "src/DaveConsensus.sol";

contract DaveConcensusScript is Script {
function run(Machine.Hash initialHash) external {
function run(Machine.Hash initialHash, IInputBox inputBox) external {
DisputeParameters memory disputeParameters = DisputeParameters({
timeConstants: TimeConstants({
matchEffort: ArbitrationConstants.MATCH_EFFORT,
Expand All @@ -28,10 +28,8 @@ contract DaveConcensusScript is Script {
height: ArbitrationConstants.height(i)
});
}

vm.startBroadcast(vm.envUint("PRIVATE_KEY"));

InputBox inputBox = new InputBox();
MultiLevelTournamentFactory factory = new MultiLevelTournamentFactory(
new TopTournamentFactory(), new MiddleTournamentFactory(), new BottomTournamentFactory(), disputeParameters
);
Expand Down
19 changes: 19 additions & 0 deletions cartesi-rollups/contracts/script/InputBox.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.17;

import {Script} from "forge-std/Script.sol";

import "rollups-contracts/inputs/InputBox.sol";

contract InputBoxScript is Script {
function run() external {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));

InputBox inputBox = new InputBox();
inputBox.addInput(address(0x0), bytes("First input")); // add an input for epoch 0

vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion cartesi-rollups/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ alloy = { version = "0.8.0", features = ["sol-types", "contract", "network", "re
anyhow = "1.0"
async-recursion = "1"
async-trait = "0.1.74"
cartesi-rollups-contracts = "=2.0.0-rc.12"
cartesi-rollups-contracts = "2.0.0-rc.13"
clap = { version = "4.5.7", features = ["derive", "env"] }
clap_derive = "=4.5.13"
futures = "0.3"
Expand Down
11 changes: 11 additions & 0 deletions cartesi-rollups/node/blockchain-reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ log = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
num-traits = { workspace = true }

[dev-dependencies]
alloy = { workspace = true, features = ["node-bindings"] }
cartesi-dave-merkle = { workspace = true }
cartesi-prt-core = { workspace = true }
cartesi-prt-contracts = { path = "../../../prt/contract-bindings" }

clap = { workspace = true }
clap_derive = { workspace = true }
rusqlite = { version = "0.31.0", features = ["bundled"] }
rusqlite_migration = "1.2.0"
Loading