Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal-refactor): adjust naming to be more conventional #358

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AssetTransferApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe('AssetTransferAPI', () => {
injectedRegistry,
});

expect(mockSystemAssetsApi._opts.injectedRegistry).toStrictEqual(injectedRegistry);
expect(mockSystemAssetsApi.opts.injectedRegistry).toStrictEqual(injectedRegistry);
});
});

Expand Down
162 changes: 81 additions & 81 deletions src/AssetTransferApi.ts

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/createXcmTypes/util/getAssetId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ describe('getAssetId', () => {
it('Should correctly return the integer assetId when given a valid native system chain token symbol', async () => {
const expected = '10';

const result = await getAssetId(systemAssetsApi._api, registry, 'USDC', 'statemine', 2, false);
const result = await getAssetId(systemAssetsApi.api, registry, 'USDC', 'statemine', 2, false);

expect(result).toEqual(expected);
});

it('Should correctly return the integer assetId when given a valid native system chain token assetId', async () => {
const expected = '8';

const result = await getAssetId(systemAssetsApi._api, registry, 'RMRK', 'statemine', 2, false);
const result = await getAssetId(systemAssetsApi.api, registry, 'RMRK', 'statemine', 2, false);

expect(result).toEqual(expected);
});

it('Should error when an asset id symbol is given that is not present in the registry or chain state', async () => {
await expect(async () => {
await getAssetId(systemAssetsApi._api, registry, 'hello', 'statemine', 2, false);
}).rejects.toThrowError('assetId hello is not a valid symbol or integer asset id');
await getAssetId(systemAssetsApi.api, registry, 'hello', 'statemine', 2, false);
}).rejects.toThrow('assetId hello is not a valid symbol or integer asset id');
});

it('Should correctly return the foreign asset multilocation when given a valid foreign asset multilocation', async () => {
const multiLocation = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}';
const expected = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}';

const result = await getAssetId(systemAssetsApi._api, registry, multiLocation, 'statemine', 2, true);
const result = await getAssetId(systemAssetsApi.api, registry, multiLocation, 'statemine', 2, true);

expect(result).toEqual(expected);
});
Expand All @@ -46,8 +46,8 @@ describe('getAssetId', () => {
const multiLocation = '{"parents":"1","interior":{"X1":{"Parachain":"212500000"}}}';

await expect(async () => {
await getAssetId(systemAssetsApi._api, registry, multiLocation, 'statemine', 2, true);
}).rejects.toThrowError(`MultiLocation ${multiLocation} not found`);
await getAssetId(systemAssetsApi.api, registry, multiLocation, 'statemine', 2, true);
}).rejects.toThrow(`MultiLocation ${multiLocation} not found`);
});
});

Expand All @@ -58,15 +58,15 @@ describe('getAssetId', () => {
it('Should correctly return the xcAsset multilocation when given a valid asset symbol', async () => {
const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2023},{"palletInstance":10}]}}}';

const result = await getAssetId(bifrostAssetsApi._api, registry, 'movr', 'bifrost', 2, false);
const result = await getAssetId(bifrostAssetsApi.api, registry, 'movr', 'bifrost', 2, false);

expect(result).toEqual(expected);
});

it('Should correctly error when given an invalid xcAsset symbol', async () => {
await expect(async () => {
await getAssetId(bifrostAssetsApi._api, registry, 'TEST', 'bifrost', 2, true);
}).rejects.toThrowError(`parachain assetId TEST is not a valid symbol assetId in bifrost`);
await getAssetId(bifrostAssetsApi.api, registry, 'TEST', 'bifrost', 2, true);
}).rejects.toThrow(`parachain assetId TEST is not a valid symbol assetId in bifrost`);
});
});

Expand All @@ -77,7 +77,7 @@ describe('getAssetId', () => {
it('Should correctly return the xcAsset integer assetId when given a valid xcAsset symbol', async () => {
const expected = '42259045809535163221576417993425387648';

const result = await getAssetId(moonriverAssetsApi._api, registry, 'xcKSM', 'bifrost', 2, false);
const result = await getAssetId(moonriverAssetsApi.api, registry, 'xcKSM', 'bifrost', 2, false);

expect(result).toEqual(expected);
});
Expand All @@ -86,7 +86,7 @@ describe('getAssetId', () => {
const expected = '42259045809535163221576417993425387648';

const result = await getAssetId(
moonriverAssetsApi._api,
moonriverAssetsApi.api,
registry,
'42259045809535163221576417993425387648',
'moonriver',
Expand All @@ -99,13 +99,13 @@ describe('getAssetId', () => {

it('Should correctly error when given an invalid xcAsset symbol', async () => {
await expect(async () => {
await getAssetId(moonriverAssetsApi._api, registry, 'TEST', 'moonriver', 2, true);
await getAssetId(moonriverAssetsApi.api, registry, 'TEST', 'moonriver', 2, true);
}).rejects.toThrowError(`parachain assetId TEST is not a valid symbol assetIid in moonriver`);
});

it('Should correctly error when given an invalid integer xcAssetId', async () => {
await expect(async () => {
await getAssetId(moonriverAssetsApi._api, registry, '25830838603860', 'moonriver', 2, true);
await getAssetId(moonriverAssetsApi.api, registry, '25830838603860', 'moonriver', 2, true);
}).rejects.toThrowError(`parachain assetId 25830838603860 is not a valid integer assetIid in moonriver`);
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/createXcmTypes/util/getAssetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { foreignAssetsMultiLocationExists } from './foreignAssetsMultiLocationEx
* @param isForeignAssetsTransfer boolean
*/
export const getAssetId = async (
_api: ApiPromise,
api: ApiPromise,
registry: Registry,
asset: string,
specName: string,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const getAssetId = async (
if (multiLocationIsInRegistry) {
assetId = asset;
} else {
const isValidForeignAsset = await foreignAssetsMultiLocationExists(_api, registry, asset, xcmVersion);
const isValidForeignAsset = await foreignAssetsMultiLocationExists(api, registry, asset, xcmVersion);

if (!isValidForeignAsset) {
throw new BaseError(`MultiLocation ${asset} not found`, BaseErrorsEnum.AssetNotFound);
Expand All @@ -96,11 +96,11 @@ export const getAssetId = async (

assetId = tokens[0];
} else if (assetIsValidInt) {
const maybeAsset = await _api.query.assets.asset(asset);
const maybeAsset = await api.query.assets.asset(asset);

if (maybeAsset.isSome) {
assetId = asset;
const assetMetadata = await _api.query.assets.metadata(asset);
const assetMetadata = await api.query.assets.metadata(asset);
const assetSymbol = assetMetadata.symbol.toHuman()?.toString();

if (assetSymbol) {
Expand Down Expand Up @@ -129,16 +129,16 @@ export const getAssetId = async (
);
}

if (_api.query.assets) {
if (api.query.assets) {
if (!assetIsValidInt) {
// if not assetHub and assetId isnt a number, query the parachain for the asset symbol
const parachainAssets = await _api.query.assets.asset.entries();
const parachainAssets = await api.query.assets.asset.entries();

for (let i = 0; i < parachainAssets.length; i++) {
const parachainAsset = parachainAssets[i];
const id = parachainAsset[0].args[0];

const metadata = await _api.query.assets.metadata(id);
const metadata = await api.query.assets.metadata(id);
if (metadata.symbol.toHuman()?.toString().toLowerCase() === asset.toLowerCase()) {
assetId = id.toString();
// add queried asset to registry
Expand Down Expand Up @@ -170,7 +170,7 @@ export const getAssetId = async (
}
} else {
// if not assetHub and assetId is a number, query the parachain for the asset
const parachainAsset = await _api.query.assets.asset(asset);
const parachainAsset = await api.query.assets.asset(asset);
if (parachainAsset.isSome) {
assetId = asset;
// add queried asset to registry
Expand Down
12 changes: 6 additions & 6 deletions src/createXcmTypes/util/getXcAssetMultiLocationByAssetId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('getXcAssetMultiLocationByAssetId', () => {
const expected =
'{"v1":{"parents":1,"interior":{"x3":[{"parachain":1000},{"palletInstance":50},{"generalIndex":1984}]}}}';
const result = await getXcAssetMultiLocationByAssetId(
bifrostApi._api,
bifrostApi.api,
assetId,
specName,
xcmVersion,
Expand All @@ -61,7 +61,7 @@ describe('getXcAssetMultiLocationByAssetId', () => {
const specName = 'bifrost';

await expect(async () => {
await getXcAssetMultiLocationByAssetId(bifrostApi._api, assetId, specName, xcmVersion, bifrostRegistry);
await getXcAssetMultiLocationByAssetId(bifrostApi.api, assetId, specName, xcmVersion, bifrostRegistry);
}).rejects.toThrowError(`parachain assetId vmover is not a valid symbol assetId in bifrost`);
});
});
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('getXcAssetMultiLocationByAssetId', () => {

const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2001},{"generalKey":"0x010a"}]}}}';
const result = await getXcAssetMultiLocationByAssetId(
moonriverApi._api,
moonriverApi.api,
assetId,
specName,
xcmVersion,
Expand All @@ -107,7 +107,7 @@ describe('getXcAssetMultiLocationByAssetId', () => {

const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2001},{"generalKey":"0x0101"}]}}}';
const result = await getXcAssetMultiLocationByAssetId(
moonriverApi._api,
moonriverApi.api,
assetId,
specName,
xcmVersion,
Expand All @@ -123,7 +123,7 @@ describe('getXcAssetMultiLocationByAssetId', () => {
const specName = 'moonriver';

await expect(async () => {
await getXcAssetMultiLocationByAssetId(moonriverApi._api, assetId, specName, xcmVersion, moonriverRegistry);
await getXcAssetMultiLocationByAssetId(moonriverApi.api, assetId, specName, xcmVersion, moonriverRegistry);
}).rejects.toThrowError(`parachain assetId mover is not a valid symbol assetIid in moonriver`);
});

Expand All @@ -133,7 +133,7 @@ describe('getXcAssetMultiLocationByAssetId', () => {
const specName = 'moonriver';

await expect(async () => {
await getXcAssetMultiLocationByAssetId(moonriverApi._api, assetId, specName, xcmVersion, moonriverRegistry);
await getXcAssetMultiLocationByAssetId(moonriverApi.api, assetId, specName, xcmVersion, moonriverRegistry);
}).rejects.toThrowError(`assetId 242424332422323423424 is not a valid symbol or integer asset id for moonriver`);
});
});
Expand Down
24 changes: 12 additions & 12 deletions src/errors/checkLocalTxInput/checkLocalTxInput.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ describe('checkLocalTxInput', () => {
const systemAssetsApi = new AssetTransferApi(adjustedMockSystemApi, 'statemine', 2);

it('Should correctly return Balances with an empty assetIds', async () => {
const res = await checkLocalTxInput(systemAssetsApi._api, [], ['10000'], specName, registry, 2, false, false);
const res = await checkLocalTxInput(systemAssetsApi.api, [], ['10000'], specName, registry, 2, false, false);
expect(res).toEqual('Balances');
});
it('Should correctly return Balances with a native token', async () => {
const res = await checkLocalTxInput(systemAssetsApi._api, ['KSM'], ['10000'], specName, registry, 2, false, false);
const res = await checkLocalTxInput(systemAssetsApi.api, ['KSM'], ['10000'], specName, registry, 2, false, false);
expect(res).toEqual('Balances');
});
it('Should correctly return Balances with an empty string assetId', async () => {
const res = await checkLocalTxInput(systemAssetsApi._api, [''], ['10000'], specName, registry, 2, false, false);
const res = await checkLocalTxInput(systemAssetsApi.api, [''], ['10000'], specName, registry, 2, false, false);
expect(res).toEqual('Balances');
});
it('Should correctly return Assets with a valid assetId', async () => {
const res = await checkLocalTxInput(systemAssetsApi._api, ['1984'], ['10000'], specName, registry, 2, false, false);
const res = await checkLocalTxInput(systemAssetsApi.api, ['1984'], ['10000'], specName, registry, 2, false, false);
expect(res).toEqual('Assets');
});
it('Should correctly throw an error for incorrect length on `assetIds`', async () => {
await expect(async () => {
await checkLocalTxInput(systemAssetsApi._api, ['1', '2'], ['10000'], specName, registry, 2, false, false);
await checkLocalTxInput(systemAssetsApi.api, ['1', '2'], ['10000'], specName, registry, 2, false, false);
}).rejects.toThrowError(
'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1',
);
});
it('Should correctly throw an error for incorrect length on `amounts`', async () => {
await expect(async () => {
await checkLocalTxInput(systemAssetsApi._api, ['1'], ['10000', '20000'], specName, registry, 2, false, false);
await checkLocalTxInput(systemAssetsApi.api, ['1'], ['10000', '20000'], specName, registry, 2, false, false);
}).rejects.toThrowError(
'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1',
);
});
it('Should correctly throw an error with an incorrect assetId', async () => {
await expect(async () => {
await checkLocalTxInput(systemAssetsApi._api, ['TST'], ['10000'], specName, registry, 2, false, false);
await checkLocalTxInput(systemAssetsApi.api, ['TST'], ['10000'], specName, registry, 2, false, false);
}).rejects.toThrowError('assetId TST is not a valid symbol or integer asset id for statemine');
});
it("Should correctly throw an error when the integer assetId doesn't exist", async () => {
await expect(async () => {
await checkLocalTxInput(systemAssetsApi._api, ['9876111'], ['10000'], specName, registry, 2, false, false);
await checkLocalTxInput(systemAssetsApi.api, ['9876111'], ['10000'], specName, registry, 2, false, false);
}).rejects.toThrowError('general index for assetId 9876111 was not found');
});

it('Should correctly return ForeignAssets when given a valid multilocation', async () => {
const res = await checkLocalTxInput(
systemAssetsApi._api,
systemAssetsApi.api,
['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'],
['10000'],
specName,
Expand All @@ -72,7 +72,7 @@ describe('checkLocalTxInput', () => {

await expect(async () => {
await checkLocalTxInput(
systemAssetsApi._api,
systemAssetsApi.api,
[incorrectMultiLocationStr],
['10000'],
specName,
Expand All @@ -90,7 +90,7 @@ describe('checkLocalTxInput', () => {

await expect(async () => {
await checkLocalTxInput(
systemAssetsApi._api,
systemAssetsApi.api,
[nonExistentMultiLocationStr],
['10000'],
specName,
Expand All @@ -106,7 +106,7 @@ describe('checkLocalTxInput', () => {
const expectedError = 'Local foreignAsset transactions must have the `assetIds` input be a length of 1';

await expect(async () => {
await checkLocalTxInput(systemAssetsApi._api, [], ['10000'], specName, registry, 2, true, false);
await checkLocalTxInput(systemAssetsApi.api, [], ['10000'], specName, registry, 2, true, false);
}).rejects.toThrowError(expectedError);
});
});
10 changes: 5 additions & 5 deletions src/errors/checkXcmTxInputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const runTests = async (tests: Test[]) => {

await expect(async () => {
await checkAssetIdInput(
parachainAssetsApi._api,
parachainAssetsApi.api,
testInputs,
currentRegistry,
specName,
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('checkAssetIds', () => {

await expect(async () => {
await checkAssetIdInput(
parachainAssetsApi._api,
parachainAssetsApi.api,
testInputs,
currentRegistry,
specName,
Expand Down Expand Up @@ -338,7 +338,7 @@ describe('checkAssetIds', () => {
const currentRegistry = registry.currentRelayRegistry;
await expect(async () => {
await checkAssetIdInput(
parachainAssetsApi._api,
parachainAssetsApi.api,
testInputs,
currentRegistry,
specName,
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('checkAssetIds', () => {

await expect(async () => {
await checkAssetIdInput(
parachainAssetsApi._api,
parachainAssetsApi.api,
testInputs,
currentRegistry,
specName,
Expand All @@ -393,7 +393,7 @@ describe('checkAssetIds', () => {

await expect(async () => {
await checkAssetIdInput(
parachainAssetsApi._api,
parachainAssetsApi.api,
['0x1234'],
currentRegistry,
'moonriver',
Expand Down
Loading
Loading