|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { XcmVersion } from './ExtrinsicBuilder.interfaces'; |
| 3 | +import { |
| 4 | + applyConcreteWrapper, |
| 5 | + normalizeConcrete, |
| 6 | + normalizeX1, |
| 7 | +} from './ExtrinsicBuilder.utils'; |
| 8 | + |
| 9 | +describe('normalizeX1', () => { |
| 10 | + it('should return original object when xcmVersion < v4', () => { |
| 11 | + const input = { |
| 12 | + interior: { X1: { Parachain: 1000 } }, |
| 13 | + }; |
| 14 | + |
| 15 | + expect(normalizeX1(XcmVersion.v3, input)).toEqual(input); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should wrap X1 value in array for xcmVersion >= v4', () => { |
| 19 | + const input = { |
| 20 | + interior: { X1: { Parachain: 1000 } }, |
| 21 | + }; |
| 22 | + const expected = { |
| 23 | + interior: { X1: [{ Parachain: 1000 }] }, |
| 24 | + }; |
| 25 | + |
| 26 | + expect(normalizeX1(XcmVersion.v4, input)).toEqual(expected); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should handle lowercase x1 key', () => { |
| 30 | + const input = { |
| 31 | + interior: { x1: { Parachain: 1000 } }, |
| 32 | + }; |
| 33 | + const expected = { |
| 34 | + interior: { x1: [{ Parachain: 1000 }] }, |
| 35 | + }; |
| 36 | + |
| 37 | + expect(normalizeX1(XcmVersion.v4, input)).toEqual(expected); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should not modify object without X1/x1 key', () => { |
| 41 | + const input = { |
| 42 | + interior: { X2: [{ Parachain: 1000 }, { GeneralIndex: 1 }] }, |
| 43 | + }; |
| 44 | + |
| 45 | + expect(normalizeX1(XcmVersion.v4, input)).toEqual(input); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +describe('normalizeConcrete', () => { |
| 50 | + it('should return original object for xcmVersion >= v4', () => { |
| 51 | + const input = { Parachain: 1000 }; |
| 52 | + |
| 53 | + expect(normalizeConcrete(XcmVersion.v4, input)).toBe(input); |
| 54 | + expect(normalizeConcrete(XcmVersion.v5, input)).toBe(input); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should wrap object in Concrete for xcmVersion < v4', () => { |
| 58 | + const input = { Parachain: 1000 }; |
| 59 | + const expected = { Concrete: { Parachain: 1000 } }; |
| 60 | + |
| 61 | + expect(normalizeConcrete(XcmVersion.v3, input)).toEqual(expected); |
| 62 | + expect(normalizeConcrete(XcmVersion.v2, input)).toEqual(expected); |
| 63 | + expect(normalizeConcrete(XcmVersion.v1, input)).toEqual(expected); |
| 64 | + }); |
| 65 | +}); |
0 commit comments