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-Wallet][Foreign API] test the check_version API method #50

Closed marekyggdrasil closed 3 years ago

marekyggdrasil commented 3 years ago

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

Prerequisites

  1. GRIN-Node
  2. GRIN-Wallet

Test procedure

  1. Run GRIN-Wallet in Foreign API listener mode
  2. Perform an API request using cURL to check_version API method
  3. Record request payload, headers and all other relevant information. Same for the response.

Expected result:

Result should correspond to the example

Include the output of command

grin-wallet -V

and your environment

uname -a
ndcroos commented 3 years ago

Prerequisites:

* grin-wallet --version: grin-wallet 5.0.0-beta.4
* grin --version: grin node 5.0.0-rc.1
* Linux debian 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 GNU/Linux
* wallet address: grin1cwutd4sr0t0ac62764r9vz6wkgpmnmpheynh5tw56zvczvh8apdszxp25w
* Python version 3.7.3
* Python script needed: https://github.com/grinfans/grin.py/blob/main/wallet_v3.py

Step 1: Run GRIN-Wallet in Foreign API listener mode

Run a wallet in Foreign API listener mode in a separate window.

~$ grin-wallet listen
Password: 
20201230 09:43:54.861 WARN grin_wallet_controller::controller - Starting TOR Hidden Service for API listener at address yo4lnvqdplp5y2k62vdfmc2owib3t3bxzetxulou2cmycmxh5bnsplqd, binding to 127.0.0.1:3415
20201230 09:44:00.922 WARN grin_wallet_controller::controller - Starting HTTP Foreign listener API server at 127.0.0.1:3415.
20201230 09:44:00.923 WARN grin_wallet_controller::controller - HTTP Foreign listener started.
20201230 09:44:00.923 WARN grin_wallet_controller::controller - Slatepack Address is: grin1cwutd4sr0t0ac62764r9vz6wkgpmnmpheynh5tw56zvczvh8apdszxp25w

This starts an HTTP Foreign API server. Alternatively, Tor could be used.

Step 2: Perform an API request using cURL to check_version API method

I used the example of issue #49 to perform the request:

$ curl -v -d '{"jsonrpc": "2.0", "method": "check_version", "id": 1, "params":[]}' http://127.0.0.1:3415/v2/foreign

Step 3: Record request payload, headers and all other relevant information. Same for the response.

This the response I received:

* Expire in 0 ms for 6 (transfer 0x557816c04f90)
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x557816c04f90)
* Connected to 127.0.0.1 (127.0.0.1) port 3415 (#0)
> POST /v2/foreign HTTP/1.1
> Host: 127.0.0.1:3415
> User-Agent: curl/7.64.0
> Accept: */*
> Content-Length: 67
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 67 out of 67 bytes
< HTTP/1.1 200 OK
< access-control-allow-origin: *
< access-control-allow-headers: Content-Type, Authorization
< content-type: application/json
< content-length: 159
< date: Wed, 30 Dec 2020 08:45:24 GMT
< 
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": {
      "foreign_api_version": 2,
      "supported_slate_versions": [
        "V4"
      ]
    }
  }
* Connection #0 to host 127.0.0.1 left intact

This corresponds to the example here.

Conclusion

The test did run as expected.

marekyggdrasil commented 3 years ago

Good work @ndcroos !