Skip to content

Commit

Permalink
feat: added xrp sign-txn tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muzaffarbhat07 committed Oct 7, 2024
1 parent bebf545 commit 3e394f9
Show file tree
Hide file tree
Showing 8 changed files with 744 additions and 0 deletions.
105 changes: 105 additions & 0 deletions packages/app-xrp/tests/03.signTxn/__fixtures__/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import {
DeviceAppError,
DeviceAppErrorType,
deviceAppErrorTypeDetails,
} from '@cypherock/sdk-interfaces';
import { ISignTxnTestCase } from './types';
import { queryToUint8Array, resultToUint8Array } from '../__helpers__';
import { ISignTxnParams } from '../../../src';

const commonParams: {
params: ISignTxnParams;
queries: {
name: string;
data: Uint8Array;
}[];
} = {
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,
]),
derivationPath: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
txn: {
rawTxn: {
TransactionType: 'Payment',
Account: 'rQGDkQchoJxMSLZR7q9GwvY3iKtDqTUYNQ',
Amount: '5000000',
Destination: 'rEgfV7YeyG4YayQQufxaqDx4aUA93SidLb',
Flags: 0,
NetworkID: undefined,
Sequence: 676674,
Fee: '12',
LastLedgerSequence: 1238396,
SigningPubKey:
'027497533006d024ffb612a2110eb327ccfeed2b752d787c96ab2d3cca425a40e8',
},
txnHex:
'53545800120000220000000024000A5342201B0012E57C6140000000004C4B4068400000000000000C7321027497533006D024FFB612A2110EB327CCFEED2B752D787C96AB2D3CCA425A40E88114FF2BC637244009494C6203505254126638AAD7CD8314A0F766DFCC0B5DDC91E7679C7539590983A41D9F',
},
},
queries: [
{
name: 'Initate query',
data: queryToUint8Array({
signTxn: {
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,
]),
derivationPath: [
0x80000000 + 44,
0x80000000 + 144,
0x80000000,
0,
0,
],
transactionSize: 120,
},
},
}),
},
],
};

const withUnknownError: ISignTxnTestCase = {
name: 'With unknown error',
...commonParams,
results: [
{
name: 'error',
data: resultToUint8Array({
signTxn: {
commonError: {
unknownError: 1,
},
},
}),
},
],
errorInstance: DeviceAppError,
errorMessage:
deviceAppErrorTypeDetails[DeviceAppErrorType.UNKNOWN_ERROR].message,
};

const withInvalidResult: ISignTxnTestCase = {
name: 'With invalid result',
...commonParams,
results: [
{
name: 'error',
data: new Uint8Array([18, 4, 26, 2, 24, 1]),
},
],
errorInstance: DeviceAppError,
errorMessage:
deviceAppErrorTypeDetails[DeviceAppErrorType.INVALID_MSG_FROM_DEVICE]
.message,
};

const error: ISignTxnTestCase[] = [withUnknownError, withInvalidResult];

export default error;
14 changes: 14 additions & 0 deletions packages/app-xrp/tests/03.signTxn/__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 invalidArgs from './invalidArgs';
import valid from './valid';

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

export default fixtures;
104 changes: 104 additions & 0 deletions packages/app-xrp/tests/03.signTxn/__fixtures__/invalidArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { ISignTxnTestCase } 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,
]),
derivationPath: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
txn: {
rawTxn: {
TransactionType: 'Payment',
Account: 'rQGDkQchoJxMSLZR7q9GwvY3iKtDqTUYNQ',
Amount: '5000000',
Destination: 'rEgfV7YeyG4YayQQufxaqDx4aUA93SidLb',
Flags: 0,
NetworkID: undefined,
Sequence: 676674,
Fee: '12',
LastLedgerSequence: 1238396,
SigningPubKey:
'027497533006d024ffb612a2110eb327ccfeed2b752d787c96ab2d3cca425a40e8',
},
txnHex:
'53545800120000220000000024000A5342201B0012E57C6140000000004C4B4068400000000000000C7321027497533006D024FFB612A2110EB327CCFEED2B752D787C96AB2D3CCA425A40E88114FF2BC637244009494C6203505254126638AAD7CD8314A0F766DFCC0B5DDC91E7679C7539590983A41D9F',
},
};

const invalidArgs: ISignTxnTestCase[] = [
{
name: 'Null',
...commonParams,
params: null as any,
},
{
name: 'Undefined',
...commonParams,
params: null as any,
},
{
name: 'Empty Object',
...commonParams,
params: {} as any,
},
{
name: 'No derivation path',
...commonParams,
params: { ...validParams, derivationPath: undefined } as any,
},
{
name: 'No wallet id',
...commonParams,
params: { ...validParams, walletId: undefined } as any,
},
{
name: 'No txn',
...commonParams,
params: { ...validParams, txn: undefined } as any,
},
{
name: 'No raw txn',
...commonParams,
params: {
...validParams,
txn: { ...validParams.txn, rawTxn: undefined },
} as any,
},
{
name: 'No txn hex',
...commonParams,
params: {
...validParams,
txn: { ...validParams.txn, txnHex: undefined },
} as any,
},
{
name: 'Empty derivation path',
...commonParams,
params: {
...validParams,
derivationPath: [],
} as any,
},
{
name: 'invalid derivation path in array (depth:2)',
...commonParams,
params: {
...validParams,
derivationPath: [
{ index: 44, isHardened: true },
{ index: 0, isHardened: true },
],
},
},
];

export default invalidArgs;
129 changes: 129 additions & 0 deletions packages/app-xrp/tests/03.signTxn/__fixtures__/invalidData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {
DeviceAppError,
DeviceAppErrorType,
deviceAppErrorTypeDetails,
} from '@cypherock/sdk-interfaces';
import { ISignTxnTestCase } from './types';
import { queryToUint8Array } from '../__helpers__';
import { ISignTxnParams } from '../../../src';

const commonParams: {
params: ISignTxnParams;
queries: {
name: string;
data: Uint8Array;
}[];
errorInstance?: any;
[key: string]: any;
} = {
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,
]),
derivationPath: [0x80000000 + 44, 0x80000000 + 144, 0x80000000, 0, 0],
txn: {
rawTxn: {
TransactionType: 'Payment',
Account: 'rQGDkQchoJxMSLZR7q9GwvY3iKtDqTUYNQ',
Amount: '5000000',
Destination: 'rEgfV7YeyG4YayQQufxaqDx4aUA93SidLb',
Flags: 0,
NetworkID: undefined,
Sequence: 676674,
Fee: '12',
LastLedgerSequence: 1238396,
SigningPubKey:
'027497533006d024ffb612a2110eb327ccfeed2b752d787c96ab2d3cca425a40e8',
},
txnHex:
'53545800120000220000000024000A5342201B0012E57C6140000000004C4B4068400000000000000C7321027497533006D024FFB612A2110EB327CCFEED2B752D787C96AB2D3CCA425A40E88114FF2BC637244009494C6203505254126638AAD7CD8314A0F766DFCC0B5DDC91E7679C7539590983A41D9F',
},
},
queries: [
{
name: 'Initate query',
data: queryToUint8Array({
signTxn: {
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,
]),
derivationPath: [
0x80000000 + 44,
0x80000000 + 144,
0x80000000,
0,
0,
],
transactionSize: 120,
},
},
}),
},
],
errorInstance: DeviceAppError,
errorMessage:
deviceAppErrorTypeDetails[DeviceAppErrorType.INVALID_MSG_FROM_DEVICE]
.message,
};

const invalidData: ISignTxnTestCase[] = [
{
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/03.signTxn/__fixtures__/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ISignTxnParams, ISignTxnResult } from '../../../src';

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

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

0 comments on commit 3e394f9

Please sign in to comment.