Skip to content

Commit c45be8e

Browse files
committed
Add a test
1 parent ce08498 commit c45be8e

File tree

1 file changed

+62
-0
lines changed
  • tests/instances/system_hooks/src

1 file changed

+62
-0
lines changed

tests/instances/system_hooks/src/lib.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,68 @@ fn test_set_bytecode_details_evm() {
296296
assert_eq!(expected_account_hash.as_u8_array(), actual_hash.0);
297297
}
298298

299+
#[test]
300+
fn test_contract_deployer_temp_hook() {
301+
let complex_upgrader_address = address!("000000000000000000000000000000000000800f");
302+
let contract_deployer_temp_hook_address = address!("0000000000000000000000000000000000007003");
303+
304+
let bytecode = hex::decode("0123456789").unwrap();
305+
let code_hash = Bytes32::from_array(
306+
hex::decode("1c4be3dec3ba88b69a8d3cd5cedd2b22f3da89b1ff9c8fd453c5a6e10c23d6f7")
307+
.unwrap()
308+
.try_into()
309+
.unwrap(),
310+
);
311+
// setBytecodeDetailsEVM(address,bytes32,uint32,bytes32)
312+
let calldata =
313+
hex::decode("f6eca0b000000000000000000000000000000000000000000000000000000000000100021c4be3dec3ba88b69a8d3cd5cedd2b22f3da89b1ff9c8fd453c5a6e10c23d6f7000000000000000000000000000000000000000000000000000000000000000579fad56e6cf52d0c8c2c033d568fc36856ba2b556774960968d79274b0e6b944")
314+
.unwrap();
315+
316+
let mut tester = TestingFramework::new()
317+
.with_preimage(code_hash, &bytecode)
318+
.with_balance(
319+
complex_upgrader_address,
320+
U256::from(1_000_000_000_000_000_u64),
321+
);
322+
323+
let tx = L1TxBuilder::new()
324+
.from(complex_upgrader_address)
325+
.to(contract_deployer_temp_hook_address)
326+
.input(calldata)
327+
.gas_price(1000)
328+
.gas_limit(200_000)
329+
.build();
330+
331+
let output = tester.execute_block(vec![tx]);
332+
333+
// Assert all txs succeeded
334+
assert!(output.tx_results.iter().cloned().enumerate().all(|(i, r)| {
335+
let success = r.clone().is_ok_and(|o| o.is_success());
336+
if !success {
337+
println!("Transaction {} failed with: {:?}", i, r)
338+
}
339+
success
340+
}));
341+
342+
let mut account = AccountProperties::default();
343+
rig::zksync_os_api::helpers::set_properties_code(&mut account, &[0x01, 0x23, 0x45, 0x67, 0x89]);
344+
let expected_account_hash = account.compute_hash();
345+
346+
let actual_hash = output
347+
.storage_writes
348+
.iter()
349+
.find(|write| {
350+
write.account.0 == ACCOUNT_PROPERTIES_STORAGE_ADDRESS.to_be_bytes()
351+
&& write.account_key.0
352+
== address_into_special_storage_key(&B160::from_limbs([0x10002, 0, 0]))
353+
.as_u8_array()
354+
})
355+
.expect("Corresponding write for force deploy not found")
356+
.value;
357+
358+
assert_eq!(expected_account_hash.as_u8_array(), actual_hash.0);
359+
}
360+
299361
#[test]
300362
fn test_set_deployed_bytecode_evm_unauthorized() {
301363
let bytecode = hex::decode("0123456789").unwrap();

0 commit comments

Comments
 (0)