Skip to content

Commit

Permalink
zksync_contracts to incapsulate FS
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Jul 21, 2024
1 parent 477ea5e commit 5a925c6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
18 changes: 18 additions & 0 deletions core/lib/contracts/src/consensus_l2_contracts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use ethabi::Contract;

use crate::{load_contract, read_bytecode, TestContract};

const CONSENSUS_REGISTRY_CONTRACT_FILE: &str =
"contracts/l2-contracts/artifacts-zk/contracts/ConsensusRegistry.sol/ConsensusRegistry.json";

pub fn load_consensus_registry_contract() -> Contract {
load_contract(CONSENSUS_REGISTRY_CONTRACT_FILE)
}

pub fn load_consensus_registry_contract_in_test() -> TestContract {
TestContract {
bytecode: read_bytecode(CONSENSUS_REGISTRY_CONTRACT_FILE),
contract: load_consensus_registry_contract(),
factory_deps: vec![],
}
}
1 change: 1 addition & 0 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, workspace_dir_or_current_dir};

pub mod consensus_l2_contracts;
pub mod test_contracts;

#[derive(Debug, Clone)]
Expand Down
17 changes: 10 additions & 7 deletions core/node/consensus/src/storage/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use anyhow::Context as _;
use zksync_concurrency::{ctx, ctx::Ctx, error::Wrap as _, time};
use zksync_consensus_roles::validator;
use zksync_contracts::{load_contract, read_bytecode, BaseSystemContracts};
use zksync_contracts::{consensus_l2_contracts, load_contract, read_bytecode, BaseSystemContracts};
use zksync_dal::CoreDal as _;
use zksync_node_genesis::{insert_genesis_batch, mock_genesis_config, GenesisParams};
use zksync_node_test_utils::{recover, snapshot, Snapshot};
Expand Down Expand Up @@ -217,23 +217,26 @@ impl VMWriter {
owner: Address,
nodes: &[&[Token]],
) -> Address {
let registry_bytecode = read_bytecode("contracts/l2-contracts/artifacts-zk/contracts/ConsensusRegistry.sol/ConsensusRegistry.json");
let registry_contract = load_contract("contracts/l2-contracts/artifacts-zk/contracts/ConsensusRegistry.sol/ConsensusRegistry.json");
let registry_contract = consensus_l2_contracts::load_consensus_registry_contract_in_test();

let mut txs: Vec<Transaction> = vec![];
let deploy_tx = self.account.get_deploy_tx_with_factory_deps(
&registry_bytecode,
&registry_contract.bytecode,
Some(&[Token::Address(owner)]),
vec![],
TxType::L2,
);
txs.push(deploy_tx.tx);
for node in nodes {
let tx = self.gen_tx_add(&registry_contract, deploy_tx.address, node);
let tx = self.gen_tx_add(&registry_contract.contract, deploy_tx.address, node);
txs.push(tx);
}
txs.push(self.gen_tx_set_validator_committee(deploy_tx.address, &registry_contract));
txs.push(self.gen_tx_set_attester_committee(deploy_tx.address, &registry_contract));
txs.push(
self.gen_tx_set_validator_committee(deploy_tx.address, &registry_contract.contract),
);
txs.push(
self.gen_tx_set_attester_committee(deploy_tx.address, &registry_contract.contract),
);

self.node.push_block(&txs).await;
self.pool
Expand Down
4 changes: 2 additions & 2 deletions core/node/consensus/src/storage/vm_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use zksync_basic_types::{
web3::contract::{Detokenize, Error, Tokenizable, Tokenize},
};
use zksync_concurrency::ctx::Ctx;
use zksync_contracts::load_contract;
use zksync_contracts::{consensus_l2_contracts, load_contract};
use zksync_node_api_server::{
execution_sandbox::{BlockArgs, BlockStartInfo},
tx_sender::TxSender,
Expand All @@ -33,7 +33,7 @@ pub struct VMReader {

impl VMReader {
pub fn new(pool: ConnectionPool, tx_sender: TxSender, registry_address: Address) -> Self {
let registry_contract = load_contract("contracts/l2-contracts/artifacts-zk/contracts/ConsensusRegistry.sol/ConsensusRegistry.json");
let registry_contract = consensus_l2_contracts::load_consensus_registry_contract();
Self {
pool,
tx_sender,
Expand Down

0 comments on commit 5a925c6

Please sign in to comment.