Skip to content

Commit

Permalink
test: added additional parachain to ethereum e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marshacb committed Jan 13, 2025
1 parent 2f1f93d commit 36909f4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 11 deletions.
6 changes: 3 additions & 3 deletions e2e-tests/bifrostPolkadot.ethereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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('Bifrost Polkadot <> Ethereum', () => {
const ethereumNetworkGlobalConsensusLocation = `{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`;
let bifrostPolkadot: NetworkContext;
let polkadotAssetHub: NetworkContext;
let polkadotBridgeHub: NetworkContext;
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('Bifrost Polkadot <> Ethereum', () => {
});

const tx = await assetTransferApi.createTransferTransaction(
ethereumNetworkGlobalConsensusLocation,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
['DOT', 'WETH.snow'],
['100000000000', '750000000000000'],
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Bifrost Polkadot <> Ethereum', () => {
});

const tx = await assetTransferApi.createTransferTransaction(
ethereumNetworkGlobalConsensusLocation,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
['DOT', 'WETH.snow'],
['100000000000', '750000000000000'],
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/hydration.ethereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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('Hydration <> Ethereum', () => {
const ethereumNetworkGlobalConsensusLocation = `{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`;
let hydration: NetworkContext;
let polkadotAssetHub: NetworkContext;
let polkadotBridgeHub: NetworkContext;
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Hydration <> Ethereum', () => {
});

const tx = await assetTransferApi.createTransferTransaction(
ethereumNetworkGlobalConsensusLocation,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
['DOT', 'WETH.snow'],
['500000000000', '75000000000000'],
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('Hydration <> Ethereum', () => {
});

const tx = await assetTransferApi.createTransferTransaction(
ethereumNetworkGlobalConsensusLocation,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
['DOT', 'WETH.snow'],
['500000000000', '75000000000000'],
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/moonbeam.ethereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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('Moonbeam <> Ethereum', () => {
const ethereumNetworkGlobalConsensusLocation = `{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`;
let moonbeam: NetworkContext;
let polkadotAssetHub: NetworkContext;
let polkadotBridgeHub: NetworkContext;
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('Moonbeam <> Ethereum', () => {
});

const tx = await assetTransferApi.createTransferTransaction(
ethereumNetworkGlobalConsensusLocation,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
['DOT', 'WETH.snow'],
['100000000000', '750000000000000'],
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Moonbeam <> Ethereum', () => {
});

const tx = await assetTransferApi.createTransferTransaction(
ethereumNetworkGlobalConsensusLocation,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
['DOT', 'WETH.snow'],
['100000000000', '750000000000000'],
Expand Down
5 changes: 3 additions & 2 deletions e2e-tests/polkadotAssetHub.bridgeHub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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);

Expand Down Expand Up @@ -62,7 +63,7 @@ describe('Polkadot AssetHub <> Ethereum', () => {

const assetTransferApi = new AssetTransferApi(polkadotAssetHub.api, 'asset-hub-polkadot', xcmVersion);
const tx = await assetTransferApi.createTransferTransaction(
`{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
[
`{"parents":"2","interior":{"X2":[{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}},{"AccountKey20":{"network":null,"key":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}]}}`,
Expand Down Expand Up @@ -110,7 +111,7 @@ describe('Polkadot AssetHub <> Ethereum', () => {

const assetTransferApi = new AssetTransferApi(polkadotAssetHub.api, 'asset-hub-polkadot', xcmVersion);
const tx = await assetTransferApi.createTransferTransaction(
`{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`,
ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
alith.address,
[
`{"parents":"2","interior":{"X2":[{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}},{"AccountKey20":{"network":null,"key":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}]}}`,
Expand Down
4 changes: 4 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ export const SYSTEM_AND_PARACHAINS_RELAY_ASSET_LOCATION = '{"parents":"1","inter
* The asset location of the native relay chain asset from the perspective of the Relay chain
*/
export const RELAY_CHAINS_NATIVE_ASSET_LOCATION = '{"parents":"0","interior":{"Here":""}}';
/**
* The global location of the Ethereum Mainnet
*/
export const ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION = `{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2024 Parity Technologies (UK) Ltd.

import { ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION } from '../../consts';
import { Registry } from '../../registry';
import { adjustedMockBifrostParachainApi } from '../../testHelpers/adjustedMockBifrostParachainApi';
import { adjustedmockHydrationParachainApi } from '../../testHelpers/adjustedMockHydrationParachainApi';
import { adjustedMockSystemApiV1016000 } from '../../testHelpers/adjustedMockSystemApiV1016000';
import { Direction, XcmBaseArgs, XcmDirection } from '../../types';
import { transferAssetsUsingTypeAndThen } from './transferAssetsUsingTypeAndThen';
Expand Down Expand Up @@ -290,4 +293,85 @@ describe('transferAssetsUsingTypeAndThen', () => {
});
});
});
describe('ParaToEthereum', () => {
it('Should correctly construct a transferAssetsUsingTypeAndThen tx from Hydration to Ethereum', async () => {
const registry = new Registry('hydradx', {
injectedRegistry: {
polkadot: {
2034: {
tokens: [],
assetsInfo: {},
foreignAssetsInfo: {},
poolPairsInfo: {},
specName: 'hydradx',
xcAssetsData: [
{
paraID: 0,
symbol: 'WETH.snow',
decimals: 18,
xcmV1MultiLocation:
'{"v1":{"parents":2,"interior":{"x2":[{"globalConsensus":{"ethereum":{"chainId":1}}},{"accountKey20":{"network":null,"key":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}]}}}',
asset: '1000189',
assetHubReserveLocation: '{"parents":"1","interior":{"X1":{"Parachain":"1000"}}}',
},
],
},
},
},
});
const isLiquidTokenTransfer = false;
const isForeignAssetsTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedmockHydrationParachainApi,
direction: Direction.ParaToEthereum as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: ['DOT', 'WETH.snow'],
amounts: ['1000000000000', '1000000000000'],
destChainId: ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION,
xcmVersion: 4,
specName: 'hydradx',
registry,
};

const ext = await transferAssetsUsingTypeAndThen(baseArgs, {
paysWithFeeDest: 'DOT',
sendersAddr: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
isLiquidTokenTransfer,
isForeignAssetsTransfer,
assetTransferType: 'DestinationReserve',
feesTransferType: 'DestinationReserve',
});

expect(ext.toHex()).toBe(
'0x4904046b0d04010100a10f0408010000070010a5d4e802020907040300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200070010a5d4e80204010002040c16040d010000010100d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d10010102020907040300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20002010907040c1300010300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20004000d01020400010100f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b2c00000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000000000',
);
});
it('Should correctly throw an error when a valid ERC20 token is not provided in assetIds', async () => {
const registry = new Registry('bifrost_polkadot', {});
const isLiquidTokenTransfer = false;
const isForeignAssetsTransfer = false;
const baseArgs: XcmBaseArgs = {
api: adjustedMockBifrostParachainApi,
direction: Direction.ParaToEthereum as XcmDirection,
destAddr: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
assetIds: ['DOT', 'BNC'],
amounts: ['1000000000000', '1000000000000'],
destChainId: ETHEREUM_MAINNET_NETWORK_GLOBAL_CONSENSUS_LOCATION, // location destChainId,
xcmVersion: 4,
specName: 'bifrost_polkadot',
registry,
};

await expect(async () => {
await transferAssetsUsingTypeAndThen(baseArgs, {
paysWithFeeDest: 'DOT',
sendersAddr: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
isLiquidTokenTransfer,
isForeignAssetsTransfer,
assetTransferType: 'DestinationReserve',
feesTransferType: 'DestinationReserve',
});
}).rejects.toThrow('A valid Snowbridge ERC20 token must provided for ParaToEthereum Direction.');
});
});
});

0 comments on commit 36909f4

Please sign in to comment.