Skip to content

Commit

Permalink
MockTransaction::copy_from
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamWuGit committed Sep 10, 2024
1 parent c995b52 commit bd9a865
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
25 changes: 25 additions & 0 deletions mock/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,29 @@ impl MockTransaction {
v
}
}

/// Copy from other MockTransaction instance.
pub fn copy_from(&mut self, other: MockTransaction) -> &mut Self {
self.hash = other.hash;
self.nonce = other.nonce;
self.block_hash = other.block_hash;
self.block_number = other.block_number;
self.transaction_index = other.transaction_index;
self.from = other.from;
self.to = other.to;
self.value = other.value;
self.gas_price = other.gas_price;
self.gas = other.gas;
self.input = other.input;
self.v = other.v;
self.r = other.r;
self.s = other.s;
self.transaction_type = other.transaction_type;
self.access_list = other.access_list;
self.max_priority_fee_per_gas = other.max_priority_fee_per_gas;
self.max_fee_per_gas = other.max_fee_per_gas;
self.chain_id = other.chain_id;

self
}
}
52 changes: 28 additions & 24 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,8 +1779,27 @@ mod test {
// TODO: move test to appropriate place
#[test]
fn test_legacy_tx_pre_eip155() {
//let ctx = build_legacy_ctx(gwei(8000_000)).unwrap();
let ctx = build_legacy_ctx2(gwei(8000_000)).unwrap();
let mut tx = MockTransaction::default();
// pre-eip155 tx downloaded from [etherscan](https://etherscan.io/getRawTx?tx=0x9cd2288e69623b109e25edc46bc518156498b521e5c162d96e1ab392ff1d9dff)
// Note: have signature data, don't generate dynamically because ethers-rs lib only implemented for eip155 type tx.
let sig_data = (
0x1c_u64,
word!("0x90b751c5870e9bc071c8d6b2bf1ee80f36ee7efd8e6fbabaa25bd3b8b68cfe9b"),
word!("0x79c25a01f12493a6d35f1330306d4e3c4e782fcbffc64c6809959577f41ff248"),
);

tx
.from(address!("0xcf40d0d2b44f2b66e07cace1372ca42b73cf21a3"))
.nonce(word!("0x2ea8"))
.gas_price(word!("0x098bca5a00"))
.gas(word!("0x0249f0"))
.value(word!("0x00"))
.transaction_type(0) // Set tx type to pre-eip155.
.input(hex::decode("606060405260008054600160a060020a0319163317905560f2806100236000396000f3606060405260e060020a6000350463f5537ede8114601c575b6002565b3460025760f06004356024356044356000805433600160a060020a039081169116141560ea5783905080600160a060020a031663a9059cbb84846000604051602001526040518360e060020a0281526004018083600160a060020a0316815260200182815260200192505050602060405180830381600087803b1560025760325a03f1156002575050604080518481529051600160a060020a0386811693508716917fd0ed88a3f042c6bbb1e3ea406079b5f2b4b198afccaa535d837f4c63abbc4de6919081900360200190a35b50505050565b00")
.expect("hex data can be decoded").into())
.sig_data(sig_data);
let ctx = build_legacy_ctx(gwei(8000_000), &tx).unwrap();
//let ctx = build_legacy_ctx2(gwei(8000_000)).unwrap();

CircuitTestBuilder::new_from_test_ctx(ctx)
.params(CircuitsParams {
Expand All @@ -1791,35 +1810,20 @@ mod test {
}

// build pre-eip155 tx
fn build_legacy_ctx(sender_balance: Word) -> Result<TestContext<1, 1>, Error> {
// pre-eip155 tx downloaded from [etherscan](https://etherscan.io/getRawTx?tx=0x9cd2288e69623b109e25edc46bc518156498b521e5c162d96e1ab392ff1d9dff)
// Note: have signature data, don't generate dynamically because ethers-rs lib only implemented for eip155 type tx.
let sig_data = (
0x1c_u64,
word!("0x90b751c5870e9bc071c8d6b2bf1ee80f36ee7efd8e6fbabaa25bd3b8b68cfe9b"),
word!("0x79c25a01f12493a6d35f1330306d4e3c4e782fcbffc64c6809959577f41ff248"),
);

fn build_legacy_ctx(
sender_balance: Word,
tx: &MockTransaction,
) -> Result<TestContext<1, 1>, Error> {
TestContext::new(
None,
|accs| {
accs[0]
.address(address!("0xcf40d0d2b44f2b66e07cace1372ca42b73cf21a3"))
.address(tx.from.address())
.balance(sender_balance)
.nonce(word!("0x2ea8"));
//accs[1].address(MOCK_ACCOUNTS[1]).balance(eth(1));
.nonce(tx.nonce);
},
|mut txs, _accs| {
txs[0]
.from(address!("0xcf40d0d2b44f2b66e07cace1372ca42b73cf21a3"))
.nonce(word!("0x2ea8"))
.gas_price(word!("0x098bca5a00"))
.gas(word!("0x0249f0"))
.value(word!("0x00"))
.transaction_type(0) // Set tx type to pre-eip155.
.input(hex::decode("606060405260008054600160a060020a0319163317905560f2806100236000396000f3606060405260e060020a6000350463f5537ede8114601c575b6002565b3460025760f06004356024356044356000805433600160a060020a039081169116141560ea5783905080600160a060020a031663a9059cbb84846000604051602001526040518360e060020a0281526004018083600160a060020a0316815260200182815260200192505050602060405180830381600087803b1560025760325a03f1156002575050604080518481529051600160a060020a0386811693508716917fd0ed88a3f042c6bbb1e3ea406079b5f2b4b198afccaa535d837f4c63abbc4de6919081900360200190a35b50505050565b00")
.expect("hex data can be decoded").into())
.sig_data(sig_data);
txs[0].copy_from(tx.clone());
},
|block, _tx| block.number(0xcafeu64),
)
Expand Down

0 comments on commit bd9a865

Please sign in to comment.