Skip to content

Commit

Permalink
deployer deploy WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkale151071 committed Jul 28, 2023
1 parent d6355ad commit c40e675
Show file tree
Hide file tree
Showing 9 changed files with 2,104 additions and 168 deletions.
1,965 changes: 1,921 additions & 44 deletions subgraph/Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion subgraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ mustache = "0.9.0"
reqwest = { version = "0.11.17", features = ["json"] }
rust-bigint = "1.2.0"
graphql_client = "0.13.0"
web3 = "0.19.0"
web3 = "0.19.0"
ethers = "2.0"
7 changes: 1 addition & 6 deletions subgraph/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
version: '3'
services:
hardhat:
image: vishalkale151071/hardhat-node
ports:
- '8545:8545'
graph-node:
image: graphprotocol/graph-node:97e0adc
ports:
Expand All @@ -15,7 +11,6 @@ services:
depends_on:
- ipfs
- postgres
- hardhat
extra_hosts:
- host.docker.internal:host-gateway
environment:
Expand All @@ -24,7 +19,7 @@ services:
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'localhost:http://hardhat:8545'
ethereum: 'localhost:http://host.docker.internal:8545'
GRAPH_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.10.0
Expand Down
13 changes: 9 additions & 4 deletions subgraph/tests/deploy_orderbook.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use utils::deploy::{deploy1820::deploy1820, deploy_orderbook::deploy_orderbook};
use utils::{
deploy::{deploy1820::deploy1820, deploy_orderbook::deploy_orderbook},
utils::{deploy_anvil_and_docker, stop_docker},
};

mod utils;
#[tokio::main]
#[test]
async fn orderbook_entity_test() -> anyhow::Result<()> {
deploy1820().await?;
deploy_orderbook().await?;
let anvil = deploy_anvil_and_docker()?;
deploy1820(&anvil).await?;
deploy_orderbook(&anvil).await?;

Ok(())
}
}
40 changes: 21 additions & 19 deletions subgraph/tests/utils/deploy/deploy1820/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use crate::utils::utils::get_web3;
use anyhow;
use std::fs::File;
use ethers::{
providers::{Http, Middleware, Provider},
types::BlockId,
types::{Bytes, NameOrAddress, TransactionRequest, U256},
utils::AnvilInstance,
};
use std::io::Read;
use web3::types::{BlockNumber, Bytes, TransactionRequest, H160, U256};
use std::{fs::File, time::Duration};

pub async fn deploy1820() -> anyhow::Result<()> {
let web3 = get_web3();
let signature_address: H160 = "0xa990077c3205cbDf861e17Fa532eeB069cE9fF96".parse()?;
let registry_address: H160 = "0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24".parse()?;
pub async fn deploy1820(anvil: &AnvilInstance) -> anyhow::Result<()> {
let provider =
Provider::<Http>::try_from(anvil.endpoint())?.interval(Duration::from_millis(10));

let signature_address: NameOrAddress = "0xa990077c3205cbDf861e17Fa532eeB069cE9fF96".parse()?;
let registry_address = "0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24";
let cost: U256 = U256::from("80000000000000000");
let mut file = File::open("tests/utils/deploy/deploy1820/ERC1820RegistryABI.json")?;
let mut erc1820_registry_abi = String::new();
Expand All @@ -19,30 +25,26 @@ pub async fn deploy1820() -> anyhow::Result<()> {
let tx_erc1820_registry_deployment = hex::decode(tx_erc1820_registry_deployment)?;
let tx_erc1820_registry_deployment = Bytes::from(tx_erc1820_registry_deployment);

let block = web3.eth().block_number().await?;
let block = BlockId::from(provider.get_block_number().await?);

let code = web3
.eth()
.code(registry_address, BlockNumber::from(block).into())
.await?;
let code = provider.get_code(registry_address, block.into()).await?;

if code == Bytes::default() {
let deployer = web3.eth().accounts().await?[1];
let nonce = web3
.eth()
.transaction_count(deployer, Some(BlockNumber::from(block)))
let deployer = anvil.addresses()[0];
let nonce = provider
.get_transaction_count(deployer, block.into())
.await?;

let tx: TransactionRequest = TransactionRequest {
to: Some(signature_address),
value: Some(cost),
from: web3.eth().accounts().await?[1],
from: Some(deployer),
nonce: Some(nonce),
..Default::default()
};

web3.eth().send_transaction(tx).await?;
web3.eth()
provider.send_transaction(tx, None).await?;
provider
.send_raw_transaction(tx_erc1820_registry_deployment)
.await?;
}
Expand Down
10 changes: 3 additions & 7 deletions subgraph/tests/utils/deploy/deploy_orderbook/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use serde_json::Value;
use std::fs::File;
use std::io::Read;
use web3::ethabi::Contract as C;
use web3::{contract::Contract, transports::Http};
use ethers::utils::AnvilInstance;

use super::touch_deployer::deploy_touch_deployer;

pub async fn deploy_orderbook() -> anyhow::Result<()> {
let touch_deployer = deploy_touch_deployer().await?;
pub async fn deploy_orderbook(anvil: &AnvilInstance) -> anyhow::Result<()> {
let _touch_deployer = deploy_touch_deployer(anvil).await?;
// let mut json = String::new();
// let mut file = File::open("tests/utils/deploy/deploy_orderbook/OrderBook.json")?;
// file.read_to_string(&mut json)?;
Expand Down
195 changes: 113 additions & 82 deletions subgraph/tests/utils/deploy/touch_deployer/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion subgraph/tests/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod deploy;
pub mod utils;
pub mod utils;
37 changes: 33 additions & 4 deletions subgraph/tests/utils/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
use web3::{transports::Http, Web3};
use anyhow::anyhow;
use ethers::utils::{Anvil, AnvilInstance};
use std::process::Command;

pub fn get_web3() -> Web3<Http> {
let web3 = web3::Web3::new(Http::new("http://localhost:8545").unwrap());
web3
pub fn deploy_anvil_and_docker() -> anyhow::Result<AnvilInstance> {
let proiver = Anvil::new().port(8545u16).spawn();

println!("Anvil deployed at : {}", proiver.endpoint());
// let output = Command::new("bash")
// .args(&["-c", "docker-compose -f docker/docker-compose.yaml up -d"])
// .output()
// .unwrap();

// if !output.status.success() {
// let stderr = format!("{}", String::from_utf8_lossy(&output.stderr.to_vec()));
// return Err(anyhow!(stderr));
// }
Ok(proiver)
}

pub fn stop_docker() -> anyhow::Result<()> {
let output = Command::new("bash")
.args(&[
"-c",
"docker-compose -f docker/docker-compose.yaml down && rm -rf docker/data ",
])
.output()
.unwrap();

if !output.status.success() {
let stderr = format!("{}", String::from_utf8_lossy(&output.stderr.to_vec()));
return Err(anyhow!(stderr));
}
Ok(())
}

0 comments on commit c40e675

Please sign in to comment.