Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

feat: add integration test #352

Merged
merged 12 commits into from
Dec 20, 2021
18 changes: 18 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Integration test

on:
workflow_dispatch:

jobs:
run-integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Prepare environment
run: |
curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/1.5.0/hurl_1.5.0_amd64.deb
sudo dpkg -i hurl_1.5.0_amd64.deb # install hurl
- name: Run integration test
run: |
shopt -s globstar # enable globstart (**)
hurl --variable mercury_testnet_host="${{ secrets.MERCURY_TESTNET_HOST }}" --test ./integration-test/**/*hurl --summary
81 changes: 81 additions & 0 deletions integration-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Integration-test for mercury

## Quick start for RPC integration test

### 1. Install `hurl`
This RPC integration-test uses [`hurl`](https://hurl.dev/docs/samples.html), a convenient CLI tools for calling and testing HTTP requests.

[Here](https://hurl.dev/docs/installation.html) is the installation documentation for `hurl`.

### 2. Run tests

The test files are named as `*.hurl`. Each test file has ONE JSONRPC HTTP call.

Execute the command below to run all tests under `./rpc`. All test data are in testnet and your must specify the `mercury_testnet_host`.

```bash
hurl --variable mercury_testnet_host="<your_mercury_testnet_host>" ./**/*.hurl --test
```

Output

```
./rpc/get_balance/get_balance_ok_address_all.hurl: RUNNING [1/3]
./rpc/get_balance/get_balance_ok_address_all.hurl: SUCCESS
./rpc/get_balance/get_balance_ok_address_ckb.hurl: RUNNING [2/3]
./rpc/get_balance/get_balance_ok_address_ckb.hurl: SUCCESS
./rpc/get_balance/get_balance_ok_address_udt.hurl: RUNNING [3/3]
./rpc/get_balance/get_balance_ok_address_udt.hurl: SUCCESS
--------------------------------------------------------------------------------
Executed: 3
Succeeded: 3 (100.0%)
Failed: 0 (0.0%)
Duration: 1924ms
```


If you want to see what the response looks like for a single test, just run the command below

```bash
hurl --variable mercury_testnet_host="<your_mercury_testnet_host>" ./rpc/get_balance/get_balance_ok_address_udt.hurl | jq
```
output
```json
{
"jsonrpc": "2.0",
"result": {
"balances": [
{
"ownership": {
"type": "Address",
"value": "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"
},
"asset_info": {
"asset_type": "UDT",
"udt_hash": "0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"
},
"free": "60",
"occupied": "0",
"freezed": "0",
"claimable": "0"
}
],
"tip_block_number": 3767610
},
"id": 100
}
```


If you want to ignore assert and just want to print RPC response, just run the command below:


```bash
hurl --variable mercury_testnet_host="<your_mercury_testnet_host>" ./rpc/get_balance/get_balance_ok_address_udt.hurl --ignore-asserts | jq
```

## Contributing

Writing hurl file is very easy. Just check the existent tests under [`test_testnet`](./test_testnet) and you will know how to write.

For more please check the [samples in hurl official site](https://hurl.dev/docs/samples.html).
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type": "Address",
"value": "ckt1q"
},
"asset_infos": [],
"tip_block_number": 3767610
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.error" exists
26 changes: 26 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_address_all.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type": "Address",
"value": "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"
},
"asset_infos": [],
"tip_block_number": 3767610
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 2

jsonpath "$.result.balances[?(@.free=='60')].asset_info.asset_type" == "UDT"
jsonpath "$.result.balances[?(@.free=='60')].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"

jsonpath "$.result.balances[?(@.free=='985799999470')].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[?(@.free=='985799999470')].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"
34 changes: 34 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_address_ckb.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type": "Address",
"value": "ckt1qyqg88ccqm59ksxp85788pnqg4rkejdgcg2qxcu2qf"
},
"asset_infos": [
{
"asset_type": "CKB",
"udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
],
"tip_block_number": 3636218
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 1

jsonpath "$.result.balances[0].ownership.type" == "Address"
jsonpath "$.result.balances[0].ownership.value" == "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd"

jsonpath "$.result.balances[0].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[0].asset_info.udt_hash" == "0x0000000000000000000000000000000000000000000000000000000000000000"

jsonpath "$.result.balances[0].free" == "6053944763147"
jsonpath "$.result.tip_block_number" == 3636218
38 changes: 38 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_address_udt.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type": "Address",
"value": "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"
},
"asset_infos": [
{
"asset_type": "UDT",
"udt_hash": "0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"
}
],
"tip_block_number": 3767610
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 1

jsonpath "$.result.balances[0].ownership.type" == "Address"
jsonpath "$.result.balances[0].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"

jsonpath "$.result.balances[0].asset_info.asset_type" == "UDT"
jsonpath "$.result.balances[0].asset_info.udt_hash" == "0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"

jsonpath "$.result.balances[0].free" == "60"
jsonpath "$.result.balances[0].occupied" == "0"
jsonpath "$.result.balances[0].freezed" == "0"
jsonpath "$.result.balances[0].claimable" == "0"

jsonpath "$.result.tip_block_number" == 3767610
27 changes: 27 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_identity_all.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type":"Identity",
"value":"0x00fa22aa0aaf155a6c816634c61512046b08923111"
},
"asset_infos": [],
"tip_block_number": 3769130
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 3

jsonpath "$.result.balances[?(@.free=='60')].asset_info.asset_type" == "UDT"
jsonpath "$.result.balances[?(@.free=='60')].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"
jsonpath "$.result.balances[?(@.free=='1000000000000')].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[?(@.free=='1000000000000')].ownership.value" == "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq06y24q4tc4tfkgze35cc23yprtpzfrzygljdjh9"
jsonpath "$.result.balances[?(@.free=='1979699999470')].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[?(@.free=='1979699999470')].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"
31 changes: 31 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_identity_ckb.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type":"Identity",
"value":"0x00fa22aa0aaf155a6c816634c61512046b08923111"
},
"asset_infos": [
{
"asset_type": "CKB",
"udt_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
],
"tip_block_number": 3769130
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 2

jsonpath "$.result.balances[?(@.free=='1979699999470')].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[?(@.free=='1979699999470')].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"

jsonpath "$.result.balances[?(@.free=='1000000000000')].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[?(@.free=='1000000000000')].ownership.value" == "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq06y24q4tc4tfkgze35cc23yprtpzfrzygljdjh9"
33 changes: 33 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_identity_udt.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type":"Identity",
"value":"0x00fa22aa0aaf155a6c816634c61512046b08923111"
},
"asset_infos": [
{
"asset_type": "UDT",
"udt_hash": "0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"
}
],
"tip_block_number": 3769130
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 1

jsonpath "$.result.balances[0].ownership.type" == "Address"
jsonpath "$.result.balances[0].ownership.value" == "ckt1qq6pngwqn6e9vlm92th84rk0l4jp2h8lurchjmnwv8kq3rt5psf4vq06y24q4tc4tfkgze35cc23yprtpzfrzygsptkzn"

jsonpath "$.result.balances[0].asset_info.asset_type" == "UDT"
jsonpath "$.result.balances[0].asset_info.udt_hash" == "0xf21e7350fa9518ed3cbb008e0e8c941d7e01a12181931d5608aa366ee22228bd"

jsonpath "$.result.balances[0].free" == "60"
25 changes: 25 additions & 0 deletions integration-test/rpc/get_balance/get_balance_ok_record.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": [
{
"item": {
"type": "Record",
"value": "ea0b230104fd3be2cc33ab50c3d591dc6cefbe8ed83f7e63c8142de4b5a0ee720000000000636b7431717a646130637230386d38356863386a6c6e6670337a65723778756c656a79777434396b7432727230767468797761613530787773717736766a7a79396b616878336c79766c67617038647038657764386738307063676365787a726a"
},
"asset_infos": []
}
],
"id": 100
}
# live cell of the given record: output #0 in tx 0xea0b230104fd3be2cc33ab50c3d591dc6cefbe8ed83f7e63c8142de4b5a0ee72

HTTP/1.1 200
[Asserts]
jsonpath "$.result.balances" count == 1

jsonpath "$.result.balances[0].ownership.type" == "Address"
jsonpath "$.result.balances[0].ownership.value" == "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqw6vjzy9kahx3lyvlgap8dp8ewd8g80pcgcexzrj"
jsonpath "$.result.balances[0].asset_info.asset_type" == "CKB"
jsonpath "$.result.balances[0].free" == "194703317445"
20 changes: 20 additions & 0 deletions integration-test/rpc/get_block_info/get_balance_ok_block_hash.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_block_info",
"params": [
{
"block_hash": "0x87405a4f39154fadb13bc23cf147985208ba33d61c277ec8409722434a694e70"
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.block_number" == 508609
jsonpath "$.result.block_hash" == "0x87405a4f39154fadb13bc23cf147985208ba33d61c277ec8409722434a694e70"

jsonpath "$.result.transactions" count == 1
jsonpath "$.result.transactions[0].tx_hash" == "0x32cc46179aa3d7b6eb29b9c692a9fc0b9c56d16751e42258193486d86e0fb5af"
jsonpath "$.result.transactions[0].timestamp" == 1601357943712
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_block_info",
"params": [
{
"block_number": 508609
}
],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.block_number" == 508609
jsonpath "$.result.block_hash" == "0x87405a4f39154fadb13bc23cf147985208ba33d61c277ec8409722434a694e70"

jsonpath "$.result.transactions" count == 1
jsonpath "$.result.transactions[0].tx_hash" == "0x32cc46179aa3d7b6eb29b9c692a9fc0b9c56d16751e42258193486d86e0fb5af"
jsonpath "$.result.transactions[0].timestamp" == 1601357943712
11 changes: 11 additions & 0 deletions integration-test/rpc/get_db_info/get_db_info_ok.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
POST {{mercury_testnet_host}}
{
"jsonrpc": "2.0",
"method": "get_db_info",
"params": [],
"id": 100
}

HTTP/1.1 200
[Asserts]
jsonpath "$.result.db" == "PostgreSQL"
Loading