Skip to content

Commit

Permalink
feat: redo after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Nov 5, 2024
1 parent 6c6f9f0 commit 9b2ba90
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/frontend/src/icp/schema/ic-token.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
19 changes: 0 additions & 19 deletions src/frontend/src/icp/utils/ic-token.utils.ts

This file was deleted.

22 changes: 10 additions & 12 deletions src/frontend/src/tests/icp/schema/ic-token.schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
27 changes: 14 additions & 13 deletions src/frontend/src/tests/icp/validation/ic-token.validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 9b2ba90

Please sign in to comment.