Function ethers_providers::spoof::state

source ·
pub fn state() -> State
Expand description

Returns an empty state override set.

§Examples

let geth = Geth::new().spawn();
let provider = Provider::<Http>::try_from(geth.endpoint()).unwrap();

let adr1: Address = "0x6fC21092DA55B392b045eD78F4732bff3C580e2c".parse()?;
let adr2: Address = "0x295a70b2de5e3953354a6a8344e616ed314d7251".parse()?;
let key = H256::from_low_u64_be(1);
let val = H256::from_low_u64_be(17);

let tx = TransactionRequest::default().to(adr2).from(adr1).into();

// override the storage at `adr2`
let mut state = spoof::state();
state.account(adr2).store(key, val);

// override the nonce at `adr1`
state.account(adr1).nonce(2.into());

provider.call_raw(&tx).state(&state).await?;