generated from wharfkit/account-creation-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
112 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,5 @@ | |
"strict": true, | ||
"target": "es2020" | ||
}, | ||
"include": ["src/**/*"] | ||
"include": ["src/**/*", "global.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters