Skip to content

Commit 7666f70

Browse files
committed
WETH integration test
1 parent 094babf commit 7666f70

20 files changed

+365
-220
lines changed

integration-tests/chopsticks/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ To install dependencies:
66
bun install
77
```
88

9+
```bash
10+
bun papi
11+
```
12+
913
To start the chains:
1014

1115
```bash

integration-tests/chopsticks/bun.lockb

100644100755
File mode changed.

integration-tests/chopsticks/overrides/polimec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { INITIAL_BALANCES } from '@/constants';
2-
import { Accounts, Assets } from '@/types';
2+
import { Accounts, Asset } from '@/types';
33

44
export const POLIMEC_WASM =
55
'../../target/release/wbuild/polimec-runtime/polimec_runtime.compact.compressed.wasm';
@@ -21,19 +21,19 @@ export const polimec_storage = {
2121
ForeignAssets: {
2222
Account: [
2323
[
24-
[Assets.USDC, Accounts.BOB],
24+
[Asset.USDC, Accounts.BOB],
2525
{
2626
balance: INITIAL_BALANCES.USDC,
2727
},
2828
],
2929
[
30-
[Assets.USDT, Accounts.BOB],
30+
[Asset.USDT, Accounts.BOB],
3131
{
3232
balance: INITIAL_BALANCES.USDT,
3333
},
3434
],
3535
[
36-
[Assets.DOT, Accounts.BOB],
36+
[Asset.DOT, Accounts.BOB],
3737
{
3838
balance: INITIAL_BALANCES.DOT,
3939
},

integration-tests/chopsticks/overrides/polkadot-hub.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { INITIAL_BALANCES } from '@/constants';
2-
import { Accounts, Assets } from '@/types';
2+
import { Accounts, Asset } from '@/types';
33

44
export const polkadot_hub_storage = {
55
System: {
@@ -18,24 +18,17 @@ export const polkadot_hub_storage = {
1818
Assets: {
1919
Account: [
2020
[
21-
[Assets.USDT, Accounts.ALICE],
21+
[Asset.USDT, Accounts.ALICE],
2222
{
2323
balance: INITIAL_BALANCES.USDT,
2424
},
2525
],
2626
[
27-
[Assets.USDC, Accounts.ALICE],
27+
[Asset.USDC, Accounts.ALICE],
2828
{
2929
balance: INITIAL_BALANCES.USDC,
3030
},
3131
],
32-
[
33-
[Assets.UNKNOWN, Accounts.ALICE],
34-
{
35-
balance: INITIAL_BALANCES.USDT,
36-
},
37-
],
3832
],
3933
},
40-
// TODO: Add the foreignAssets storage to give to ALICE WETH = INITIAL_BALANCES.WETH
4134
} as const;

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

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { DERIVE_PATHS } from '@/constants';
2-
import type { Accounts, ChainClient, ChainToDefinition, Chains } from '@/types';
2+
import {
3+
type Accounts,
4+
type Asset,
5+
AssetLocation,
6+
type AssetSourceRelation,
7+
type ChainClient,
8+
type ChainToDefinition,
9+
Chains,
10+
} from '@/types';
311
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
412
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from '@polkadot-labs/hdkd-helpers';
513
import type { PolkadotSigner, TypedApi } from 'polkadot-api';
@@ -67,19 +75,31 @@ export abstract class BaseChainManager {
6775
return events[0]?.payload.actual_fee || 0n;
6876
}
6977

70-
async getNativeBalanceOf(account: Accounts) {
71-
const api = this.getApi(this.getChainType());
72-
const balance = await api.query.System.Account.getValue(account);
73-
return balance.data.free;
78+
// Make sure to override this in the other managers
79+
abstract getAssetSourceRelation(asset: Asset): AssetSourceRelation | undefined;
80+
81+
async getAssetBalanceOf(account: Accounts, asset: Asset): Promise<bigint> {
82+
const api = this.getApi(Chains.PolkadotHub);
83+
const asset_source_relation = this.getAssetSourceRelation(asset);
84+
const asset_location = AssetLocation(asset, asset_source_relation);
85+
const account_balances_result = await api.apis.FungiblesApi.query_account_balances(account);
86+
87+
if (account_balances_result.success === true && account_balances_result.value.type === 'V4') {
88+
const assets = account_balances_result.value.value;
89+
for (const asset of assets) {
90+
if (asset.id === asset_location && asset.fun.type === 'Fungible') {
91+
return asset.fun.value;
92+
}
93+
}
94+
}
95+
return 0n;
7496
}
7597

7698
// @ts-expect-error - TODO: Not sure which is the correct type for this
7799
abstract getXcmPallet();
78100

79101
abstract getChainType(): Chains;
80102

81-
abstract getAssetBalanceOf(account: Accounts, asset: number): Promise<bigint>;
82-
83103
abstract connect(): void;
84104

85105
abstract disconnect(): void;

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Accounts, type Assets, Chains } from '@/types';
1+
import { type Accounts, Asset, AssetSourceRelation, Chains } from '@/types';
22
import { polimec } from '@polkadot-api/descriptors';
33
import { createClient } from 'polkadot-api';
44
import { getWsProvider } from 'polkadot-api/ws-provider/web';
@@ -34,10 +34,17 @@ export class PolimecManager extends BaseChainManager {
3434
return '58kXueYKLr5b8yCeY3Gd1nLQX2zSJLXjfMzTAuksNq25CFEL' as Accounts;
3535
}
3636

37-
async getAssetBalanceOf(account: Accounts, asset: Assets) {
38-
const api = this.getApi(Chains.Polimec);
39-
const balance = await api.query.ForeignAssets.Account.getValue(asset, account);
40-
return balance?.balance || 0n;
37+
getAssetSourceRelation(asset: Asset): AssetSourceRelation | undefined {
38+
switch (asset) {
39+
case Asset.DOT:
40+
return AssetSourceRelation.Parent;
41+
case Asset.USDT:
42+
return AssetSourceRelation.Sibling;
43+
case Asset.USDC:
44+
return AssetSourceRelation.Sibling;
45+
case Asset.WETH:
46+
return undefined;
47+
}
4148
}
4249

4350
async getXcmFee() {

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

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { type Accounts, type Assets, Chains } from '@/types';
1+
import { type Accounts, Asset, AssetLocation, AssetSourceRelation, Chains } from '@/types';
22
import { pah } from '@polkadot-api/descriptors';
3+
import { XcmV3MultiassetFungibility } from '@polkadot-api/descriptors/dist/common-types';
34
import { createClient } from 'polkadot-api';
45
import { getWsProvider } from 'polkadot-api/ws-provider/web';
56
import { BaseChainManager } from './BaseManager';
@@ -30,10 +31,17 @@ export class PolkadotHubManager extends BaseChainManager {
3031
return api.tx.PolkadotXcm;
3132
}
3233

33-
async getAssetBalanceOf(account: Accounts, asset: Assets) {
34-
const api = this.getApi(Chains.PolkadotHub);
35-
const balance = await api.query.Assets.Account.getValue(asset, account);
36-
return balance?.balance || 0n;
34+
getAssetSourceRelation(asset: Asset): AssetSourceRelation | undefined {
35+
switch (asset) {
36+
case Asset.DOT:
37+
return AssetSourceRelation.Parent;
38+
case Asset.USDT:
39+
return AssetSourceRelation.Self;
40+
case Asset.USDC:
41+
return AssetSourceRelation.Self;
42+
case Asset.WETH:
43+
return undefined;
44+
}
3745
}
3846

3947
async getSwapCredit() {

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Accounts, Chains } from '@/types';
1+
import { type Accounts, Asset, AssetSourceRelation, Chains } from '@/types';
22
import { polkadot } from '@polkadot-api/descriptors';
33
import { createClient } from 'polkadot-api';
44
import { getWsProvider } from 'polkadot-api/ws-provider/web';
@@ -30,8 +30,17 @@ export class PolkadotManager extends BaseChainManager {
3030
return api.tx.XcmPallet;
3131
}
3232

33-
async getAssetBalanceOf(_account: Accounts, _asset: number): Promise<bigint> {
34-
throw new Error('Polkadot does not support assets');
33+
getAssetSourceRelation(asset: Asset): AssetSourceRelation | undefined {
34+
switch (asset) {
35+
case Asset.DOT:
36+
return AssetSourceRelation.Self;
37+
case Asset.USDT:
38+
return undefined;
39+
case Asset.USDC:
40+
return undefined;
41+
case Asset.WETH:
42+
return undefined;
43+
}
3544
}
3645

3746
async getXcmFee() {

integration-tests/chopsticks/src/setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class ChainSetup {
8080
'wasm-override': POLIMEC_WASM,
8181
'import-storage': polimec_storage,
8282
'build-block-mode': BuildBlockMode.Instant,
83+
'runtime-log-level': 3,
8384
});
8485
}
8586

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

+37-27
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TRANSFER_AMOUNTS } from '@/constants';
33
import { createChainManager } from '@/managers/Factory';
44
import { ChainSetup } from '@/setup';
55
import { HubToPolimecTransfer } from '@/transfers/HubToPolimec';
6-
import { Accounts, Assets, Chains } from '@/types';
6+
import { Accounts, Asset, AssetSourceRelation, Chains } from '@/types';
77

88
describe('Polkadot Hub -> Polimec Transfer Tests', () => {
99
const sourceManager = createChainManager(Chains.PolkadotHub);
@@ -18,33 +18,43 @@ describe('Polkadot Hub -> Polimec Transfer Tests', () => {
1818
});
1919
afterAll(async () => await chainSetup.cleanup());
2020

21-
test('Send DOT to Polimec', () =>
22-
transferTest.testTransfer({
23-
amount: TRANSFER_AMOUNTS.NATIVE,
24-
account: Accounts.ALICE,
25-
asset: Assets.DOT,
26-
}));
27-
28-
test('Send USDt to Polimec', () =>
29-
transferTest.testTransfer({
30-
amount: TRANSFER_AMOUNTS.TOKENS,
31-
account: Accounts.ALICE,
32-
asset: Assets.USDT,
33-
}));
34-
35-
test('Send USDC to Polimec', () =>
36-
transferTest.testTransfer({
37-
amount: TRANSFER_AMOUNTS.TOKENS,
38-
account: Accounts.ALICE,
39-
asset: Assets.USDC,
40-
}));
41-
42-
test('Send Unknown Asset to Polimec', () =>
43-
expect(() =>
21+
test(
22+
'Send DOT to Polimec',
23+
() =>
4424
transferTest.testTransfer({
45-
amount: TRANSFER_AMOUNTS.TOKENS,
25+
amount: TRANSFER_AMOUNTS.NATIVE,
4626
account: Accounts.ALICE,
47-
asset: Assets.UNKNOWN,
27+
asset: Asset.DOT,
28+
assetSourceRelation: AssetSourceRelation.Parent,
4829
}),
49-
).toThrow());
30+
{ timeout: 25000 },
31+
);
32+
//
33+
// test('Send USDT to Polimec', () =>
34+
// transferTest.testTransfer({
35+
// amount: TRANSFER_AMOUNTS.TOKENS,
36+
// account: Accounts.ALICE,
37+
// asset: Asset.USDT,
38+
// assetSourceRelation: AssetSourceRelation.Self,
39+
// }), {timeout: 25000});
40+
//
41+
// test('Send USDC to Polimec', () =>
42+
// transferTest.testTransfer({
43+
// amount: TRANSFER_AMOUNTS.TOKENS,
44+
// account: Accounts.ALICE,
45+
// asset: Asset.USDC,
46+
// assetSourceRelation: AssetSourceRelation.Self,
47+
// }), {timeout: 25000});
48+
49+
// test(
50+
// 'Send WETH to Polimec',
51+
// () =>
52+
// transferTest.testTransfer({
53+
// amount: TRANSFER_AMOUNTS.BRIDGED,
54+
// account: Accounts.ALICE,
55+
// asset: Asset.WETH,
56+
// assetSourceRelation: undefined,
57+
// }),
58+
// { timeout: 25000 },
59+
// );
5060
});

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

+34-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createChainManager } from '@/managers/Factory';
44
import { polimec_storage } from '@/polimec';
55
import { ChainSetup } from '@/setup';
66
import { PolimecToHubTransfer } from '@/transfers/PolimecToHub';
7-
import { Accounts, Assets, Chains } from '@/types';
7+
import { Accounts, Asset, AssetSourceRelation, Chains } from '@/types';
88

99
describe('Polimec -> Hub Transfer Tests', () => {
1010
const sourceManager = createChainManager(Chains.Polimec);
@@ -19,24 +19,39 @@ describe('Polimec -> Hub Transfer Tests', () => {
1919
});
2020
afterAll(async () => await chainSetup.cleanup());
2121

22-
test('Send USDC to Hub', () =>
23-
transferTest.testTransfer({
24-
amount: TRANSFER_AMOUNTS.TOKENS,
25-
account: Accounts.BOB,
26-
asset: Assets.USDC,
27-
}));
22+
test(
23+
'Send USDC to Hub',
24+
() =>
25+
transferTest.testTransfer({
26+
amount: TRANSFER_AMOUNTS.TOKENS,
27+
account: Accounts.BOB,
28+
asset: Asset.USDC,
29+
assetSourceRelation: AssetSourceRelation.Sibling,
30+
}),
31+
{ timeout: 25000 },
32+
);
2833

29-
test('Send USDt to Hub', () =>
30-
transferTest.testTransfer({
31-
amount: TRANSFER_AMOUNTS.TOKENS,
32-
account: Accounts.BOB,
33-
asset: Assets.USDT,
34-
}));
34+
test(
35+
'Send USDT to Hub',
36+
() =>
37+
transferTest.testTransfer({
38+
amount: TRANSFER_AMOUNTS.TOKENS,
39+
account: Accounts.BOB,
40+
asset: Asset.USDT,
41+
assetSourceRelation: AssetSourceRelation.Sibling,
42+
}),
43+
{ timeout: 25000 },
44+
);
3545

36-
test('Send DOT to Hub', () =>
37-
transferTest.testTransfer({
38-
amount: TRANSFER_AMOUNTS.NATIVE,
39-
account: Accounts.BOB,
40-
asset: Assets.DOT,
41-
}));
46+
test(
47+
'Send DOT to Hub',
48+
() =>
49+
transferTest.testTransfer({
50+
amount: TRANSFER_AMOUNTS.NATIVE,
51+
account: Accounts.BOB,
52+
asset: Asset.DOT,
53+
assetSourceRelation: AssetSourceRelation.Parent,
54+
}),
55+
{ timeout: 25000 },
56+
);
4257
});

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TRANSFER_AMOUNTS } from '@/constants';
33
import { createChainManager } from '@/managers/Factory';
44
import { ChainSetup } from '@/setup';
55
import { PolkadotToPolimecTransfer } from '@/transfers/PolkadotToPolimec';
6-
import { Accounts, Assets, Chains } from '@/types';
6+
import { Accounts, Asset, Chains } from '@/types';
77

88
describe('Polkadot -> Polimec Transfer Tests', () => {
99
const chainSetup = new ChainSetup();
@@ -19,10 +19,14 @@ describe('Polkadot -> Polimec Transfer Tests', () => {
1919
});
2020
afterAll(async () => await chainSetup.cleanup());
2121

22-
test('Send DOT to Polimec', () =>
23-
transferTest.testTransfer({
24-
amount: TRANSFER_AMOUNTS.NATIVE,
25-
account: Accounts.ALICE,
26-
asset: Assets.DOT,
27-
}));
22+
test(
23+
'Send DOT to Polimec',
24+
() =>
25+
transferTest.testTransfer({
26+
amount: TRANSFER_AMOUNTS.NATIVE,
27+
account: Accounts.ALICE,
28+
asset: Asset.DOT,
29+
}),
30+
{ timeout: 25000 },
31+
);
2832
});

0 commit comments

Comments
 (0)