-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π feat(lld): Track users creating or joining a Ledger keyring on LLD #8283
Open
thesan
wants to merge
8
commits into
develop
Choose a base branch
from
feat/lld-lkrp-getorcreate-analytics
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
β0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a16e69c
feat(lld): track Ledger Sync activation on LLD
thesan 3e27682
chore(lld): test useAddMember
thesan d723a7a
feat(lld): track LLD Ledger Sync activation with the qrcode flow
thesan 94e2268
chore(lld): move tracking next to setTrustchain action
thesan 8da918e
chore(lld): move the var declarations in the useAddMember test to theβ¦
thesan 2710c3a
feat(lld): Track "ledgersync_deactivated" events
thesan 2a002ac
fix(lld): make sure the member is new to the trustchain on the QRcodeβ¦
thesan 8869638
chore: update change log
thesan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ledger-live-desktop": minor | ||
--- | ||
|
||
Track users creating, joining, and leaving Ledger keyrings on LLD |
173 changes: 173 additions & 0 deletions
173
apps/ledger-live-desktop/src/newArch/features/WalletSync/__tests__/useAddMember.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,173 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { renderHook, waitFor } from "@testing-library/react"; | ||
import { TrustchainResultType } from "@ledgerhq/ledger-key-ring-protocol/types"; | ||
import { DeviceModelId } from "@ledgerhq/types-devices"; | ||
import { Flow, Step } from "~/renderer/reducers/walletSync"; | ||
import { useAddMember } from "../hooks/useAddMember"; | ||
import { | ||
TrustchainAlreadyInitialized, | ||
TrustchainAlreadyInitializedWithOtherSeed, | ||
} from "@ledgerhq/ledger-key-ring-protocol/errors"; | ||
|
||
const device = { deviceId: "", modelId: DeviceModelId.stax, wired: true }; | ||
const trustchain = { | ||
rootId: "trustchainId", | ||
walletSyncEncryptionKey: "0x123", | ||
applicationPath: "m/0'/16'/1'", | ||
}; | ||
|
||
const Mocks = { | ||
sdk: { getOrCreateTrustchain: jest.fn() }, | ||
memberCredentialsSelector: jest.fn(), | ||
setTrustchain: jest.fn(), | ||
setFlow: jest.fn(), | ||
track: jest.fn(), | ||
}; | ||
|
||
describe("useAddMember", () => { | ||
it("should create a new trustchain", async () => { | ||
Mocks.sdk.getOrCreateTrustchain.mockResolvedValue({ | ||
trustchain, | ||
type: TrustchainResultType.created, | ||
}); | ||
const { result } = renderHook(() => useAddMember({ device })); | ||
|
||
await waitFor(() => expect(Mocks.sdk.getOrCreateTrustchain).toHaveBeenCalled()); | ||
|
||
expect(result.current.error).toBeNull(); | ||
expect(Mocks.setTrustchain).toHaveBeenCalledWith(trustchain); | ||
expect(Mocks.setFlow).toHaveBeenCalledWith({ | ||
flow: Flow.Activation, | ||
step: Step.ActivationLoading, | ||
nextStep: Step.ActivationFinal, | ||
hasTrustchainBeenCreated: true, | ||
}); | ||
expect(Mocks.track).toHaveBeenCalledTimes(1); | ||
expect(Mocks.track).toHaveBeenCalledWith("ledgersync_activated"); | ||
}); | ||
|
||
it("should get an existing trustchain", async () => { | ||
Mocks.sdk.getOrCreateTrustchain.mockResolvedValue({ | ||
trustchain, | ||
type: TrustchainResultType.restored, | ||
}); | ||
const { result } = renderHook(() => useAddMember({ device })); | ||
|
||
await waitFor(() => expect(Mocks.sdk.getOrCreateTrustchain).toHaveBeenCalled()); | ||
|
||
expect(result.current.error).toBeNull(); | ||
expect(Mocks.setTrustchain).toHaveBeenCalledWith(trustchain); | ||
expect(Mocks.setFlow).toHaveBeenCalledWith({ | ||
flow: Flow.Activation, | ||
step: Step.ActivationLoading, | ||
nextStep: Step.SynchronizationFinal, | ||
hasTrustchainBeenCreated: false, | ||
}); | ||
expect(Mocks.track).toHaveBeenCalledTimes(1); | ||
expect(Mocks.track).toHaveBeenCalledWith("ledgersync_activated"); | ||
}); | ||
|
||
it("should handle missing device", async () => { | ||
const { result } = renderHook(() => useAddMember({ device: null })); | ||
|
||
expect(result.current.error).toBeNull(); | ||
expect(Mocks.setTrustchain).not.toHaveBeenCalledWith(trustchain); | ||
expect(Mocks.setFlow).toHaveBeenCalledWith({ | ||
flow: Flow.Activation, | ||
step: Step.DeviceAction, | ||
}); | ||
expect(Mocks.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should handle already initialized trustchain", async () => { | ||
Mocks.sdk.getOrCreateTrustchain.mockRejectedValue(new TrustchainAlreadyInitialized()); | ||
const { result } = renderHook(() => useAddMember({ device })); | ||
|
||
await waitFor(() => expect(Mocks.sdk.getOrCreateTrustchain).toHaveBeenCalled()); | ||
|
||
expect(result.current.error).toBeNull(); | ||
expect(Mocks.setTrustchain).not.toHaveBeenCalledWith(trustchain); | ||
expect(Mocks.setFlow).toHaveBeenCalledWith({ | ||
flow: Flow.Synchronize, | ||
step: Step.AlreadySecuredSameSeed, | ||
}); | ||
expect(Mocks.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should handle trustchain initialized with other seed", async () => { | ||
Mocks.sdk.getOrCreateTrustchain.mockRejectedValue( | ||
new TrustchainAlreadyInitializedWithOtherSeed(), | ||
); | ||
const { result } = renderHook(() => useAddMember({ device })); | ||
|
||
await waitFor(() => expect(Mocks.sdk.getOrCreateTrustchain).toHaveBeenCalled()); | ||
|
||
expect(result.current.error).toBeNull(); | ||
expect(Mocks.setTrustchain).not.toHaveBeenCalledWith(trustchain); | ||
expect(Mocks.setFlow).toHaveBeenCalledWith({ | ||
flow: Flow.Synchronize, | ||
step: Step.AlreadySecuredOtherSeed, | ||
}); | ||
expect(Mocks.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should handle missing member credentials", async () => { | ||
Mocks.memberCredentialsSelector.mockReturnValue(null); | ||
const { result } = renderHook(() => useAddMember({ device })); | ||
|
||
expect(result.current.error).toBeInstanceOf(Error); | ||
expect(Mocks.sdk.getOrCreateTrustchain).not.toHaveBeenCalled(); | ||
expect(Mocks.setTrustchain).not.toHaveBeenCalledWith(trustchain); | ||
expect(Mocks.setFlow).not.toHaveBeenCalled(); | ||
expect(Mocks.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should handle other sdk errors", async () => { | ||
Mocks.sdk.getOrCreateTrustchain.mockRejectedValue(new Error("Random error")); | ||
const { result } = renderHook(() => useAddMember({ device })); | ||
|
||
await waitFor(() => expect(Mocks.sdk.getOrCreateTrustchain).toHaveBeenCalled()); | ||
|
||
expect(result.current.error).toBeInstanceOf(Error); | ||
expect((result.current.error as Error).message).toBe("Random error"); | ||
expect(Mocks.setTrustchain).not.toHaveBeenCalled(); | ||
expect(Mocks.setFlow).not.toHaveBeenCalled(); | ||
expect(Mocks.track).not.toHaveBeenCalled(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
Mocks.memberCredentialsSelector.mockReturnValue({ | ||
pubkey: "pubkey", | ||
privatekey: "privatekey", | ||
}); | ||
}); | ||
}); | ||
|
||
jest.mock("react-redux", () => { | ||
const dispatch = jest.fn(); | ||
return { | ||
useDispatch: () => dispatch, | ||
useSelector: (selector: () => unknown) => selector(), | ||
}; | ||
}); | ||
|
||
jest.mock("@ledgerhq/ledger-key-ring-protocol/store", () => ({ | ||
memberCredentialsSelector: () => Mocks.memberCredentialsSelector(), | ||
trustchainSelector: () => null, | ||
setTrustchain: (trustchain: unknown) => Mocks.setTrustchain(trustchain), | ||
})); | ||
|
||
jest.mock("~/renderer/actions/walletSync", () => ({ | ||
setFlow: (flow: unknown) => Mocks.setFlow(flow), | ||
})); | ||
|
||
jest.mock("~/renderer/analytics/segment", () => ({ | ||
track: (event: string) => Mocks.track(event), | ||
})); | ||
|
||
jest.mock("../hooks/useTrustchainSdk", () => ({ | ||
useTrustchainSdk: () => Mocks.sdk, | ||
})); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would move this bloc to the top before using the variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the beforeEach ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no the variable declarations , mock setups starting from line 134