Skip to content

Commit

Permalink
Add test using snowbridge message
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Nov 8, 2024
1 parent f6511b6 commit 153c28a
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions test/suites/dev-tanssi-relay/slashes/test_slashes_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { jumpToSession } from "../../../util/block";

describeSuite({
id: "DTR1801",
title: "Babe offences should trigger a slash",
title: "Test slashes are being sent to ethereum using bridge",
foundationMethods: "dev",
testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;
Expand All @@ -17,17 +17,55 @@ describeSuite({
});
it({
id: "E01",
title: "Babe offences trigger a slash",
title: "Test using rootTestSendMsgToEth",
test: async function () {
await jumpToSession(context, 1);

// Send test message to ethereum
const msgId = "0x0000000000000000000000000000000000000000000000000000000000000001";
const h256 = "0x0000000000000000000000000000000000000000000000000000000000000002";
const removeAliceFromInvulnerables = await polkadotJs.tx.sudo
.sudo(polkadotJs.tx.externalValidatorSlashes.rootTestSendMsgToEth(msgId, h256))
const payloadH256 = "0x0000000000000000000000000000000000000000000000000000000000000002";
const tx = await polkadotJs.tx.sudo
.sudo(polkadotJs.tx.externalValidatorSlashes.rootTestSendMsgToEth(msgId, payloadH256))
.signAsync(alice);
await context.createBlock([removeAliceFromInvulnerables]);
await context.createBlock([tx]);

// Should have resulted in a new "other" digest log being included in the block
const baseHeader = await polkadotJs.rpc.chain.getHeader();
const allLogs = baseHeader.digest.logs.map((x) => x.toJSON());
const otherLogs = allLogs.filter((x) => x["other"]);
expect(otherLogs.length).to.be.equal(1);
const logHex = otherLogs[0]["other"];

// Also a MessagesCommitted event with the same hash as the digest log
const events = await polkadotJs.query.system.events();
const ev1 = events.filter((a) => {
return a.event.method == "MessagesCommitted";
});
expect(ev1.length).to.be.equal(1);
const ev1Data = ev1[0].event.data[0].toJSON();

// logHex == 0x00 + ev1Data
// Example:
// logHex: 0x0064cf0ef843ad5a26c2cc27cf345fe0fd8b72cd6297879caa626c4d72bbe4f9b0
// ev1Data: 0x64cf0ef843ad5a26c2cc27cf345fe0fd8b72cd6297879caa626c4d72bbe4f9b0
const prefixedEv1Data = `0x00${ev1Data.slice(2)}`;
expect(prefixedEv1Data).to.be.equal(logHex);
},
});

it({
id: "E02",
title: "Test using ethereumSystem.upgrade",
test: async function () {
await jumpToSession(context, 1);

// Send test message to ethereum
const implAddress = "0x0000000000000000000000000000000000000001";
const implCodeHash = "0x0000000000000000000000000000000000000000000000000000000000000002";
const tx = await polkadotJs.tx.sudo
.sudo(polkadotJs.tx.ethereumSystem.upgrade(implAddress, implCodeHash, null))
.signAsync(alice);
await context.createBlock([tx]);

// Should have resulted in a new "other" digest log being included in the block
const baseHeader = await polkadotJs.rpc.chain.getHeader();
Expand Down

0 comments on commit 153c28a

Please sign in to comment.