fix(examples): contract with abi test (#757)
This commit is contained in:
parent
96ef787230
commit
4980d8b67a
|
@ -214,7 +214,7 @@ jobs:
|
||||||
- uses: Swatinem/rust-cache@v1
|
- uses: Swatinem/rust-cache@v1
|
||||||
with:
|
with:
|
||||||
cache-on-failure: true
|
cache-on-failure: true
|
||||||
- name: cargo test
|
- name: Run all examples
|
||||||
run: |
|
run: |
|
||||||
export PATH=$HOME/bin:$PATH
|
export PATH=$HOME/bin:$PATH
|
||||||
./scripts/examples.sh
|
./scripts/examples.sh
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ethers::{prelude::*, utils::Ganache};
|
use ethers::{
|
||||||
use ethers_solc::{ArtifactOutput, Project, ProjectCompileOutput, ProjectPathsConfig};
|
prelude::*,
|
||||||
|
solc::{Project, ProjectPathsConfig},
|
||||||
|
utils::Ganache,
|
||||||
|
};
|
||||||
use std::{convert::TryFrom, path::PathBuf, sync::Arc, time::Duration};
|
use std::{convert::TryFrom, path::PathBuf, sync::Arc, time::Duration};
|
||||||
|
|
||||||
// Generate the type-safe contract bindings by providing the ABI
|
// 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
|
// we use `root` for both the project root and for where to search for contracts since
|
||||||
// everything is in the same directory
|
// everything is in the same directory
|
||||||
let paths = ProjectPathsConfig::builder().root(&root).sources(&root).build().unwrap();
|
let paths = ProjectPathsConfig::builder().root(&root).sources(&root).build().unwrap();
|
||||||
|
|
||||||
// get the solc project instance using the paths above
|
// get the solc project instance using the paths above
|
||||||
let solc = Project::builder()
|
let project = Project::builder().paths(paths).ephemeral().no_artifacts().build().unwrap();
|
||||||
.paths(paths)
|
|
||||||
.ephemeral()
|
|
||||||
.artifacts(ArtifactOutput::Nothing)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
// compile the project and get the artifacts
|
// compile the project and get the artifacts
|
||||||
let compiled = solc.compile().unwrap();
|
let output = project.compile().unwrap();
|
||||||
let compiled = match compiled {
|
let contract = output.find("SimpleStorage").expect("could not find contract").into_owned();
|
||||||
ProjectCompileOutput::Compiled((output, _)) => output,
|
let (abi, bytecode, _) = contract.into_parts_or_default();
|
||||||
_ => 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");
|
|
||||||
|
|
||||||
// 2. instantiate our wallet & ganache
|
// 2. instantiate our wallet & ganache
|
||||||
let ganache = Ganache::new().spawn();
|
let ganache = Ganache::new().spawn();
|
||||||
|
@ -52,11 +46,7 @@ async fn main() -> Result<()> {
|
||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
|
|
||||||
// 5. create a factory which will be used to deploy instances of the contract
|
// 5. create a factory which will be used to deploy instances of the contract
|
||||||
let factory = ContractFactory::new(
|
let factory = ContractFactory::new(abi, bytecode, client.clone());
|
||||||
contract.abi.unwrap().clone(),
|
|
||||||
contract.bytecode().unwrap().clone(),
|
|
||||||
client.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// 6. deploy it with the constructor arguments
|
// 6. deploy it with the constructor arguments
|
||||||
let contract = factory.deploy("initial value".to_string())?.legacy().send().await?;
|
let contract = factory.deploy("initial value".to_string())?.legacy().send().await?;
|
||||||
|
|
Loading…
Reference in New Issue