-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpolkadotAssetHub.bridgeHub.spec.ts
144 lines (121 loc) · 4.61 KB
/
polkadotAssetHub.bridgeHub.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { setupNetworks, testingPairs, withExpect } from '@acala-network/chopsticks-testing';
import { NetworkContext } from '@acala-network/chopsticks-utils';
import { setTimeout } from 'timers/promises';
import { afterEach, beforeEach, expect, test } from 'vitest';
import { AssetTransferApi } from '../src/AssetTransferApi';
import { ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION } from '../src/consts';
const { checkSystemEvents } = withExpect(expect);
describe('Polkadot AssetHub <> Ethereum', () => {
const snowbridgeWETHLocation = {
parents: 2,
interior: {
X2: [
{ GlobalConsensus: { Ethereum: { chainId: 1 } } },
{ AccountKey20: { network: null, key: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' } },
],
},
};
let polkadotBridgeHub: NetworkContext;
let polkadotAssetHub: NetworkContext;
const { alice, alith } = testingPairs();
beforeEach(async () => {
const { polkadotBridgeHub1, polkadotAssetHub1 } = await setupNetworks({
polkadotBridgeHub1: {
endpoint: 'wss://bridge-hub-polkadot-rpc.dwellir.com',
db: './db.sqlite',
port: 8003,
},
polkadotAssetHub1: {
endpoint: 'wss://asset-hub-polkadot-rpc.dwellir.com',
db: './db.sqlite',
port: 8004,
},
});
polkadotBridgeHub = polkadotBridgeHub1;
polkadotAssetHub = polkadotAssetHub1;
}, 1000000);
afterEach(async () => {
await polkadotBridgeHub.teardown();
await polkadotAssetHub.teardown();
}, 1000000);
describe('XCM V3', () => {
const xcmVersion = 3;
test('Snowbridge WETH From AssetHub to Ethereum', async () => {
await polkadotAssetHub.dev.setStorage({
System: {
Account: [
[[alice.address], { providers: 1, data: { free: 10 * 1e12 } }], // DOT
],
},
ForeignAssets: {
Account: [[[snowbridgeWETHLocation, alice.address], { balance: 75000000000000 }]],
},
});
const assetTransferApi = new AssetTransferApi(polkadotAssetHub.api, 'asset-hub-polkadot', xcmVersion);
const tx = await assetTransferApi.createTransferTransaction(
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
[
`{"parents":"2","interior":{"X2":[{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}},{"AccountKey20":{"network":null,"key":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}]}}`,
],
['25000000000000'],
{
format: 'payload',
xcmVersion,
sendersAddr: alice.address,
},
);
const extrinsic = assetTransferApi.api.registry.createType('Extrinsic', { method: tx.tx.method }, { version: 4 });
await polkadotAssetHub.api.tx(extrinsic).signAndSend(alice);
await polkadotAssetHub.dev.newBlock();
await checkSystemEvents(polkadotAssetHub, 'polkadotXcm')
.redact({ redactKeys: new RegExp('messageId') })
.toMatchSnapshot('assetHub xcm message sent');
await setTimeout(10000);
await polkadotBridgeHub.dev.timeTravel(1);
await checkSystemEvents(polkadotBridgeHub, 'ethereumOutboundQueue')
.redact({ redactKeys: new RegExp('nonce') })
.toMatchSnapshot('bridgehub ethereum outbound queue events');
}, 200000);
});
describe('XCM V4', () => {
const xcmVersion = 4;
test('Snowbridge WETH From AssetHub to Ethereum', async () => {
await polkadotAssetHub.dev.setStorage({
System: {
Account: [
[[alice.address], { providers: 1, data: { free: 10 * 1e12 } }], // DOT
],
},
ForeignAssets: {
Account: [[[snowbridgeWETHLocation, alice.address], { balance: 75000000000000 }]],
},
});
const assetTransferApi = new AssetTransferApi(polkadotAssetHub.api, 'asset-hub-polkadot', xcmVersion);
const tx = await assetTransferApi.createTransferTransaction(
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
[
`{"parents":"2","interior":{"X2":[{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}},{"AccountKey20":{"network":null,"key":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}]}}`,
],
['25000000000000'],
{
format: 'payload',
xcmVersion,
sendersAddr: alice.address,
},
);
const extrinsic = assetTransferApi.api.registry.createType('Extrinsic', { method: tx.tx.method }, { version: 4 });
await polkadotAssetHub.api.tx(extrinsic).signAndSend(alice);
await polkadotAssetHub.dev.newBlock();
await checkSystemEvents(polkadotAssetHub, 'polkadotXcm')
.redact({ redactKeys: new RegExp('messageId') })
.toMatchSnapshot('assetHub xcm message sent');
await setTimeout(10000);
await polkadotBridgeHub.dev.timeTravel(1);
await checkSystemEvents(polkadotBridgeHub, 'ethereumOutboundQueue')
.redact({ redactKeys: new RegExp('nonce') })
.toMatchSnapshot('bridgehub ethereum outbound queue events');
}, 200000);
});
});