Repository: raiden-network/raiden-contracts

Issue:
add CI test: all data/deployment_*.json files exist and all expected fields have valid values
This issue keeps track of the last part of https://github.com/raiden-network/raiden-contracts/issues/347
> add CI test to make sure all the expected data/deployment_[CHAIN].json files exist and that all expected fields have valid values.


Discussion:
pirapira: Please review #647 first.
pirapira: Please review #651 first.
pirapira: I think the test is failing because the last `kovan` deployment was done on a light client, and a `gas_cost` field is missing.
codecov[bot]: # [Codecov](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=h1) Report
> Merging [#629](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=desc) into [master](https://codecov.io/gh/raiden-network/raiden-contracts/commit/96423513bb9f56ea080780c16a02d0475cbbb61f?src=pr&el=desc) will **decrease** coverage by `45.45%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/graphs/tree.svg?width=650&token=q8aKDUjiN7&height=150&src=pr)](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #629       +/-   ##
==========================================
- Coverage   75.75%   30.3%   -45.46%     
==========================================
  Files          17      17               
  Lines        1122    1122               
  Branches      119     119               
==========================================
- Hits          850     340      -510     
- Misses        232     776      +544     
+ Partials       40       6       -34
```


| [Impacted Files](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [raiden\_contracts/utils/join-contracts.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9qb2luLWNvbnRyYWN0cy5weQ==) | `0% <0%> (-93.75%)` | :arrow_down: |
| [raiden\_contracts/utils/bytecode.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9ieXRlY29kZS5weQ==) | `25% <0%> (-75%)` | :arrow_down: |
| [raiden\_contracts/utils/events.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9ldmVudHMucHk=) | `16.66% <0%> (-72.73%)` | :arrow_down: |
| [raiden\_contracts/utils/pending\_transfers.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9wZW5kaW5nX3RyYW5zZmVycy5weQ==) | `28.84% <0%> (-71.16%)` | :arrow_down: |
| [raiden\_contracts/utils/logs.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9sb2dzLnB5) | `19.23% <0%> (-68.27%)` | :arrow_down: |
| [raiden\_contracts/contract\_manager.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy9jb250cmFjdF9tYW5hZ2VyLnB5) | `22.53% <0%> (-59.16%)` | :arrow_down: |
| [raiden\_contracts/utils/merkle.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9tZXJrbGUucHk=) | `26.47% <0%> (-55.89%)` | :arrow_down: |
| [raiden\_contracts/deploy/etherscan\_verify.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy9kZXBsb3kvZXRoZXJzY2FuX3ZlcmlmeS5weQ==) | `23.46% <0%> (-51.03%)` | :arrow_down: |
| [raiden\_contracts/utils/proofs.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9wcm9vZnMucHk=) | `45.94% <0%> (-45.95%)` | :arrow_down: |
| [raiden\_contracts/utils/transaction.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy90cmFuc2FjdGlvbi5weQ==) | `21.73% <0%> (-43.48%)` | :arrow_down: |
| ... and [2 more](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=footer). Last update [9642351...10564a5](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

codecov[bot]: # [Codecov](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=h1) Report
> Merging [#629](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=desc) into [master](https://codecov.io/gh/raiden-network/raiden-contracts/commit/96423513bb9f56ea080780c16a02d0475cbbb61f?src=pr&el=desc) will **decrease** coverage by `45.45%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/graphs/tree.svg?width=650&token=q8aKDUjiN7&height=150&src=pr)](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #629       +/-   ##
==========================================
- Coverage   75.75%   30.3%   -45.46%     
==========================================
  Files          17      17               
  Lines        1122    1122               
  Branches      119     119               
==========================================
- Hits          850     340      -510     
- Misses        232     776      +544     
+ Partials       40       6       -34
```


| [Impacted Files](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [raiden\_contracts/utils/join-contracts.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9qb2luLWNvbnRyYWN0cy5weQ==) | `0% <0%> (-93.75%)` | :arrow_down: |
| [raiden\_contracts/utils/bytecode.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9ieXRlY29kZS5weQ==) | `25% <0%> (-75%)` | :arrow_down: |
| [raiden\_contracts/utils/events.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9ldmVudHMucHk=) | `16.66% <0%> (-72.73%)` | :arrow_down: |
| [raiden\_contracts/utils/pending\_transfers.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9wZW5kaW5nX3RyYW5zZmVycy5weQ==) | `28.84% <0%> (-71.16%)` | :arrow_down: |
| [raiden\_contracts/utils/logs.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9sb2dzLnB5) | `19.23% <0%> (-68.27%)` | :arrow_down: |
| [raiden\_contracts/contract\_manager.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy9jb250cmFjdF9tYW5hZ2VyLnB5) | `22.53% <0%> (-59.16%)` | :arrow_down: |
| [raiden\_contracts/utils/merkle.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9tZXJrbGUucHk=) | `26.47% <0%> (-55.89%)` | :arrow_down: |
| [raiden\_contracts/deploy/etherscan\_verify.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy9kZXBsb3kvZXRoZXJzY2FuX3ZlcmlmeS5weQ==) | `23.46% <0%> (-51.03%)` | :arrow_down: |
| [raiden\_contracts/utils/proofs.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy9wcm9vZnMucHk=) | `45.94% <0%> (-45.95%)` | :arrow_down: |
| [raiden\_contracts/utils/transaction.py](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree#diff-cmFpZGVuX2NvbnRyYWN0cy91dGlscy90cmFuc2FjdGlvbi5weQ==) | `21.73% <0%> (-43.48%)` | :arrow_down: |
| ... and [2 more](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=footer). Last update [9642351...10564a5](https://codecov.io/gh/raiden-network/raiden-contracts/pull/629?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/raiden_contracts/data/deployment_kovan.json b/raiden_contracts/data/deployment_kovan.json
index c21114b..8689224 100644
--- a/raiden_contracts/data/deployment_kovan.json
+++ b/raiden_contracts/data/deployment_kovan.json
@@ -1,1 +1,1 @@
-{"contracts_version": "0.9.0", "chain_id": 42, "contracts": {"EndpointRegistry": {"address": "0x0C1Cbc66dd97757336d76Ed6F00F93FfAA071b3E", "transaction_hash": "0x97d5d279b5ae3815e516527489ded517d4c7316caf0ff71c5dff22db9f3fabe5", "block_number": 10466694, "gas_cost": null, "constructor_arguments": []}, "SecretRegistry": {"address": "0xC759D50B0aeABc315D430870A8cd2C62396C3795", "transaction_hash": "0x503fd0d479a1619a96fd6b04dd277f1522b4d935c3552c7cfc874a361d65f088", "block_number": 10466695, "gas_cost": null, "constructor_arguments": []}, "TokenNetworkRegistry": {"address": "0x30A310509C3f77521c7078A077F5Cf6bCee2352c", "transaction_hash": "0x04cc2a00e94aa9c1cda003271d9e8b4404d9bed7fd18d2875a9b18a16bcffd46", "block_number": 10466698, "gas_cost": null, "constructor_arguments": ["0xC759D50B0aeABc315D430870A8cd2C62396C3795", 42, 500, 555428, 115792089237316195423570985008687907853269984665640564039457584007913129639935]}}}
\ No newline at end of file
+{"contracts_version": "0.9.0", "chain_id": 42, "contracts": {"EndpointRegistry": {"address": "0x5fFcBfFCfDdA9791E49d9b5188f2a589202a3c2B", "transaction_hash": "0x7705bdcf91e2d16ee3ee7e4118b51fbc8b869787cdc34093381d6db9dcbb3570", "block_number": 10479567, "gas_cost": 555302, "constructor_arguments": []}, "SecretRegistry": {"address": "0x4d9fd4FC41d45Fa6934ba24525Dbe6B86526036b", "transaction_hash": "0xca061c921c6d094a445422bcffb4b63981a5cdf88c3439a188dde9d13ef442e5", "block_number": 10479568, "gas_cost": 313274, "constructor_arguments": []}, "TokenNetworkRegistry": {"address": "0xd1582756859C14bbd7D27D4f8fD7Bddab21b840f", "transaction_hash": "0x24dce589b16109f67ceb44de3e30aefcf79448c16631d2c76fd32910843e663c", "block_number": 10479570, "gas_cost": 4755664, "constructor_arguments": ["0x4d9fd4FC41d45Fa6934ba24525Dbe6B86526036b", 42, 500, 555428, 115792089237316195423570985008687907853269984665640564039457584007913129639935]}}}
\ No newline at end of file
diff --git a/raiden_contracts/data/deployment_services_kovan.json b/raiden_contracts/data/deployment_services_kovan.json
index ba1fbe9..be1abed 100644
--- a/raiden_contracts/data/deployment_services_kovan.json
+++ b/raiden_contracts/data/deployment_services_kovan.json
@@ -1,1 +1,1 @@
-{"contracts_version": "0.9.0", "chain_id": 42, "contracts": {"ServiceRegistry": {"address": "0xc1627BE8ef1327a96724BDaB7EE1C5E06959Dd72", "transaction_hash": "0x115126895c59b8f6d5fe67bd3e289d0bb807aacbf0139904cd5c790f1e7ac56f", "block_number": 10477769, "gas_cost": 748814, "constructor_arguments": ["0x7470c3ff77aFf39F42230796D3aD66AbaDCad35F"]}, "UserDeposit": {"address": "0x62efab4A8EA9a46d62bb15F9743BC057e2101628", "transaction_hash": "0x9313243b9590cb18a8824a019aff9794bc2a499006d4dd0022231c0abf79424c", "block_number": 10477770, "gas_cost": 1414425, "constructor_arguments": ["0x7470c3ff77aFf39F42230796D3aD66AbaDCad35F"]}, "MonitoringService": {"address": "0x7Ac4798Ae52996662A08d15d77780cA662Ae56Aa", "transaction_hash": "0xcb33adfe3a67850a11f2734ad66adea36da6f85ee55046eac0ee6cf97543fb25", "block_number": 10477772, "gas_cost": 1603898, "constructor_arguments": ["0x7470c3ff77aFf39F42230796D3aD66AbaDCad35F", "0xc1627BE8ef1327a96724BDaB7EE1C5E06959Dd72", "0x62efab4A8EA9a46d62bb15F9743BC057e2101628"]}, "OneToN": {"address": "0x5d0b6db51ea72124B07E4A5F1B33623dE646f7B0", "transaction_hash": "0x87802cd508ffa903a2f5d875d6c34ca1554d99c24b41369087097129c3f51b11", "block_number": 10477773, "gas_cost": 758340, "constructor_arguments": ["0x62efab4A8EA9a46d62bb15F9743BC057e2101628"]}}}
\ No newline at end of file
+{"contracts_version": "0.9.0", "chain_id": 42, "contracts": {"ServiceRegistry": {"address": "0xa71f689E08cB4d40e151021905928bB5b2cCDa45", "transaction_hash": "0xa9d9bdab1c738f1fdb0bdc87a431b666f38a2a4f208ec5f6668b0b71f3593811", "block_number": 10479580, "gas_cost": 748814, "constructor_arguments": ["0xaD41ae749b9F9E55C5ccC6120560Ac9808367f2d"]}, "UserDeposit": {"address": "0xb9A7dEcE479dBCdcd9a6B3B3d2E8e26E52c71Ee6", "transaction_hash": "0xbdce797e4283da5b8d7890044aabe4aecadcf7f01306c84c67105e6e93a44b94", "block_number": 10479582, "gas_cost": 1414425, "constructor_arguments": ["0xaD41ae749b9F9E55C5ccC6120560Ac9808367f2d"]}, "MonitoringService": {"address": "0x6D894D27e96b9382fD3Fe7e8D9C1c065571273A4", "transaction_hash": "0xc84668b462fda03627d1e95b47d15b599b7ae52a86460927196f6ada8910c0cb", "block_number": 10479583, "gas_cost": 1603898, "constructor_arguments": ["0xaD41ae749b9F9E55C5ccC6120560Ac9808367f2d", "0xa71f689E08cB4d40e151021905928bB5b2cCDa45", "0xb9A7dEcE479dBCdcd9a6B3B3d2E8e26E52c71Ee6"]}, "OneToN": {"address": "0xF3dA6440941F526F1afAFdbE707c663F5E63735F", "transaction_hash": "0x2aec080ce62d3a290432ec538ff991cb2c48bd8d6e70dbdc41cea4941de22dbe", "block_number": 10479585, "gas_cost": 758340, "constructor_arguments": ["0xb9A7dEcE479dBCdcd9a6B3B3d2E8e26E52c71Ee6"]}}}
\ No newline at end of file


Test patch:
diff --git a/raiden_contracts/tests/test_deploy_data.py b/raiden_contracts/tests/test_deploy_data.py
new file mode 100644
index 0000000..cbcf606
--- /dev/null
+++ b/raiden_contracts/tests/test_deploy_data.py
@@ -0,0 +1,78 @@
+from typing import Optional
+
+import pytest
+
+from raiden_contracts.constants import CONTRACTS_VERSION
+from raiden_contracts.contract_manager import (
+    contracts_data_path,
+    contracts_deployed_path,
+    get_contracts_deployed,
+)
+
+
+@pytest.mark.parametrize("version", [None, CONTRACTS_VERSION])
+def test_deploy_data_dir_exists(version: Optional[str]):
+    """ Make sure directories exist for deployment data """
+    assert contracts_data_path(version).exists(), "deployment data do not exist"
+    assert contracts_data_path(version).is_dir()
+
+
+@pytest.mark.parametrize('version', [None, CONTRACTS_VERSION])
+def test_deploy_data_dir_is_not_nested(version: Optional[str]):
+    """ Make sure 'data' directories do not contain 'data*' recursively """
+    assert list(contracts_data_path(version).glob('./data*')) == []
+
+
+@pytest.mark.parametrize("version", [None, CONTRACTS_VERSION])
+@pytest.mark.parametrize("chain_id", [3, 4, 42])
+@pytest.mark.parametrize("services", [False, True])
+def test_deploy_data_file_exists(
+        version: Optional[str],
+        chain_id: int,
+        services: bool,
+):
+    """ Make sure files exist for deployment data of each chain_id """
+    assert contracts_deployed_path(chain_id, version, services).exists()
+
+
+def reasonable_deployment_of_a_contract(deployed):
+    """ Checks an entry under deployment_*.json under a contract name """
+    assert isinstance(deployed["address"], str)
+    assert len(deployed["address"]) == 42
+    assert isinstance(deployed["transaction_hash"], str)
+    assert len(deployed["transaction_hash"]) == 66
+    assert isinstance(deployed["block_number"], int)
+    assert deployed["block_number"] > 0
+    assert isinstance(deployed["gas_cost"], int)
+    assert deployed["gas_cost"] > 0
+    assert isinstance(deployed["constructor_arguments"], list)
+
+
+@pytest.mark.parametrize("version", [None])
+@pytest.mark.parametrize("chain_id", [3, 4, 42])
+def test_deploy_data_has_fields_raiden(
+        version: Optional[str],
+        chain_id: int,
+):
+    data = get_contracts_deployed(chain_id, version, services=False)
+    assert data["contracts_version"] == version if version else CONTRACTS_VERSION
+    assert data["chain_id"] == chain_id
+    contracts = data["contracts"]
+    for name in {"EndpointRegistry", "TokenNetworkRegistry", "SecretRegistry"}:
+        deployed = contracts[name]
+        reasonable_deployment_of_a_contract(deployed)
+
+
+@pytest.mark.parametrize("version", [None])
+@pytest.mark.parametrize("chain_id", [3, 4, 42])
+def test_deploy_data_has_fields_services(
+        version: Optional[str],
+        chain_id: int,
+):
+    data = get_contracts_deployed(chain_id, version, services=True)
+    assert data["contracts_version"] == version if version else CONTRACTS_VERSION
+    assert data["chain_id"] == chain_id
+    contracts = data["contracts"]
+    for name in {"ServiceRegistry", "MonitoringService", "OneToN", "UserDeposit"}:
+        deployed = contracts[name]
+        reasonable_deployment_of_a_contract(deployed)