fix: failing test and check --all-targets in ci (#560)
* fix: update failing example * ci: check all targets
This commit is contained in:
parent
e72636210c
commit
c08f8ba876
|
@ -14,6 +14,22 @@ env:
|
|||
RINKEBY_PRIVATE_KEY: ${{ secrets.RINKEBY_PRIVATE_KEY }}
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: check all
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install stable toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
with:
|
||||
cache-on-failure: true
|
||||
- name: cargo check
|
||||
run: cargo check -p ethers --all-targets --all-features
|
||||
|
||||
tests:
|
||||
name: ethereum tests
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -84,6 +84,7 @@ impl<R> ResponseData<R> {
|
|||
|
||||
impl ResponseData<serde_json::Value> {
|
||||
/// Encode the error to json value if it is an error
|
||||
#[allow(dead_code)]
|
||||
pub fn into_value(self) -> serde_json::Result<serde_json::Value> {
|
||||
match self {
|
||||
ResponseData::Success { result } => Ok(result),
|
||||
|
|
|
@ -393,6 +393,15 @@ impl CompilerOutput {
|
|||
OutputDiagnostics { errors: &self.errors, ignored_error_codes }
|
||||
}
|
||||
|
||||
/// Finds the first contract with the given name
|
||||
pub fn find(&self, contract: impl AsRef<str>) -> Option<CompactContractRef> {
|
||||
let contract = contract.as_ref();
|
||||
self.contracts
|
||||
.values()
|
||||
.find_map(|contracts| contracts.get(contract))
|
||||
.map(CompactContractRef::from)
|
||||
}
|
||||
|
||||
/// Given the contract file's path and the contract's name, tries to return the contract's
|
||||
/// bytecode, runtime bytecode, and abi
|
||||
pub fn get(&self, path: &str, contract: &str) -> Option<CompactContractRef> {
|
||||
|
@ -474,6 +483,24 @@ pub struct CompactContract {
|
|||
pub bin_runtime: Option<Bytes>,
|
||||
}
|
||||
|
||||
impl CompactContract {
|
||||
/// Returns the contents of this type as a single
|
||||
pub fn into_parts(self) -> (Option<Abi>, Option<Bytes>, Option<Bytes>) {
|
||||
(self.abi, self.bin, self.bin_runtime)
|
||||
}
|
||||
|
||||
/// Returns the individual parts of this contract.
|
||||
///
|
||||
/// If the values are `None`, then `Default` is returned.
|
||||
pub fn into_parts_or_default(self) -> (Abi, Bytes, Bytes) {
|
||||
(
|
||||
self.abi.unwrap_or_default(),
|
||||
self.bin.unwrap_or_default(),
|
||||
self.bin_runtime.unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Contract> for CompactContract {
|
||||
fn from(c: Contract) -> Self {
|
||||
let (bin, bin_runtime) = if let Some(evm) = c.evm {
|
||||
|
@ -486,8 +513,14 @@ impl From<Contract> for CompactContract {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<CompactContractRef<'a>> for CompactContract {
|
||||
fn from(c: CompactContractRef<'a>) -> Self {
|
||||
Self { abi: c.abi.cloned(), bin: c.bin.cloned(), bin_runtime: c.bin_runtime.cloned() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper type to serialize while borrowing from `Contract`
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[derive(Copy, Clone, Debug, Serialize)]
|
||||
pub struct CompactContractRef<'a> {
|
||||
pub abi: Option<&'a Abi>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
|
@ -496,6 +529,20 @@ pub struct CompactContractRef<'a> {
|
|||
pub bin_runtime: Option<&'a Bytes>,
|
||||
}
|
||||
|
||||
impl<'a> CompactContractRef<'a> {
|
||||
/// Clones the referenced values and returns as tuples
|
||||
pub fn into_parts(self) -> (Option<Abi>, Option<Bytes>, Option<Bytes>) {
|
||||
CompactContract::from(self).into_parts()
|
||||
}
|
||||
|
||||
/// Returns the individual parts of this contract.
|
||||
///
|
||||
/// If the values are `None`, then `Default` is returned.
|
||||
pub fn into_parts_or_default(self) -> (Abi, Bytes, Bytes) {
|
||||
CompactContract::from(self).into_parts_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Contract> for CompactContractRef<'a> {
|
||||
fn from(c: &'a Contract) -> Self {
|
||||
let (bin, bin_runtime) = if let Some(ref evm) = c.evm {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
use anyhow::Result;
|
||||
use ethers::{
|
||||
prelude::*,
|
||||
utils::{compile_and_launch_ganache, Ganache, Solc},
|
||||
};
|
||||
use std::{convert::TryFrom, sync::Arc, time::Duration};
|
||||
use ethers::{prelude::*, utils::Ganache};
|
||||
use std::{convert::TryFrom, path::Path, sync::Arc, time::Duration};
|
||||
|
||||
// Generate the type-safe contract bindings by providing the ABI
|
||||
// definition in human readable format
|
||||
|
@ -17,11 +14,14 @@ abigen!(
|
|||
async fn main() -> Result<()> {
|
||||
// 1. compile the contract (note this requires that you are inside the `examples` directory) and
|
||||
// launch ganache
|
||||
let (compiled, ganache) =
|
||||
compile_and_launch_ganache(Solc::new("**/contract.sol"), Ganache::new()).await?;
|
||||
let ganache = Ganache::new().spawn();
|
||||
|
||||
let contract = compiled.get("SimpleStorage").expect("could not find contract");
|
||||
dbg!("OK");
|
||||
// set the path to the contract, `CARGO_MANIFEST_DIR` points to the directory containing the
|
||||
// manifest of `ethers`. which will be `../` relative to this file
|
||||
let source = Path::new(&env!("CARGO_MANIFEST_DIR")).join("examples/contract.sol");
|
||||
let compiled = Solc::default().compile_source(source).expect("Could not compile contracts");
|
||||
let (abi, bytecode, _runtime_bytecode) =
|
||||
compiled.find("SimpleStorage").expect("could not find contract").into_parts_or_default();
|
||||
|
||||
// 2. instantiate our wallet
|
||||
let wallet: LocalWallet = ganache.keys()[0].clone().into();
|
||||
|
@ -35,8 +35,7 @@ async fn main() -> Result<()> {
|
|||
let client = Arc::new(client);
|
||||
|
||||
// 5. create a factory which will be used to deploy instances of the contract
|
||||
let factory =
|
||||
ContractFactory::new(contract.abi.clone(), contract.bytecode.clone(), client.clone());
|
||||
let factory = ContractFactory::new(abi, bytecode, client.clone());
|
||||
|
||||
// 6. deploy it with the constructor arguments
|
||||
let contract = factory.deploy("initial value".to_string())?.legacy().send().await?;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use ethers::prelude::*;
|
||||
use std::time::Duration;
|
||||
|
||||
#[tokio::main]
|
||||
#[cfg(feature = "ipc")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let provider =
|
||||
Provider::connect_ipc("~/.ethereum/geth.ipc").await?.interval(Duration::from_millis(2000));
|
||||
use ethers::prelude::*;
|
||||
|
||||
let provider = Provider::connect_ipc("~/.ethereum/geth.ipc")
|
||||
.await?
|
||||
.interval(std::time::Duration::from_millis(2000));
|
||||
let block = provider.get_block_number().await?;
|
||||
println!("Current block: {}", block);
|
||||
let mut stream = provider.watch_blocks().await?.stream();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#[tokio::main]
|
||||
#[cfg(feature = "ledger")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use ethers::{prelude::*, utils::parse_ether};
|
||||
|
||||
// Connect over websockets
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#[tokio::main]
|
||||
#[cfg(feature = "yubi")]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use ethers::{prelude::*, utils::parse_ether};
|
||||
use yubihsm::{Connector, Credentials, UsbConfig};
|
||||
|
||||
|
|
Loading…
Reference in New Issue