Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: TEST_CONFIG=test_config_example.json

4 changes: 2 additions & 2 deletions interact/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pdao-near-interact"
version = "0.0.1"
authors = ["PDAO Team <hello@postech-dao.xyz>"]
authors = ["happyhappy <bjyoon513@gmail.com>", "PDAO Team <hello@postech-dao.xyz>"]
edition = '2021'
include = ["src/**/*", "Cargo.toml"]
license = "MIT"
Expand All @@ -13,7 +13,7 @@ serde = { version = "1.0", features = ["derive"] }
tokio-postgres = "0.7.6"
tokio = { version = "1.0", features = ["full"] }
futures = "0.3"
reqwest = "0.11"
reqwest = { version = "0.11", features = ["json"] }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

무관한 커밋에 들어있습니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 3497363

serde_json = "1.0"
anyhow = "1.0"
thiserror = "1.0"
5 changes: 3 additions & 2 deletions interact/test_config_example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"full_node_url": "https://example.com",
"network_id": "testnet",
"test_node_url": "https://rpc.testnet.near.org",
"account_public": "example.testnet.public",
"account_private": "example.testnet.private",
"wasm_binary_path": "example/path"
}
}
86 changes: 78 additions & 8 deletions interact/tests/suite1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tokio::time::{sleep, Duration};

#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
full_node_url: String,
network_id: String,
test_node_url: String,
account_public: String,
account_private: String,
wasm_binary_path: String,
Expand All @@ -23,28 +27,94 @@ impl Config {
}

#[tokio::test]
#[ignore]
async fn check_connection() {
let _config = Config::read_from_env();
let config = Config::read_from_env();
// check whether the full node is responding by a simple request
unimplemented!();
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"id": "dontcare",
"method": "status",
"params": []
});

let res = client
.post(&config.test_node_url)
.json(&payload)
.send()
.await
.unwrap();

let json = res.json::<Value>().await.unwrap();
assert_eq!(json["result"]["chain_id"], config.network_id);
}

#[tokio::test]
#[ignore]
async fn check_block_number() {
let _config = Config::read_from_env();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

// check the latest block number recognized by the full node **twice** with some delay,
// so that we can assure that the full node is properly updating its blocks
unimplemented!();
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"id": "dontcare",
"method": "block",
"params": {
"finality": "final"
}
});

let first_res = client
.post(&_config.test_node_url)
.json(&payload)
.send()
.await
.unwrap();

let first_json = first_res.json::<Value>().await.unwrap();

sleep(Duration::from_secs(2)).await;

let second_res = client
.post(&_config.test_node_url)
.json(&payload)
.send()
.await
.unwrap();

let second_json = second_res.json::<Value>().await.unwrap();

assert!(
second_json["result"]["header"]["height"].as_u64()
> first_json["result"]["header"]["height"].as_u64()
);
}

#[tokio::test]
#[ignore]
async fn check_account() {
let _config = Config::read_from_env();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

// by requesting the full node, check whether the account given by the config has enough native token to pay gas fee
unimplemented!();
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "view_account",
"finality": "final",
"account_id": "nearkat.testnet"
}
});

let res = client
.post(&_config.test_node_url)
.json(&payload)
.send()
.await
.unwrap();

let json = res.json::<Value>().await.unwrap();
assert_eq!(json["error"], Value::Null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has enough native token to pay gas fee 에 대한 테스트 내용이 없는 것 같네요.

}

#[tokio::test]
Expand Down