icon-project / icon-bridge

The centralized bridge of ICON
Apache License 2.0
21 stars 15 forks source link

add tests to relay #339

Open manishbista28 opened 2 years ago

manishbista28 commented 2 years ago

Overview

Current bmr source code does not include extensive set of unit tests. The ones that are already present make rpc calls to external systems to fetch data. We should be adding more tests to increase code coverage.

Story

Some of the tests can be

  1. check if verifier works as expected (positive and negative tests)
  2. check if relay can restart upon encountering errors and does not get stuck
  3. check if gas price calculation in bsc chain works as expected
  4. check balance_threshold logic
  5. check if input configuration are properly parsed and handled, etc

Acceptance Criteria

Some of the requirements of a unit test can be

  1. they complete within finite time
  2. do not depend upon external rpc calls (mock data if possible)
MuhammedIrfan commented 2 years ago

For NEAR implementation, we have implemented a small framework for unit testing, We can try to extend that to other parts of the relay as well. I would highly appreciate your feedback and improvements to the framework.

We have decoupled test data and test cases and created an interface for RPC API that helps us inject mock data for testing.

Test cases are implemented in sender_test.go, receiver_test.go, client_test.go

Test Data is present in https://github.com/icon-project/icon-bridge/tree/hugobyte/development/cmd/iconbridge/chain/near/tests

Mock API mock_api.go facilitates injecting mock data. Default mock data to be injected are defined in default.go and are loaded using a factory factory.go

Default Mock data can be overridden and more data can be loaded from the test data suite as shown in https://github.com/icon-project/icon-bridge/blob/hugobyte/development/cmd/iconbridge/chain/near/tests/get_receipt_proof.go#L23-L32