Skip to content

Commit

Permalink
- Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naorye2 committed Jun 26, 2024
1 parent 8a30e88 commit 304d76d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/__test__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe("getDiscoveryWallets()", () => {
it("should return all discovery wallets", async () => {
const sn = getWallet({})
const discoveryWallets = await sn.getDiscoveryWallets()
expect(discoveryWallets.length).toBe(2)
expect(discoveryWallets.length).toBe(3)
expect(discoveryWallets.map((w) => w.id)).contains(ArgentXMock.id)
expect(discoveryWallets.map((w) => w.id)).contains(BraavosMock.id)
})
Expand Down
30 changes: 20 additions & 10 deletions packages/core/src/__test__/wallet.mock.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import wallets from "../discovery"
import { Permission, type StarknetWindowObject } from "@starknet-io/types-js"

type WalletMock = Pick<StarknetWindowObject, "id" | "name" | "icon" | "request">

export const UnknownWalletAMock: WalletMock = {
export const UnknownWalletAMock: StarknetWindowObject = {
id: "wallet-a",
name: "Wallet A",
version: "0.0.0",
icon: "https://avatars.dicebear.com/api/initials/Wallet%20A.svg",
request: async () => false,
on: () => {},
off: () => {},
}
export const UnknownWalletBMock: WalletMock = {
export const UnknownWalletBMock: StarknetWindowObject = {
id: "wallet-b",
name: "Wallet B",
version: "0.0.0",
icon: "https://avatars.dicebear.com/api/initials/Wallet%20B.svg",
request: async () => false,
on: () => {},
off: () => {},
}

export const ArgentXMock: WalletMock = {
export const ArgentXMock: StarknetWindowObject = {
...wallets.find((w) => w.id === "argentX")!,
version: "0.0.0",
request: async (request) => {
switch (request.type) {
case "wallet_getPermissions":
Expand All @@ -26,10 +31,13 @@ export const ArgentXMock: WalletMock = {
return undefined as any
}
},
on: () => {},
off: () => {},
}

export const BraavosMock: WalletMock = {
export const BraavosMock: StarknetWindowObject = {
...wallets.find((w) => w.id === "braavos")!,
version: "0.0.0",
request: async (request) => {
switch (request.type) {
case "wallet_getPermissions":
Expand All @@ -38,10 +46,12 @@ export const BraavosMock: WalletMock = {
return undefined as any
}
},
on: () => {},
off: () => {},
}

export function makeAuthorized(authorized: boolean) {
return (wallet: WalletMock) =>
return (wallet: StarknetWindowObject) =>
({
...wallet,
request: async (request) => {
Expand All @@ -52,11 +62,11 @@ export function makeAuthorized(authorized: boolean) {
return wallet.request(request)
}
},
} as WalletMock)
} as StarknetWindowObject)
}

export function makeConnected(isConnected: boolean) {
return (wallet: WalletMock) => {
return (wallet: StarknetWindowObject) => {
return {
...makeAuthorized(true)(wallet),
request: async ({ type }) => {
Expand All @@ -67,6 +77,6 @@ export function makeConnected(isConnected: boolean) {
return []
}
},
} as WalletMock
} as StarknetWindowObject
}
}
2 changes: 1 addition & 1 deletion packages/core/src/wallet/virtualWallets/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VirtualWallet } from "../../types"
import { metaMaskVirtualWallet } from "./metaMaskVirtualWallet"
import type { StarknetWindowObject } from "starknet-types"
import type { StarknetWindowObject } from "@starknet-io/types-js"

const virtualWallets: VirtualWallet[] = [metaMaskVirtualWallet]

Expand Down

0 comments on commit 304d76d

Please sign in to comment.