Skip to content
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
127 changes: 127 additions & 0 deletions crates/bundle/src/call/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,131 @@ mod test {

assert_eq!(resp, deserialized);
}

/// Generate test vectors for TypeScript SDK.
///
/// Run with: `cargo t -p signet-bundle -- --ignored --nocapture`
#[test]
#[ignore]
fn generate_call_bundle_vectors() {
let vectors = vec![
(
"minimal",
SignetCallBundle {
bundle: EthCallBundle {
txs: vec![b"\x02\xf8test_tx_1".into()],
block_number: 12345678,
state_block_number: BlockNumberOrTag::Number(12345677),
..Default::default()
},
},
),
(
"with_overrides",
SignetCallBundle {
bundle: EthCallBundle {
txs: vec![b"\x02\xf8test_tx_1".into()],
block_number: 12345678,
state_block_number: BlockNumberOrTag::Number(12345677),
timestamp: Some(1700000000),
gas_limit: Some(30000000),
base_fee: Some(1000000000),
..Default::default()
},
},
),
(
"with_coinbase",
SignetCallBundle {
bundle: EthCallBundle {
txs: vec![b"\x02\xf8test_tx_1".into()],
block_number: 12345678,
state_block_number: BlockNumberOrTag::Latest,
coinbase: Some(Address::repeat_byte(0x42)),
timeout: Some(5),
..Default::default()
},
},
),
];

let output: Vec<_> = vectors
.into_iter()
.map(|(name, bundle)| {
serde_json::json!({
"name": name,
"bundle": bundle,
})
})
.collect();

println!("// SignetCallBundle vectors\n{}", serde_json::to_string_pretty(&output).unwrap());

// Also generate response vectors
let response_vectors = vec![
(
"minimal_response",
SignetCallBundleResponse::from(EthCallBundleResponse {
bundle_hash: B256::repeat_byte(0xaa),
bundle_gas_price: U256::from(1000000000u64),
coinbase_diff: U256::from(100000000000000u64),
eth_sent_to_coinbase: U256::from(50000000000000u64),
gas_fees: U256::from(50000000000000u64),
results: vec![EthCallBundleTransactionResult {
coinbase_diff: U256::from(100000000000000u64),
eth_sent_to_coinbase: U256::from(50000000000000u64),
from_address: Address::repeat_byte(0x11),
gas_fees: U256::from(50000000000000u64),
gas_price: U256::from(1000000000u64),
gas_used: 21000,
to_address: Some(Address::repeat_byte(0x22)),
tx_hash: B256::repeat_byte(0xbb),
value: Some(Bytes::from(b"result_data")),
revert: None,
}],
state_block_number: 12345677,
total_gas_used: 21000,
}),
),
(
"reverted_response",
SignetCallBundleResponse::from(EthCallBundleResponse {
bundle_hash: B256::repeat_byte(0xcc),
bundle_gas_price: U256::from(1000000000u64),
coinbase_diff: U256::from(0u64),
eth_sent_to_coinbase: U256::from(0u64),
gas_fees: U256::from(21000000000000u64),
results: vec![EthCallBundleTransactionResult {
coinbase_diff: U256::from(0u64),
eth_sent_to_coinbase: U256::from(0u64),
from_address: Address::repeat_byte(0x33),
gas_fees: U256::from(21000000000000u64),
gas_price: U256::from(1000000000u64),
gas_used: 21000,
to_address: Some(Address::repeat_byte(0x44)),
tx_hash: B256::repeat_byte(0xdd),
value: None,
revert: Some(Bytes::from(b"execution reverted")),
}],
state_block_number: 12345677,
total_gas_used: 21000,
}),
),
];

let response_output: Vec<_> = response_vectors
.into_iter()
.map(|(name, resp)| {
serde_json::json!({
"name": name,
"response": resp,
})
})
.collect();

println!(
"\n// SignetCallBundleResponse vectors\n{}",
serde_json::to_string_pretty(&response_output).unwrap()
);
}
}
101 changes: 101 additions & 0 deletions crates/bundle/src/send/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,105 @@ mod test {

assert!(deserialized.host_txs.is_empty());
}

/// Generate test vectors for TypeScript SDK.
///
/// Run with: `cargo t -p signet-bundle -- --ignored --nocapture`
#[test]
#[ignore]
fn generate_eth_bundle_vectors() {
use alloy::primitives::Address;

let vectors = vec![
(
"minimal",
SignetEthBundle::new(
EthSendBundle {
txs: vec![b"\x02\xf8test_tx_1".into()],
block_number: 12345678,
..Default::default()
},
vec![],
),
),
(
"with_timestamps",
SignetEthBundle::new(
EthSendBundle {
txs: vec![b"\x02\xf8test_tx_1".into()],
block_number: 12345678,
min_timestamp: Some(1700000000),
max_timestamp: Some(1700003600),
..Default::default()
},
vec![],
),
),
(
"with_reverting_hashes",
SignetEthBundle::new(
EthSendBundle {
txs: vec![b"\x02\xf8test_tx_1".into(), b"\x02\xf8test_tx_2".into()],
block_number: 12345678,
reverting_tx_hashes: vec![B256::repeat_byte(0xab), B256::repeat_byte(0xcd)],
..Default::default()
},
vec![],
),
),
(
"with_host_txs",
SignetEthBundle::new(
EthSendBundle {
txs: vec![b"\x02\xf8rollup_tx".into()],
block_number: 12345678,
..Default::default()
},
vec![b"\x02\xf8host_tx_1".into(), b"\x02\xf8host_tx_2".into()],
),
),
(
"full_bundle",
SignetEthBundle::new(
EthSendBundle {
txs: vec![b"\x02\xf8tx_1".into(), b"\x02\xf8tx_2".into()],
block_number: 12345678,
min_timestamp: Some(1700000000),
max_timestamp: Some(1700003600),
reverting_tx_hashes: vec![B256::repeat_byte(0xef)],
dropping_tx_hashes: vec![B256::repeat_byte(0x11)],
refund_percent: Some(90),
refund_recipient: Some(Address::repeat_byte(0x22)),
refund_tx_hashes: vec![B256::repeat_byte(0x33)],
..Default::default()
},
vec![b"\x02\xf8host_tx".into()],
),
),
(
"replacement_bundle",
SignetEthBundle::new(
EthSendBundle {
txs: vec![b"\x02\xf8replacement_tx".into()],
block_number: 12345678,
replacement_uuid: Some("550e8400-e29b-41d4-a716-446655440000".to_owned()),
..Default::default()
},
vec![],
),
),
];

let output: Vec<_> = vectors
.into_iter()
.map(|(name, bundle)| {
serde_json::json!({
"name": name,
"bundle": bundle,
})
})
.collect();

println!("// SignetEthBundle vectors\n{}", serde_json::to_string_pretty(&output).unwrap());
}
}
Loading