Multichain Relayer and Gas Station example
In this article you'll learn how to run end-to-end tests on the entire Multichain Relayer system. You'll find two tests available: an integrated test and a manual test. The integration test is the best way to check that all multichain gas relayer systems are working well together. Manual testing is a good way to debug issues if any individual part of the system isn't working.
Requirements
Before you start testing, set up your local environment and install the Relayer server, the Event indexer and NEAR CLI.
For this tutorial, you need to have installed:
- Python >=3.10
- Rust
- Multichain Relayer Server
- Gas Station Event indexer
- NEAR CLI RS: Make sure to configure it with the correct network and account.
Integration test
This test is the best way to verify that all multichain gas relayer systems are working well together.
In separate terminals, you need to run the following tools:
- Multichain Relayer server, with a valid
config.toml
configuration file - Gas Station indexer, with correct values in
config.toml
- Python integration test script
Multichain Relayer server
The main function of this server is interfacing with foreign chain RPCs sending both pre-signed funding transactions to cover gas and the actual pre-signed transaction once the funding is done.
To run the Multichain Relayer Server:
- Configure the Multichain Relayer by editing the
config.toml
file - Start the multichain relayer server:
cargo run
Find the Multichain Relayer server source code in this GitHub repository.
Gas Station Event indexer
The event indexer is a Python script that picks up events emitted from the gas station contract used for generating signed foreign chain transactions and calls the multichain relayer /send_funding_and_user_signed_txns
endpoint locally.
To run the Gas Station indexer:
-
Ensure you have the Multichain Relayer Server running on
localhost:3030
-
Create the virtual environment and install requirements:
make install
-
Update the
config.toml
configuration file with appropriate values (usecanhazgas.near
for mainnet)network = "testnet"
# gas station contract account id
contract_id = "canhazgas.testnet" -
Populate the environment file containing AWS credentials for reading from Near Lake
cp .env.sample .env
-
Run the indexer script:
make run
Find the Gas Station Event indexer source code in this GitHub repository.
Run integration test
To run the integration test, switch to the multichain-relayer-server
repository folder and execute the Python script:
python3 integration_tests/integration_test.py
You can use the optional --verbose
flag to print subprocess output:
python3 integration_tests/integration_test.py --verbose
Manual testing
This section offers instructions on how to manually perform end-to-end tests on the entire multichain relayer system including the gas station contract, indexer, and relayer server.
This test is a good way to debug issues if any individual part of the system isn't working.
Test setup
The following instructions are only need to be called once to initialize the account on the Gas Station. Make sure to replace the <account_id>
(string) with the account you want to initialize and <token_id>
(integer) with the token id of the NFT you minted in step 2:
- Registration / Storage Deposit:
near contract call-function as-transaction v2.nft.kagi.testnet \
storage_deposit json-args {} prepaid-gas '100.0 Tgas' attached-deposit '1 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send - Mint NFT - make sure to save the token id from the logs of this call
near contract call-function as-transaction v2.nft.kagi.testnet \
mint json-args {} prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send - Approve the Gas Station for this Token (use or use
canhazgas.near
for mainnet):near contract call-function as-transaction v2.nft.kagi.testnet \
ckt_approve_call json-args '{"token_id":"<token_id>","account_id":"canhazgas.testnet","msg":""}' \
prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send