From a126cfd0b42523a595b9b278afe8a0ee0f240c92 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Fri, 22 Nov 2024 12:35:58 +0100 Subject: [PATCH] add tests to new functions --- .../builder/fixtures/builderParamsMock.ts | 11 ++ .../src/asset-min/AssetMinBuilder.test.ts | 23 ++++ .../AssetMinBuilder.test.ts.snap | 32 ++++++ .../src/balance/BalanceBuilder.test.ts | 25 +++++ .../__snapshots__/BalanceBuilder.test.ts.snap | 33 ++++++ .../__snapshots__/polkadotXcm.test.ts.snap | 103 ++++++++++++++++++ .../pallets/polkadotXcm/polkadotXcm.test.ts | 18 +++ 7 files changed, 245 insertions(+) diff --git a/packages/builder/fixtures/builderParamsMock.ts b/packages/builder/fixtures/builderParamsMock.ts index 63cdeab4..d90db2e3 100644 --- a/packages/builder/fixtures/builderParamsMock.ts +++ b/packages/builder/fixtures/builderParamsMock.ts @@ -80,3 +80,14 @@ export const buildParachainParamsMock: ExtrinsicConfigBuilderPrams = { palletInstance: 10, source: alphanetAssetHubMock, }; + +export const buildParamsMockEth: ExtrinsicConfigBuilderPrams = { + address: '0xeF46c7649270C912704fB09B75097f6E32208b85', + amount: 99_000_000_000n, + asset: '0xeF46c7649270C912704fB09B75097f6E32208b85', + destination: moonbaseAlphaMock, + fee: 5_000_000_000n, + feeAsset: 'WETH.e', + palletInstance: 10, + source: alphanetAssetHubMock, +}; diff --git a/packages/builder/src/asset-min/AssetMinBuilder.test.ts b/packages/builder/src/asset-min/AssetMinBuilder.test.ts index 93c261a5..e6904596 100644 --- a/packages/builder/src/asset-min/AssetMinBuilder.test.ts +++ b/packages/builder/src/asset-min/AssetMinBuilder.test.ts @@ -78,4 +78,27 @@ describe('assetMinBuilder', () => { }); }); }); + + describe('foreignAssets', () => { + describe('asset', () => { + const config = AssetMinBuilder() + .foreignAssets() + .asset() + .build({ asset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' }); + + it('should be correct config', () => { + expect(config).toMatchSnapshot(); + }); + + it('should transform correctly', async () => { + await expect( + config.transform({ + unwrapOrDefault: () => ({ + minBalance: balanceOf(999), + }), + }), + ).resolves.toMatchSnapshot(); + }); + }); + }); }); diff --git a/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap b/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap index adbc79f6..41839f0a 100644 --- a/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap +++ b/packages/builder/src/asset-min/__snapshots__/AssetMinBuilder.test.ts.snap @@ -42,6 +42,38 @@ SubstrateQueryConfig { exports[`assetMinBuilder > assets > asset > should transform correctly 1`] = `999n`; +exports[`assetMinBuilder > foreignAssets > asset > should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + { + "interior": { + "X2": [ + { + "globalconsensus": { + "ethereum": { + "chainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + }, + }, + ], + }, + "parents": 2, + }, + ], + "func": "asset", + "module": "foreignAssets", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`assetMinBuilder > foreignAssets > asset > should transform correctly 1`] = `999n`; + exports[`assetMinBuilder assetRegistry assetMetadatas should be correct config 1`] = ` SubstrateQueryConfig { "args": [ diff --git a/packages/builder/src/balance/BalanceBuilder.test.ts b/packages/builder/src/balance/BalanceBuilder.test.ts index 556dcc63..d901021c 100644 --- a/packages/builder/src/balance/BalanceBuilder.test.ts +++ b/packages/builder/src/balance/BalanceBuilder.test.ts @@ -47,6 +47,31 @@ describe('balanceBuilder', () => { }); }); + describe('foreignAssets', () => { + describe('account', () => { + const config = BalanceBuilder() + .substrate() + .foreignAssets() + .account() + .build({ + address: account, + asset: `0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2`, + }) as SubstrateQueryConfig; + + it('should be correct config', () => { + expect(config).toMatchSnapshot(); + }); + + it('should transform correctly', async () => { + await expect( + config.transform({ + unwrapOrDefault: () => ({ balance: balanceOf(999) }), + }), + ).resolves.toMatchSnapshot(); + }); + }); + }); + describe('system', () => { describe('account', () => { const config = BalanceBuilder() diff --git a/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap b/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap index 2369c5e0..f322e223 100644 --- a/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap +++ b/packages/builder/src/balance/__snapshots__/BalanceBuilder.test.ts.snap @@ -15,6 +15,39 @@ SubstrateQueryConfig { exports[`balanceBuilder > assets > account > should transform correctly 1`] = `999n`; +exports[`balanceBuilder > foreignAssets > account > should be correct config 1`] = ` +SubstrateQueryConfig { + "args": [ + { + "interior": { + "X2": [ + { + "GlobalConsensus": { + "ethereum": { + "chainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + }, + }, + ], + }, + "parents": 2, + }, + "", + ], + "func": "account", + "module": "foreignAssets", + "transform": [Function], + "type": "Substrate", +} +`; + +exports[`balanceBuilder > foreignAssets > account > should transform correctly 1`] = `999n`; + exports[`balanceBuilder > system > account > should be correct config 1`] = ` SubstrateQueryConfig { "args": [ diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap index 64049ba7..e7fe0738 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap @@ -462,6 +462,109 @@ exports[`polkadotXcm > limitedReserveWithdrawAssets > x2 > should get correct ar ] `; +exports[`polkadotXcm > transferAssetsUsingTypeAndThen > x2 > should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferAssetsUsingTypeAndThen", + "getArgs": [Function], + "module": "polkadotXcm", + "type": "Substrate", +} +`; + +exports[`polkadotXcm > transferAssetsUsingTypeAndThen > x2 > should get correct arguments 1`] = ` +[ + { + "V4": { + "interior": { + "X1": [ + { + "Parachain": 1000, + }, + ], + }, + "parents": 1, + }, + }, + { + "V4": [ + { + "fun": { + "fungible": 99000000000n, + }, + "id": { + "interior": { + "X2": [ + { + "globalConsensus": { + "Ethereum": { + "ChainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + ], + }, + "parents": 2, + }, + }, + ], + }, + "LocalReserve", + { + "V4": { + "interior": { + "X2": [ + { + "globalConsensus": { + "Ethereum": { + "ChainId": 1, + }, + }, + }, + { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + ], + }, + "parents": 2, + }, + }, + "LocalReserve", + { + "V4": [ + { + "DepositAsset": { + "assets": { + "Wild": { + "AllCounted": 1, + }, + }, + "beneficiary": { + "interior": { + "X1": [ + { + "AccountKey20": { + "key": "0xeF46c7649270C912704fB09B75097f6E32208b85", + }, + }, + ], + }, + "parents": 0, + }, + }, + }, + ], + }, + "Unlimited", +] +`; + exports[`polkadotXcm limitedReserveTransferAssets here should be correct config 1`] = ` ExtrinsicConfig { "func": "limitedReserveTransferAssets", diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts index 64823acd..4baa0fbf 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts @@ -4,6 +4,7 @@ import { describe, expect, it } from 'vitest'; import { buildParachainParamsMock, buildParamsMock, + buildParamsMockEth, buildParamsSameAssetMock, } from '../../../../fixtures'; import { polkadotXcm } from './polkadotXcm'; @@ -119,4 +120,21 @@ describe('polkadotXcm', () => { }); }); }); + + describe('transferAssetsUsingTypeAndThen', () => { + describe('x2', () => { + const extrinsic = polkadotXcm() + .transferAssetsUsingTypeAndThen() + .globalConcensusEthereum() + .build(buildParamsMockEth); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); + }); });