-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,466 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { MockDeviceConnection } from '@cypherock/sdk-interfaces'; | ||
import { afterEach, beforeEach, describe, expect, test } from '@jest/globals'; | ||
|
||
import * as sdkMocks from '../../src/__mocks__/sdk'; | ||
import { StarknetApp } from '../../src/index'; | ||
|
||
describe('StarknetApp.create', () => { | ||
let connection: MockDeviceConnection; | ||
|
||
beforeEach(async () => { | ||
connection = await MockDeviceConnection.create(); | ||
sdkMocks.create.mockClear(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await connection.destroy(); | ||
}); | ||
|
||
test('should be able to create solana app instance', async () => { | ||
await StarknetApp.create(connection); | ||
|
||
expect(sdkMocks.create).toHaveBeenCalledTimes(1); | ||
expect(sdkMocks.create.mock.lastCall).toContainEqual(connection); | ||
}); | ||
}); |
94 changes: 94 additions & 0 deletions
94
packages/app-starknet/tests/02.getPublicKeys/__fixtures__/error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { | ||
DeviceAppError, | ||
DeviceAppErrorType, | ||
deviceAppErrorTypeDetails, | ||
} from '@cypherock/sdk-interfaces'; | ||
import { IGetPublicKeysTestCase } from './types'; | ||
import { Query } from '../../../src/proto/generated/starknet/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 + 0xa55, | ||
0x80000000 + 0x4741e9c9, | ||
0x80000000 + 0x447a6028, | ||
0x80000000, | ||
0x80000000, | ||
0xc, | ||
], | ||
}, | ||
], | ||
chainId: 1, | ||
}, | ||
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 + 0xa55, | ||
0x80000000 + 0x4741e9c9, | ||
0x80000000 + 0x447a6028, | ||
0x80000000, | ||
0x80000000, | ||
0xc, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
).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
14
packages/app-starknet/tests/02.getPublicKeys/__fixtures__/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
79 changes: 79 additions & 0 deletions
79
packages/app-starknet/tests/02.getPublicKeys/__fixtures__/invalidArgs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
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 + 0xa55, | ||
0x80000000 + 0x4741e9c9, | ||
0x80000000 + 0x447a6028, | ||
0x80000000, | ||
0x80000000, | ||
0xc, | ||
], | ||
}, | ||
], | ||
chainId: '1', | ||
}; | ||
|
||
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: 'No wallet id', | ||
...commonParams, | ||
params: { ...validParams, walletId: undefined } as any, | ||
}, | ||
{ | ||
name: 'Empty derivation path', | ||
...commonParams, | ||
params: { | ||
...validParams, | ||
derivationPaths: [], | ||
} as any, | ||
}, | ||
{ | ||
name: 'invalid derivation path in array (depth:1)', | ||
...commonParams, | ||
params: { | ||
...validParams, | ||
derivationPaths: [ | ||
{ | ||
path: [0x80000000], | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
export default invalidArgs; |
123 changes: 123 additions & 0 deletions
123
packages/app-starknet/tests/02.getPublicKeys/__fixtures__/invalidData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { | ||
DeviceAppError, | ||
DeviceAppErrorType, | ||
deviceAppErrorTypeDetails, | ||
} from '@cypherock/sdk-interfaces'; | ||
import { IGetPublicKeysTestCase } from './types'; | ||
import { Query } from '../../../src/proto/generated/starknet/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 + 0xa55, | ||
0x80000000 + 0x4741e9c9, | ||
0x80000000 + 0x447a6028, | ||
0x80000000, | ||
0x80000000, | ||
0xc, | ||
], | ||
}, | ||
], | ||
chainId: 1, | ||
}, | ||
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 + 0xa55, | ||
0x80000000 + 0x4741e9c9, | ||
0x80000000 + 0x447a6028, | ||
0x80000000, | ||
0x80000000, | ||
0xc, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
).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; |
Oops, something went wrong.