This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Mock Blockchain Client
Jonas Hals edited this page May 8, 2020
·
3 revisions
Included in the automated integration tests, there is a mock blockchain client that can be used to replicate clients for different blockchains.
- New blockchain implementations should be created in the
blockchain
package (integration/mock-client/blockchain
). - The new file should export one function to handle requests, and the function signature should be
(conn string, msg JsonrpcMessage) ([]JsonrpcMessage, error)
. - Connection type is either "rpc" or "ws".
- On successful RPC connections, there should only be 1 message returned, and error should be
nil
. - On successful WS connections, there should be at least 1 message returned, and error should be
nil
. Multiple messages are sent in the order they are returned from the function. - The new implementation should be registered in
common.go
:
case "my_blockchain":
return HandleMyBlockchainRequest(conn, msg)
- To add the new implementation to the tests, add the endpoint in
docker-compose.yml
external-initiator:
command:
- '{"name":"my_blockchain-mock-http","type":"my_blockchain","url":"http://mock:8080/rpc/my_blockchain","refreshInterval":600}'
- '{"name":"my_blockchain-mock-ws","type":"my_blockchain","url":"ws://mock:8080/ws/my_blockchain"}'
RPC requests have URL endpoint http://mock:8080/rpc/<blockchain>
, while WS requests have endpoint ws://mock:8080/ws/<blockchain>
.
For custom HTTP endpoints, use http://mock:8080/http/<blockchain>
.
- Last step is to run these tests. In
run_test
, add the scripts to run the tests for these endpoints:
./integration/test_ei_event "my_blockchain-mock-http"
./integration/test_ei_event "my_blockchain-mock-ws"