-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
147 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,47 @@ | ||
// Copyright 2024 Parity Technologies (UK) Ltd. | ||
|
||
import { Registry } from '../../registry'; | ||
import { isRelayNativeAsset } from './isRelayNativeAsset'; | ||
|
||
describe('isRelayNativeAsset', () => { | ||
const tokens = ['KSM']; | ||
it('Should return true', () => { | ||
expect(isRelayNativeAsset(tokens, 'KSM')).toEqual(true); | ||
describe('RelayToSystem', () => { | ||
const specName = 'kusama'; | ||
const registry = new Registry(specName, {}); | ||
|
||
it('Should return true when an empty string is provided as the assetId', () => { | ||
expect(isRelayNativeAsset(registry, '')).toEqual(true); | ||
}); | ||
it('Should return true when a symbol assetId matches the relay assetId', () => { | ||
expect(isRelayNativeAsset(registry, 'KSM')).toEqual(true); | ||
}); | ||
it('Should return false when a symbol assetId does not match the relay assetId', () => { | ||
expect(isRelayNativeAsset(registry, 'DOT')).toEqual(false); | ||
}); | ||
it('Should return true when the relay chains asset location is given as input from the perspective of the relay chain', () => { | ||
expect(isRelayNativeAsset(registry, '{"parents":"0","interior":{"Here":""}}')).toEqual(true); | ||
}); | ||
it('Should return false when the relay chains asset location is given as input from the perspective of a child chain', () => { | ||
expect(isRelayNativeAsset(registry, '{"parents":"1","interior":{"Here":""}}')).toEqual(false); | ||
}); | ||
}); | ||
it('Should return false', () => { | ||
expect(isRelayNativeAsset(tokens, 'DOT')).toEqual(false); | ||
describe('SystemToRelay', () => { | ||
const specName = 'statemint'; | ||
const registry = new Registry(specName, {}); | ||
|
||
it('Should return true when an empty string is provided as the assetId', () => { | ||
expect(isRelayNativeAsset(registry, '')).toEqual(true); | ||
}); | ||
it('Should return true when a symbol assetId matches the relay assetId', () => { | ||
expect(isRelayNativeAsset(registry, 'DOT')).toEqual(true); | ||
}); | ||
it('Should return false when a symbol assetId does not match the relay assetId', () => { | ||
expect(isRelayNativeAsset(registry, 'KSM')).toEqual(false); | ||
}); | ||
it('Should return true when the relay chains asset location is given as input from the persepect of AssetHub', () => { | ||
expect(isRelayNativeAsset(registry, '{"parents":"1","interior":{"Here":""}}')).toEqual(true); | ||
}); | ||
it('Should return false when the relay chains asset location is given as input from the perspective of the relay chain', () => { | ||
expect(isRelayNativeAsset(registry, '{"parents":"0","interior":{"Here":""}}')).toEqual(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
// Copyright 2023 Parity Technologies (UK) Ltd. | ||
// Copyright 2024 Parity Technologies (UK) Ltd. | ||
|
||
import { Registry } from '../../registry'; | ||
import { checkLocalRelayInput } from './checkLocalRelayInput'; | ||
import { LocalTxType } from './types'; | ||
|
||
describe('checkLocalRelayInput', () => { | ||
const registry = new Registry('statemine', { chainName: 'rococo' }); | ||
|
||
it('Should return LocalTxType.Balances', () => { | ||
const res = checkLocalRelayInput([], ['10000']); | ||
const res = checkLocalRelayInput([], ['10000'], registry); | ||
expect(res).toEqual(LocalTxType.Balances); | ||
}); | ||
it('Should error with an invalid input', () => { | ||
expect(() => checkLocalRelayInput(['dot', 'ksm'], ['100000'])).toThrow( | ||
expect(() => checkLocalRelayInput(['roc', 'ksm'], ['100000'], registry)).toThrow( | ||
'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 error when a non native asset is passed in', () => { | ||
expect(() => | ||
checkLocalRelayInput(['{"parents":"3","interior":{"X1":{"GlobalConsensus":"Westend"}}}'], ['100000'], registry), | ||
).toThrow( | ||
'AssetId {"parents":"3","interior":{"X1":{"GlobalConsensus":"Westend"}}} is not the native asset of rococo relay chain. Expected an assetId of ROC or asset location {"parents":"0","interior":{"Here":""}}', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
// Copyright 2023 Parity Technologies (UK) Ltd. | ||
// Copyright 2024 Parity Technologies (UK) Ltd. | ||
|
||
import { RELAY_CHAIN_IDS, RELAY_CHAINS_NATIVE_ASSET_LOCATION } from '../../consts'; | ||
import { isRelayNativeAsset } from '../../createXcmTypes/util/isRelayNativeAsset'; | ||
import { Registry } from '../../registry'; | ||
import { BaseError, BaseErrorsEnum } from '../BaseError'; | ||
import { LocalTxType } from './types'; | ||
|
||
export const checkLocalRelayInput = (assetIds: string[], amounts: string[]): LocalTxType => { | ||
export const checkLocalRelayInput = (assetIds: string[], amounts: string[], registry: Registry): LocalTxType => { | ||
if (assetIds.length > 1 || amounts.length !== 1) { | ||
throw new BaseError( | ||
'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1', | ||
BaseErrorsEnum.InvalidInput, | ||
); | ||
} | ||
const relayChainId = RELAY_CHAIN_IDS[0]; | ||
const relayChain = registry.currentRelayRegistry[relayChainId]; | ||
const relayChainNativeAsset = relayChain.tokens[0]; | ||
|
||
const assetIsRelayNativeAsset = assetIds.length === 0 ? true : isRelayNativeAsset(registry, assetIds[0]); | ||
if (!assetIsRelayNativeAsset) { | ||
throw new BaseError( | ||
`AssetId ${assetIds[0]} is not the native asset of ${relayChain.specName} relay chain. Expected an assetId of ${relayChainNativeAsset} or asset location ${RELAY_CHAINS_NATIVE_ASSET_LOCATION}`, | ||
); | ||
} | ||
|
||
return LocalTxType.Balances; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.