Skip to content

Commit

Permalink
add tests to new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Nov 22, 2024
1 parent 204bc2b commit a126cfd
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
23 changes: 23 additions & 0 deletions packages/builder/src/asset-min/AssetMinBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
25 changes: 25 additions & 0 deletions packages/builder/src/balance/BalanceBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
"<ACCOUNT>",
],
"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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, expect, it } from 'vitest';
import {
buildParachainParamsMock,
buildParamsMock,
buildParamsMockEth,
buildParamsSameAssetMock,
} from '../../../../fixtures';
import { polkadotXcm } from './polkadotXcm';
Expand Down Expand Up @@ -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();
});
});
});
});

0 comments on commit a126cfd

Please sign in to comment.