Skip to content

Commit

Permalink
integration: improve metamask provider mock
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair committed Mar 23, 2022
1 parent 3ed5407 commit 471fe2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
4 changes: 0 additions & 4 deletions integration/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import { terraTests } from "./terra";
import { kavaTests } from "./kava";
import { WalletSuite } from "./wallets/suite";

import { ethereum } from "./wallets/mocks/@metamask/detect-provider";

jest.mock("@metamask/detect-provider", () => async () => Promise.resolve(ethereum));

/**
* We run all the integration tests against every device, even though some
* devices might not support a given Coin mixin. Tests in the various suites
Expand Down
24 changes: 24 additions & 0 deletions integration/src/wallets/__mocks__/@metamask/detect-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default async function detectEthereumProvider() {
return {
request: jest.fn(({ method, params }: any) => {
switch (method) {
case "eth_accounts":
case "eth_requestAccounts":
return ["0x3f2329C9ADFbcCd9A84f52c906E936A42dA18CB8"];
case "personal_sign":
const [message] = params;

if (message === '48656c6c6f20576f726c64')
return '0x29f7212ecc1c76cea81174af267b67506f754ea8c73f144afa900a0d85b24b21319621aeb062903e856352f38305710190869c3ce5a1425d65ef4fa558d0fc251b'

throw new Error('unknown message');
case "eth_sendTransaction":
const [{ to }] = params;

return `txHash-${to}`;
default:
throw new Error(`ethereum: Unkown method ${method}`);
}
})
}
}
2 changes: 2 additions & 0 deletions integration/src/wallets/metamask.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jest.mock("@metamask/detect-provider");

import * as core from "@shapeshiftoss/hdwallet-core";
import * as metamask from "@shapeshiftoss/hdwallet-metamask";

Expand Down
21 changes: 0 additions & 21 deletions integration/src/wallets/mocks/@metamask/detect-provider.ts

This file was deleted.

0 comments on commit 471fe2f

Please sign in to comment.