Skip to content

Commit e17ed0d

Browse files
authored
deploy with address (#759)
* deploy with address
1 parent f31d22b commit e17ed0d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ethcontract-mock/src/details/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ impl MockTransport {
9393
address
9494
}
9595

96+
/// Deploys a new contract with the given ABI and address
97+
pub fn deploy_with_address(&self, abi: &Abi, address: Address) {
98+
let mut state = self.state.lock().unwrap();
99+
100+
assert!(
101+
state
102+
.contracts
103+
.insert(address, Contract::new(address, abi))
104+
.is_none(),
105+
"replacing contract at address {:?}",
106+
address
107+
);
108+
}
109+
96110
pub fn update_gas_price(&self, gas_price: u64) {
97111
let mut state = self.state.lock().unwrap();
98112
state.gas_price = gas_price;

ethcontract-mock/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ impl Mock {
289289
}
290290
}
291291

292+
/// Deploys a new mocked contract with specified address and returns an object that allows
293+
/// configuring expectations for contract methods.
294+
pub fn deploy_with_address(&self, abi: Abi, address: Address) -> Contract {
295+
self.transport.deploy_with_address(&abi, address);
296+
Contract {
297+
transport: self.transport.clone(),
298+
address,
299+
abi,
300+
}
301+
}
302+
292303
/// Updates gas price that is returned by RPC call `eth_gasPrice`.
293304
///
294305
/// Mock node does not simulate gas consumption, so this value does not

0 commit comments

Comments
 (0)