test: update broken test and use it module for ethers-contract (#1502)

* refactor: make ethers-contract tests it module

* update failing test

* assert console is generated

* chore(clippy): make clippy happy

* update broken test

* move sol files back

* chore: rustfmt

* chore(clippy): make clippy happy
This commit is contained in:
Matthias Seitz 2022-07-24 23:41:06 +02:00 committed by GitHub
parent fb8ebd8231
commit d22fb2bd0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 13 deletions

View File

@ -129,6 +129,7 @@ where
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # #[cfg(feature = "abigen")]
/// # async fn test<M:ethers_providers::Middleware>(contract: ethers_contract::Contract<M>) { /// # async fn test<M:ethers_providers::Middleware>(contract: ethers_contract::Contract<M>) {
/// # use ethers_core::types::*; /// # use ethers_core::types::*;
/// # use futures_util::stream::StreamExt; /// # use futures_util::stream::StreamExt;

View File

@ -77,6 +77,7 @@ where
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # #[cfg(feature = "abigen")]
/// # async fn test<M:ethers_providers::Middleware>(contract: ethers_contract::Contract<M>) { /// # async fn test<M:ethers_providers::Middleware>(contract: ethers_contract::Contract<M>) {
/// # use ethers_core::types::*; /// # use ethers_core::types::*;
/// # use futures_util::stream::StreamExt; /// # use futures_util::stream::StreamExt;

View File

@ -188,7 +188,7 @@ fn can_gen_return_struct() {
ArrayRelayerReturn { outputs: vec![4.into(), 9.into(), 2.into()], some_number: 42.into() }; ArrayRelayerReturn { outputs: vec![4.into(), 9.into(), 2.into()], some_number: 42.into() };
verify(array); verify(array);
let single = SingleUnnamedReturn { 0: 4321.into() }; let single = SingleUnnamedReturn(4321.into());
verify(single); verify(single);
// doesnt exist: // doesnt exist:

View File

@ -53,7 +53,7 @@ fn can_derive_abi_type_empty_struct() {
struct Call(); struct Call();
#[derive(Debug, Clone, PartialEq, Eq, EthAbiType)] #[derive(Debug, Clone, PartialEq, Eq, EthAbiType)]
struct Call2 {}; struct Call2;
#[derive(Debug, Clone, PartialEq, Eq, EthAbiType)] #[derive(Debug, Clone, PartialEq, Eq, EthAbiType)]
struct Call3; struct Call3;

View File

@ -29,6 +29,7 @@ pub struct ValueChanged {
} }
/// compiles the given contract and returns the ABI and Bytecode /// compiles the given contract and returns the ABI and Bytecode
#[track_caller]
pub fn compile_contract(name: &str, filename: &str) -> (Abi, Bytes) { pub fn compile_contract(name: &str, filename: &str) -> (Abi, Bytes) {
let path = format!("./tests/solidity-contracts/{}", filename); let path = format!("./tests/solidity-contracts/{}", filename);
let compiled = Solc::default().compile_source(&path).unwrap(); let compiled = Solc::default().compile_source(&path).unwrap();

View File

@ -0,0 +1,5 @@
//! ensure console.sol can be generated via abigen!
ethers_contract::abigen!(HardhatConsole, "./tests/solidity-contracts/console.json",);
fn assert_console_calls(_: &hardhat_console::HardhatConsoleCalls) {}

View File

@ -1,6 +1,5 @@
#![allow(unused)] #![allow(unused)]
mod common; pub use crate::common::*;
pub use common::*;
use ethers_contract::{abigen, ContractFactory, EthAbiType}; use ethers_contract::{abigen, ContractFactory, EthAbiType};
use ethers_core::types::{Filter, ValueOrArray, H256}; use ethers_core::types::{Filter, ValueOrArray, H256};

View File

@ -0,0 +1,10 @@
#![allow(unused)]
mod abigen;
pub(crate) mod common;
#[cfg(feature = "abigen")]
mod console;
#[cfg(feature = "abigen")]
mod contract;
fn main() {}

File diff suppressed because one or more lines are too long

View File

@ -14,8 +14,7 @@ async fn txpool() {
let account = provider.get_accounts().await.unwrap()[0]; let account = provider.get_accounts().await.unwrap()[0];
let value: u64 = 42; let value: u64 = 42;
let gas_price = U256::from_dec_str("221435145689").unwrap(); let gas_price = U256::from_dec_str("221435145689").unwrap();
let mut tx = let tx = TransactionRequest::new().to(account).from(account).value(value).gas_price(gas_price);
TransactionRequest::new().to(account).from(account).value(value).gas_price(gas_price);
// send a few transactions // send a few transactions
let mut txs = Vec::new(); let mut txs = Vec::new();
@ -44,11 +43,7 @@ async fn txpool() {
assert!(content.queued.is_empty()); assert!(content.queued.is_empty());
let content = content.pending.get(&account).unwrap(); let content = content.pending.get(&account).unwrap();
// the txs get their gas and nonce auto-set upon mempool entry for nonce in 0..10 {
tx = tx.gas(21000); assert!(content.contains_key(&nonce.to_string()));
for i in 0..10 {
tx = tx.nonce(i);
let req = content.get(&i.to_string()).unwrap();
assert_eq!(req, &tx);
} }
} }