Skip to content

Commit

Permalink
chore: getting tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Jul 27, 2024
1 parent 08f8eac commit 92ab2b2
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 71 deletions.
28 changes: 28 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {
EIP6963AnnounceProviderEvent,
EIP6963RequestProviderEvent,
MetaMaskInpageProvider,
} from '@metamask/providers'

declare global {
/*
* Window type extension to support ethereum
*/

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Window {
ethereum: MetaMaskInpageProvider & {
setProvider?: (provider: MetaMaskInpageProvider) => void
detected?: MetaMaskInpageProvider[]
providers?: MetaMaskInpageProvider[]
}
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface WindowEventMap {
'eip6963:requestProvider': EIP6963RequestProviderEvent
'eip6963:announceProvider': EIP6963AnnounceProviderEvent
}
}

export {}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@wharfkit/account-creation-plugin-template",
"description": "A template to create account-creation plugins for use with @wharfkit/session.",
"name": "@wharfkit/account-creation-plugin-metamask",
"description": "A MetaMask plugin to create EOS accounts using Metamask public keys.",
"version": "1.0.0",
"homepage": "https://github.com/wharfkit/account-creation-plugin-template",
"homepage": "https://github.com/wharfkit/wallet-plugin-metamask",
"license": "BSD-3-Clause",
"main": "lib/account-creation-plugin-template.js",
"module": "lib/account-creation-plugin-template.m.js",
"types": "lib/account-creation-plugin-template.d.ts",
"main": "lib/account-creation-plugin-metamask.js",
"module": "lib/account-creation-plugin-metamask.m.js",
"types": "lib/account-creation-plugin-metamask.d.ts",
"sideEffects": false,
"files": [
"lib/*",
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {
"@greymass/create-account": "^1.0.2",
"@metamask/providers": "^17.1.2",
"@metamask/providers": "^17.0.0",
"tslib": "^2.1.0"
},
"peerDependencies": {
Expand All @@ -36,7 +36,7 @@
"@types/node": "^18.7.18",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@wharfkit/mock-data": "^1.0.2",
"@wharfkit/mock-data": "^1.2.0",
"@wharfkit/session": "^1.2.7",
"chai": "^4.3.4",
"eslint": "^8.13.0",
Expand Down
35 changes: 15 additions & 20 deletions test/tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import {assert} from 'chai'
import {Chains, PermissionLevel, SessionKit} from '@wharfkit/session'
import {
mockChainDefinition,
mockPermissionLevel,
mockSessionKitArgs,
mockSessionKitOptions,
} from '@wharfkit/mock-data'
import {Chains, SessionKit} from '@wharfkit/session'
import {mockSessionKitArgs} from '@wharfkit/mock-data'

import {AccountCreationPluginTEMPLATE} from '$lib'
import {AccountCreationPluginMetamask} from '$lib'
import {setupEthereumMock} from './mocks/ethereum'

suite('AccountCreationPluginTEMPLATE', function () {
suite('AccountCreationPluginMetamask', function () {
setup(function () {
setupEthereumMock() // Set up the Ethereum mock before each test
})
test('createAccount', async function () {
// const kit = new SessionKit(
// {
// ...mockSessionKitArgs,
// accountCreationPlugins: [new AccountCreationPluginTEMPLATE()],
// },
// mockSessionKitOptions
// )
const kit = new SessionKit(mockSessionKitArgs, {
accountCreationPlugins: [new AccountCreationPluginMetamask()],
})
// This will throw an error because we are not mocking the
// browser environment or the Metamask provider in this test
// const result = await kit.createAccount({
// chain: mockChainDefinition.id,
// permissionLevel: mockPermissionLevel,
// chain: Chains.EOS,
// pluginId: 'account-creation-plugin-metamask',
// })
// Add your own assertions here...
})
})
42 changes: 42 additions & 0 deletions test/tests/mocks/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference path="../../../global.d.ts" />

import {MetaMaskInpageProvider} from '@metamask/providers'

class MockMetaMaskInpageProvider implements Partial<MetaMaskInpageProvider> {
request(args: {method: string; params?: any}) {
switch (args.method) {
case 'wallet_getSnaps':
return Promise.resolve({})
case 'wallet_requestSnaps':
return Promise.resolve({
'local:http://localhost:8080': {
id: 'local:http://localhost:8080',
version: '1.0.0',
},
})
case 'wallet_invokeSnap':
if (args.params.request.method === 'antelope_getPublicKey') {
return Promise.resolve(
'PUB_K1_6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5BoDq63'
)
}
if (args.params.request.method === 'antelope_signTransaction') {
return Promise.resolve(
'SIG_K1_KfCdjsrTnx5cBpbA5cUdHZAsRYsnC9uKzuS1shFeqfMCfdZwX4PBm9pfHwGRT6ffz3eavhtkyNci5GoFozQAx8P8PBnDmj'
)
}
return Promise.resolve(null)
case 'web3_clientVersion':
return Promise.resolve(['MetaMask/v10.8.1'])
default:
return Promise.resolve(null)
}
}
}

const mockProvider = new MockMetaMaskInpageProvider()

export function setupEthereumMock() {
global.window = global.window || {}
global.window.ethereum = mockProvider as any
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"strict": true,
"target": "es2020"
},
"include": ["src/**/*"]
"include": ["src/**/*", "global.d.ts"]
}
60 changes: 18 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
once "^1.4.0"
readable-stream "^3.6.2"

"@metamask/providers@^17.1.2":
"@metamask/providers@^17.0.0":
version "17.1.2"
resolved "https://registry.yarnpkg.com/@metamask/providers/-/providers-17.1.2.tgz#bb29c9cbf66be4c3f83d3e24ffea93f750b3db39"
integrity sha512-hACtF02yaUYThvWrRtVU4JAc+ZLCZ4PJUYBw6dK9Rze50J7zCxtss2mB7H8w76iLx//b5hjgXx6y92gPVjuYWg==
Expand Down Expand Up @@ -747,16 +747,6 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@wharfkit/abicache@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@wharfkit/abicache/-/abicache-1.1.1.tgz#03624d03d9466e7def278786aaf074d274fc5650"
integrity sha512-CfpHzCLxFATcfReqdJDUxEDSHIeBF3jFx0cP8RcTDyhC2jX4cd+Q/wqjw/kCni3xrBM7cIGUp9c9NZdvdTK9Cg==
dependencies:
"@wharfkit/antelope" "^0.7.3"
"@wharfkit/signing-request" "^3.0.0"
pako "^2.0.4"
tslib "^2.1.0"

"@wharfkit/abicache@^1.2.0", "@wharfkit/abicache@^1.2.1":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@wharfkit/abicache/-/abicache-1.2.2.tgz#c3d83485e3e3782ac94ced460915bad1ceee0be9"
Expand Down Expand Up @@ -790,7 +780,7 @@
hash.js "^1.0.0"
tslib "^2.0.3"

"@wharfkit/antelope@^1.0.0", "@wharfkit/antelope@^1.0.2", "@wharfkit/antelope@^1.0.4", "@wharfkit/antelope@^1.0.7":
"@wharfkit/antelope@^1.0.0", "@wharfkit/antelope@^1.0.2", "@wharfkit/antelope@^1.0.4", "@wharfkit/antelope@^1.0.5", "@wharfkit/antelope@^1.0.7":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-1.0.8.tgz#e05a62f3b2598ca8b9e9a5ddd2e5a04937f3f1b8"
integrity sha512-RMpSHv5LteQtxiNlunLAwlaAGz4Gq4SErlyN1mVbqly14UB3GA1jRlosEZUGkCy7DdYDuY1tIFlAJJ+2lXeZIA==
Expand All @@ -802,13 +792,6 @@
pako "^2.1.0"
tslib "^2.0.3"

"@wharfkit/common@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@wharfkit/common/-/common-1.1.0.tgz#1ee9dd1ba9e202002fadd20593f5f42a3e67c827"
integrity sha512-A1Ta8zrEXkuEQcEiEexG0BVrYOxqm75qbLYU9tGNhyw4z/vQiF6rzmCOqhmWGg6nE2J2GYPvrPZPZzDmRGtG+w==
dependencies:
tslib "^2.1.0"

"@wharfkit/common@^1.2.0":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@wharfkit/common/-/common-1.2.2.tgz#db264656723e7d7ec5a49c589121522fa6f35d7e"
Expand All @@ -826,14 +809,14 @@
"@wharfkit/signing-request" "^3.1.0"
tslib "^2.1.0"

"@wharfkit/mock-data@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@wharfkit/mock-data/-/mock-data-1.0.2.tgz#81d6327c76032b40e5acf209d507cf6ca2a3ae9f"
integrity sha512-Mbf/rZX2dqj5r+h+6NcRsDfRdHZ5OWEk0oIZ6iarXEBV65jmODoLdZlS906m9ndC1bi1ewCm/276JDimIqtLkQ==
"@wharfkit/mock-data@^1.2.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@wharfkit/mock-data/-/mock-data-1.3.0.tgz#7a9caa7c7fb2ad839bc12593de1b7a546b673ae6"
integrity sha512-LkhAkrUOvG6o+lPWb2Q6JCrs9++F2XowGK42PODh35Xu9an5H+THMGjpUhTC1sPiYkfjhkmBbAzMpZbHjkXj4w==
dependencies:
"@wharfkit/antelope" "^0.7.3"
"@wharfkit/session" "^1.0.0"
"@wharfkit/wallet-plugin-privatekey" "^1.0.0"
"@wharfkit/antelope" "^1.0.5"
"@wharfkit/session" "^1.2.7"
"@wharfkit/wallet-plugin-privatekey" "^1.1.0"
node-fetch "^2.6.1"
tslib "^2.1.0"

Expand All @@ -847,18 +830,6 @@
js-big-decimal "^2.0.7"
tslib "^2.1.0"

"@wharfkit/session@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@wharfkit/session/-/session-1.0.0.tgz#09c60d01a6185ab2e451d34462d84de2d7013220"
integrity sha512-wXmvOVBZ1Rp/9HPUzGPaD/vpGXv2FCNgl8JRLopKgKPHkkEX/u4untshHR8AwSc0ZitjOlv6ubR2h9/UW8h6ug==
dependencies:
"@wharfkit/abicache" "^1.1.1"
"@wharfkit/antelope" "^0.7.3"
"@wharfkit/common" "^1.1.0"
"@wharfkit/signing-request" "^3.0.0"
pako "^2.0.4"
tslib "^2.1.0"

"@wharfkit/session@^1.2.7":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@wharfkit/session/-/session-1.3.1.tgz#2cbfa14aafc21abba060e97dab24e9263c78ad6e"
Expand Down Expand Up @@ -898,13 +869,18 @@
bn.js "^4.11.9"
tslib "^2.1.0"

"@wharfkit/wallet-plugin-privatekey@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@wharfkit/wallet-plugin-privatekey/-/wallet-plugin-privatekey-1.0.0.tgz#2600cce1117ce9391c8078649e05ceaf93780f1d"
integrity sha512-V+/7T/cwoHM8fDaM3MZ1DFKrX2+NddBkkWJ8BIFfmEZnGR1W8Qr77t+piOP0/6UM2etmuZh98XLwZS33vORQ0A==
"@wharfkit/wallet-plugin-privatekey@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@wharfkit/wallet-plugin-privatekey/-/wallet-plugin-privatekey-1.1.0.tgz#5985bff61895c54d2afbef359cd42da4f3871c7d"
integrity sha512-45LPj7AOVDm4RugDEhy0fnQX/BcMffeJPjGUCUrLazJ2S0Sti8nNk4nqiJqyme84c/0gq7d65vvwlmVfGtPVEg==
dependencies:
tslib "^2.1.0"

"@wharfkit/web-renderer@^1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@wharfkit/web-renderer/-/web-renderer-1.2.5.tgz#60f529288e96acd32df20ddb86423c39af909d55"
integrity sha512-aAD7Sl+6aAx1hDRqP+rSxKrINqZvN1ernqGFrTKbJZ+miy6V0wz2bW8pffjHLTENU8T7KHmq9DkMuQmRE7t7uQ==

"@yarnpkg/lockfile@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
Expand Down

0 comments on commit 92ab2b2

Please sign in to comment.