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

connectHorizontal open any channel #689

Merged
merged 2 commits into from
Mar 11, 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
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to avoid env in the core package. they are global variables so all the reason to avoid global variables applies.
we should just pass arguments into here, and should be the cli package to handle envs. also need to document them

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we have a few places when we use env, we need to address them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
})
})
Loading