forked from polkawallet-io/bridge
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathparallel.spec.ts
More file actions
115 lines (91 loc) · 3.77 KB
/
parallel.spec.ts
File metadata and controls
115 lines (91 loc) · 3.77 KB
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
import { firstValueFrom } from "rxjs";
import { ApiProvider } from "../api-provider";
import { chains, ChainName } from "../configs";
import { Bridge } from "..";
import { KintsugiAdapter } from "./interlay";
import { HeikoAdapter } from "./parallel";
import { buildTestTxWithConfigData } from "../utils/shared-spec-methods";
// helper method for getting balances, configs, fees, and constructing xcm extrinsics
async function runMyTestSuite(testAccount: string, bridge: Bridge, from: ChainName, to: ChainName, token: string) {
const {fromBalance, toBalance, inputConfig, destFee, tx} = await buildTestTxWithConfigData(testAccount, bridge, from, to, token);
// from balance prints/checks
console.log(
`balance ${token}: free-${fromBalance.free.toNumber()} locked-${fromBalance.locked.toNumber()} available-${fromBalance.available.toNumber()}`
);
expect(fromBalance.available.toNumber()).toBeGreaterThanOrEqual(0);
expect(fromBalance.free.toNumber()).toBeGreaterThanOrEqual(
fromBalance.available.toNumber()
);
expect(fromBalance.free.toNumber()).toEqual(
fromBalance.locked.add(fromBalance.available).toNumber()
);
// toBalance prints/checks
console.log(
`balance at destination ${token}: free-${toBalance.free.toNumber()} locked-${toBalance.locked.toNumber()} available-${toBalance.available.toNumber()}`
);
// inputConfig prints/checks
console.log(
`inputConfig: min-${inputConfig.minInput.toNumber()} max-${inputConfig.maxInput.toNumber()} ss58-${
inputConfig.ss58Prefix
} estimateFee-${inputConfig.estimateFee}`
);
expect(inputConfig.minInput.toNumber()).toBeGreaterThan(0);
expect(inputConfig.maxInput.toNumber()).toBeLessThanOrEqual(
fromBalance.available.toNumber()
);
// destFee prints/checks
console.log(
`destFee: fee-${destFee.balance.toNumber()} ${destFee.token}`
);
expect(destFee.balance.toNumber()).toBeGreaterThan(0);
// tx method & params checks
expect(tx.method.section).toEqual("xTokens");
expect(tx.args.length).toEqual(4);
expect(tx.method.method).toEqual("transfer");
};
describe.skip("parallel-adapter should work", () => {
jest.setTimeout(30000);
// alice
const testAccount = "hJKzPoi3MQnSLvbShxeDmzbtHncrMXe5zwS3Wa36P6kXeNpcv";
const provider = new ApiProvider();
async function connect(chains: ChainName[]) {
return firstValueFrom(provider.connectFromChain(chains, undefined));
}
test("connect parallel-heiko to do xcm", async () => {
const fromChains = ["heiko", "kintsugi"] as ChainName[];
await connect(fromChains);
const heiko = new HeikoAdapter();
const kintsugi = new KintsugiAdapter();
await heiko.setApi(provider.getApi(fromChains[0]));
await kintsugi.setApi(provider.getApi(fromChains[1]));
const bridge = new Bridge({
adapters: [heiko, kintsugi],
});
expect(
bridge.router.getDestinationChains({
from: chains.heiko,
token: "KBTC",
}).length
).toEqual(1);
await runMyTestSuite(testAccount, bridge, "heiko", "kintsugi", "KBTC");
});
// in preparation for later addition of parallel <-> interlay XCM
// test("connect parallel to do xcm", async () => {
// const fromChains = ["parallel", "interlay"] as ChainName[];
// await connect(fromChains);
// const parallel = new ParallelAdapter();
// const interlay = new InterlayAdapter();
// await parallel.setApi(provider.getApi(fromChains[0]));
// await interlay.setApi(provider.getApi(fromChains[1]));
// const bridge = new Bridge({
// adapters: [parallel, interlay],
// });
// expect(
// bridge.router.getDestinationChains({
// from: chains.interlay,
// token: "IBTC",
// }).length
// ).toEqual(1);
// await runMyTestSuite(testAccount, bridge, "parallel", "interlay", "IBTC");
// });
});