Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tomasz-rotate-subset
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Dec 9, 2024
2 parents faac9e9 + 61c9874 commit b6f46d7
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 9 deletions.
38 changes: 38 additions & 0 deletions test/scripts/bridge/assets/execution-relay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"source": {
"ethereum": {
"endpoint": "ws://127.0.0.1:8546"
},
"contracts": {
"Gateway": null
},
"channel-id": null,
"beacon": {
"endpoint": "http://127.0.0.1:9596",
"stateEndpoint": "http://127.0.0.1:9596",
"spec": {
"syncCommitteeSize": 512,
"slotsInEpoch": 32,
"epochsPerSyncCommitteePeriod": 256,
"denebForkedEpoch": 0
},
"datastore": {
"location": "",
"maxEntries": 100
}
}
},
"sink": {
"parachain": {
"endpoint": "",
"maxWatchedExtrinsics": 8,
"headerRedundancy": 20
}
},
"instantVerification": false,
"schedule": {
"id": null,
"totalRelayerCount": 1,
"sleepInterval": 1
}
}
2 changes: 1 addition & 1 deletion test/scripts/bridge/build-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ -d "$relayer_root_dir" ];
then
echo "Relayer seems to be already setup. Skipping git fetch"
else
git clone https://github.com/Snowfork/snowbridge $relayer_root_dir
git clone https://github.com/moondance-labs/snowbridge $relayer_root_dir
pushd $relayer_root_dir
git fetch && git checkout $RELAYER_TAG
popd
Expand Down
4 changes: 3 additions & 1 deletion test/scripts/bridge/generate-contract-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ pnpm generateContracts "$output_dir/contracts.json" > /dev/null
popd > /dev/null

# Output the file so that invoker can read it
cat "$output_dir/contracts.json"
contract_output=$(cat "$output_dir/contracts.json")

echo "{ \"data\": $contract_output, \"ethereum_key\": \"$ethereum_key\" }"
12 changes: 10 additions & 2 deletions test/scripts/bridge/set-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_helpers_dir="$web_dir/packages/test-helpers"
relay_dir="$relayer_root_dir/relayer"
relay_bin="$relay_dir/build/snowbridge-relay"

RELAYER_TAG="relayer-v1.0.30" # we will need to investigate if this is right
RELAYER_TAG="demo-v1.0.30-tanssi" # TODO: Demo tag please change
GETH_TAG="v1.14.11" # We will need to investigate if this is right
LODESTAR_TAG="v1.19.0"

Expand Down Expand Up @@ -96,10 +96,18 @@ export EXCHANGE_RATE="${EXCHANGE_RATE:-2500000000000000}"
export DELIVERY_COST="${DELIVERY_COST:-10000000000}"
export FEE_MULTIPLIER="${FEE_MULTIPLIER:-1000000000000000000}"


## Vault
export BRIDGE_HUB_INITIAL_DEPOSIT="${ETH_BRIDGE_HUB_INITIAL_DEPOSIT:-10000000000000000000}"

## Message passing
export PRIMARY_GOVERNANCE_CHANNEL_ID="0x0000000000000000000000000000000000000000000000000000000000000001"
# Execution relay account (//ExecutionRelay 5CFNWKMFPsw5Cs2Teo6Pvg7rWyjKiFfqPZs8U4MZXzMYFwXL in testnet)
execution_relayer_assethub_pub_key="${EXECUTION_RELAYER_PUB_KEY:-0x08228efd065c58a043da95c8bf177659fc587643e71e7ed1534666177730196f}"
# Funded ethereum key
ethereum_key="0x5e002a1af63fd31f1c25258f3082dc889762664cb8f218d86da85dff8b07b342"
# Above key's address
ethereum_address="90A987B944Cb1dCcE5564e5FDeCD7a54D3de27Fe"


address_for() {
jq -r ".contracts.${1}.address" "$output_dir/contracts.json"
Expand Down
18 changes: 18 additions & 0 deletions test/scripts/bridge/setup-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ config_relayer() {
| .source.beacon.datastore.location = $data_store_dir
' \
$assets_dir/beacon-relay.json >$output_dir/beacon-relay.json


# Configure execution relay for starlight
jq \
--arg eth_endpoint_ws $eth_endpoint_ws \
--arg k1 "$(address_for GatewayProxy)" \
--arg relay_chain_endpoint $RELAYCHAIN_ENDPOINT \
--arg channelID $PRIMARY_GOVERNANCE_CHANNEL_ID \
--arg data_store_dir $data_store_dir \
'
.source.ethereum.endpoint = $eth_endpoint_ws
| .source.contracts.Gateway = $k1
| .source."channel-id" = $channelID
| .source.beacon.datastore.location = $data_store_dir
| .sink.parachain.endpoint = $relay_chain_endpoint
| .schedule.id = 0
' \
$assets_dir/execution-relay.json >$output_dir/execution-relay.json
}

write_beacon_checkpoint() {
Expand Down
14 changes: 14 additions & 0 deletions test/scripts/bridge/start-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ start_relayer() {
done
) &
echo "beacon_relay=$!" >> $artifacts_dir/daemons.pid

# Launch execution relay
(
: >$output_dir/execution-relay.log
while :; do
echo "Starting execution relay at $(date)"
"${relay_bin}" run execution \
--config $output_dir/execution-relay.json \
--substrate.private-key "//ExecutionRelay" \
>>"$logs_dir"/execution-relay.log 2>&1 || true
sleep 20
done
) &
echo "execution_relay=$!" >> $artifacts_dir/daemons.pid
}

echo "start relayers only!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { ApiPromise, Keyring } from "@polkadot/api";
import { spawn, exec } from "node:child_process";
import { signAndSendAndInclude, waitSessions } from "../../util/block.ts";
import { ethers } from "ethers";
import { decodeAddress } from "@polkadot/util-crypto";
import { u8aToHex } from "@polkadot/util";

// Change this if we change the storage parameter in runtime
const GATEWAY_STORAGE_KEY = "0xaed97c7854d601808b98ae43079dafb3";

function execCommand(command: string, options?) {
return new Promise((resolve, reject) => {
Expand All @@ -26,6 +31,13 @@ describeSuite({
let relayerChildProcess;
let alice;
let beefyClientDetails;
let gatewayProxyAddress;
let gatewayDetails;

let ethereumWallet;

let operatorAccount;
let operatorNimbusKey;

beforeAll(async () => {
relayApi = context.polkadotJs("Tanssi-relay");
Expand All @@ -36,11 +48,21 @@ describeSuite({
const keyring = new Keyring({ type: "sr25519" });
alice = keyring.addFromUri("//Alice", { name: "Alice default" });
const beaconRelay = keyring.addFromUri("//BeaconRelay", { name: "Beacon relay default" });
const executionRelay = keyring.addFromUri("//ExecutionRelay", { name: "Execution relay default" });

const txHash = await relayApi.tx.balances
.transferAllowDeath(beaconRelay.address, 1_000_000_000_000)
// Operator keys
operatorAccount = keyring.addFromUri("//" + "Bob", { name: "COLLATOR" + " ACCOUNT" });
operatorNimbusKey = keyring.addFromUri("//" + "COLLATOR_NIMBUS", { name: "COLLATOR" + " NIMBUS" });

await relayApi.tx.session.setKeys(u8aToHex(operatorNimbusKey), []).signAndSend(operatorAccount);

const fundingTxHash = await relayApi.tx.utility
.batch([
relayApi.tx.balances.transferAllowDeath(beaconRelay.address, 1_000_000_000_000),
relayApi.tx.balances.transferAllowDeath(executionRelay.address, 1_000_000_000_000),
])
.signAndSend(alice);
console.log("Transferred money to beacon relay", txHash.toHex());
console.log("Transferred money to relayers", fundingTxHash.toHex());

ethereumNodeChildProcess = spawn("./scripts/bridge/start-ethereum-node.sh", {
shell: true,
Expand All @@ -67,8 +89,22 @@ describeSuite({
const contractInfoData = JSON.parse(
<string>(await execCommand("./scripts/bridge/generate-contract-info.sh")).stdout
);
console.log("BeefyClient contract address is:", contractInfoData.contracts.BeefyClient.address);
beefyClientDetails = contractInfoData.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:", contractInfoData.data.contracts.GatewayProxy.address);
gatewayProxyAddress = contractInfoData.data.contracts.GatewayProxy.address;
gatewayDetails = contractInfoData.data.contracts.Gateway;

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);

const initialBeaconUpdate = JSON.parse(
<string>(
Expand Down Expand Up @@ -138,6 +174,44 @@ describeSuite({
},
});

it({
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 rawValidators = [
u8aToHex(operatorAccount.addressRaw),
"0x7894567890123456789012345678901234567890123456789012345678901234",
"0x4564567890123456789012345678901234567890123456789012345678901234",
];

try {
const tx = await gatewayContract.sendOperatorsData(rawValidators, 1);
await tx.wait();
} catch (error) {
throw new Error(`Failed to send operator data: ${error.message}`, error.code);
}

// wait some time for the data to be relayed
await waitSessions(context, relayApi, 2, null, "Tanssi-relay");

const externalValidators = await relayApi.query.externalValidators.externalValidators();
expect(externalValidators).to.not.deep.eq(externalValidatorsBefore);

const externalValidatorsHex = externalValidators.toJSON().map((x) => {
return u8aToHex(decodeAddress(x));
});

expect(externalValidatorsHex).to.deep.eq(rawValidators);

const sessionValidators = await relayApi.query.session.validators();
expect(sessionValidators.includes(operatorNimbusKey));
},
});

afterAll(async () => {
console.log("Cleaning up");
if (ethereumNodeChildProcess) {
Expand Down

0 comments on commit b6f46d7

Please sign in to comment.