Gravity test framework adds Binance Smart Chain via Ankr


In this article, we’re introducing the integration of Binance Smart Chain testnet to the Gravity test framework via an Ankr node, focusing on the key steps of incorporating a new target chain into the network.

Gravity’s recently launched devnet version is designed for public testing of upcoming Gravity updates to maintain compatibility and synchronization with regularly updated integrated networks.

One of the crucial ideas that can help retain blockchain agnosticism of the protocol is the integration of a wide range of major target chains, besides Ethereum and Waves, which have been part of the network since the start. This is needed to establish an adequate technical foundation that would encompass the majority of features potentially required by target chains, thus facilitating new integrations.

Binance has recently launched Binance Smart Chain (BSC), a public blockchain that runs in parallel with Binance Chain and enables the creation of smart contracts and BNB staking. BSC is fully compatible with EVM (Ethereum Virtual Machine) and supports the rich universe of Ethereum tools and DApps, which makes it easy for developers to port their projects over from Ethereum.

In the current crypto market conditions, BSC has been a timely addition, capable of leveraging many opportunities that arise on the DeFi front, therefore making it a prominent candidate for integrating into the Gravity network.

While preparing this integration, the Gravity team utilized easy-to-use, one-click BSC node deployment solutions by Ankr, a partner of Waves.

In this article about using BSC as a representative case of seamless integration of an EVM-compatible blockchain, we will further explore the framework for integration tests — a flow for adding new target chains that we are offering to open-source Gravity developers.

Gravity integration test framework

Currently, the integration testing framework contains tests related to cross-chain transfers based on SuSy, a blockchain-agnostic cross-chain asset transfer gateway protocol implemented over Gravity.

The integration-tests repository verifies the entire functionality of a SuSy gateway in a given target chain. Tests for the contracts are written in Golang using a general-purpose library, testing. As stated in the previous article about the integration test framework, the core underlying principle of any integration test implemented within Gravity is this:

To test a specific functionality, which may be, for instance, part of the logic of NEBULA-SC in the Ethereum blockchain that implements data verification, one would need to deploy an Ethereum node, deploy contracts, mock a needed state and call several verification operations, expecting a definite, well-specified answer at the end of the test.

If a set of tests executed in a newly integrated target chain is successful, then all stages of the implemented integration, starting from the logic that implements reading from the blockchain (extraction) and ending with on-chain data verification, should be deemed successful, too. Code that has been debugged using the framework can be reused to fully integrate a specific target chain and its smart contracts into the main Gravity network, as will be described in detail in the upcoming articles.

BSC integration overview

Preparing accounts and infrastructure

In this section, we will take you through the steps of integrating and launching Gravity tests on the Binance Smart Chain testnet, using a Binance Smart Chain Full Node provided by Ankr.

To run tests on your machine or a dedicated server, make sure that docker & docker-compose are installed and available for use. For the convenience of developers, we have provided a pre-funded account on the Binance Chain: 0x657FeC03D0a19Ad719903E3ee1339B762627100d (link to BSC explorer). However, in case there aren’t enough funds, you may need to pre-fund this address with test coins (BNB) using the BNB faucet.

If you want to use your own testnet account to conduct tests, use this guide explaining how to create a Binance testnet account using Math wallet and fund it with testnet BNBs. After the creation of an account, export your private key as a text file in the Math wallet settings and paste the key into the ./integration-tests/solidity/0.7/config.bsc-testnet.json file, replacing the first private oracle key (“oraclepk”).

Image for post

Preparing a node & running tests

Ankr provides one-click solutions to easily spin up nodes of various blockchains. We highly recommend that you deploy your own Binance Smart Chain node to interact with the BSC testnet.

  1. First, head to and click the Deploy A Node button.

Image for post

2. Search for the Binance card, hover over it, and press the Deploy button next to Smart Chain Full Node

Image for post

3. Before launch, configure your node to use the Testnet & Fast Sync Mode and choose a suitable payment method for Ankr services (deposit or daily-billing). After payment, save the node API URL.

Image for post

4. Paste the node API URL into the ./integration-tests/solidity/0.7/config.bsc-testnet.json file, replacing the default endpoint.

Image for post

5. Finally, run the bash-script to deploy and test contracts in the BSC testnet.

Image for post

As you can see on the screenshot, all the tests have successfully passed, meaning that the source code of Gravity is fully compatible with Binance Smart Chain, and it is ready for the next integration step.

Modifying source code of Gravity contracts

The integration tests framework already contains a compiled code of Gravity smart contracts. In some cases, the code needs to be rewritten to ensure compatibility with a given target chain.

When modifying the source code of the contracts, launch The compilation script will produce a build in a container for the Solidity compiler versions 5 and 7, as well as abigen utilities: note that the contracts have a pre-generated ABI (application binary interface). These can be found, for instance, in rh_tests/api/nebula for NEBULA-SC, or rh_tests/api/ibport for the IB-Port (an example of a USER-SC). The compilation may take a long time during the first run.

This article offers a guide on how BSC can be tested from within the integration test framework that enables implementing and testing Gravity contracts. We believe that this framework can facilitate development experience for external collaborators, ensuring faster expansion of the Gravity ecosystem. In the next article about BSC integration, we will explain how to finalize the integration by adding the target chain into the Gravity Core interface and deploying all necessary smart contracts to testnet BSC accounts. Stay tuned!

You may also like