@ledgerhq/live-common 34.48.0-nightly.1 → 34.48.0-nightly.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bridge/crypto-assets/index.d.ts.map +1 -1
- package/lib/bridge/crypto-assets/index.js +0 -4
- package/lib/bridge/crypto-assets/index.js.map +1 -1
- package/lib/bridge/crypto-assets/index.test.js +0 -36
- package/lib/bridge/crypto-assets/index.test.js.map +1 -1
- package/lib/config/sharedConfig.d.ts.map +1 -1
- package/lib/config/sharedConfig.js +2 -0
- package/lib/config/sharedConfig.js.map +1 -1
- package/lib/e2e/index.d.ts +3 -4
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/families/canton/bridge/mock-data.d.ts +6 -0
- package/lib/families/canton/bridge/mock-data.d.ts.map +1 -0
- package/lib/families/canton/bridge/mock-data.js +120 -0
- package/lib/families/canton/bridge/mock-data.js.map +1 -0
- package/lib/families/canton/bridge/mock.d.ts +12 -0
- package/lib/families/canton/bridge/mock.d.ts.map +1 -0
- package/lib/families/canton/bridge/mock.js +154 -0
- package/lib/families/canton/bridge/mock.js.map +1 -0
- package/lib/families/canton/config.d.ts.map +1 -1
- package/lib/families/canton/config.js +5 -2
- package/lib/families/canton/config.js.map +1 -1
- package/lib/families/canton/setup.d.ts.map +1 -1
- package/lib/families/canton/setup.js +8 -2
- package/lib/families/canton/setup.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +0 -1
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/generated/bridge/mock.d.ts +8 -0
- package/lib/generated/bridge/mock.d.ts.map +1 -1
- package/lib/generated/bridge/mock.js +26 -24
- package/lib/generated/bridge/mock.js.map +1 -1
- package/lib/modularDrawer/hooks/useAssetsData.d.ts +1 -0
- package/lib/modularDrawer/hooks/useAssetsData.d.ts.map +1 -1
- package/lib/modularDrawer/hooks/useAssetsData.js +3 -2
- package/lib/modularDrawer/hooks/useAssetsData.js.map +1 -1
- package/lib/modularDrawer/hooks/useSearch.d.ts +16 -0
- package/lib/modularDrawer/hooks/useSearch.d.ts.map +1 -0
- package/lib/modularDrawer/hooks/useSearch.js +24 -0
- package/lib/modularDrawer/hooks/useSearch.js.map +1 -0
- package/lib/notifications/ServiceStatusProvider/index.d.ts +16 -1
- package/lib/notifications/ServiceStatusProvider/index.d.ts.map +1 -1
- package/lib/notifications/ServiceStatusProvider/index.js +31 -7
- package/lib/notifications/ServiceStatusProvider/index.js.map +1 -1
- package/lib/notifications/ServiceStatusProvider/index.test.d.ts +2 -0
- package/lib/notifications/ServiceStatusProvider/index.test.d.ts.map +1 -0
- package/lib/notifications/ServiceStatusProvider/index.test.js +88 -0
- package/lib/notifications/ServiceStatusProvider/index.test.js.map +1 -0
- package/lib/notifications/ServiceStatusProvider/ledger-components.d.ts +2 -0
- package/lib/notifications/ServiceStatusProvider/ledger-components.d.ts.map +1 -0
- package/lib/notifications/ServiceStatusProvider/ledger-components.js +16 -0
- package/lib/notifications/ServiceStatusProvider/ledger-components.js.map +1 -0
- package/lib/wallet-api/ACRE/server.d.ts +13 -6
- package/lib/wallet-api/ACRE/server.d.ts.map +1 -1
- package/lib/wallet-api/ACRE/server.js +142 -1
- package/lib/wallet-api/ACRE/server.js.map +1 -1
- package/lib/wallet-api/ACRE/server.test.d.ts +2 -0
- package/lib/wallet-api/ACRE/server.test.d.ts.map +1 -0
- package/lib/wallet-api/ACRE/server.test.js +393 -0
- package/lib/wallet-api/ACRE/server.test.js.map +1 -0
- package/lib-es/bridge/crypto-assets/index.d.ts.map +1 -1
- package/lib-es/bridge/crypto-assets/index.js +0 -4
- package/lib-es/bridge/crypto-assets/index.js.map +1 -1
- package/lib-es/bridge/crypto-assets/index.test.js +0 -36
- package/lib-es/bridge/crypto-assets/index.test.js.map +1 -1
- package/lib-es/config/sharedConfig.d.ts.map +1 -1
- package/lib-es/config/sharedConfig.js +2 -0
- package/lib-es/config/sharedConfig.js.map +1 -1
- package/lib-es/e2e/index.d.ts +3 -4
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/families/canton/bridge/mock-data.d.ts +6 -0
- package/lib-es/families/canton/bridge/mock-data.d.ts.map +1 -0
- package/lib-es/families/canton/bridge/mock-data.js +116 -0
- package/lib-es/families/canton/bridge/mock-data.js.map +1 -0
- package/lib-es/families/canton/bridge/mock.d.ts +12 -0
- package/lib-es/families/canton/bridge/mock.d.ts.map +1 -0
- package/lib-es/families/canton/bridge/mock.js +152 -0
- package/lib-es/families/canton/bridge/mock.js.map +1 -0
- package/lib-es/families/canton/config.d.ts.map +1 -1
- package/lib-es/families/canton/config.js +5 -2
- package/lib-es/families/canton/config.js.map +1 -1
- package/lib-es/families/canton/setup.d.ts.map +1 -1
- package/lib-es/families/canton/setup.js +8 -2
- package/lib-es/families/canton/setup.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +0 -1
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/generated/bridge/mock.d.ts +8 -0
- package/lib-es/generated/bridge/mock.d.ts.map +1 -1
- package/lib-es/generated/bridge/mock.js +2 -0
- package/lib-es/generated/bridge/mock.js.map +1 -1
- package/lib-es/modularDrawer/hooks/useAssetsData.d.ts +1 -0
- package/lib-es/modularDrawer/hooks/useAssetsData.d.ts.map +1 -1
- package/lib-es/modularDrawer/hooks/useAssetsData.js +3 -2
- package/lib-es/modularDrawer/hooks/useAssetsData.js.map +1 -1
- package/lib-es/modularDrawer/hooks/useSearch.d.ts +16 -0
- package/lib-es/modularDrawer/hooks/useSearch.d.ts.map +1 -0
- package/lib-es/modularDrawer/hooks/useSearch.js +20 -0
- package/lib-es/modularDrawer/hooks/useSearch.js.map +1 -0
- package/lib-es/notifications/ServiceStatusProvider/index.d.ts +16 -1
- package/lib-es/notifications/ServiceStatusProvider/index.d.ts.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.js +31 -7
- package/lib-es/notifications/ServiceStatusProvider/index.js.map +1 -1
- package/lib-es/notifications/ServiceStatusProvider/index.test.d.ts +2 -0
- package/lib-es/notifications/ServiceStatusProvider/index.test.d.ts.map +1 -0
- package/lib-es/notifications/ServiceStatusProvider/index.test.js +86 -0
- package/lib-es/notifications/ServiceStatusProvider/index.test.js.map +1 -0
- package/lib-es/notifications/ServiceStatusProvider/ledger-components.d.ts +2 -0
- package/lib-es/notifications/ServiceStatusProvider/ledger-components.d.ts.map +1 -0
- package/lib-es/notifications/ServiceStatusProvider/ledger-components.js +13 -0
- package/lib-es/notifications/ServiceStatusProvider/ledger-components.js.map +1 -0
- package/lib-es/wallet-api/ACRE/server.d.ts +13 -6
- package/lib-es/wallet-api/ACRE/server.d.ts.map +1 -1
- package/lib-es/wallet-api/ACRE/server.js +140 -2
- package/lib-es/wallet-api/ACRE/server.js.map +1 -1
- package/lib-es/wallet-api/ACRE/server.test.d.ts +2 -0
- package/lib-es/wallet-api/ACRE/server.test.d.ts.map +1 -0
- package/lib-es/wallet-api/ACRE/server.test.js +388 -0
- package/lib-es/wallet-api/ACRE/server.test.js.map +1 -0
- package/package.json +48 -48
- package/src/bridge/crypto-assets/index.test.ts +0 -47
- package/src/bridge/crypto-assets/index.ts +0 -5
- package/src/config/sharedConfig.ts +2 -0
- package/src/families/canton/bridge/mock-data.ts +175 -0
- package/src/families/canton/bridge/mock.ts +180 -0
- package/src/families/canton/config.ts +5 -3
- package/src/families/canton/setup.ts +8 -5
- package/src/featureFlags/defaultFeatures.ts +0 -1
- package/src/generated/bridge/mock.ts +2 -0
- package/src/modularDrawer/hooks/useAssetsData.ts +3 -2
- package/src/modularDrawer/hooks/useSearch.ts +52 -0
- package/src/notifications/ServiceStatusProvider/index.test.ts +102 -0
- package/src/notifications/ServiceStatusProvider/index.tsx +37 -12
- package/src/notifications/ServiceStatusProvider/ledger-components.ts +12 -0
- package/src/wallet-api/ACRE/server.test.ts +470 -0
- package/src/wallet-api/ACRE/server.ts +202 -14
- package/lib/bridge/crypto-assets/cal-integration.d.ts +0 -4
- package/lib/bridge/crypto-assets/cal-integration.d.ts.map +0 -1
- package/lib/bridge/crypto-assets/cal-integration.js +0 -26
- package/lib/bridge/crypto-assets/cal-integration.js.map +0 -1
- package/lib/bridge/crypto-assets/cal-integration.test.d.ts +0 -2
- package/lib/bridge/crypto-assets/cal-integration.test.d.ts.map +0 -1
- package/lib/bridge/crypto-assets/cal-integration.test.js +0 -45
- package/lib/bridge/crypto-assets/cal-integration.test.js.map +0 -1
- package/lib/bridge/crypto-assets/cal-store.d.ts +0 -14
- package/lib/bridge/crypto-assets/cal-store.d.ts.map +0 -1
- package/lib/bridge/crypto-assets/cal-store.js +0 -58
- package/lib/bridge/crypto-assets/cal-store.js.map +0 -1
- package/lib/bridge/crypto-assets/cal-store.test.d.ts +0 -2
- package/lib/bridge/crypto-assets/cal-store.test.d.ts.map +0 -1
- package/lib/bridge/crypto-assets/cal-store.test.js +0 -70
- package/lib/bridge/crypto-assets/cal-store.test.js.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-integration.d.ts +0 -4
- package/lib-es/bridge/crypto-assets/cal-integration.d.ts.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-integration.js +0 -21
- package/lib-es/bridge/crypto-assets/cal-integration.js.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-integration.test.d.ts +0 -2
- package/lib-es/bridge/crypto-assets/cal-integration.test.d.ts.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-integration.test.js +0 -43
- package/lib-es/bridge/crypto-assets/cal-integration.test.js.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-store.d.ts +0 -14
- package/lib-es/bridge/crypto-assets/cal-store.d.ts.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-store.js +0 -54
- package/lib-es/bridge/crypto-assets/cal-store.js.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-store.test.d.ts +0 -2
- package/lib-es/bridge/crypto-assets/cal-store.test.d.ts.map +0 -1
- package/lib-es/bridge/crypto-assets/cal-store.test.js +0 -68
- package/lib-es/bridge/crypto-assets/cal-store.test.js.map +0 -1
- package/src/bridge/crypto-assets/cal-integration.test.ts +0 -53
- package/src/bridge/crypto-assets/cal-integration.ts +0 -23
- package/src/bridge/crypto-assets/cal-store.test.ts +0 -93
- package/src/bridge/crypto-assets/cal-store.ts +0 -63
@@ -0,0 +1,470 @@
|
|
1
|
+
import { handlers } from "./server";
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
3
|
+
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
4
|
+
import BigNumber from "bignumber.js";
|
5
|
+
import { AppPlatform, AppBranch, Visibility } from "../types";
|
6
|
+
|
7
|
+
// Mock dependencies
|
8
|
+
jest.mock("@ledgerhq/wallet-api-server", () => ({
|
9
|
+
RPCHandler: jest.fn(),
|
10
|
+
customWrapper: jest.fn(handler => handler),
|
11
|
+
}));
|
12
|
+
|
13
|
+
jest.mock("@ledgerhq/cryptoassets", () => ({
|
14
|
+
findTokenById: jest.fn(),
|
15
|
+
findTokenByAddressInCurrency: jest.fn(),
|
16
|
+
getCryptoCurrencyById: jest.fn(),
|
17
|
+
}));
|
18
|
+
|
19
|
+
jest.mock("../converters", () => ({
|
20
|
+
getAccountIdFromWalletAccountId: jest.fn(),
|
21
|
+
getWalletAPITransactionSignFlowInfos: jest.fn(),
|
22
|
+
}));
|
23
|
+
|
24
|
+
jest.mock("../../bridge", () => ({
|
25
|
+
getAccountBridge: jest.fn(),
|
26
|
+
}));
|
27
|
+
|
28
|
+
jest.mock("@ledgerhq/live-env", () => ({
|
29
|
+
getEnv: jest.fn(),
|
30
|
+
}));
|
31
|
+
|
32
|
+
// Mock types
|
33
|
+
const mockTracking = {
|
34
|
+
signMessageRequested: jest.fn(),
|
35
|
+
signMessageSuccess: jest.fn(),
|
36
|
+
signMessageFail: jest.fn(),
|
37
|
+
signMessageNoParams: jest.fn(),
|
38
|
+
signMessageUserRefused: jest.fn(),
|
39
|
+
signTransactionRequested: jest.fn(),
|
40
|
+
signTransactionSuccess: jest.fn(),
|
41
|
+
signTransactionFail: jest.fn(),
|
42
|
+
signTransactionNoParams: jest.fn(),
|
43
|
+
signTransactionAndBroadcastNoParams: jest.fn(),
|
44
|
+
broadcastSuccess: jest.fn(),
|
45
|
+
broadcastFail: jest.fn(),
|
46
|
+
broadcastOperationDetailsClick: jest.fn(),
|
47
|
+
};
|
48
|
+
|
49
|
+
const mockManifest = {
|
50
|
+
id: "test-manifest",
|
51
|
+
name: "Test App",
|
52
|
+
url: "https://test.app",
|
53
|
+
homepageUrl: "https://test.app",
|
54
|
+
icon: "data:image/png;base64,test",
|
55
|
+
apiVersion: "1.0.0",
|
56
|
+
permissions: [],
|
57
|
+
domains: [],
|
58
|
+
categories: [],
|
59
|
+
platforms: ["desktop", "ios"] as AppPlatform[],
|
60
|
+
manifestVersion: "1.0.0",
|
61
|
+
branch: "stable" as AppBranch,
|
62
|
+
currencies: [],
|
63
|
+
visibility: "complete" as Visibility,
|
64
|
+
content: {
|
65
|
+
shortDescription: { en: "Test app" },
|
66
|
+
description: { en: "Test app description" },
|
67
|
+
},
|
68
|
+
};
|
69
|
+
|
70
|
+
const mockEthereumCurrency: CryptoCurrency = {
|
71
|
+
type: "CryptoCurrency",
|
72
|
+
id: "ethereum",
|
73
|
+
coinType: 60,
|
74
|
+
name: "Ethereum",
|
75
|
+
managerAppName: "Ethereum",
|
76
|
+
ticker: "ETH",
|
77
|
+
scheme: "ethereum",
|
78
|
+
color: "#0ebdcd",
|
79
|
+
symbol: "Ξ",
|
80
|
+
family: "evm",
|
81
|
+
blockAvgTime: 15,
|
82
|
+
units: [
|
83
|
+
{
|
84
|
+
name: "ether",
|
85
|
+
code: "ETH",
|
86
|
+
magnitude: 18,
|
87
|
+
},
|
88
|
+
],
|
89
|
+
keywords: ["eth", "ethereum"],
|
90
|
+
explorerViews: [],
|
91
|
+
explorerId: "eth",
|
92
|
+
};
|
93
|
+
|
94
|
+
const mockTokenCurrency: TokenCurrency = {
|
95
|
+
type: "TokenCurrency",
|
96
|
+
id: "ethereum/erc20/acre_btc",
|
97
|
+
contractAddress: "0x1234567890123456789012345678901234567890",
|
98
|
+
parentCurrency: mockEthereumCurrency,
|
99
|
+
tokenType: "erc20",
|
100
|
+
name: "ACRE Bitcoin",
|
101
|
+
ticker: "acreBTC",
|
102
|
+
units: [
|
103
|
+
{
|
104
|
+
name: "ACRE Bitcoin",
|
105
|
+
code: "acreBTC",
|
106
|
+
magnitude: 8,
|
107
|
+
},
|
108
|
+
],
|
109
|
+
};
|
110
|
+
|
111
|
+
const mockAccount: Account = {
|
112
|
+
type: "Account",
|
113
|
+
id: "js:2:ethereum:0x1234567890123456789012345678901234567890:ethereum",
|
114
|
+
seedIdentifier: "0x1234567890123456789012345678901234567890",
|
115
|
+
derivationMode: "",
|
116
|
+
index: 0,
|
117
|
+
freshAddress: "0x1234567890123456789012345678901234567890",
|
118
|
+
freshAddressPath: "44'/60'/0'/0/0",
|
119
|
+
used: false,
|
120
|
+
blockHeight: 0,
|
121
|
+
creationDate: new Date(),
|
122
|
+
balance: new BigNumber(0),
|
123
|
+
spendableBalance: new BigNumber(0),
|
124
|
+
operationsCount: 0,
|
125
|
+
operations: [],
|
126
|
+
pendingOperations: [],
|
127
|
+
currency: mockEthereumCurrency,
|
128
|
+
lastSyncDate: new Date(),
|
129
|
+
swapHistory: [],
|
130
|
+
balanceHistoryCache: {
|
131
|
+
HOUR: { latestDate: null, balances: [] },
|
132
|
+
DAY: { latestDate: null, balances: [] },
|
133
|
+
WEEK: { latestDate: null, balances: [] },
|
134
|
+
},
|
135
|
+
syncHash: "0x00000000",
|
136
|
+
subAccounts: [],
|
137
|
+
nfts: [],
|
138
|
+
};
|
139
|
+
|
140
|
+
jest.mock("@ledgerhq/coin-framework/account/index", () => ({
|
141
|
+
getParentAccount: jest.fn(),
|
142
|
+
getMainAccount: jest.fn(),
|
143
|
+
makeEmptyTokenAccount: jest.fn(),
|
144
|
+
isTokenAccount: jest.fn(),
|
145
|
+
}));
|
146
|
+
|
147
|
+
describe("ACRE Server Handlers", () => {
|
148
|
+
let mockUiHooks: any;
|
149
|
+
let serverHandlers: any;
|
150
|
+
|
151
|
+
beforeEach(() => {
|
152
|
+
jest.clearAllMocks();
|
153
|
+
mockUiHooks = {
|
154
|
+
"custom.acre.messageSign": jest.fn().mockImplementation(({ onSuccess }) => {
|
155
|
+
onSuccess("0x1234567890abcdef");
|
156
|
+
}),
|
157
|
+
"custom.acre.transactionSign": jest.fn().mockImplementation(({ onSuccess }) => {
|
158
|
+
onSuccess({
|
159
|
+
operation: { hash: "0x1234567890abcdef" },
|
160
|
+
signature: "0xabcdef1234567890",
|
161
|
+
});
|
162
|
+
}),
|
163
|
+
"custom.acre.transactionBroadcast": jest.fn(),
|
164
|
+
"custom.acre.registerAccount": jest.fn().mockImplementation(({ onSuccess }) => {
|
165
|
+
onSuccess();
|
166
|
+
}),
|
167
|
+
};
|
168
|
+
|
169
|
+
// Mock the cryptoassets functions globally
|
170
|
+
const { findTokenByAddressInCurrency, getCryptoCurrencyById } =
|
171
|
+
jest.requireMock("@ledgerhq/cryptoassets");
|
172
|
+
findTokenByAddressInCurrency.mockReturnValue(mockTokenCurrency);
|
173
|
+
getCryptoCurrencyById.mockReturnValue(mockEthereumCurrency);
|
174
|
+
|
175
|
+
// Mock the account functions
|
176
|
+
const { makeEmptyTokenAccount, getMainAccount, getParentAccount } = jest.requireMock(
|
177
|
+
"@ledgerhq/coin-framework/account/index",
|
178
|
+
);
|
179
|
+
makeEmptyTokenAccount.mockReturnValue({
|
180
|
+
type: "TokenAccount",
|
181
|
+
id: "mock-token-account-id",
|
182
|
+
parentId: "mock-parent-id",
|
183
|
+
token: mockTokenCurrency,
|
184
|
+
balance: new BigNumber(0),
|
185
|
+
spendableBalance: new BigNumber(0),
|
186
|
+
creationDate: new Date(),
|
187
|
+
operationsCount: 0,
|
188
|
+
operations: [],
|
189
|
+
pendingOperations: [],
|
190
|
+
balanceHistoryCache: {
|
191
|
+
HOUR: { latestDate: null, balances: [] },
|
192
|
+
DAY: { latestDate: null, balances: [] },
|
193
|
+
WEEK: { latestDate: null, balances: [] },
|
194
|
+
},
|
195
|
+
swapHistory: [],
|
196
|
+
});
|
197
|
+
getMainAccount.mockReturnValue(mockAccount);
|
198
|
+
getParentAccount.mockReturnValue(undefined);
|
199
|
+
|
200
|
+
// Mock the converter functions
|
201
|
+
const { getAccountIdFromWalletAccountId, getWalletAPITransactionSignFlowInfos } =
|
202
|
+
jest.requireMock("../converters");
|
203
|
+
getAccountIdFromWalletAccountId.mockReturnValue(
|
204
|
+
"js:2:ethereum:0x1234567890123456789012345678901234567890:ethereum",
|
205
|
+
);
|
206
|
+
getWalletAPITransactionSignFlowInfos.mockReturnValue({
|
207
|
+
canEditFees: true,
|
208
|
+
liveTx: { family: "evm" },
|
209
|
+
hasFeesProvided: true,
|
210
|
+
});
|
211
|
+
|
212
|
+
// Mock the bridge
|
213
|
+
const { getAccountBridge } = jest.requireMock("../../bridge");
|
214
|
+
getAccountBridge.mockReturnValue({
|
215
|
+
broadcast: jest.fn().mockResolvedValue({ hash: "0x1234567890abcdef" }),
|
216
|
+
});
|
217
|
+
|
218
|
+
serverHandlers = handlers({
|
219
|
+
accounts: [mockAccount],
|
220
|
+
tracking: mockTracking,
|
221
|
+
manifest: mockManifest,
|
222
|
+
uiHooks: mockUiHooks,
|
223
|
+
});
|
224
|
+
});
|
225
|
+
|
226
|
+
describe("custom.acre.messageSign", () => {
|
227
|
+
it("should handle message signing request successfully", async () => {
|
228
|
+
const mockParams = {
|
229
|
+
accountId: "test-account-id",
|
230
|
+
message: { type: "SignIn", message: "test" },
|
231
|
+
derivationPath: "0/0",
|
232
|
+
options: { hwAppId: "test-app" },
|
233
|
+
meta: { test: "data" },
|
234
|
+
};
|
235
|
+
|
236
|
+
const mockSignature = "0x1234567890abcdef";
|
237
|
+
mockUiHooks["custom.acre.messageSign"].mockImplementation(({ onSuccess }) => {
|
238
|
+
onSuccess(mockSignature);
|
239
|
+
});
|
240
|
+
|
241
|
+
const result = await serverHandlers["custom.acre.messageSign"](mockParams);
|
242
|
+
|
243
|
+
expect(result).toEqual({
|
244
|
+
hexSignedMessage: "1234567890abcdef",
|
245
|
+
});
|
246
|
+
expect(mockTracking.signMessageRequested).toHaveBeenCalledWith(mockManifest);
|
247
|
+
expect(mockTracking.signMessageSuccess).toHaveBeenCalledWith(mockManifest);
|
248
|
+
});
|
249
|
+
|
250
|
+
it("should handle missing parameters", async () => {
|
251
|
+
const result = await serverHandlers["custom.acre.messageSign"](null);
|
252
|
+
|
253
|
+
expect(result).toEqual({
|
254
|
+
hexSignedMessage: "",
|
255
|
+
});
|
256
|
+
expect(mockTracking.signMessageNoParams).toHaveBeenCalledWith(mockManifest);
|
257
|
+
});
|
258
|
+
|
259
|
+
it("should handle account not found", async () => {
|
260
|
+
const mockParams = {
|
261
|
+
accountId: "non-existent-account",
|
262
|
+
message: { type: "SignIn", message: "test" },
|
263
|
+
derivationPath: "0/0",
|
264
|
+
options: {},
|
265
|
+
meta: {},
|
266
|
+
};
|
267
|
+
|
268
|
+
// Mock getAccountIdFromWalletAccountId to return null for non-existent account
|
269
|
+
const { getAccountIdFromWalletAccountId } = jest.requireMock("../converters");
|
270
|
+
getAccountIdFromWalletAccountId.mockReturnValueOnce(null);
|
271
|
+
|
272
|
+
await expect(serverHandlers["custom.acre.messageSign"](mockParams)).rejects.toThrow(
|
273
|
+
"accountId non-existent-account unknown",
|
274
|
+
);
|
275
|
+
});
|
276
|
+
});
|
277
|
+
|
278
|
+
describe("custom.acre.transactionSign", () => {
|
279
|
+
it("should handle transaction signing request successfully", async () => {
|
280
|
+
const mockParams = {
|
281
|
+
accountId: "test-account-id",
|
282
|
+
rawTransaction: "0x1234567890abcdef",
|
283
|
+
options: { hwAppId: "test-app" },
|
284
|
+
meta: { test: "data" },
|
285
|
+
tokenCurrency: "ethereum/erc20/test",
|
286
|
+
};
|
287
|
+
|
288
|
+
const mockSignedOperation = {
|
289
|
+
operation: { hash: "0x1234567890abcdef" },
|
290
|
+
signature: "0xabcdef1234567890",
|
291
|
+
};
|
292
|
+
|
293
|
+
mockUiHooks["custom.acre.transactionSign"].mockImplementation(({ onSuccess }) => {
|
294
|
+
onSuccess(mockSignedOperation);
|
295
|
+
});
|
296
|
+
|
297
|
+
const result = await serverHandlers["custom.acre.transactionSign"](mockParams);
|
298
|
+
|
299
|
+
expect(result).toEqual({
|
300
|
+
signedTransactionHex: "307861626364656631323334353637383930",
|
301
|
+
});
|
302
|
+
expect(mockTracking.signTransactionRequested).toHaveBeenCalledWith(mockManifest);
|
303
|
+
expect(mockTracking.signTransactionSuccess).toHaveBeenCalledWith(mockManifest);
|
304
|
+
});
|
305
|
+
|
306
|
+
it("should handle missing parameters", async () => {
|
307
|
+
const result = await serverHandlers["custom.acre.transactionSign"](null);
|
308
|
+
|
309
|
+
expect(result).toEqual({
|
310
|
+
signedTransactionHex: "",
|
311
|
+
});
|
312
|
+
expect(mockTracking.signTransactionNoParams).toHaveBeenCalledWith(mockManifest);
|
313
|
+
});
|
314
|
+
});
|
315
|
+
|
316
|
+
describe("custom.acre.transactionSignAndBroadcast", () => {
|
317
|
+
it("should handle transaction sign and broadcast successfully", async () => {
|
318
|
+
const mockParams = {
|
319
|
+
accountId: "test-account-id",
|
320
|
+
rawTransaction: "0x1234567890abcdef",
|
321
|
+
options: { hwAppId: "test-app" },
|
322
|
+
meta: { test: "data" },
|
323
|
+
tokenCurrency: "ethereum/erc20/test",
|
324
|
+
};
|
325
|
+
|
326
|
+
const mockSignedOperation = {
|
327
|
+
operation: { hash: "0x1234567890abcdef" },
|
328
|
+
signature: "0xabcdef1234567890",
|
329
|
+
};
|
330
|
+
|
331
|
+
mockUiHooks["custom.acre.transactionSign"].mockImplementation(({ onSuccess }) => {
|
332
|
+
onSuccess(mockSignedOperation);
|
333
|
+
});
|
334
|
+
|
335
|
+
const result = await serverHandlers["custom.acre.transactionSignAndBroadcast"](mockParams);
|
336
|
+
|
337
|
+
expect(result).toEqual({
|
338
|
+
transactionHash: "0x1234567890abcdef",
|
339
|
+
});
|
340
|
+
});
|
341
|
+
|
342
|
+
it("should handle missing parameters", async () => {
|
343
|
+
const result = await serverHandlers["custom.acre.transactionSignAndBroadcast"](null);
|
344
|
+
|
345
|
+
expect(result).toEqual({
|
346
|
+
transactionHash: "",
|
347
|
+
});
|
348
|
+
expect(mockTracking.signTransactionAndBroadcastNoParams).toHaveBeenCalledWith(mockManifest);
|
349
|
+
});
|
350
|
+
});
|
351
|
+
|
352
|
+
describe("custom.acre.registerYieldBearingEthereumAddress", () => {
|
353
|
+
const mockParams = {
|
354
|
+
ethereumAddress: "0x9876543210987654321098765432109876543210",
|
355
|
+
tokenContractAddress: "0x1234567890123456789012345678901234567890",
|
356
|
+
meta: { test: "data" },
|
357
|
+
};
|
358
|
+
|
359
|
+
it("should register new yield-bearing Ethereum address successfully on mobile", async () => {
|
360
|
+
const result =
|
361
|
+
await serverHandlers["custom.acre.registerYieldBearingEthereumAddress"](mockParams);
|
362
|
+
|
363
|
+
expect(result.success).toBe(true);
|
364
|
+
expect(result.accountName).toBe("Yield-bearing BTC on ACRE");
|
365
|
+
expect(result.ethereumAddress).toBe(mockParams.ethereumAddress);
|
366
|
+
expect(result.tokenContractAddress).toBe(mockParams.tokenContractAddress);
|
367
|
+
|
368
|
+
// Verify UI hook was called with correct parameters
|
369
|
+
expect(mockUiHooks["custom.acre.registerAccount"]).toHaveBeenCalledWith({
|
370
|
+
parentAccount: expect.objectContaining({
|
371
|
+
type: "Account",
|
372
|
+
id: expect.stringContaining("0x9876543210987654321098765432109876543210"),
|
373
|
+
}),
|
374
|
+
accountName: "Yield-bearing BTC on ACRE",
|
375
|
+
existingAccounts: [mockAccount],
|
376
|
+
onSuccess: expect.any(Function),
|
377
|
+
onError: expect.any(Function),
|
378
|
+
});
|
379
|
+
});
|
380
|
+
|
381
|
+
it("should register new yield-bearing Ethereum address successfully on desktop", async () => {
|
382
|
+
const desktopServerHandlers = handlers({
|
383
|
+
accounts: [mockAccount],
|
384
|
+
tracking: mockTracking,
|
385
|
+
manifest: mockManifest,
|
386
|
+
uiHooks: mockUiHooks,
|
387
|
+
});
|
388
|
+
|
389
|
+
const result = await (
|
390
|
+
desktopServerHandlers["custom.acre.registerYieldBearingEthereumAddress"] as any
|
391
|
+
)(mockParams);
|
392
|
+
|
393
|
+
expect(result.success).toBe(true);
|
394
|
+
|
395
|
+
expect(mockUiHooks["custom.acre.registerAccount"]).toHaveBeenCalledWith({
|
396
|
+
parentAccount: expect.objectContaining({
|
397
|
+
type: "Account",
|
398
|
+
id: expect.stringContaining("0x9876543210987654321098765432109876543210"),
|
399
|
+
}),
|
400
|
+
accountName: "Yield-bearing BTC on ACRE",
|
401
|
+
existingAccounts: [mockAccount],
|
402
|
+
onSuccess: expect.any(Function),
|
403
|
+
onError: expect.any(Function),
|
404
|
+
});
|
405
|
+
});
|
406
|
+
|
407
|
+
it("should handle existing account gracefully", async () => {
|
408
|
+
const existingAccount = {
|
409
|
+
...mockAccount,
|
410
|
+
freshAddress: mockParams.ethereumAddress,
|
411
|
+
};
|
412
|
+
|
413
|
+
const serverHandlersWithExisting = handlers({
|
414
|
+
accounts: [existingAccount],
|
415
|
+
tracking: mockTracking,
|
416
|
+
manifest: mockManifest,
|
417
|
+
uiHooks: mockUiHooks,
|
418
|
+
});
|
419
|
+
|
420
|
+
const result = await (
|
421
|
+
serverHandlersWithExisting["custom.acre.registerYieldBearingEthereumAddress"] as any
|
422
|
+
)(mockParams);
|
423
|
+
|
424
|
+
expect(result.success).toBe(true);
|
425
|
+
expect(result.parentAccountId).toBe(existingAccount.id);
|
426
|
+
expect(result.tokenAccountId).toBe(existingAccount.id);
|
427
|
+
expect(mockUiHooks["custom.acre.registerAccount"]).not.toHaveBeenCalled();
|
428
|
+
});
|
429
|
+
|
430
|
+
it("should handle missing UI hook", async () => {
|
431
|
+
const serverHandlersWithoutHook = handlers({
|
432
|
+
accounts: [mockAccount],
|
433
|
+
tracking: mockTracking,
|
434
|
+
manifest: mockManifest,
|
435
|
+
uiHooks: {
|
436
|
+
...mockUiHooks,
|
437
|
+
"custom.acre.registerAccount": undefined,
|
438
|
+
},
|
439
|
+
});
|
440
|
+
|
441
|
+
await expect(
|
442
|
+
(serverHandlersWithoutHook["custom.acre.registerYieldBearingEthereumAddress"] as any)(
|
443
|
+
mockParams,
|
444
|
+
),
|
445
|
+
).rejects.toThrow("No account registration UI hook available");
|
446
|
+
});
|
447
|
+
|
448
|
+
it("should validate Ethereum address format", async () => {
|
449
|
+
const invalidParams = {
|
450
|
+
...mockParams,
|
451
|
+
ethereumAddress: "invalid-address",
|
452
|
+
};
|
453
|
+
|
454
|
+
await expect(
|
455
|
+
serverHandlers["custom.acre.registerYieldBearingEthereumAddress"](invalidParams),
|
456
|
+
).rejects.toThrow("Invalid Ethereum address format");
|
457
|
+
});
|
458
|
+
|
459
|
+
it("should require either tokenContractAddress or tokenTicker", async () => {
|
460
|
+
const invalidParams = {
|
461
|
+
ethereumAddress: mockParams.ethereumAddress,
|
462
|
+
meta: mockParams.meta,
|
463
|
+
};
|
464
|
+
|
465
|
+
await expect(
|
466
|
+
serverHandlers["custom.acre.registerYieldBearingEthereumAddress"](invalidParams),
|
467
|
+
).rejects.toThrow("Either tokenContractAddress or tokenTicker must be provided");
|
468
|
+
});
|
469
|
+
});
|
470
|
+
});
|