fix(examples): contract with abi test (#757)

This commit is contained in:
Georgios Konstantopoulos 2022-01-04 11:32:17 +02:00 committed by GitHub
parent 96ef787230
commit 4980d8b67a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 22 deletions

View File

@ -214,7 +214,7 @@ jobs:
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: cargo test
- name: Run all examples
run: |
export PATH=$HOME/bin:$PATH
./scripts/examples.sh

View File

@ -1,6 +1,9 @@
use anyhow::Result;
use ethers::{prelude::*, utils::Ganache};
use ethers_solc::{ArtifactOutput, Project, ProjectCompileOutput, ProjectPathsConfig};
use ethers::{
prelude::*,
solc::{Project, ProjectPathsConfig},
utils::Ganache,
};
use std::{convert::TryFrom, path::PathBuf, sync::Arc, time::Duration};
// Generate the type-safe contract bindings by providing the ABI
@ -22,22 +25,13 @@ async fn main() -> Result<()> {
// we use `root` for both the project root and for where to search for contracts since
// everything is in the same directory
let paths = ProjectPathsConfig::builder().root(&root).sources(&root).build().unwrap();
// get the solc project instance using the paths above
let solc = Project::builder()
.paths(paths)
.ephemeral()
.artifacts(ArtifactOutput::Nothing)
.build()
.unwrap();
let project = Project::builder().paths(paths).ephemeral().no_artifacts().build().unwrap();
// compile the project and get the artifacts
let compiled = solc.compile().unwrap();
let compiled = match compiled {
ProjectCompileOutput::Compiled((output, _)) => output,
_ => panic!("expected compilation artifacts"),
};
let path = root.join("contract.sol");
let path = path.to_str();
let contract = compiled.get(path.unwrap(), "SimpleStorage").expect("could not find contract");
let output = project.compile().unwrap();
let contract = output.find("SimpleStorage").expect("could not find contract").into_owned();
let (abi, bytecode, _) = contract.into_parts_or_default();
// 2. instantiate our wallet & ganache
let ganache = Ganache::new().spawn();
@ -52,11 +46,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.unwrap().clone(),
contract.bytecode().unwrap().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?;