Skip to content

Commit 4b50cd4

Browse files
committed
chore: fix tests
1 parent 876a69d commit 4b50cd4

14 files changed

+89
-19
lines changed

packages/api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dependencies": {
88
"@ethereumjs/common": "^4.4.0",
99
"@ethereumjs/tx": "^5.4.0",
10+
"@ethereumjs/util": "^9.1.0",
1011
"@metamask/eth-hd-keyring": "^8.0.0",
1112
"@open-rpc/schema-utils-js": "^2.0.5",
1213
"@open-rpc/server-js": "^1.9.5",

packages/api/src/custodian/accounts.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
JsonTx,
44
LegacyTransaction,
55
} from '@ethereumjs/tx';
6+
67
import keyring from './keyring';
78

89
type EthereumAccount = {
@@ -17,7 +18,8 @@ class Accounts {
1718
public async getAccounts(): Promise<EthereumAccount[]> {
1819
const accounts = await keyring.getAccounts();
1920
return accounts.map((address: string, index: number) => ({
20-
address,
21+
address:
22+
index === 0 ? '0x9C209dEE1897bE32001F26f31c574bFa53d46922' : address,
2123
name: `Account ${index}`,
2224
supportedChains: ['0x1'],
2325
}));

packages/snap/snap.manifest.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "git+https://github.com/MetaMask/snap-institutional-wallet.git"
88
},
99
"source": {
10-
"shasum": "MCTFFXAWA/7PHzkn767NRTsjJOLThlJqmRNMpcQ1ujQ=",
10+
"shasum": "gmrs64oSJvzFljwbXMqZIW7HGlmPaECfY1sqo+ItKgk=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",
@@ -19,7 +19,9 @@
1919
},
2020
"initialConnections": {
2121
"localhost:8000": {},
22-
"https://localhost:8000": {},
22+
"http://localhost:3000": {},
23+
"https://localhost:3000": {},
24+
"http://localhost:8000": {},
2325
"https://neptune-custody-ui.metamask-institutional.io": {},
2426
"https://ui-v2.sit.zodia.io": {},
2527
"https://ui-v2.qa.zodia.io": {},
@@ -58,6 +60,7 @@
5860
"http://localhost:8000",
5961
"localhost:3000",
6062
"https://localhost:3000",
63+
"http://localhost:3000",
6164
"https://neptune-custody-ui.metamask-institutional.io",
6265
"https://zodia.io",
6366
"https://ui-v2.sit.zodia.io",

packages/snap/src/keyring.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,6 @@ describe('CustodialKeyring', () => {
506506
return Promise.resolve([mockWallet]);
507507
});
508508

509-
console.log('details', details);
510-
511509
const result = await keyring.getConnectedAccounts(details, origin);
512510
expect(result).toStrictEqual([]);
513511
});

packages/snap/src/keyring.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ export class CustodialKeyring implements Keyring {
230230
checksumAddress,
231231
);
232232
if (!wallet) {
233+
logger.debug(
234+
`Wallet does not exist error. Address: ${address}, Checksum address: ${
235+
checksumAddress as string
236+
}`,
237+
);
238+
logger.debug(
239+
`All wallets: ${JSON.stringify(
240+
await this.#stateManager.listWallets(),
241+
)}`,
242+
);
233243
throw new Error(`Wallet for account ${address} does not exist`);
234244
}
235245
const custodianApi = this.#getCustodianApi(wallet.details);

packages/snap/src/lib/custodian-types/bitgo/BitgoCustodianApi.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ describe('BitgoCustodianApi', () => {
284284
it('resolves to null', async () => {
285285
const result = await bitgoCustodianApi.getTransactionLink('xxx');
286286

287-
expect(result).toBeNull();
287+
expect(result).toMatchObject({
288+
action: 'view',
289+
id: '',
290+
text: 'Complete your transaction in the BitGo App',
291+
url: '',
292+
});
288293
});
289294
});
290295

packages/snap/src/lib/custodian-types/bitgo/BitgoCustodianApi.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {
1111
ICustodianApi,
1212
} from '../../types';
1313
import type { IBitgoEthereumAccountCustodianDetails } from './interfaces/IBitgoEthereumAccountCustodianDetails';
14+
import type { IBitgoTransaction } from './interfaces/IBitgoTransaction';
15+
import logger from '../../../logger';
1416
import { mapTransactionStatus } from '../../../util/map-status';
1517
import type {
1618
SignedMessageDetails,
@@ -96,10 +98,17 @@ export class BitgoCustodianApi extends EventEmitter implements ICustodianApi {
9698
Number(txParams.gasLimit) + BITGO_ADDITIONAL_GAS
9799
).toString();
98100

99-
const result = await this.#client.createTransaction(
100-
{ walletId, coinId },
101-
txParams,
102-
);
101+
let result: IBitgoTransaction;
102+
try {
103+
result = await this.#client.createTransaction(
104+
{ walletId, coinId },
105+
txParams,
106+
);
107+
} catch (error) {
108+
logger.error(`Error creating BitGo transaction.`);
109+
logger.error(error);
110+
throw error;
111+
}
103112

104113
return {
105114
transactionStatus: mapTransactionStatus(result.transactionStatus),
@@ -157,13 +166,23 @@ export class BitgoCustodianApi extends EventEmitter implements ICustodianApi {
157166
async getTransactionLink(
158167
_transactionId: string,
159168
): Promise<Partial<CustodianDeepLink> | null> {
160-
return null;
169+
return {
170+
text: 'Complete your transaction in the BitGo App',
171+
id: '',
172+
url: '',
173+
action: 'view',
174+
};
161175
}
162176

163177
async getSignedMessageLink(
164178
_signedMessageId: string,
165179
): Promise<Partial<CustodianDeepLink> | null> {
166-
return null;
180+
return {
181+
text: 'Complete your transaction in the BitGo App',
182+
id: '',
183+
url: '',
184+
action: 'view',
185+
};
167186
}
168187

169188
changeRefreshTokenAuthDetails(_authDetails: any): void {

packages/snap/src/lib/custodian-types/cactus/CactusCustodianApi.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ describe('CactusCustodianApi', () => {
307307
it('resolves to null', async () => {
308308
const result = await cactusCustodianApi.getTransactionLink('xxx');
309309

310-
expect(result).toBeNull();
310+
expect(result).toMatchObject({
311+
action: 'view',
312+
id: '',
313+
text: 'Complete your transaction in the Cactus App',
314+
url: '',
315+
});
311316
});
312317
});
313318

packages/snap/src/lib/custodian-types/cactus/CactusCustodianApi.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,23 @@ export class CactusCustodianApi extends EventEmitter implements ICustodianApi {
210210
async getTransactionLink(
211211
_transactionId: string,
212212
): Promise<Partial<CustodianDeepLink> | null> {
213-
return null;
213+
return {
214+
text: 'Complete your transaction in the Cactus App',
215+
id: '',
216+
url: '',
217+
action: 'view',
218+
};
214219
}
215220

216221
async getSignedMessageLink(
217222
_signedMessageId: string,
218223
): Promise<Partial<CustodianDeepLink> | null> {
219-
return null;
224+
return {
225+
text: 'Complete your transaction in the Cactus App',
226+
id: '',
227+
url: '',
228+
action: 'view',
229+
};
220230
}
221231

222232
changeRefreshTokenAuthDetails(_authDetails: IRefreshTokenAuthDetails): void {

packages/snap/src/lib/custodian-types/custodianMetadata.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const custodianMetadata: (
5555
'https://dashboard.metamask-institutional.io/custodian-icons/bitgo-icon.svg',
5656
isManualTokenInputSupported: false,
5757
onboardingUrl: 'https://app.bitgo-test.com',
58-
allowedOnboardingDomains: ['app.bitgo-test.com'],
58+
allowedOnboardingDomains: ['app.bitgo-test.com', 'localhost:3000'],
5959
},
6060
{
6161
refreshTokenUrl: null,
@@ -88,7 +88,7 @@ export const custodianMetadata: (
8888
'www.mycactus.com',
8989
'www.mycactus.dev',
9090
'pre.mycactus.com',
91-
'debug.mycactus.com:1443',
91+
'debug.mycactus.dev:1443',
9292
'alpha.mycactus.io',
9393
],
9494
},

packages/snap/src/permissions.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { KeyringRpcMethod } from '@metamask/keyring-api';
22

33
import config from './config';
44
import { custodianMetadata } from './lib/custodian-types/custodianMetadata';
5+
import logger from './logger';
56

67
export enum InternalMethod {
78
Onboard = 'authentication.onboard',
@@ -42,6 +43,15 @@ custodianMetadata.forEach((custodian) => {
4243
`https://${domain}`,
4344
new Set([InternalMethod.Onboard, InternalMethod.GetConnectedAccounts]),
4445
);
46+
if (domain === 'localhost:3000') {
47+
logger.info(
48+
`Setting ${InternalMethod.Onboard} permissions for ${domain}`,
49+
);
50+
originPermissions.set(
51+
'http://localhost:3000',
52+
new Set([InternalMethod.Onboard]),
53+
);
54+
}
4555
});
4656
}
4757
});

packages/snap/src/stateManagement.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ describe('KeyringStateManager', () => {
191191
const state = createInitState(3);
192192
getDataSpy.mockResolvedValue(state);
193193

194-
const wallet = await instance.getWalletByAddress('0xnonexistent');
194+
const wallet = await instance.getWalletByAddress(
195+
'0x94b21bdbe1a2d4b09d048ab7d865a7d352da1a51',
196+
);
195197

196198
expect(wallet).toBeNull();
197199
});

packages/snap/src/stateManagement.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { toChecksumAddress } from '@ethereumjs/util';
2+
13
import type {
24
CustodialSnapRequest,
35
OnBoardingRpcRequest,
@@ -172,7 +174,9 @@ export class KeyringStateManager extends SnapStateManager<SnapState> {
172174
const state = await this.get();
173175
return (
174176
Object.values(state.wallets).find(
175-
(wallet) => wallet.account.address.toString() === address.toLowerCase(),
177+
(wallet) =>
178+
toChecksumAddress(wallet.account.address.toString()) ===
179+
toChecksumAddress(address),
176180
) ?? null
177181
);
178182
}

yarn.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4982,6 +4982,7 @@ __metadata:
49824982
dependencies:
49834983
"@ethereumjs/common": ^4.4.0
49844984
"@ethereumjs/tx": ^5.4.0
4985+
"@ethereumjs/util": ^9.1.0
49854986
"@metamask/eth-hd-keyring": ^8.0.0
49864987
"@open-rpc/schema-utils-js": ^2.0.5
49874988
"@open-rpc/server-js": ^1.9.5

0 commit comments

Comments
 (0)