use std::str::FromStr;
use eth_types::{address, bytecode, bytecode::Bytecode, word, Address, Bytes, Hash, Word};
use ethers_signers::LocalWallet;
use lazy_static::lazy_static;
use rand::{random, SeedableRng};
use rand_chacha::ChaCha20Rng;
mod account;
mod block;
mod sha3;
pub mod test_ctx;
pub mod test_ctx2;
mod transaction;
mod withdrawal;
pub(crate) use account::MockAccount;
pub(crate) use block::MockBlock;
pub use sha3::Sha3CodeGen;
pub use test_ctx::TestContext;
pub use test_ctx2::TestContext2;
pub use transaction::{AddrOrWallet, MockTransaction, CORRECT_MOCK_TXS};
pub const MOCK_BLOCK_GAS_LIMIT: u64 = 10_000_000_000_000_000;
lazy_static! {
pub static ref MOCK_1_ETH: Word = eth(1);
pub static ref MOCK_COINBASE: Address =
address!("0x00000000000000000000000000000000c014ba5e");
pub static ref MOCK_GASPRICE: Word = Word::from(1u8);
pub static ref MOCK_BASEFEE: Word = Word::zero();
pub static ref MOCK_GASLIMIT: Word = Word::from(0x2386f26fc10000u64);
pub static ref MOCK_CHAIN_ID: Word = Word::from(1338u64);
pub static ref MOCK_DIFFICULTY: Word = Word::from(0x200000u64);
pub static ref MOCK_MIX_HASH: Hash =
Hash::from_str("0x3fbea7af642a4e20cd93a945a1f5e23bd72fc5261153e09102cf718980aeff38").unwrap();
pub static ref MOCK_ACCOUNTS: Vec<Address> = vec![
address!("0x000000000000000000000000000000000cafe111"),
address!("0x000000000000000000000000000000000cafe222"),
address!("0x000000000000000000000000000000000cafe333"),
address!("0x000000000000000000000000000000000cafe444"),
address!("0x000000000000000000000000000000000cafe555"),
];
pub static ref MOCK_CODES: Vec<Bytes> = vec![
Bytes::from([0x60, 0x10, 0x00]), Bytes::from([0x60, 0x01, 0x60, 0x02, 0x01, 0x00]), Bytes::from([0x60, 0x01, 0x60, 0x02, 0x02, 0x00]), Bytes::from([0x60, 0x02, 0x60, 0x01, 0x03, 0x00]), Bytes::from([0x60, 0x09, 0x60, 0x03, 0x04, 0x00]), Bytes::from([0x30; 256]), ];
pub static ref MOCK_WALLETS: Vec<LocalWallet> = {
let mut rng = ChaCha20Rng::seed_from_u64(2u64);
vec![
LocalWallet::new(&mut rng),
LocalWallet::new(&mut rng),
LocalWallet::new(&mut rng),
]
};
pub static ref MOCK_DEPLOYED_CONTRACT_BYTECODE: Word = word!("6B6020600060003760206000F3600052600C6014F3");
}
pub fn eth(x: u64) -> Word {
Word::from(x) * Word::from(10u64.pow(18))
}
pub fn gwei(x: u64) -> Word {
Word::from(x) * Word::from(10u64.pow(9))
}
pub struct MockCallBytecodeParams {
pub address: Address,
pub pushdata: Vec<u8>,
pub return_data_offset: usize,
pub return_data_size: usize,
pub call_data_length: usize,
pub call_data_offset: usize,
pub gas: u64,
pub instructions_after_call: Bytecode,
}
impl Default for MockCallBytecodeParams {
fn default() -> Self {
MockCallBytecodeParams {
address: address!("0x0000000000000000000000000000000000000000"),
pushdata: Vec::new(),
return_data_offset: 0x00usize,
return_data_size: 0x00usize,
call_data_length: 0x00usize,
call_data_offset: 0x00usize,
gas: 0x1_0000u64,
instructions_after_call: Bytecode::default(),
}
}
}
pub fn rand_bytes(size: usize) -> Vec<u8> {
(0..size).map(|_| random()).collect::<Vec<u8>>()
}
pub fn generate_mock_call_bytecode(params: MockCallBytecodeParams) -> Bytecode {
bytecode! {
.op_mstore(
0u64,
Word::from_big_endian(¶ms.pushdata)
)
.op_call(
params.gas,
params.address,
0u64,
params.call_data_offset,
params.call_data_length,
params.return_data_size,
params.return_data_offset,
)
.append(¶ms.instructions_after_call)
STOP
}
}