fix: make multicall work by reference (#58)

* fix: make multicall work by reference

* chore: update readme with solc / ganache requirements

* chore: cargo fmt

* chore: fix doctests

* fix: disable sparkpool gasnow test
This commit is contained in:
Georgios Konstantopoulos 2020-08-21 15:54:23 +03:00 committed by GitHub
parent 237f011259
commit cff6eb45a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 18 deletions

View File

@ -20,6 +20,16 @@ ethers = { git = "https://github.com/gakonst/ethers-rs" }
</details> </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 Support
[Celo](http://celo.org/) support is turned on via the feature-flag `celo`: [Celo](http://celo.org/) support is turned on via the feature-flag `celo`:

View File

@ -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 /// // 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. /// // for the Multicall contract, you can pass the `Some(multicall_addr)` argument.
/// // Construction of the `Multicall` instance follows the builder pattern /// // Construction of the `Multicall` instance follows the builder pattern
/// let multicall = Multicall::new(Arc::clone(&client), None) /// let mut multicall = Multicall::new(Arc::clone(&client), None).await?;
/// .await? /// multicall
/// .add_call(first_call) /// .add_call(first_call)
/// .add_call(second_call); /// .add_call(second_call);
/// ///
@ -203,7 +203,7 @@ where
/// ///
/// If more than the maximum number of supported calls are added. The maximum /// If more than the maximum number of supported calls are added. The maximum
/// limits is constrained due to tokenization/detokenization support for tuples /// 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 { if self.calls.len() >= 16 {
panic!("Cannot support more than {} calls", 16); panic!("Cannot support more than {} calls", 16);
} }
@ -229,7 +229,7 @@ where
/// ///
/// If more than the maximum number of supported calls are added. The maximum /// If more than the maximum number of supported calls are added. The maximum
/// limits is constrained due to tokenization/detokenization support for tuples /// 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); let call = self.contract.get_eth_balance(addr);
self.add_call(call) self.add_call(call)
} }
@ -254,8 +254,8 @@ where
/// # let broadcast_1 = contract.method::<_, H256>("setValue", "some value".to_owned())?; /// # let broadcast_1 = contract.method::<_, H256>("setValue", "some value".to_owned())?;
/// # let broadcast_2 = contract.method::<_, H256>("setValue", "new value".to_owned())?; /// # let broadcast_2 = contract.method::<_, H256>("setValue", "new value".to_owned())?;
/// # /// #
/// let multicall = Multicall::new(client, None) /// let mut multicall = Multicall::new(client, None).await?;
/// .await? /// multicall
/// .add_call(broadcast_1) /// .add_call(broadcast_1)
/// .add_call(broadcast_2); /// .add_call(broadcast_2);
/// ///
@ -263,7 +263,7 @@ where
/// ///
/// # let call_1 = contract.method::<_, String>("getValue", ())?; /// # let call_1 = contract.method::<_, String>("getValue", ())?;
/// # let call_2 = contract.method::<_, Address>("lastSender", ())?; /// # let call_2 = contract.method::<_, Address>("lastSender", ())?;
/// let multicall = multicall /// multicall
/// .clear_calls() /// .clear_calls()
/// .add_call(call_1) /// .add_call(call_1)
/// .add_call(call_2); /// .add_call(call_2);
@ -271,7 +271,7 @@ where
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
pub fn clear_calls(mut self) -> Self { pub fn clear_calls(&mut self) -> &mut Self {
self.calls.clear(); self.calls.clear();
self self
} }

View File

@ -264,9 +264,9 @@ mod eth_tests {
.unwrap(); .unwrap();
// initiate the Multicall instance and add calls one by one in builder style // initiate the Multicall instance and add calls one by one in builder style
let multicall = Multicall::new(client4.clone(), Some(addr)) let mut multicall = Multicall::new(client4.clone(), Some(addr)).await.unwrap();
.await
.unwrap() multicall
.add_call(value) .add_call(value)
.add_call(value2) .add_call(value2)
.add_call(last_sender) .add_call(last_sender)
@ -295,8 +295,8 @@ mod eth_tests {
// new calls. Previously we used the `.call()` functionality to do a batch of calls in one // 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 // go. Now we will use the `.send()` functionality to broadcast a batch of transactions
// in one go // in one go
let multicall_send = multicall let mut multicall_send = multicall.clone();
.clone() multicall_send
.clear_calls() .clear_calls()
.add_call(broadcast) .add_call(broadcast)
.add_call(broadcast2); .add_call(broadcast2);
@ -321,7 +321,7 @@ mod eth_tests {
// query ETH balances of multiple addresses // query ETH balances of multiple addresses
// these keys haven't been used to do any tx // these keys haven't been used to do any tx
// so should have 100 ETH // so should have 100 ETH
let multicall = multicall multicall
.clear_calls() .clear_calls()
.eth_balance_of(Address::from(&ganache.keys()[4])) .eth_balance_of(Address::from(&ganache.keys()[4]))
.eth_balance_of(Address::from(&ganache.keys()[5])) .eth_balance_of(Address::from(&ganache.keys()[5]))

View File

@ -100,10 +100,12 @@ mod eth_tests {
let data_4 = etherchain_oracle.fetch().await; let data_4 = etherchain_oracle.fetch().await;
assert!(data_4.is_ok()); assert!(data_4.is_ok());
// initialize and fetch gas estimates from Etherchain // TODO: Temporarily disabled SparkPool's GasOracle while the API is still
let gas_now_oracle = GasNow::new().category(GasCategory::Fastest); // evolving.
let data_5 = gas_now_oracle.fetch().await; // // initialize and fetch gas estimates from SparkPool
assert!(data_5.is_ok()); // 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>) { async fn generic_pending_txs_test<P: JsonRpcClient>(provider: Provider<P>) {