Skip to content

Commit 7335e0c

Browse files
committed
made scripts easier to work with
made scripts easier to work with
1 parent 9074f4d commit 7335e0c

File tree

8 files changed

+232
-241
lines changed

8 files changed

+232
-241
lines changed

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
[package]
2-
32
name = "minimal-rollup"
43
version = "0.1.0"
54
edition = "2021"
65

6+
[lib]
7+
name = "minimal_rollup"
8+
path = "offchain/lib.rs"
9+
710
[[bin]]
811
name = "signal_slot"
912
path = "offchain/signal_slot.rs"
1013

11-
[[bin]]
12-
name = "utils"
13-
path = "offchain/utils.rs"
14-
1514
[[bin]]
1615
name = "sample_signal_proof"
1716
path = "offchain/sample_signal_proof.rs"
File renamed without changes.

offchain/sample_deposit_proof.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
use alloy::primitives::utils::parse_units;
2+
use alloy::sol_types::SolCall;
13
use eyre::Result;
24

35
mod signal_slot;
46
use signal_slot::get_signal_slot;
57

6-
mod utils;
7-
use utils::{deploy_eth_bridge, deploy_signal_service, get_proofs, get_provider, SignalProof};
8+
use minimal_rollup::{
9+
deploy_eth_bridge, deploy_signal_service, get_proofs, get_provider, SignalProof,
10+
};
811

9-
use alloy::hex::decode;
12+
use alloy::hex::{self, decode};
1013
use alloy::primitives::{Address, Bytes, FixedBytes, U256};
1114
use std::fs;
1215

16+
use alloy::sol;
17+
18+
sol! {
19+
function somePayableFunction(uint256 someArg) external payable returns (uint256);
20+
function someNonpayableFunction(uint256 someArg) external returns (uint256);
21+
}
22+
1323
fn expand_vector(vec: Vec<Bytes>, name: &str) -> String {
1424
let mut expanded = String::new();
1525
for (i, item) in vec.iter().enumerate() {
@@ -20,7 +30,7 @@ fn expand_vector(vec: Vec<Bytes>, name: &str) -> String {
2030
return expanded;
2131
}
2232

23-
fn create_deposit_call(
33+
pub fn create_deposit_call(
2434
proof: SignalProof,
2535
nonce: usize,
2636
signer: Address,
@@ -66,14 +76,33 @@ fn deposit_specification() -> Vec<DepositSpecification> {
6676
// This is an address on the destination chain, so it seems natural to use one generated there
6777
// In this case, the CrossChainDepositExists.sol test case defines _randomAddress("recipient");
6878
let recipient = "0x99A270Be1AA5E97633177041859aEEB9a0670fAa";
79+
6980
// Use both zero and non-zero amounts (in this case 4 ether)
70-
let amounts = vec![0_u128, 4000000000000000000_u128];
81+
let amounts: Vec<U256> = vec![U256::ZERO, parse_units("4", "ether").unwrap().into()];
82+
7183
// Use different calldata to try different functions and inputs
84+
let valid_payable_function_call = somePayableFunctionCall {
85+
someArg: U256::from(1234),
86+
}
87+
.abi_encode();
88+
let invalid_payable_function_call = somePayableFunctionCall {
89+
someArg: U256::from(1235),
90+
}
91+
.abi_encode();
92+
let valid_nonpayable_function_call = someNonpayableFunctionCall {
93+
someArg: U256::from(1234),
94+
}
95+
.abi_encode();
96+
97+
let valid_payable_encoded = hex::encode(valid_payable_function_call);
98+
let invalid_payable_encoded = hex::encode(invalid_payable_function_call);
99+
let valid_nonpayable_encoded = hex::encode(valid_nonpayable_function_call);
100+
72101
let calldata = vec![
73-
"", // empty
74-
"9b28f6fb00000000000000000000000000000000000000000000000000000000000004d2", // (valid) call to somePayableFunction(1234)
75-
"9b28f6fb00000000000000000000000000000000000000000000000000000000000004d3", // (invalid) call to somePayableFunction(1235)
76-
"5932a71200000000000000000000000000000000000000000000000000000000000004d2", // (valid) call to `someNonPayableFunction(1234)`
102+
"",
103+
&valid_payable_encoded,
104+
&invalid_payable_encoded,
105+
&valid_nonpayable_encoded,
77106
];
78107

79108
let zero_canceler = Address::ZERO;
@@ -102,6 +131,7 @@ async fn main() -> Result<()> {
102131
let deposits = deposit_specification();
103132
assert!(deposits.len() > 0, "No deposits to prove");
104133
let mut ids: Vec<FixedBytes<32>> = vec![];
134+
105135
// Perform all deposits
106136
for (_i, spec) in deposits.iter().enumerate() {
107137
let tx = eth_bridge
@@ -150,7 +180,7 @@ async fn main() -> Result<()> {
150180
.as_str();
151181
}
152182

153-
let template = fs::read_to_string("offchain/sample_deposit_proof.tmpl")?;
183+
let template = fs::read_to_string("offchain/tmpl/sample_deposit_proof.tmpl")?;
154184
let formatted = template
155185
.replace(
156186
"{signal_service_address}",

offchain/sample_signal_proof.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use eyre::Result;
33
mod signal_slot;
44
use signal_slot::get_signal_slot;
55

6-
mod utils;
7-
use utils::{deploy_signal_service, get_proofs, get_provider};
6+
use minimal_rollup::{deploy_signal_service, get_proofs, get_provider};
87

98
use alloy::primitives::Bytes;
109
use std::fs;
@@ -32,7 +31,7 @@ async fn main() -> Result<()> {
3231
let proof = get_proofs(&provider, slot, &signal_service).await?;
3332

3433

35-
let template = fs::read_to_string("offchain/sample_proof.tmpl")?;
34+
let template = fs::read_to_string("offchain/tmpl/sample_proof.tmpl")?;
3635
let formatted = template
3736
.replace("{signal_service_address}", signal_service.address().to_string().as_str())
3837
.replace("{block_hash}", proof.block_hash.to_string().as_str())
@@ -47,4 +46,3 @@ async fn main() -> Result<()> {
4746
println!("{}", formatted);
4847
Ok(())
4948
}
50-
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)