-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathmock-wallet.test.ts
More file actions
120 lines (105 loc) · 3.43 KB
/
mock-wallet.test.ts
File metadata and controls
120 lines (105 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { ethers } from 'ethers'
import { WalletRequestHandler, WindowMessageHandler } from '@0xsequence/provider'
import { Account } from '@0xsequence/account'
import { ChainId, NetworkConfig } from '@0xsequence/network'
import { LocalRelayer } from '@0xsequence/relayer'
import { configureLogger } from '@0xsequence/utils'
import { testAccounts, getEOAWallet } from '../testutils'
import { test, assert } from '../../utils/assert'
import * as utils from '@0xsequence/tests'
import { Orchestrator } from '@0xsequence/signhub'
import { trackers } from '@0xsequence/sessions'
configureLogger({ logLevel: 'DEBUG', silence: false })
//
// Wallet, a test wallet
//
const main = async () => {
//
// Providers
//
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545')
const provider2 = new ethers.providers.JsonRpcProvider('http://localhost:9545')
//
// Deploy Sequence WalletContext (deterministic)
//
const deployedWalletContext = await utils.context.deploySequenceContexts(provider.getSigner())
await utils.context.deploySequenceContexts(provider2.getSigner())
// Generate a new wallet every time, otherwise tests will fail
// due to EIP-6492 being used only sometimes (some tests deploy the wallet)
const owner = ethers.Wallet.createRandom()
const relayer = new LocalRelayer(getEOAWallet(testAccounts[5].privateKey))
const relayer2 = new LocalRelayer(getEOAWallet(testAccounts[5].privateKey, provider2))
// Network available list
const networks: NetworkConfig[] = [
{
name: 'hardhat',
chainId: 31337 as ChainId,
rpcUrl: provider.connection.url,
provider: provider,
relayer: relayer,
isDefaultChain: true,
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
},
{
name: 'hardhat2',
chainId: 31338 as ChainId,
rpcUrl: provider2.connection.url,
provider: provider2,
relayer: relayer2,
nativeToken: {
symbol: 'ETH',
name: 'Ether',
decimals: 18
}
}
]
// Account for managing multi-network wallets
// TODO: make this a 3-key multisig with threshold of 2
// const account = new Account(
// {
// initialConfig: wallet.config,
// networks,
// context: deployedWalletContext
// },
// owner
// )
const account = await Account.new({
config: {
threshold: 2,
checkpoint: 0,
signers: [
{
address: owner.address,
weight: 2
}
]
},
networks,
contexts: deployedWalletContext,
orchestrator: new Orchestrator([owner]),
tracker: new trackers.local.LocalConfigTracker(provider)
})
// the json-rpc signer via the wallet
const walletRequestHandler = new WalletRequestHandler(undefined, null, networks)
// fake/force an async wallet initialization for the wallet-request handler. This is the behaviour
// of the wallet-webapp, so lets ensure the mock wallet does the same thing too.
setTimeout(() => {
walletRequestHandler.signIn(account)
}, 1000)
// setup and register window message transport
const windowHandler = new WindowMessageHandler(walletRequestHandler)
windowHandler.register()
}
main()
export const tests = async () => {
// TODO: add tests() method to verify some wallet functionality such a login
// and adding / removing keys, etc..
// + mock in a RemoteSigner as well.
await test('stub', async () => {
assert.true(true, 'ok')
})
}