Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working e2e test with symbiotic #791

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/scripts/bridge-build-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ GOBIN=$output_bin_dir go install github.com/ferranbt/fastssz/[email protected]

$bridge_scripts/build-ethereum-node.sh
$bridge_scripts/build-relayer.sh
$bridge_scripts/build-symbiotic-contracts.sh

pushd $ts_scripts_dir
pnpm install
popd
2 changes: 1 addition & 1 deletion test/scripts/bridge/assets/execution-relay.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"instantVerification": false,
"schedule": {
"id": null,
"id": 1,
"totalRelayerCount": 1,
"sleepInterval": 1
}
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/bridge/assets/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"gasLimit": "80000000",
"alloc": {
"90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe": {
"balance": "10000000000000000000000"
"balance": "1000000000000000000000000"
},
"Be68fC2d8249eb60bfCf0e71D5A0d2F2e292c4eD": {
"balance": "100000000000000000000"
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/bridge/build-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ else
popd
fi

$scripts_path/build-eth-contracts.sh
$scripts_path/build-snowbridge-contracts.sh

echo "Building Relayer"
pushd $relayer_root_dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ scripts_path="$(realpath ./scripts/bridge)"

source $scripts_path/set-env.sh

echo "Building contracts"
echo "Building snowbridge contracts"

pushd $contract_dir
forge build
Expand Down
26 changes: 26 additions & 0 deletions test/scripts/bridge/build-symbiotic-contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Exit on any error
set -e

scripts_path="$(realpath ./scripts/bridge)"

source $scripts_path/set-env.sh

echo "Building symbiotic contracts"

echo "Checkout Symbiotic contract repository"

if [ -d "$symbiotic_contracts_dir" ];
then
echo "Symbiotic contract repository seems to be already setup. Skipping git fetch"
else
git clone https://github.com/moondance-labs/tanssi-symbiotic $symbiotic_contracts_dir
pushd $symbiotic_contracts_dir
git fetch && git checkout 518f7e9d0059d24d899d2fc8340da5387a127b3b
popd
fi

pushd $symbiotic_contracts_dir
forge build
popd
15 changes: 11 additions & 4 deletions test/scripts/bridge/deploy-ethereum-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ source $scripts_path/set-env.sh
deploy_command() {
local deploy_script=$1

pushd "$contract_dir"
forge script \
OWNER_PRIVATE_KEY=$ethereum_key forge script \
--rpc-url $eth_endpoint_http \
--legacy \
--broadcast \
-vvv \
--slow \
--skip-simulation \
$deploy_script
popd
}

echo "Deploying contracts"
echo "Deploying snowbridge contracts"
pushd "$contract_dir"
deploy_command scripts/DeployLocal.sol:DeployLocal
popd

echo "Deploying symbiotic contracts"
pushd "$symbiotic_contracts_dir"
deploy_command script/test/DeployTanssiEcosystemDemo.s.sol:DeployTanssiEcosystem
popd
15 changes: 0 additions & 15 deletions test/scripts/bridge/generate-contract-info.sh

This file was deleted.

17 changes: 17 additions & 0 deletions test/scripts/bridge/generate-eth-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -eu

scripts_path="$(realpath ./scripts/bridge)"
source $scripts_path/set-env.sh

pushd "$ts_scripts_dir" > /dev/null
contract_dir="$artifacts_dir/relayer/contracts" deploy_script="DeployLocal.sol" pnpm generateContracts "$output_dir/snowbridge_contracts.json" > /dev/null
contract_dir="$artifacts_dir/tanssi-symbiotic" deploy_script="DeployTanssiEcosystemDemo.s.sol" pnpm generateContracts "$output_dir/symbiotic_contracts.json" > /dev/null
popd > /dev/null

# Output the file so that invoker can read it
snowbridge_info=$(cat "$output_dir/snowbridge_contracts.json")
symbiotic_info=$(cat "$output_dir/symbiotic_contracts.json")

echo "{ \"snowbridge_info\": $snowbridge_info, \"symbiotic_info\": $symbiotic_info, \"ethereum_key\": \"$ethereum_key\" }"
10 changes: 8 additions & 2 deletions test/scripts/bridge/set-env.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
root_dir="$(realpath .)"

scripts_root_dir="$root_dir/scripts/bridge"
ts_scripts_dir="$scripts_root_dir/ts-scripts"
assets_dir="$scripts_root_dir/assets"

artifacts_dir="$root_dir/tmp/bridge"
Expand All @@ -15,6 +16,7 @@ mkdir -p $output_bin_dir
export PATH="$output_bin_dir:$PATH"

relayer_root_dir="$artifacts_dir/relayer"
symbiotic_contracts_dir="$artifacts_dir/tanssi-symbiotic"
web_dir="$relayer_root_dir/web"
export contract_dir="$relayer_root_dir/contracts"
test_helpers_dir="$web_dir/packages/test-helpers"
Expand Down Expand Up @@ -109,8 +111,12 @@ ethereum_key="0x5e002a1af63fd31f1c25258f3082dc889762664cb8f218d86da85dff8b07b342
ethereum_address="90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe"


address_for() {
jq -r ".contracts.${1}.address" "$output_dir/contracts.json"
snowbridge_address_for() {
jq -r ".contracts.${1}.address" "$output_dir/snowbridge_contracts.json"
}

symbiotic_address_for() {
jq -r ".contracts.${1}.address" "$output_dir/symbiotic_contracts.json"
}

kill_all() {
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/bridge/setup-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mkdir -p $data_store_dir
config_relayer() {
# Configure beefy relay
jq \
--arg k1 "$(address_for BeefyClient)" \
--arg k1 "$(snowbridge_address_for BeefyClient)" \
--arg eth_endpoint_ws $eth_endpoint_ws \
--arg eth_gas_limit $eth_gas_limit \
--arg relay_chain_endpoint $RELAYCHAIN_ENDPOINT \
Expand Down Expand Up @@ -45,7 +45,7 @@ config_relayer() {
# Configure execution relay for starlight
jq \
--arg eth_endpoint_ws $eth_endpoint_ws \
--arg k1 "$(address_for GatewayProxy)" \
--arg k1 "$(snowbridge_address_for GatewayProxy)" \
--arg relay_chain_endpoint $RELAYCHAIN_ENDPOINT \
--arg channelID $PRIMARY_GOVERNANCE_CHANNEL_ID \
--arg data_store_dir $data_store_dir \
Expand Down
13 changes: 13 additions & 0 deletions test/scripts/bridge/ts-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@tanssi-symbiotic/test-helpers",
"version": "1.0.0",
"description": "Tanssi symbiotic test helpers",
"license": "Apache-2.0",
"scripts": {
"generateContracts": "npx tsx src/generateContractInfo.ts"
},
"dependencies": {
"@types/node": "^18.16.8",
"tsx": "^4.19.2"
}
}
42 changes: 42 additions & 0 deletions test/scripts/bridge/ts-scripts/src/generateContractInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from "node:fs";
import path from "node:path";

const run = async () => {
const NetworkId = process.env.ETH_NETWORK_ID || 11155111;
const basedir = process.env.contract_dir || "../contracts";
const DeployInfoFile = path.join(basedir, "broadcast", process.env.deploy_script, `${NetworkId}/run-latest.json`);
const BuildInfoDir = path.join(basedir, "./out");
const DestFile = process.argv.length >= 3 ? process.argv[2] : process.env["output_dir"] + "/contracts.json";
type Contract = {
[key: string]: ContractInfo;
};
const contracts: Contract = {};
const deploymentInfo = JSON.parse(fs.readFileSync(DeployInfoFile, "utf8"));
type ContractInfo = {
abi?: object;
address?: string;
};
for (const transaction of deploymentInfo.transactions) {
if (transaction.transactionType === "CREATE") {
const contractName: string = transaction.contractName;
if (contractName) {
const contractInfo: ContractInfo = { address: transaction.contractAddress };
const contractBuildingInfo = JSON.parse(
fs.readFileSync(path.join(BuildInfoDir, contractName + ".sol", contractName + ".json"), "utf8")
);
contractInfo.abi = contractBuildingInfo.abi;
contracts[contractName] = contractInfo;
}
}
}
fs.writeFileSync(DestFile, JSON.stringify({ contracts }, null, 2), "utf8");
};

run()
.then(() => {
console.log("Contract File generated successfully");
process.exit(0);
})
.catch((err) => {
console.error(err);
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ describeSuite({
let relayerChildProcess;
let alice;
let beefyClientDetails;
let gatewayProxyAddress;
let gatewayDetails;

const ethUrl = "ws://127.0.0.1:8546";
let customHttpProvider;
let ethereumWallet;
let middlewareContract;
let gatewayProxyAddress;
let middlewareDetails;

let operatorAccount;
let operatorNimbusKey;
Expand All @@ -57,7 +60,6 @@ describeSuite({
operatorAccount = keyring.addFromUri("//Charlie", { name: "Charlie default" });
// We rotate the keys for charlie so that we have access to them from this test as well as the node
operatorNimbusKey = await relayCharlieApi.rpc.author.rotateKeys();
console.log(`operatorNimbusKey: ${operatorNimbusKey}`);
await relayApi.tx.session.setKeys(operatorNimbusKey, []).signAndSend(operatorAccount);

const fundingTxHash = await relayApi.tx.utility
Expand Down Expand Up @@ -86,29 +88,39 @@ describeSuite({
console.log("Waiting some time for ethereum node to produce block, before we deploy contract");
await sleep(20000);

await execCommand("./scripts/bridge/deploy-ethereum-contracts.sh");
await execCommand("./scripts/bridge/deploy-ethereum-contracts.sh", {
env: {
OPERATOR1_KEY: u8aToHex(operatorAccount.addressRaw),
...process.env,
},
});

console.log("Contracts deployed");

const contractInfoData = JSON.parse(
<string>(await execCommand("./scripts/bridge/generate-contract-info.sh")).stdout
);
const ethInfo = JSON.parse(<string>(await execCommand("./scripts/bridge/generate-eth-info.sh")).stdout);

console.log("BeefyClient contract address is:", ethInfo.snowbridge_info.contracts.BeefyClient.address);
beefyClientDetails = ethInfo.snowbridge_info.contracts.BeefyClient;

console.log("BeefyClient contract address is:", contractInfoData.data.contracts.BeefyClient.address);
beefyClientDetails = contractInfoData.data.contracts.BeefyClient;
console.log("Gateway contract proxy address is:", ethInfo.snowbridge_info.contracts.GatewayProxy.address);
gatewayProxyAddress = ethInfo.snowbridge_info.contracts.GatewayProxy.address;

console.log("Gateway contract proxy address is:", contractInfoData.data.contracts.GatewayProxy.address);
gatewayProxyAddress = contractInfoData.data.contracts.GatewayProxy.address;
gatewayDetails = contractInfoData.data.contracts.Gateway;
console.log("Symbiotic middleware address is: ", ethInfo.symbiotic_info.contracts.Middleware.address);
middlewareDetails = ethInfo.symbiotic_info.contracts.Middleware;

console.log("Setting gateway address to proxy contract:", gatewayProxyAddress);
const setGatewayAddressTxHash = await relayApi.tx.sudo
.sudo(relayApi.tx.system.setStorage([[GATEWAY_STORAGE_KEY, gatewayProxyAddress]]))
.signAndSend(alice);
console.log("Set gateway address transaction hash:", setGatewayAddressTxHash.toHex());

const customHttpProvider = new ethers.WebSocketProvider("ws://127.0.0.1:8546");
ethereumWallet = new ethers.Wallet(contractInfoData.ethereum_key, customHttpProvider);
customHttpProvider = new ethers.WebSocketProvider(ethUrl);
ethereumWallet = new ethers.Wallet(ethInfo.ethereum_key, customHttpProvider);

// Setting up Middleware
middlewareContract = new ethers.Contract(middlewareDetails.address, middlewareDetails.abi, ethereumWallet);
const tx = await middlewareContract.setGateway(gatewayProxyAddress);
await tx.wait();

const initialBeaconUpdate = JSON.parse(
<string>(
Expand Down Expand Up @@ -163,8 +175,6 @@ describeSuite({
id: "T02",
title: "Dancelight Blocks are being recognized on ethereum",
test: async function () {
const url = "ws://127.0.0.1:8546";
const customHttpProvider = new ethers.WebSocketProvider(url);
const beefyContract = new ethers.Contract(
beefyClientDetails.address,
beefyClientDetails.abi,
Expand All @@ -182,21 +192,21 @@ describeSuite({
id: "T03",
title: "Message can be passed from ethereum to Starlight",
test: async function () {
const gatewayContract = new ethers.Contract(gatewayProxyAddress, gatewayDetails.abi, ethereumWallet);

const externalValidatorsBefore = await relayApi.query.externalValidators.externalValidators();

const sessionValidatorsBefore = await relayApi.query.session.validators();
expect(!sessionValidatorsBefore.includes(operatorNimbusKey));
const epoch = await middlewareContract.getCurrentEpoch();
const currentOperators = await middlewareContract.getOperatorsByEpoch(epoch);
const currentOperatorsKeys = [];
for (let i = 0; i < currentOperators.length; i++) {
currentOperatorsKeys.push(await middlewareContract.getCurrentOperatorKey(currentOperators[i]));
}

const rawValidators = [
u8aToHex(operatorAccount.addressRaw),
"0x7894567890123456789012345678901234567890123456789012345678901234",
"0x4564567890123456789012345678901234567890123456789012345678901234",
];
console.log("Middleware: Epoch is:", epoch);
console.log("Middleware: Operator keys are:", currentOperatorsKeys);
console.log("Starlight: External validators are:", externalValidatorsBefore.toJSON());

try {
const tx = await gatewayContract.sendOperatorsData(rawValidators, 1);
const tx = await middlewareContract.sendCurrentOperatorsKeys();
await tx.wait();
} catch (error) {
throw new Error(`Failed to send operator data: ${error.message}`, error.code);
Expand Down Expand Up @@ -226,10 +236,12 @@ describeSuite({
return u8aToHex(decodeAddress(x));
});

expect(externalValidatorsHex).to.deep.eq(rawValidators);
console.log("After message transfer:");

console.log("Middleware: Operator keys are:", currentOperatorsKeys);
console.log("Starlight: External validators are:", externalValidatorsHex);

const sessionValidators = await relayApi.query.session.validators();
expect(sessionValidators.includes(operatorNimbusKey));
expect(externalValidatorsHex).to.deep.eq(currentOperatorsKeys);
},
});

Expand Down
Loading