Skip to content

Commit

Permalink
connectHorizontal open any channel (#689)
Browse files Browse the repository at this point in the history
* connectHorizontal open any channel

* filter itself
  • Loading branch information
ermalkaleci authored Mar 11, 2024
1 parent 654a530 commit e23208c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/xcm/horizontal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@ export const connectHorizontal = async (parachains: Record<number, Blockchain>)
}
}
})

const hrmpHeads = await chain.head.read('BTreeMap<u32, H256>', meta.query.parachainSystem.lastHrmpMqcHeads)
if (hrmpHeads && !process.env.DISABLE_AUTO_HRMP) {
const existingChannels = Array.from(hrmpHeads.keys()).map((x) => x.toNumber())
for (const paraId of Object.keys(parachains).filter((x) => x !== id)) {
if (!existingChannels.includes(Number(paraId))) {
chain.submitHorizontalMessages(Number(paraId), [])
}
}
}
}
}
30 changes: 30 additions & 0 deletions packages/e2e/src/__snapshots__/connect-horizontal.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`connectHorizontal > connectHorizontal opens channel > system events 1`] = `
[
{
"data": {
"messageHash": "(hash)",
},
"method": "XcmpMessageSent",
"section": "xcmpQueue",
},
]
`;

exports[`connectHorizontal > connectHorizontal opens channel > system events 2`] = `
[
{
"data": {
"error": "TooExpensive",
"messageHash": "(hash)",
"weight": {
"proofSize": 0,
"refTime": 600000000,
},
},
"method": "Fail",
"section": "xcmpQueue",
},
]
`;
69 changes: 69 additions & 0 deletions packages/e2e/src/connect-horizontal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { connectHorizontal } from '@acala-network/chopsticks-core/xcm/horizontal.js'
import { describe, it } from 'vitest'

import { checkSystemEvents, setupContext, testingPairs } from './helper.js'
import networks from './networks.js'

describe('connectHorizontal', () => {
it('connectHorizontal opens channel', async () => {
const { alice } = testingPairs()
const acala = await networks.acala({ blockNumber: 5729464 })
await acala.dev.setStorage({
System: {
Account: [[[alice.address], { providers: 1, data: { free: 1000e12 } }]],
},
})
const zeitgeist = await setupContext({
endpoint: 'wss://zeitgeist-rpc.dwellir.com',
blockNumber: 5084336,
db: !process.env.RUN_TESTS_WITHOUT_DB ? 'e2e-tests-db.sqlite' : undefined,
})

await connectHorizontal({
2000: acala.chain,
2092: zeitgeist.chain,
})

await acala.dev.newBlock()
await zeitgeist.dev.newBlock()

// This tx will be sent to Zeitgeist and fail but it's fine for this test as we only want to test the connection
await acala.api.tx.xTokens
.transfer(
{
Token: 'ACA',
},
1e12,
{
V3: {
parents: 1,
interior: {
X2: [
{
Parachain: 2092,
},
{
AccountId32: {
id: alice.addressRaw,
},
},
],
},
},
},
{
Unlimited: null,
},
)
.signAndSend(alice)

await acala.dev.newBlock()
await checkSystemEvents(acala, 'xcmpQueue', 'XcmpMessageSent').toMatchSnapshot()

await zeitgeist.dev.newBlock()
await checkSystemEvents(zeitgeist, 'xcmpQueue', 'Fail').toMatchSnapshot()

await acala.teardown()
await zeitgeist.teardown()
})
})

0 comments on commit e23208c

Please sign in to comment.