diff --git a/src/frontend/src/icp/schema/ic-token.schema.ts b/src/frontend/src/icp/schema/ic-token.schema.ts index 9630ee0dd5..58bcf682e2 100644 --- a/src/frontend/src/icp/schema/ic-token.schema.ts +++ b/src/frontend/src/icp/schema/ic-token.schema.ts @@ -16,8 +16,7 @@ export const IcAppMetadataSchema = z.object({ export const IcCanistersSchema = z.object({ ledgerCanisterId: CanisterIdTextSchema, - // TODO: Make canister .optional() - indexCanisterId: CanisterIdTextSchema + indexCanisterId: CanisterIdTextSchema.optional() }); export const IcCanistersStrictSchema = IcCanistersSchema.extend({ diff --git a/src/frontend/src/icp/utils/ic-token.utils.ts b/src/frontend/src/icp/utils/ic-token.utils.ts deleted file mode 100644 index e10206dc2d..0000000000 --- a/src/frontend/src/icp/utils/ic-token.utils.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { IcCanistersStrict, IcToken } from '$icp/types/ic-token'; -import { IcCanistersStrictSchema, IcTokenSchema } from '$icp/validation/ic-token.validation'; -import type { Token } from '$lib/types/token'; - -export const isIcToken = (token: Token): token is IcToken => { - const { success } = IcTokenSchema.safeParse(token); - return success; -}; - -export const isNotIcToken = (token: Token): token is Exclude => !isIcToken(token); - -export const isIcTokenCanistersStrict = (token: IcToken): token is IcToken & IcCanistersStrict => { - const { success } = IcCanistersStrictSchema.safeParse(token); - return success; -}; - -export const isNotIcTokenCanistersStrict = ( - token: IcToken -): token is Exclude => !isIcTokenCanistersStrict(token); diff --git a/src/frontend/src/tests/icp/schema/ic-token.schema.spec.ts b/src/frontend/src/tests/icp/schema/ic-token.schema.spec.ts index 992204bf2a..a426ef89b1 100644 --- a/src/frontend/src/tests/icp/schema/ic-token.schema.spec.ts +++ b/src/frontend/src/tests/icp/schema/ic-token.schema.spec.ts @@ -99,13 +99,12 @@ describe('ic-token.schema', () => { expect(IcCanistersSchema.parse(validData)).toEqual(validData); }); - // TODO: uncomment when Index canister becomes optional - // it('should validate with ledger canister only', () => { - // const validData = { - // ledgerCanisterId: mockCanisters.ledgerCanisterId - // }; - // expect(IcCanistersSchema.parse(validData)).toEqual(validData); - // }); + it('should validate with ledger canister only', () => { + const validData = { + ledgerCanisterId: mockCanisters.ledgerCanisterId + }; + expect(IcCanistersSchema.parse(validData)).toEqual(validData); + }); it('should fail with invalid ledger canister id', () => { const invalidData = { @@ -219,11 +218,10 @@ describe('ic-token.schema', () => { expect(IcInterfaceSchema.parse(validData)).toEqual(validData); }); - // TODO: uncomment when Index canister becomes optional - // it('should validate without Index canister', () => { - // const { indexCanisterId: _, ...restValidData } = validData; - // expect(IcInterfaceSchema.parse(restValidData)).toEqual(restValidData); - // }); + it('should validate without Index canister', () => { + const { indexCanisterId: _, ...restValidData } = validData; + expect(IcInterfaceSchema.parse(restValidData)).toEqual(restValidData); + }); it('should fail with incorrect IcCanisters data', () => { const invalidData = { diff --git a/src/frontend/src/tests/icp/validation/ic-token.validation.spec.ts b/src/frontend/src/tests/icp/validation/ic-token.validation.spec.ts index d18122cab7..42dfa81889 100644 --- a/src/frontend/src/tests/icp/validation/ic-token.validation.spec.ts +++ b/src/frontend/src/tests/icp/validation/ic-token.validation.spec.ts @@ -23,9 +23,7 @@ describe('ic-token.validation', () => { }; const validIcCanisters: IcCanisters = { - ledgerCanisterId: IC_CKBTC_LEDGER_CANISTER_ID, - // TODO: to be removed when indexCanisterId becomes optional - indexCanisterId: IC_CKBTC_INDEX_CANISTER_ID + ledgerCanisterId: IC_CKBTC_LEDGER_CANISTER_ID }; const validIcToken: IcToken = { @@ -35,6 +33,11 @@ describe('ic-token.validation', () => { position: 1 }; + const validIcTokenWithIndex: IcToken = { + ...validIcToken, + indexCanisterId: IC_CKBTC_INDEX_CANISTER_ID + }; + describe('isIcToken', () => { it('should return true for a valid IcToken', () => { expect(isIcToken(validIcToken)).toBe(true); @@ -57,13 +60,12 @@ describe('ic-token.validation', () => { describe('isIcTokenCanistersStrict', () => { it('should return true for a valid IcToken with IcCanistersStrict', () => { - expect(isIcTokenCanistersStrict(validIcToken)).toBe(true); + expect(isIcTokenCanistersStrict(validIcTokenWithIndex)).toBe(true); }); - // TODO: test missing indexCanisterId when it becomes optional - // it('should return false for a valid IcToken without strict canisters fields', () => { - // expect(isIcTokenCanistersStrict(validIcToken)).toBe(false); - // }); + it('should return false for a valid IcToken without strict canisters fields', () => { + expect(isIcTokenCanistersStrict(validIcToken)).toBe(false); + }); it('should return false for a token type casted to IcToken', () => { expect(isIcTokenCanistersStrict(validToken as IcToken)).toBe(false); @@ -72,13 +74,12 @@ describe('ic-token.validation', () => { describe('isNotIcTokenCanistersStrict', () => { it('should return false for a valid IcToken with IcCanistersStrict', () => { - expect(isNotIcTokenCanistersStrict(validIcToken)).toBe(false); + expect(isNotIcTokenCanistersStrict(validIcTokenWithIndex)).toBe(false); }); - // TODO: test missing indexCanisterId when it becomes optional - // it('should return true for a valid IcToken without strict canisters fields', () => { - // expect(isNotIcTokenCanistersStrict(validIcToken)).toBe(true); - // }); + it('should return true for a valid IcToken without strict canisters fields', () => { + expect(isNotIcTokenCanistersStrict(validIcToken)).toBe(true); + }); it('should return true for a token type casted to IcToken', () => { expect(isNotIcTokenCanistersStrict(validToken as IcToken)).toBe(true);