-
Notifications
You must be signed in to change notification settings - Fork 362
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
1 parent
832a9d8
commit b2aa6c2
Showing
11 changed files
with
311 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { deviceIdMap } from "./deviceIdMap"; | ||
import { DeviceModelId as DMKDeviceModelId } from "@ledgerhq/device-management-kit"; | ||
import { DeviceModelId as LLDeviceModelId } from "@ledgerhq/types-devices"; | ||
|
||
describe("deviceIdMap", () => { | ||
it("should map DMK device model ids to LL device model ids", () => { | ||
expect(deviceIdMap[DMKDeviceModelId.FLEX]).toBe(LLDeviceModelId.europa); | ||
}); | ||
}); |
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,21 @@ | ||
import { DeviceBusyError } from "@ledgerhq/device-management-kit"; | ||
import { isAllowedOnboardingStatePollingErrorDmk } from "./errors"; | ||
import { WebHidSendReportError } from "@ledgerhq/device-transport-kit-web-hid"; | ||
|
||
describe("isAllowedOnboardingStatePollingErrorDmk", () => { | ||
it("should return true if the error is a DeviceBusyError", () => { | ||
expect(isAllowedOnboardingStatePollingErrorDmk(new DeviceBusyError())).toBe(true); | ||
}); | ||
|
||
it("should return true if the error is a WebHidSendReportError", () => { | ||
expect(isAllowedOnboardingStatePollingErrorDmk(new WebHidSendReportError())).toBe(true); | ||
}); | ||
|
||
it("should return false if the error is not a DeviceBusyError or WebHidSendReportError", () => { | ||
expect(isAllowedOnboardingStatePollingErrorDmk(new Error())).toBe(false); | ||
}); | ||
|
||
it("should return false if the error is undefined", () => { | ||
expect(isAllowedOnboardingStatePollingErrorDmk(undefined)).toBe(false); | ||
}); | ||
}); |
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
63 changes: 63 additions & 0 deletions
63
libs/live-dmk/src/transport/DeviceManagementKitTransport.test.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,63 @@ | ||
import { of, Subject } from "rxjs"; | ||
import { | ||
DeviceModelId, | ||
DeviceStatus, | ||
DiscoveredDevice, | ||
DeviceSessionState, | ||
} from "@ledgerhq/device-management-kit"; | ||
import { DeviceManagementKitTransport } from "./DeviceManagementKitTransport"; | ||
import { deviceManagementKit } from "../hooks/useDeviceManagementKit"; | ||
// import { activeDeviceSessionSubject } from "../config/activeDeviceSession"; | ||
|
||
let obs: Subject<DeviceSessionState> = new Subject<DeviceSessionState>(); | ||
let transport: DeviceManagementKitTransport; | ||
describe("DeviceManagementKitTransport", () => { | ||
beforeAll(async () => { | ||
vi.spyOn(deviceManagementKit, "listenToKnownDevices").mockImplementation(() => { | ||
return of<DiscoveredDevice[]>([ | ||
{ | ||
id: `test-123`, | ||
deviceModel: { | ||
id: `stax-123`, | ||
model: DeviceModelId.STAX, | ||
name: "stax", | ||
}, | ||
transport: "web-hid", | ||
}, | ||
]); | ||
}); | ||
vi.spyOn(deviceManagementKit, "connect").mockResolvedValue(`session-123`); | ||
vi.spyOn(deviceManagementKit, "getDeviceSessionState").mockImplementation(() => { | ||
obs.next({ | ||
deviceStatus: DeviceStatus.CONNECTED, | ||
} as DeviceSessionState); | ||
return obs; | ||
}); | ||
|
||
transport = await DeviceManagementKitTransport.open(); | ||
}); | ||
|
||
afterEach(() => { | ||
obs.complete(); | ||
obs = new Subject<DeviceSessionState>(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("should open a device", async () => { | ||
expect(transport).toBeInstanceOf(DeviceManagementKitTransport); | ||
}); | ||
|
||
it("should be able to exchange APDU", async () => { | ||
vi.spyOn(deviceManagementKit, "sendApdu").mockResolvedValue({ | ||
data: Buffer.from([]), | ||
statusCode: Buffer.from([0x90, 0x00]), | ||
}); | ||
|
||
const expected = Buffer.from([0x90, 0x00]); | ||
const apdu = Buffer.from([0x00, 0x01, 0x02, 0x03]); | ||
|
||
const response = await transport.exchange(apdu); | ||
|
||
expect(response).toEqual(expected); | ||
}); | ||
}); |
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
Oops, something went wrong.