Grinnode-live / 2020-grin-bug-bash-challenge

Finding bugs in Grin-Wallet & Grin-nodes for a bounty prior to Grin fork v5.
3 stars 1 forks source link

[GRIN-Node][Owner API 2.0] test the get_status API method #55

Closed marekyggdrasil closed 3 years ago

marekyggdrasil commented 3 years ago

Description Goal of this issue is to test the get_status API method

Prerequisites

  1. GRIN-Node

Test procedure

  1. Run GRIN-Node in Owner API listener mode
  2. Run the get_connected_peers API method

Expected result:

Output should match the example. Include all cURL requests and responses.

Include the exact version of your grin-node and also your environment

uname -a
goyle commented 3 years ago

Description

Goal of this issue is to test the get_status API method.

Prerequisites

  1. GRIN-Node

Test Procedure

  1. Run GRIN-Node in Owner API listener mode
  2. Run the get_status API method.

Expected Result

Output should match the example. Include all cURL requests and responses.

Dropdown of the json rpc example. ```json { "jsonrpc": "2.0", "method": "get_status", "params": [], "id": 1 } { "id": 1, "jsonrpc": "2.0", "result": { "Ok": { "protocol_version": "2", "user_agent": "MW/Grin 2.x.x", "connections": "8", "tip": { "height": 371553, "last_block_pushed": "00001d1623db988d7ed10c5b6319360a52f20c89b4710474145806ba0e8455ec", "prev_block_to_last": "0000029f51bacee81c49a27b4bc9c6c446e03183867c922890f90bb17108d89f", "total_difficulty": 1127628411943045 }, "sync_status": "header_sync", "sync_info": { "current_height": 371553, "highest_height": 0 } } } } ```

Include the exact version of your grin-node and also your environment.

uname -a

Environment

OS: Debian 10 \ Grin Node: grin 5.0.0-rc.2 \ System Info: Linux debian3 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 GNU/Linux

Steps

1: Building the Node

See here for the full steps for building GRIN-Node v5.0.0-rc.2. 1. Download GRIN-Node v5.0.0-rc.2. ```shell $ wget https://github.com/mimblewimble/grin/archive/v5.0.0-rc.2.tar.gz ``` 1. Extract `v5.0.0-rc.2.tar.gz`. ```shell $ tar -xvf v5.0.0-rc.2.tar.gz ``` * Output should be as follows. ``` grin-5.0.0-rc.2/ grin-5.0.0-rc.2/.cargo/ grin-5.0.0-rc.2/.cargo/config grin-5.0.0-rc.2/.ci/ grin-5.0.0-rc.2/.ci/general-jobs grin-5.0.0-rc.2/.ci/release.yml grin-5.0.0-rc.2/.ci/test.yml grin-5.0.0-rc.2/.ci/windows-release.yml grin-5.0.0-rc.2/.editorconfig grin-5.0.0-rc.2/.github/ ... ``` 1. Install Rust. ```shell $ curl https://sh.rustup.rs -sSf | sh; source $HOME/.cargo/env ``` * Proceed with installation with default profile. ``` default host triple: x86_64-unknown-linux-gnu default toolchain: stable (default) profile: default modify PATH variable: yes ``` * Output should be as follows. ``` stable-x86_64-unknown-linux-gnu installed - rustc 1.48.0 (7eac88abb 2020-11-16) ``` 1. Download dependencies, including `libcursesw5`. ```shell # apt install build-essential git tor cmake git libgit2-dev clang libncursesw5 libncurses5-dev libncursesw5-dev zlib1g-dev pkg-config libssl-dev llvm ``` 1. Build GRIN-Node v5.0.0-rc.2. ```shell $ cd grin-5.0.0-rc.2/ $ cargo build --release ``` 1. Start node. ``` $ ./grin ``` 1. Wait until Grin has fully synced. 1. Success!

2: Running GRIN-Node in Owner API Listener Mode

  1. Initialize the GRIN-Node. The node will start in the owner API listener mode by default.
    $ cd grin-5.0.0-rc.2/target/release/
    $ ./grin
  2. The TUI should now appear and your GRIN-Node will be running.

3: Testing the get_status API method

  1. Open a new terminal and run the following cURL command.
    $ curl -ugrin:$(cat ~/.grin/main/.api_secret) localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "get_status", "params": [], "id": 1}' -w "\n" -v
  2. The output will appear as expected.

Final Results

Output of the cURL Request

* Expire in 0 ms for 6 (transfer 0x55749ccfdf90)
* Expire in 1 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 1 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 1 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 1 ms for 1 (transfer 0x55749ccfdf90)
...
...
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
* Expire in 0 ms for 1 (transfer 0x55749ccfdf90)
*   Trying ::1...
* TCP_NODELAY set
* Expire in 150000 ms for 3 (transfer 0x55749ccfdf90)
* Expire in 200 ms for 4 (transfer 0x55749ccfdf90)
* connect to ::1 port 3413 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 150000 ms for 3 (transfer 0x55749ccfdf90)
* Connected to localhost (127.0.0.1) port 3413 (#0)
* Server auth using Basic with user 'grin'
> POST /v2/owner HTTP/1.1
> Host: localhost:3413
> Authorization: Basic Z3Jpbjp6M0tCMEdNQUVrQ2I3SlRYTUN5Yw==
> User-Agent: curl/7.64.0
> Accept: */*
> Content-Length: 65
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 65 out of 65 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 490
< date: Thu, 31 Dec 2020 21:58:14 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": {
      "connections": 8,
      "protocol_version": 1000,
      "sync_status": "no_sync",
      "tip": {
        "height": 1026734,
        "last_block_pushed": "0002190695e74c3d7cb93c9c95d87506fc5a8912436b7cd826a1c2475728ca77",
        "prev_block_to_last": "0003caa5249843b4a2efd653fec210eee81bfa3c4bdc1bccf3636f7dbeee09fa",
        "total_difficulty": 1738910833446705
      },
      "user_agent": "MW/Grin 5.0.0-rc.2"
    }
  }
* Connection #0 to host localhost left intact
}

Conclusion

The actual results matches the expected results, which is successfully getting the node status. It displays useful information about the node, network, and current sync status. The version of the node is v5.0.0-rc.2 and uses protocol version 1000. It shows 8 as the number of peer connections that it has currently. The sync status of the testing node is at no_sync having already fully synced the chain data while the node is running.

marekyggdrasil commented 3 years ago

Thanks @goyle !