Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 4.52 KB

File metadata and controls

36 lines (24 loc) · 4.52 KB

Raiden Network Smart Contracts Tests

Writing Tests

  • when implementing a new feature or changing code, make sure your PR also contains tests that cover the changes.
  • always think about edge cases, go over each Solidity source code line that was changed in your PR and make sure a test covers it if needed.
  • don’t only test the happy case. If you don't have with pytest.raises(): in your tests, something is wrong

How to Start Testing a Contract

  • create a test_contract_name.py test file for testing the constructor & all public variables for that contract (including the version) - see TokenNetwork tests
  • if the contract is big - create multiple test_contract/[contract]_contract_function_name.py test files for testing each contract function separately. E.g. test_channel_open.py (we don't have the contract name here, but we have channel, which is specific enough)

Testing the Constructor & Contract Public Variables

  • have a version test. E.g. test_version
  • test TypeErrors - make sure your constructor receives the intended number of arguments, of the intended type. E.g. test_constructor_call for the TokenNetwork contract.
  • check that all public contract variables indeed have public access. E.g. test_constructor_call_state from the TokenNetworkRegistry contract

Testing a Function

Tests usually follow this order when writing them in a file:

  • test TypeErrors - make sure your function receives the intended number of arguments, of the intended type. E.g. test_open_channel_call
  • go through each line of code and see whether a test can be written to cover it. E.g. for this line channel_counter += 1; in TokenNetwork.openChannel, this test_counter was added
  • test_function_name_state - always exists and tests the contract state for when the function is successful (no pytest.raises, but much assert):
    • pre-call tests for all contract state variables that are related, all related getter functions
    • post-call tests for all contract state variables that are related, all related getter functions, comparing to the pre-call ones
    • E.g. test_open_channel_state
    • some of these checks are written as fixtures and reused by tests. You can find them in fixtures/channel.py E.g. common_settle_state_tests
  • tests for each event. E.g. test_open_channel_event

State Fixtures