Skip to content

Commit

Permalink
remove repetive code
Browse files Browse the repository at this point in the history
  • Loading branch information
NanezX committed Dec 8, 2023
1 parent 190dd34 commit 014b981
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions subgraph/tests/utils/deploy/meta_getter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
use crate::{generated::AuthoringMetaGetter, utils::setup::get_wallets_handler};
use ethers::types::{Bytes, H160};
use ethers::types::Bytes;
use once_cell::sync::Lazy;
use tokio::sync::OnceCell;

static META_GETTER: Lazy<OnceCell<H160>> = Lazy::new(|| OnceCell::new());
static META_GETTER: Lazy<OnceCell<Bytes>> = Lazy::new(|| OnceCell::new());

async fn meta_getter() -> anyhow::Result<H160> {
match authoring_meta_getter_deploy().await {
Ok(address) => Ok(address),
Err(error) => Err(error),
}
async fn meta_getter() -> anyhow::Result<Bytes> {
let deployer = get_wallets_handler().get_client(0).await?;
let contract = AuthoringMetaGetter::deploy(deployer, ())?.send().await?;
Ok(contract.get_authoring_meta().await?)
}

async fn get_meta_address() -> anyhow::Result<&'static H160> {
pub async fn get_authoring_meta() -> anyhow::Result<&'static Bytes> {
META_GETTER
.get_or_try_init(|| async { meta_getter().await })
.await
.map_err(|e| e)
}

async fn authoring_meta_getter_deploy() -> anyhow::Result<H160> {
let deployer = get_wallets_handler().get_client(0).await?;
let contract = AuthoringMetaGetter::deploy(deployer, ())?.send().await?;
Ok(contract.address())
}

/// Get the AuthoringMeta bytes to deploy ExpressionDeployers.
pub async fn get_authoring_meta() -> anyhow::Result<Bytes> {
let meta_address = get_meta_address().await?;
let deployer = get_wallets_handler().get_client(0).await?;

Ok(AuthoringMetaGetter::new(*meta_address, deployer)
.get_authoring_meta()
.await?)
}

0 comments on commit 014b981

Please sign in to comment.