Skip to content

Commit

Permalink
fix: added get-public-key tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muzaffarbhat07 committed Oct 7, 2024
1 parent 27f2925 commit fdc822e
Show file tree
Hide file tree
Showing 8 changed files with 608 additions and 0 deletions.
79 changes: 79 additions & 0 deletions packages/app-xrp/tests/02.getPublicKeys/__fixtures__/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
DeviceAppError,
DeviceAppErrorType,
deviceAppErrorTypeDetails,
} from '@cypherock/sdk-interfaces';
import { IGetPublicKeysTestCase } from './types';
import { Query } from '../../../src/proto/generated/xrp/core';

const commonParams = {
params: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187, 121,
64,
]),
derivationPaths: [
{
path: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
},
],
},
queries: [
{
name: 'Initate query',
data: Uint8Array.from(
Query.encode(
Query.create({
getPublicKeys: {
initiate: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160,
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
86, 128, 26, 3, 187, 121, 64,
]),
derivationPaths: [
{
path: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
},
],
},
},
}),
).finish(),
),
},
],
};

const withUnknownError: IGetPublicKeysTestCase = {
name: 'With unknown error',
...commonParams,
results: [
{
name: 'error',
data: new Uint8Array([10, 4, 18, 2, 8, 1]),
},
],
errorInstance: DeviceAppError,
errorMessage:
deviceAppErrorTypeDetails[DeviceAppErrorType.UNKNOWN_ERROR].message,
};

const withInvalidAppId: IGetPublicKeysTestCase = {
name: 'With invalid msg from device',
...commonParams,
results: [
{
name: 'error',
data: new Uint8Array([10, 4, 18, 2, 16, 1]),
},
],
errorInstance: DeviceAppError,
errorMessage:
deviceAppErrorTypeDetails[DeviceAppErrorType.CORRUPT_DATA].message,
};

const error: IGetPublicKeysTestCase[] = [withUnknownError, withInvalidAppId];

export default error;
14 changes: 14 additions & 0 deletions packages/app-xrp/tests/02.getPublicKeys/__fixtures__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IFixtures } from './types';
import error from './error';
import invalidData from './invalidData';
import valid from './valid';
import invalidArgs from './invalidArgs';

const fixtures: IFixtures = {
valid,
error,
invalidData,
invalidArgs,
};

export default fixtures;
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { IGetPublicKeysTestCase } from './types';

const commonParams = {
queries: [{ name: 'empty', data: new Uint8Array([]) }],
results: [{ name: 'empty', data: new Uint8Array([]) }],
errorInstance: Error,
errorMessage: /AssertionError/,
};

const validParams = {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187, 121,
64,
]),
derivationPaths: [
{
path: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
},
],
};

const invalidArgs: IGetPublicKeysTestCase[] = [
{
name: 'Null',
...commonParams,
params: null as any,
},
{
name: 'Undefined',
...commonParams,
params: null as any,
},
{
name: 'Empty Object',
...commonParams,
params: {} as any,
},
{
name: 'No derivation paths',
...commonParams,
params: { ...validParams, derivationPaths: undefined } as any,
},
{
name: 'Empty derivation path',
...commonParams,
params: {
...validParams,
derivationPaths: [],
} as any,
},
{
name: 'invalid derivation path in array (depth:2)',
...commonParams,
params: {
...validParams,
derivationPaths: [
{
path: [
{ index: 44, isHardened: true },
{ index: 144, isHardened: true },
],
},
],
},
},
];

export default invalidArgs;
108 changes: 108 additions & 0 deletions packages/app-xrp/tests/02.getPublicKeys/__fixtures__/invalidData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import {
DeviceAppError,
DeviceAppErrorType,
deviceAppErrorTypeDetails,
} from '@cypherock/sdk-interfaces';
import { IGetPublicKeysTestCase } from './types';
import { Query } from '../../../src/proto/generated/xrp/core';

const commonParams = {
params: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187, 121,
64,
]),
derivationPaths: [
{
path: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
},
],
},
queries: [
{
name: 'Initate query',
data: Uint8Array.from(
Query.encode(
Query.create({
getPublicKeys: {
initiate: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160,
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
86, 128, 26, 3, 187, 121, 64,
]),
derivationPaths: [
{
path: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
},
],
},
},
}),
).finish(),
),
},
],
errorInstance: DeviceAppError,
errorMessage:
deviceAppErrorTypeDetails[DeviceAppErrorType.INVALID_MSG_FROM_DEVICE]
.message,
};

const invalidData: IGetPublicKeysTestCase[] = [
{
name: 'Invalid data',
...commonParams,
results: [
{
name: 'error',
data: new Uint8Array([
109, 112, 102, 98, 72, 57, 117, 109, 75, 69, 83, 117, 117, 49, 103,
78, 100, 105, 87, 83, 116, 106, 71, 54, 67, 110, 104, 77, 86, 49, 113,
97, 78, 111, 50, 98, 118, 52, 67, 113, 72, 122, 120, 85, 98, 53, 86,
68, 115, 86, 52, 77, 86, 112, 83, 70, 86, 78, 121, 121, 109, 83, 112,
98, 74, 76, 55, 57, 75, 89, 86, 57, 75, 56, 88, 82, 100, 105, 98, 70,
109, 118, 54, 116, 86, 54, 116, 50, 122, 52, 100, 87, 110, 111, 110,
78, 52, 78, 77, 89, 109,
]),
},
],
},
{
name: 'Invalid data',
...commonParams,
results: [
{
name: 'error',
data: new Uint8Array([
10, 34, 10, 3, 90, 221, 135, 18, 2, 8, 1, 24, 1, 34, 11, 8, 2, 18, 7,
8,
]),
},
],
},
{
name: 'Invalid data',
...commonParams,

results: [
{
name: 'error',
data: new Uint8Array([10]),
},
],
},
{
name: 'Invalid data',
...commonParams,
results: [
{
name: 'error',
data: new Uint8Array([]),
},
],
},
];

export default invalidData;
28 changes: 28 additions & 0 deletions packages/app-xrp/tests/02.getPublicKeys/__fixtures__/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IGetPublicKeysParams, IGetPublicKeysResult } from '../../../src';

export interface IGetPublicKeysTestCase {
name: string;
params: IGetPublicKeysParams;
queries: {
name: string;
data: Uint8Array;
}[];
results: {
name: string;
data: Uint8Array;
statuses?: { flowStatus: number; expectEventCalls?: number[] }[];
}[];
mocks?: {
eventCalls?: number[][];
};
output?: Partial<IGetPublicKeysResult>;
errorInstance?: any;
[key: string]: any;
}

export interface IFixtures {
valid: IGetPublicKeysTestCase[];
invalidData: IGetPublicKeysTestCase[];
error: IGetPublicKeysTestCase[];
invalidArgs: IGetPublicKeysTestCase[];
}
Loading

0 comments on commit fdc822e

Please sign in to comment.