To follow this test, you'll need the following tools installed on your machine:
- Git (https://git-scm.com/)
- Node.js (https://nodejs.org/)
- You need to add the credentials in the
test/test-cross-chain-call.test.js
, which consist of theuserKey
and theprojectKey
. To get your user key, follow this tutorial. To get your project key, follow this tutorial.
It should look like this:
harbor = new Harbor({
userKey: "cFeJWnDwQFVTSF2AabM2W5",
projectKey: "fPMeKGPUfyBTCoq2omv3G4",
});
The above keys are for demonstration only. They don't actually work! Also, the Harbor SDK does not support parallel test execution, yet. But this is coming soon!
- Set the testnet name value in the
test/test-cross-chain-call.test.js
file. You can do this by updating theTESTNET_NAME
variable to a unique name of your choice. For example:
let TESTNET_NAME = ""
- Install the project dependencies by running the following command:
yarn install
- Finally, compile the contracts:
rm -rf artifacts && npx hardhat compile
You will be looking at two contracts, one on the Ethereum blockchain and another on the Polygon blockchain. The Ethereum contract will act as the message sender while the Polygon contract will act as the message receiver.
You can read the contracts in-depth if you'd like to learn more about them.
The test is located in the test/test-cross-chain-call.test.js
. Open it and follow along!
Before you move on to running the tests, you need to know how you are applying the Axelar Testnet configuration that contains the 2 custom contracts.
The variable harborConfig
contains the JSON:
const harborConfig = {
bridges: [
{
name: "AXELAR",
chains: ["ethereum", "polygon"],
},
],
chains: [
{
chain: "ethereum",
config: {
artifactsPath: "./artifacts/",
deploy: {
scripts: "./deploy/ethereum",
},
environment: {
AXL_GATEWAY_ADDR: "$axl_gateway_addr",
AXL_GAS_RECEIVER_ADDR: "$axl_gasReceiver_addr",
},
},
tag: "v7",
},
{
chain: "polygon",
config: {
artifactsPath: "./artifacts",
deploy: {
scripts: "./deploy/polygon",
},
environment: {
AXL_GATEWAY_ADDR: "$axl_gateway_addr",
AXL_GAS_RECEIVER_ADDR: "$axl_gasReceiver_addr",
},
},
tag: "v7",
},
],
};
This Testnet configuration contains two important attributes, bridges
and chains
:
- In
bridges
, you specify thename
of bridge that you are applying along with the array ofchains
that you'd like to include in the bridge - In
chains
, you configure each separate chain further with it's own artifacts and deployment scripts.- You must specify the
AXL_GATEWAY_ADDR
andAXL_GAS_RECEIVER_ADDR
in theenvironment
attribute.- This is because both contracts needs these arguments in it's constructor, otherwise they won't work with the Axelar protocol
- Both their values
$axl_gateway_addr
and$axl_gasReceiver_addr
are automatically filled by Harbor whilst it applies the Testnet
- You must specify the
READ MORE ABOUT THE CONFIGURATION FILE HERE
To execute the test, tun the following command in your terminal:
yarn jest test/test-cross-chain-call.test.js
As explained above, this test applies the Axelar configuration with the custom contracts, checks for the chains / off-chain actors existence on the Testnet while also executing and asserting the cross-chain transaction from Ethereum to Polygon.
After you apply the Testnet in the beforeAll
function, you must check that the testnet, the chains and the off-chain actor (just the relayer) exist!
Next, you need to prove that the cross-chain message passing works. Your Ethereum contract, MessageSender
, needs to send a message. After that transaction is made, the attribute value()
is expected to change to the new message in the contract MessageReceiver
on Polygon. Asserting that the MessageReceiver
's value
equals to the MESSAGE
variable that was set in the test is enough to prove that the cross-chain transaction worked!