Skip to content

Commit 75e48f9

Browse files
chore: tests for all getDelegatedKeys methods
1 parent 99ba633 commit 75e48f9

25 files changed

+322
-160
lines changed

suite-common/redux-utils/src/extraDependenciesType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66

77
import { MetadataAddPayload } from '@suite-common/metadata-types';
88
import { SecureStorage } from '@suite-common/secure-storage';
9-
import { SuiteSync } from '@suite-common/suite-sync-storage';
9+
import { SuiteSync } from '@suite-common/suite-sync';
1010
import {
1111
ReportSecurityCheckProps,
1212
Route,

suite-common/suite-sync-storage/src/SuiteSync.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

suite-common/suite-sync-storage/src/SuiteSyncStorage.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { SuiteSyncOwner } from '@suite-common/suite-types/';
2+
13
import { AccountLabelsStore } from './labeling/AccountLabelsStore';
24
import { AddressLabelsStore } from './labeling/AddressLabelsStore';
35
import { OutputLabelsStore } from './labeling/OutputLabelsStore';
@@ -17,3 +19,19 @@ export type SuiteSyncStorage = {
1719
updateRelayUrl(url: string): Promise<void>;
1820
dispose(): Promise<void>;
1921
};
22+
23+
type SuiteStorageCreatorParams = {
24+
suiteSyncOwner: SuiteSyncOwner;
25+
relayUrl: string;
26+
};
27+
28+
/**
29+
* This is a service responsible for creating the SuiteSyncStorage. Every Owner
30+
* has its own Storage. Currently only Evolu storage is implemented, but in theory,
31+
* you can have different one as well.
32+
*/
33+
export type CreateSuiteStorage = (params: SuiteStorageCreatorParams) => SuiteSyncStorage;
34+
35+
export type CreateSuiteStorageDep = {
36+
createSuiteStorage: CreateSuiteStorage;
37+
};

suite-common/suite-sync-storage/src/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
export type {
2-
SuiteSyncStorageRepository,
3-
CreateSuiteSyncStorageRepository,
2+
SuiteSyncStorage,
43
CreateSuiteStorage,
54
CreateSuiteStorageDep,
6-
} from './SuiteSyncStorageRepository';
7-
export { createSuiteSyncStorageRepositoryFactory } from './SuiteSyncStorageRepository';
8-
export type { SuiteSyncStorage } from './SuiteSyncStorage';
5+
} from './SuiteSyncStorage';
6+
97
export type { CreateSuiteSyncOwner, CreateSuiteSyncOwnerDep } from './Owner';
108
export { CreateSuiteSyncOwnerError } from './Owner';
11-
export type {
12-
SuiteSync,
13-
ChangeRelayUrl,
14-
SubscribeSuiteSyncStorage,
15-
TurnOfSuiteSync,
16-
UnsubscribeSuiteSyncStorage,
17-
} from './SuiteSync';
189

1910
// Labeling
2011
export type { AddressLabelsStore, AddressLabel } from './labeling/AddressLabelsStore';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { CreateSuiteSyncOwnerDep } from '@suite-common/suite-sync-storage';
2+
3+
import { SuiteSyncStorageRepositoryDep } from './SuiteSyncStorageRepository';
4+
import { ChangeRelayUrlDep } from './relay/changeRelayUrl';
5+
import { TurnOffSuiteSyncForWalletDep } from './storage/turnOffSuiteSyncForWallet';
6+
import { TurnOnSuiteSyncForWalletDep } from './storage/turnOnSuiteSyncForWallet';
7+
import { TurnOffSuiteSyncDep } from './turnOffSuiteSync';
8+
9+
export type SuiteSync = ChangeRelayUrlDep &
10+
SuiteSyncStorageRepositoryDep &
11+
CreateSuiteSyncOwnerDep &
12+
TurnOffSuiteSyncDep &
13+
TurnOnSuiteSyncForWalletDep &
14+
TurnOffSuiteSyncForWalletDep;

suite-common/suite-sync-storage/src/SuiteSyncStorageRepository.ts renamed to suite-common/suite-sync/src/SuiteSyncStorageRepository.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1+
import { CreateSuiteStorageDep, SuiteSyncStorage } from '@suite-common/suite-sync-storage';
12
import { SuiteSyncOwner, SuiteSyncOwnerId } from '@suite-common/suite-types';
23

3-
import { SuiteSyncStorage } from './SuiteSyncStorage';
4-
5-
type SuiteStorageCreatorParams = {
6-
suiteSyncOwner: SuiteSyncOwner;
7-
relayUrl: string;
8-
};
9-
10-
/**
11-
* This is a service responsible for creating the SuiteSyncStorage. Every Owner
12-
* has its own Storage. Currently only Evolu storage is implemented, but in theory,
13-
* you can have different one as well.
14-
*/
15-
export type CreateSuiteStorage = (params: SuiteStorageCreatorParams) => SuiteSyncStorage;
16-
17-
export type CreateSuiteStorageDep = {
18-
createSuiteStorage: CreateSuiteStorage;
19-
};
20-
214
export type CreateSuiteSyncStorageRepositoryFactoryDeps = CreateSuiteStorageDep & {
225
defaultRelayUrl: string;
236
getRelayUrl: () => string | null;
@@ -30,6 +13,10 @@ export type SuiteSyncStorageRepository = {
3013

3114
export type CreateSuiteSyncStorageRepository = () => SuiteSyncStorageRepository;
3215

16+
export type SuiteSyncStorageRepositoryDep = {
17+
suiteSyncStorageRepository: SuiteSyncStorageRepository;
18+
};
19+
3320
/**
3421
* Every Wallet has its own SuiteSyncStorage with Owner derived
3522
* from its secret (Seed+Passphrase) .

suite-common/suite-sync/src/createSuiteSyncCompositionRoot.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { Dispatch } from '@reduxjs/toolkit';
22

33
import { SecureStorageDep } from '@suite-common/secure-storage';
4+
import { CreateSuiteStorageDep, CreateSuiteSyncOwnerDep } from '@suite-common/suite-sync-storage';
5+
// Circular issue, see: https://github.com/trezor/trezor-suite/issues/21553
6+
import { selectThp } from '@suite-common/thp/src/thpSelectors';
47
import {
5-
CreateSuiteStorageDep,
6-
CreateSuiteSyncOwnerDep,
7-
SuiteSync,
8-
createSuiteSyncStorageRepositoryFactory,
9-
} from '@suite-common/suite-sync-storage';
10-
import {
8+
RetrieveDelegatedIdentityKeyFromDeviceDeps,
119
createEnsureDelegatedIdentityKey,
1210
createLoadDelegatedIdentityKeyFromState,
11+
createRetrieveDelegatedIdentityKeyFromDevice,
1312
createSaveDelegatedIdentityKey,
1413
selectAllDeviceOwners,
1514
selectDeviceDelegatedIdentityKey,
1615
} from '@suite-common/wallet-core';
1716

17+
import { SuiteSync } from './SuiteSync';
18+
import { createSuiteSyncStorageRepositoryFactory } from './SuiteSyncStorageRepository';
1819
import {
1920
EnsureSuiteSyncOwnerDeps,
2021
createEnsureSuiteSyncOwnerKeys,
@@ -23,16 +24,17 @@ import { createSubscribeLabeling } from './labeling/createSubscribeLabeling';
2324
import { createRefreshSuiteSyncKeys } from './refreshSuiteSyncKeys';
2425
import { createChangeRelayUrl } from './relay/changeRelayUrl';
2526
import { DEFAULT_SUITE_SYNC_RELAY_URL } from './relay/relayUrl';
26-
import { createSubscribeSuiteSyncStorage } from './storage/subscribeSuiteSyncStorage';
2727
import { createSubscriptionStorage } from './storage/subscriptionStorage';
28-
import { createUnsubscribeSuiteSyncStorage } from './storage/unsubscribeSuiteSync';
28+
import { createTurnOffSuiteSyncForWallet } from './storage/turnOffSuiteSyncForWallet';
29+
import { createTurnOnSuiteSyncForWallet } from './storage/turnOnSuiteSyncForWallet';
2930
import { selectSuiteSyncRelayUrl } from './suiteSyncSelectors';
3031
import { createTurnOffSuiteSync } from './turnOffSuiteSync';
3132

3233
type CreateSuiteSyncCompositionRootDeps = {
3334
getState: () => any;
3435
dispatch: Dispatch;
35-
trezorConnect: EnsureSuiteSyncOwnerDeps['trezorConnect'];
36+
trezorConnect: EnsureSuiteSyncOwnerDeps['trezorConnect'] &
37+
RetrieveDelegatedIdentityKeyFromDeviceDeps['trezorConnect'];
3638
} & CreateSuiteStorageDep &
3739
CreateSuiteSyncOwnerDep &
3840
SecureStorageDep;
@@ -67,11 +69,14 @@ export const createSuiteSyncCompositionRoot = (
6769
getDeviceDelegatedIdentityKey: deviceId =>
6870
selectDeviceDelegatedIdentityKey(deps.getState(), deviceId),
6971
}),
72+
retrieveDelegatedIdentityKeyFromDevice: createRetrieveDelegatedIdentityKeyFromDevice({
73+
trezorConnect: deps.trezorConnect,
74+
}),
7075
saveDelegatedIdentityKey: createSaveDelegatedIdentityKey({
7176
dispatch: deps.dispatch,
7277
secureStorage: deps.secureStorage,
7378
}),
74-
getState: deps.getState,
79+
getThpStaticKey: () => selectThp(deps.getState()).staticKey,
7580
});
7681
// Todo: ------------------------------------------------------------
7782

@@ -82,14 +87,14 @@ export const createSuiteSyncCompositionRoot = (
8287
ensureSuiteSyncOwnerKeys,
8388
});
8489

85-
const subscribeSuiteSyncStorage = createSubscribeSuiteSyncStorage({
90+
const turnOnSuiteSyncForWallet = createTurnOnSuiteSyncForWallet({
8691
dispatch: deps.dispatch,
8792
getState: deps.getState,
8893
subscribeLabeling,
8994
refreshSuiteSyncKeys,
9095
});
9196

92-
const unsubscribeSuiteSyncStorage = createUnsubscribeSuiteSyncStorage({
97+
const turnOffSuiteSyncForWallet = createTurnOffSuiteSyncForWallet({
9398
suiteSyncStorageRepository,
9499
subscriptionStorage,
95100
});
@@ -102,11 +107,11 @@ export const createSuiteSyncCompositionRoot = (
102107
}),
103108
suiteSyncStorageRepository,
104109
createSuiteSyncOwner: deps.createSuiteSyncOwner,
105-
subscribeSuiteSyncStorage,
106-
unsubscribeSuiteSyncStorage,
110+
turnOnSuiteSyncForWallet,
111+
turnOffSuiteSyncForWallet,
107112
turnOffSuiteSync: createTurnOffSuiteSync({
108113
getState: deps.getState,
109-
unsubscribeSuiteSyncStorage,
114+
turnOffSuiteSyncForWallet,
110115
}),
111116
};
112117
};

suite-common/suite-sync/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export { prepareSuiteSyncReducer, initialSuiteSyncState } from './suiteSyncReduc
1414
export type { SuiteSyncState, SuiteSyncSettings } from './suiteSyncReducer';
1515
export { suiteSyncActions } from './suiteSyncActions';
1616
export { DEFAULT_SUITE_SYNC_RELAY_URL } from './relay/relayUrl';
17+
export type { SuiteSync } from './SuiteSync';
18+
export type {
19+
SuiteSyncStorageRepository,
20+
CreateSuiteSyncStorageRepository,
21+
} from './SuiteSyncStorageRepository';
22+
export { createSuiteSyncStorageRepositoryFactory } from './SuiteSyncStorageRepository';
1723

1824
// Labeling
1925
// Todo: refactor to services, so they can be isolated & tested!

suite-common/suite-sync/src/labeling/createSubscribeLabeling.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Dispatch } from '@reduxjs/toolkit';
22

3-
import { SuiteSyncStorageRepository } from '@suite-common/suite-sync-storage';
43
import { SuiteSyncOwner } from '@suite-common/suite-types';
54
import { WalletDescriptor } from '@suite-common/wallet-types';
65

76
import { clearAllLabels, labelingActions } from './labelingActions';
8-
import { SubscriptionStorage } from '../storage/subscriptionStorage';
7+
import { SuiteSyncStorageRepositoryDep } from '../SuiteSyncStorageRepository';
8+
import { SubscriptionStorageDep } from '../storage/subscriptionStorage';
99

1010
type SubscribeLabelingParams = {
1111
owner: SuiteSyncOwner;
@@ -14,11 +14,10 @@ type SubscribeLabelingParams = {
1414

1515
export type SubscribeLabeling = (params: SubscribeLabelingParams) => void;
1616

17-
export type CreateSubscribeLabelingDeps = {
18-
suiteSyncStorageRepository: SuiteSyncStorageRepository;
19-
subscriptionStorage: SubscriptionStorage;
20-
dispatch: Dispatch;
21-
};
17+
export type CreateSubscribeLabelingDeps = SuiteSyncStorageRepositoryDep &
18+
SubscriptionStorageDep & {
19+
dispatch: Dispatch;
20+
};
2221

2322
export const createSubscribeLabeling =
2423
(deps: CreateSubscribeLabelingDeps): SubscribeLabeling =>

suite-common/suite-sync/src/relay/changeRelayUrl.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { Dispatch } from '@reduxjs/toolkit';
22

3-
import { ChangeRelayUrl, SuiteSyncStorageRepository } from '@suite-common/suite-sync-storage';
43
import { SuiteSyncOwner } from '@suite-common/suite-types';
54

65
import { setSuiteSyncRelayUrl } from '../suiteSyncActions';
76
import { DEFAULT_SUITE_SYNC_RELAY_URL } from './relayUrl';
7+
import { SuiteSyncStorageRepositoryDep } from '../SuiteSyncStorageRepository';
88

99
export type ChangeRelayUrlDeps = {
1010
getAllDevicesOwners: () => SuiteSyncOwner[];
1111
dispatch: Dispatch;
12-
suiteSyncStorageRepository: SuiteSyncStorageRepository;
12+
} & SuiteSyncStorageRepositoryDep;
13+
14+
export type ChangeRelayUrl = (params: { relayUrl: string | null }) => Promise<void>;
15+
16+
export type ChangeRelayUrlDep = {
17+
changeRelayUrl: ChangeRelayUrl;
1318
};
1419

1520
export const createChangeRelayUrl =

0 commit comments

Comments
 (0)