Skip to content

Commit 22f81ae

Browse files
authored
🐛 Update the integration tests (#464)
## What? This pull request includes several updates and improvements to the `integration-tests/chopsticks` project. The main changes involve updating dependencies, enhancing test cases, and cleaning up the codebase by removing unnecessary console logs and imports. ### Dependency Updates: * Updated `@acala-network/chopsticks` to version `1.0.3` and `@polkadot-labs/hdkd` to version `0.0.12` in `package.json`. * Updated `polkadot-api` dependency to version `^1.9.3` in `package.json`. ### Test Case Enhancements: * Re-enabled previously commented-out test cases for transferring USDC, USDT, and DOT to the Hub in `polimec.test.ts`. ### Code Cleanup: * Removed unnecessary console logs from various files, including `PolimecManager.ts`, `BaseTransfer.ts`, `BridgeToPolimec.ts`, `HubToPolimec.ts`, `PolimecToHub.ts`, and `PolkadotToPolimec.ts`. [[1]](diffhunk://#diff-17504b68de01739408ba3271f1474bc42e5e8544b68aab412f359b1345b54fa2L77-R78) [[2]](diffhunk://#diff-5dd414351aca9c6251af3425bc64e3032d2da671fd96d6912c104be8e91a2c36L67) [[3]](diffhunk://#diff-d3f932bd8fa0e6df0cbaf55474b048e8008b43a22b2f502d1ea624fd1d0b9b7eL105-L107) [[4]](diffhunk://#diff-1e5c3625dda1821bb7716a768e632713bb3b4bdaeb8105f0e7fb92761aeec0a1R117) [[5]](diffhunk://#diff-a6b4d0706a66eb8e96a37d085dc9a5b248854854c12d437295efddba2ea5908dL49) [[6]](diffhunk://#diff-31316894b2f94a7e3245783d130ae173feb892061bbe6a5fdcacfb445f999004R124-L125) * Removed unused import `ETH_ADDRESS` from `polimec.ts`, `BridgeToPolimec.ts`, and `PolimecToHub.ts`. [[1]](diffhunk://#diff-b166cb800d57cb015c4fe852e382234955e8733273ff1d7352aa25bf45c81e79L1-R1) [[2]](diffhunk://#diff-d3f932bd8fa0e6df0cbaf55474b048e8008b43a22b2f502d1ea624fd1d0b9b7eL2-R2) [[3]](diffhunk://#diff-a6b4d0706a66eb8e96a37d085dc9a5b248854854c12d437295efddba2ea5908dL2) ### Documentation Update: * Added prerequisites and usage instructions to the `README.md` file in the `chopsticks` directory.
2 parents ec125d4 + b080d94 commit 22f81ae

13 files changed

+174
-152
lines changed
+24-13
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
1-
# chopsticks
1+
# XCM Integration Tests: Polkadot API x Chopsticks
2+
3+
## Prerequisites
4+
5+
- [Bun](https://bun.sh/docs/installation)
6+
7+
## Usage
28

39
To install dependencies:
410

511
```bash
612
bun install
713
```
814

15+
To generate the Chains descriptors:
16+
917
```bash
1018
bun papi
1119
```
1220

1321
> [!NOTE]
14-
> Sometimes you need to regenerate the Polimec descriptors. To do that, run:
22+
> If you need to regenerate the Polimec descriptors (e.g. you changed something on the Runtime). You can run:
1523
>
1624
> ```bash
25+
> bun papi
1726
> bun papi add polimec --wasm ../../target/release/wbuild/polimec-runtime/polimec_runtime.compact.compressed.wasm
1827
> ```
1928
20-
To start the chains:
21-
22-
```bash
23-
bun run dev
24-
```
29+
> [!NOTE]
30+
> If you need to regenerate the descriptors. You can delete the `.papi` folder and run:
31+
> ```bash
32+
> bun papi add polimec --wasm ../../target/release/wbuild/polimec-runtime/polimec_runtime.compact.compressed.wasm
33+
> bun papi add bridge -w wss://sys.ibp.network/bridgehub-polkadot
34+
> bun papi add pah -w wss://sys.ibp.network/statemint
35+
> bun papi add polkadot -w wss://rpc.ibp.network/polkadot
36+
> ```
2537
26-
To run the tests:
38+
To run all the tests:
2739
2840
```bash
2941
bun run test
3042
```
3143
44+
To run a specific test case, e.g Polkadot to Polimec:
3245

33-
> [!IMPORTANT]
34-
> TODO: Add:
35-
> - [ ] Polimec SA on AH: Add ETH balance to it in the Chopstick ovveride
36-
> - [ ] Polimec to Asset Hub: ETH transfer. This is a "normal" transfer_asset call.
37-
> - [ ] Polimec to Ethereum: ETH transfer. This is a bit more complex, example extrinsic: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fhydration.ibp.network#/extrinsics/decode/0x6b0d04010100a10f040801000007464a69c7e002020907040300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200130000e8890423c78a0204010002040816040d01000001010088ca48e3e1d0f1c50bd6b504e1312d21f5bd45ed147e3c30c77eb5e4d63bdc6310010102020907040300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000201090704081300010300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20004000d010204000103001501c1413e4178c38567ada8945a80351f7b849600
46+
```bash
47+
bun run test polkadot
48+
```

integration-tests/chopsticks/bun.lock

+111-93
Large diffs are not rendered by default.

integration-tests/chopsticks/overrides/polimec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { INITIAL_BALANCES, ETH_ADDRESS } from '@/constants';
1+
import { INITIAL_BALANCES } from '@/constants';
22
import { Accounts } from '@/types';
33

44
export const POLIMEC_WASM =

integration-tests/chopsticks/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"test": "env LOG_LEVEL=error bun test"
88
},
99
"devDependencies": {
10-
"@acala-network/chopsticks": "1.0.2",
10+
"@acala-network/chopsticks": "1.0.3",
1111
"@biomejs/biome": "1.9.4",
12-
"@polkadot-labs/hdkd": "0.0.11",
12+
"@polkadot-labs/hdkd": "0.0.12",
1313
"@types/bun": "latest"
1414
},
1515
"peerDependencies": {
1616
"typescript": "^5.7.3"
1717
},
1818
"dependencies": {
1919
"@polkadot-api/descriptors": "file:.papi/descriptors",
20-
"polkadot-api": "^1.9.0"
20+
"polkadot-api": "^1.9.3"
2121
}
2222
}

integration-tests/chopsticks/src/managers/PolimecManager.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ export class PolimecManager extends BaseChainManager {
7474
async getXcmFee() {
7575
const api = this.getApi(Chains.Polimec);
7676
const events = await api.event.PolkadotXcm.FeesPaid.pull();
77-
console.dir(events, { depth: null });
7877

79-
return events[0]?.payload.fees?.[0]?.fun?.value ?? 0n;
78+
return (events[0]?.payload.fees?.[0]?.fun?.value as bigint) ?? 0n;
8079
}
8180

8281
async getTransactionFee() {

integration-tests/chopsticks/src/setup.ts

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export class ChainSetup {
100100
'wasm-override': POLIMEC_WASM,
101101
'import-storage': polimec_storage,
102102
'build-block-mode': BuildBlockMode.Instant,
103-
'runtime-log-level': 5,
104103
});
105104
}
106105

integration-tests/chopsticks/src/tests/polimec.test.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,35 @@ describe('Polimec -> Hub Transfer Tests', () => {
1919
});
2020
afterAll(async () => await chainSetup.cleanup());
2121

22-
// test(
23-
// 'Send USDC to Hub',
24-
// () =>
25-
// transferTest.testTransfer({
26-
// account: Accounts.BOB,
27-
// assets: [[Asset.USDC, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Sibling]],
28-
// }),
29-
// { timeout: 25000 },
30-
// );
31-
//
32-
// test(
33-
// 'Send USDT to Hub',
34-
// () =>
35-
// transferTest.testTransfer({
36-
// account: Accounts.BOB,
37-
// assets: [[Asset.USDT, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Sibling]],
38-
// }),
39-
// { timeout: 25000 },
40-
// );
22+
test(
23+
'Send USDC to Hub',
24+
() =>
25+
transferTest.testTransfer({
26+
account: Accounts.BOB,
27+
assets: [[Asset.USDC, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Sibling]],
28+
}),
29+
{ timeout: 25000 },
30+
);
4131

42-
// test(
43-
// 'Send DOT to Hub',
44-
// () =>
45-
// transferTest.testTransfer({
46-
// account: Accounts.BOB,
47-
// assets: [[Asset.DOT, TRANSFER_AMOUNTS.NATIVE, AssetSourceRelation.Parent]],
48-
// }),
49-
// { timeout: 25000 },
50-
// );
32+
test(
33+
'Send USDT to Hub',
34+
() =>
35+
transferTest.testTransfer({
36+
account: Accounts.BOB,
37+
assets: [[Asset.USDT, TRANSFER_AMOUNTS.TOKENS, AssetSourceRelation.Sibling]],
38+
}),
39+
{ timeout: 25000 },
40+
);
41+
42+
test(
43+
'Send DOT to Hub',
44+
() =>
45+
transferTest.testTransfer({
46+
account: Accounts.BOB,
47+
assets: [[Asset.DOT, TRANSFER_AMOUNTS.NATIVE, AssetSourceRelation.Parent]],
48+
}),
49+
{ timeout: 25000 },
50+
);
5151

5252
test(
5353
'Send PLMC to Hub',

integration-tests/chopsticks/src/transfers/BaseTransfer.ts

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export abstract class BaseTransferTest {
6464
protected async verifyExecution() {
6565
const events = await this.destManager.getMessageQueueEvents();
6666

67-
console.dir(events, { depth: null });
6867
expect(events).not.toBeEmpty();
6968
expect(events).toBeArray();
7069
expect(events).toHaveLength(1);

integration-tests/chopsticks/src/transfers/BridgeToPolimec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'bun:test';
2-
import { DEFAULT_TOPIC, ETH_AMOUNT, FEE_AMOUNT, ETH_ADDRESS } from '@/constants';
2+
import { DEFAULT_TOPIC, ETH_ADDRESS, ETH_AMOUNT, FEE_AMOUNT } from '@/constants';
33
import type { BridgerHubManagaer } from '@/managers/BridgeHubManager';
44
import type { PolimecManager } from '@/managers/PolimecManager';
55
import type { PolkadotHubManager } from '@/managers/PolkadotHubManager';
@@ -102,9 +102,6 @@ export class BridgeToPolimecTransfer extends BaseTransferTest {
102102
(event) => event.type === 'ForeignAssets' && event.value.type === 'Issued',
103103
);
104104

105-
console.log('Issued Events on Destination: \n');
106-
console.dir(issuedEventsOnDest, { depth: null });
107-
108105
// TODO: Check why we have 3 events instead of 2 (ETH + DOT). Curently we have 3 events (ETH + DOT + DOT)
109106
expect(issuedEventsOnDest.length).toBe(3);
110107

integration-tests/chopsticks/src/transfers/HubToPolimec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class HubToPolimecTransfer extends BaseTransferTest {
2727
super(sourceManager, destManager);
2828
}
2929

30-
async executeTransfer({ account, assets }: TransferOptions) {
30+
async executeTransfer({ account, assets, fee_asset_item }: TransferOptions) {
3131
const [sourceBlock, destBlock] = await Promise.all([
3232
this.sourceManager.getBlockNumber(),
3333
this.destManager.getBlockNumber(),
@@ -39,6 +39,7 @@ export class HubToPolimecTransfer extends BaseTransferTest {
3939
toChain: Chains.Polimec,
4040
assets: versioned_assets,
4141
recv: account,
42+
fee_asset_item: fee_asset_item ?? 0,
4243
});
4344

4445
const api = this.sourceManager.getApi(Chains.PolkadotHub);
@@ -113,6 +114,7 @@ export class HubToPolimecTransfer extends BaseTransferTest {
113114
toChain: Chains.Polimec,
114115
assets: versioned_assets,
115116
recv: transferOptions.account,
117+
fee_asset_item: transferOptions.fee_asset_item ?? 0,
116118
});
117119

118120
let remoteFeeAssetId: XcmVersionedAssetId;

integration-tests/chopsticks/src/transfers/PolimecToHub.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect } from 'bun:test';
2-
import { INITIAL_BALANCES } from '@/constants';
32
import type { PolimecManager } from '@/managers/PolimecManager';
43
import type { PolkadotHubManager } from '@/managers/PolkadotHubManager';
54
import {
@@ -46,7 +45,6 @@ export class PolimecToHubTransfer extends BaseTransferTest {
4645
.getXcmPallet()
4746
.transfer_assets(data)
4847
.signAndSubmit(this.sourceManager.getSigner(account));
49-
console.dir(res, { depth: null });
5048

5149
expect(res.ok).toBeTrue();
5250
return { sourceBlock, destBlock };

integration-tests/chopsticks/src/transfers/PolkadotToPolimec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ export class PolkadotToPolimecTransfer extends BaseTransferTest {
121121
toChain: Chains.PolkadotHub,
122122
assets: versioned_assets,
123123
recv: transferOptions.account,
124+
fee_asset_item: transferOptions.fee_asset_item ?? 0,
124125
});
125-
console.dir(transferData, { depth: null, colors: true });
126126

127127
let remoteFeeAssetId: XcmVersionedAssetId;
128128
const lastAsset = unwrap(transferOptions.assets[0]);

integration-tests/chopsticks/src/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
type polimec,
1111
type polkadot,
1212
} from '@polkadot-api/descriptors';
13-
import { FixedSizeBinary, type PolkadotClient, type TypedApi } from 'polkadot-api';
14-
import { ETH_ADDRESS } from './constants';
13+
import type { PolkadotClient, TypedApi } from 'polkadot-api';
1514

1615
type Polimec = typeof polimec;
1716
type PolkadotHub = typeof pah;

0 commit comments

Comments
 (0)