diff --git a/subgraph/tests/orderbook_entity.rs b/subgraph/tests/entities.rs similarity index 68% rename from subgraph/tests/orderbook_entity.rs rename to subgraph/tests/entities.rs index cc06f79c9..aac395a78 100644 --- a/subgraph/tests/orderbook_entity.rs +++ b/subgraph/tests/entities.rs @@ -37,7 +37,13 @@ async fn orderbook_entity_test() -> Result<()> { // .expect("cannot deploy expression_deployer"); // /////////////////////////////////////////////// - // // Deploy ERC20 token contract (A) + // // Deploy ERC20 token contract (A)command) and convert to Bytes + // let ob_meta_hashed = Bytes::from(keccak256(read_orderbook_meta())); + + // assert_eq!(response.id, orderbook.address()); + // assert_eq!(response.address, orderbook.address()); + // assert_eq!(response.deployer, wallet_0.address()); + // assert_eq!(response.meta, ob_meta_hashed); // let token_a = deploy_erc20_mock(None) // .await // .expect("failed on deploy erc20 token A"); @@ -106,3 +112,41 @@ async fn orderbook_entity_test() -> Result<()> { Ok(()) } + +#[tokio::main] +#[test] +async fn rain_meta_v1_entity_test() -> Result<()> { + // Always checking if OB is deployed, so we attemp to obtaing it + let _ = get_orderbook().await.expect("cannot get OB"); + + // Wait for Subgraph sync + wait().await.expect("cannot get SG sync status"); + + // Read meta from root repository (output from nix command) and convert to Bytes + let ob_meta = read_orderbook_meta(); + let ob_meta_bytes = Bytes::from(ob_meta.clone()); + let ob_meta_hashed = Bytes::from(keccak256(ob_meta)); + + // Query the RainMetaV1 entity + let response = Query::rain_meta_v1(ob_meta_hashed.clone()) + .await + .expect("cannot get the rain meta query response"); + + assert_eq!(response.id, ob_meta_hashed); + assert_eq!(response.meta_bytes, ob_meta_bytes); + // assert_eq!(response.content, ob_meta_bytes); + + println!("response.content: {:?}", response.content); + + // let response = Query::rain_meta_v1(orderbook.address()) + // .await + // .expect("cannot get the rain meta query response"); + + // // This wallet is used to deploy the OrderBook at initialization, so it is the deployer + // let wallet_0 = utils::get_wallet(0); + + // // Read meta from root repository (output from nix command) and convert to Bytes + // let ob_meta_hashed = Bytes::from(keccak256(read_orderbook_meta())); + + Ok(()) +} diff --git a/subgraph/tests/subgraph/query/mod.rs b/subgraph/tests/subgraph/query/mod.rs index ff318ca12..8413d1668 100644 --- a/subgraph/tests/subgraph/query/mod.rs +++ b/subgraph/tests/subgraph/query/mod.rs @@ -1,8 +1,10 @@ pub(crate) mod orderbook; +pub(crate) mod rain_meta_v1; use anyhow::Result; -use ethers::types::Address; +use ethers::types::{Address, Bytes}; use orderbook::{get_orderbook_query, OrderBookResponse}; +use rain_meta_v1::{get_rain_meta_v1, RainMetaV1Response}; pub struct Query; @@ -10,4 +12,8 @@ impl Query { pub async fn orderbook(address: Address) -> Result { get_orderbook_query(address).await } + + pub async fn rain_meta_v1(id: Bytes) -> Result { + get_rain_meta_v1(id).await + } } diff --git a/subgraph/tests/subgraph/query/orderbook/mod.rs b/subgraph/tests/subgraph/query/orderbook/mod.rs index a982a8d0e..cd1924a0f 100644 --- a/subgraph/tests/subgraph/query/orderbook/mod.rs +++ b/subgraph/tests/subgraph/query/orderbook/mod.rs @@ -1,5 +1,5 @@ use self::order_book::ResponseData; -use crate::subgraph::wait::wait; +use crate::subgraph::wait; use anyhow::{anyhow, Result}; use ethers::types::{Address, Bytes}; use graphql_client::{GraphQLQuery, Response}; @@ -27,7 +27,7 @@ pub struct OrderBookResponse { impl OrderBookResponse { pub fn from(response: ResponseData) -> OrderBookResponse { - let orderbook = response.order_book.unwrap(); + let orderbook: order_book::OrderBookOrderBook = response.order_book.unwrap(); let meta_bytes = orderbook .meta @@ -55,6 +55,7 @@ pub async fn get_orderbook_query(orderbook_address: Address) -> Result, +} + +impl RainMetaV1Response { + pub fn from(response: ResponseData) -> RainMetaV1Response { + let data = response.rain_meta_v1.unwrap(); + + let content_data: Vec = + data.content.unwrap_or(vec![RainMetaV1RainMetaV1Content { + id: Bytes::from([0u8, 32]), + }]); + + let content: Vec = content_data.iter().map(|meta| meta.id.clone()).collect(); + + RainMetaV1Response { + id: data.id, + meta_bytes: data.meta_bytes, + content, + } + } +} + +pub async fn get_rain_meta_v1(rain_meta_id: Bytes) -> Result { + wait().await?; + + let url = Url::from_str(&"http://localhost:8000/subgraphs/name/test/test") + .expect("cannot get the sg url"); + + let variables = rain_meta_v1::Variables { + rain_meta: rain_meta_id.to_string().into(), + }; + + let request_body = RainMetaV1::build_query(variables); + let client = reqwest::Client::new(); + let res = client.post(url.clone()).json(&request_body).send().await?; + + let response_body: Response = res.json().await?; + + match response_body.data { + Some(data) => { + let response: RainMetaV1Response = RainMetaV1Response::from(data); + Ok(response) + } + None => Err(anyhow!("Failed to get metaboard")), + } +} diff --git a/subgraph/tests/subgraph/query/rain_meta_v1/rain_meta_v1.graphql b/subgraph/tests/subgraph/query/rain_meta_v1/rain_meta_v1.graphql new file mode 100644 index 000000000..99a3724ce --- /dev/null +++ b/subgraph/tests/subgraph/query/rain_meta_v1/rain_meta_v1.graphql @@ -0,0 +1,9 @@ +query RainMetaV1($rain_meta: String) { + rainMetaV1(id: $rain_meta) { + id + metaBytes + content { + id + } + } +} diff --git a/subgraph/tests/subgraph/wait/mod.rs b/subgraph/tests/subgraph/wait/mod.rs index cc484bb22..24a0778a8 100644 --- a/subgraph/tests/subgraph/wait/mod.rs +++ b/subgraph/tests/subgraph/wait/mod.rs @@ -25,6 +25,8 @@ pub struct SyncStatus; pub async fn wait() -> anyhow::Result { let block_number = get_block_number().await; + // let _ = get_orderbook().await.expect("cannot get OB in waiting"); + let url = Url::from_str(&"http://localhost:8030/graphql")?; let variables = sync_status::Variables {}; diff --git a/subgraph/tests/utils/deploy/mod.rs b/subgraph/tests/utils/deploy/mod.rs index 7148646ea..1384d841b 100644 --- a/subgraph/tests/utils/deploy/mod.rs +++ b/subgraph/tests/utils/deploy/mod.rs @@ -1,6 +1,6 @@ mod erc20_mock; mod meta_getter; -mod orderbook; +pub mod orderbook; mod registry1820; mod touch_deployer; diff --git a/subgraph/tests/utils/deploy/orderbook/setup.rs b/subgraph/tests/utils/deploy/orderbook/setup.rs index a504f4f37..c8e179aaa 100644 --- a/subgraph/tests/utils/deploy/orderbook/setup.rs +++ b/subgraph/tests/utils/deploy/orderbook/setup.rs @@ -1,6 +1,6 @@ use crate::{ - subgraph::{deploy, Config}, generated::OrderBook, + subgraph::{deploy, Config}, utils::get_block_number, }; use anyhow::Result; @@ -36,9 +36,6 @@ pub async fn init_orderbook( .await .expect("cannot deploy OB at setup initialization"); - // let addrr = orderbook.address(); - // let ob_address = format!("{:?}", orderbook.address()); - let sg_config = Config { contract_address: &format!("{:?}", orderbook.address()), block_number: get_block_number().await.as_u64(),