Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: make multicall work by reference (#58)
Browse files Browse the repository at this point in the history
* fix: make multicall work by reference

* chore: update readme with solc / ganache requirements

* chore: cargo fmt

* chore: fix doctests

* fix: disable sparkpool gasnow test
  • Loading branch information
gakonst authored Aug 21, 2020
1 parent 237f011 commit cff6eb4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ ethers = { git = "https://github.com/gakonst/ethers-rs" }

</details>

## Running the tests

Tests require the following installed:
1. [`solc`](https://solidity.readthedocs.io/en/latest/installing-solidity.html)
2. [`ganache-cli`](https://github.com/trufflesuite/ganache-cli#installation)

In addition, it is recommended that you set the `ETHERSCAN_API_KEY` environment variable
for [the abigen via Etherscan](https://github.com/gakonst/ethers-rs/blob/master/ethers/tests/major_contracts.rs) tests.
You can get one [here](https://etherscan.io/apis).

### Celo Support

[Celo](http://celo.org/) support is turned on via the feature-flag `celo`:
Expand Down
16 changes: 8 additions & 8 deletions ethers-contract/src/multicall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ pub static ADDRESS_BOOK: Lazy<HashMap<U256, Address>> = Lazy::new(|| {
/// // the Multicall contract and we set that to `None`. If you wish to provide the address
/// // for the Multicall contract, you can pass the `Some(multicall_addr)` argument.
/// // Construction of the `Multicall` instance follows the builder pattern
/// let multicall = Multicall::new(Arc::clone(&client), None)
/// .await?
/// let mut multicall = Multicall::new(Arc::clone(&client), None).await?;
/// multicall
/// .add_call(first_call)
/// .add_call(second_call);
///
Expand Down Expand Up @@ -203,7 +203,7 @@ where
///
/// If more than the maximum number of supported calls are added. The maximum
/// limits is constrained due to tokenization/detokenization support for tuples
pub fn add_call<D: Detokenize>(mut self, call: ContractCall<P, S, D>) -> Self {
pub fn add_call<D: Detokenize>(&mut self, call: ContractCall<P, S, D>) -> &mut Self {
if self.calls.len() >= 16 {
panic!("Cannot support more than {} calls", 16);
}
Expand All @@ -229,7 +229,7 @@ where
///
/// If more than the maximum number of supported calls are added. The maximum
/// limits is constrained due to tokenization/detokenization support for tuples
pub fn eth_balance_of(self, addr: Address) -> Self {
pub fn eth_balance_of(&mut self, addr: Address) -> &mut Self {
let call = self.contract.get_eth_balance(addr);
self.add_call(call)
}
Expand All @@ -254,24 +254,24 @@ where
/// # let broadcast_1 = contract.method::<_, H256>("setValue", "some value".to_owned())?;
/// # let broadcast_2 = contract.method::<_, H256>("setValue", "new value".to_owned())?;
/// #
/// let multicall = Multicall::new(client, None)
/// .await?
/// let mut multicall = Multicall::new(client, None).await?;
/// multicall
/// .add_call(broadcast_1)
/// .add_call(broadcast_2);
///
/// let _tx_hash = multicall.send().await?;
///
/// # let call_1 = contract.method::<_, String>("getValue", ())?;
/// # let call_2 = contract.method::<_, Address>("lastSender", ())?;
/// let multicall = multicall
/// multicall
/// .clear_calls()
/// .add_call(call_1)
/// .add_call(call_2);
/// let return_data: (String, Address) = multicall.call().await?;
/// # Ok(())
/// # }
/// ```
pub fn clear_calls(mut self) -> Self {
pub fn clear_calls(&mut self) -> &mut Self {
self.calls.clear();
self
}
Expand Down
12 changes: 6 additions & 6 deletions ethers-contract/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ mod eth_tests {
.unwrap();

// initiate the Multicall instance and add calls one by one in builder style
let multicall = Multicall::new(client4.clone(), Some(addr))
.await
.unwrap()
let mut multicall = Multicall::new(client4.clone(), Some(addr)).await.unwrap();

multicall
.add_call(value)
.add_call(value2)
.add_call(last_sender)
Expand Down Expand Up @@ -295,8 +295,8 @@ mod eth_tests {
// new calls. Previously we used the `.call()` functionality to do a batch of calls in one
// go. Now we will use the `.send()` functionality to broadcast a batch of transactions
// in one go
let multicall_send = multicall
.clone()
let mut multicall_send = multicall.clone();
multicall_send
.clear_calls()
.add_call(broadcast)
.add_call(broadcast2);
Expand All @@ -321,7 +321,7 @@ mod eth_tests {
// query ETH balances of multiple addresses
// these keys haven't been used to do any tx
// so should have 100 ETH
let multicall = multicall
multicall
.clear_calls()
.eth_balance_of(Address::from(&ganache.keys()[4]))
.eth_balance_of(Address::from(&ganache.keys()[5]))
Expand Down
10 changes: 6 additions & 4 deletions ethers-providers/tests/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ mod eth_tests {
let data_4 = etherchain_oracle.fetch().await;
assert!(data_4.is_ok());

// initialize and fetch gas estimates from Etherchain
let gas_now_oracle = GasNow::new().category(GasCategory::Fastest);
let data_5 = gas_now_oracle.fetch().await;
assert!(data_5.is_ok());
// TODO: Temporarily disabled SparkPool's GasOracle while the API is still
// evolving.
// // initialize and fetch gas estimates from SparkPool
// let gas_now_oracle = GasNow::new().category(GasCategory::Fastest);
// let data_5 = gas_now_oracle.fetch().await;
// assert!(data_5.is_ok());
}

async fn generic_pending_txs_test<P: JsonRpcClient>(provider: Provider<P>) {
Expand Down

0 comments on commit cff6eb4

Please sign in to comment.