-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adjustments after integrating XCM in the dapp * normalize extrinsic build for xcm versions * update test snapshot * add tests for normalize functions * remove unused import * change wording and remove log * Update packages/builder/src/extrinsic/ExtrinsicBuilder.utils.ts Co-authored-by: Richard Kenigs <[email protected]> * apply type inference and fix tyeps --------- Co-authored-by: Richard Kenigs <[email protected]>
- Loading branch information
Showing
11 changed files
with
211 additions
and
96 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/builder/src/extrinsic/ExtrinsicBuilder.utils.test.ts
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { XcmVersion } from './ExtrinsicBuilder.interfaces'; | ||
import { normalizeConcrete, normalizeX1 } from './ExtrinsicBuilder.utils'; | ||
|
||
describe('normalizeX1', () => { | ||
it('should return original object when xcmVersion < v4', () => { | ||
const input = { | ||
interior: { X1: { Parachain: 1000 } }, | ||
}; | ||
|
||
expect(normalizeX1(XcmVersion.v3, input)).toEqual(input); | ||
}); | ||
|
||
it('should wrap X1 value in array for xcmVersion >= v4', () => { | ||
const input = { | ||
interior: { X1: { Parachain: 1000 } }, | ||
}; | ||
const expected = { | ||
interior: { X1: [{ Parachain: 1000 }] }, | ||
}; | ||
|
||
expect(normalizeX1(XcmVersion.v4, input)).toEqual(expected); | ||
}); | ||
|
||
it('should handle lowercase x1 key', () => { | ||
const input = { | ||
interior: { x1: { Parachain: 1000 } }, | ||
}; | ||
const expected = { | ||
interior: { x1: [{ Parachain: 1000 }] }, | ||
}; | ||
|
||
expect(normalizeX1(XcmVersion.v4, input)).toEqual(expected); | ||
}); | ||
|
||
it('should not modify object without X1/x1 key', () => { | ||
const input = { | ||
interior: { X2: [{ Parachain: 1000 }, { GeneralIndex: 1 }] }, | ||
}; | ||
|
||
expect(normalizeX1(XcmVersion.v4, input)).toEqual(input); | ||
}); | ||
}); | ||
|
||
describe('normalizeConcrete', () => { | ||
it('should return original object for xcmVersion >= v4', () => { | ||
const input = { Parachain: 1000 }; | ||
|
||
expect(normalizeConcrete(XcmVersion.v4, input)).toBe(input); | ||
expect(normalizeConcrete(XcmVersion.v5, input)).toBe(input); | ||
}); | ||
|
||
it('should wrap object in Concrete for xcmVersion < v4', () => { | ||
const input = { Parachain: 1000 }; | ||
const expected = { Concrete: { Parachain: 1000 } }; | ||
|
||
expect(normalizeConcrete(XcmVersion.v3, input)).toEqual(expected); | ||
expect(normalizeConcrete(XcmVersion.v2, input)).toEqual(expected); | ||
expect(normalizeConcrete(XcmVersion.v1, input)).toEqual(expected); | ||
}); | ||
}); |
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
Oops, something went wrong.