Skip to content

Commit

Permalink
add EvmStateBuilder struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Jan 18, 2022
1 parent 9f60ec1 commit e955e72
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
83 changes: 83 additions & 0 deletions chain-impl-mockchain/src/ledger/tests/evm_tests.rs
@@ -0,0 +1,83 @@
use chain_evm::primitive_types::{H160, H256, U256};
use chain_evm::state::Account;
use chain_evm::Address;

use crate::config::{EvmConfig, EvmConfigParams};
use crate::evm::EvmTransaction;
use crate::ledger::evm::Ledger;

struct EvmStateBuilder {
ledger: Ledger,
config: EvmConfigParams,
}

impl EvmStateBuilder {
pub fn new() -> Self {
Self {
ledger: Default::default(),
config: Default::default(),
}
}
}

impl EvmStateBuilder {
pub fn set_evm_config(mut self, config: EvmConfig) -> Self {
self.config.config = config;
self
}

pub fn set_account(mut self, address: Address, account: Account) -> Self {
self.ledger.accounts = self.ledger.accounts.put(address, account);
self
}

pub fn set_gas_price(mut self, gas_price: U256) -> Self {
self.config.environment.gas_price = gas_price;
self
}

pub fn set_origin(mut self, origin: H160) -> Self {
self.config.environment.origin = origin;
self
}

pub fn set_chain_id(mut self, chain_id: U256) -> Self {
self.config.environment.chain_id = chain_id;
self
}

pub fn set_block_hashes(mut self, block_hashes: Vec<H256>) -> Self {
self.config.environment.block_hashes = block_hashes;
self
}

pub fn set_block_number(mut self, block_number: U256) -> Self {
self.config.environment.block_number = block_number;
self
}

pub fn set_block_coinbase(mut self, block_coinbase: H160) -> Self {
self.config.environment.block_coinbase = block_coinbase;
self
}

pub fn set_block_timestamp(mut self, block_timestamp: U256) -> Self {
self.config.environment.block_timestamp = block_timestamp;
self
}

pub fn set_block_difficulty(mut self, block_difficulty: U256) -> Self {
self.config.environment.block_difficulty = block_difficulty;
self
}

pub fn set_block_gas_limit(mut self, block_gas_limit: U256) -> Self {
self.config.environment.block_gas_limit = block_gas_limit;
self
}

pub fn set_block_base_fee_per_gas(mut self, block_base_fee_per_gas: U256) -> Self {
self.config.environment.block_base_fee_per_gas = block_base_fee_per_gas;
self
}
}
2 changes: 2 additions & 0 deletions chain-impl-mockchain/src/ledger/tests/mod.rs
Expand Up @@ -3,6 +3,8 @@ mod macros;
pub mod apply_block_tests;
pub mod certificate_tests;
pub mod discrimination_tests;
#[cfg(feature = "evm")]
pub mod evm_tests;
pub mod initial_funds_tests;
pub mod ledger_tests;
pub mod transaction_tests;

0 comments on commit e955e72

Please sign in to comment.