-
-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathcontrollerManager.js
134 lines (131 loc) · 4.12 KB
/
controllerManager.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module.exports = (controller, firmwares) => ({
/**
* @version
* version of firmware in emulator, only few are supported
* @wipe
* shall be emulator wiped before start? defaults to true
*/
setupEmu: async options => {
const defaults = {
// some random empty seed. most of the test don't need any account history so it is better not to slow them down with all all seed
mnemonic:
'alcohol woman abuse must during monitor noble actual mixed trade anger aisle',
pin: '',
passphrase_protection: false,
label: 'My Trevor',
needs_backup: false,
};
// before setup, stop bridge and start it again after it. it has no performance hit
// and avoids 'wrong previous session' errors from bridge. actual setup is done
// through udp transport if bridge transport is not available
await controller.send({ type: 'bridge-stop' });
await controller.send({
type: 'emulator-setup',
...defaults,
...options,
});
await controller.send({ type: 'bridge-start' });
return null;
},
sendToAddressAndMineBlock: async options => {
await controller.send({
type: 'regtest-send-to-address',
...options,
});
return null;
},
mineBlocks: async options => {
await controller.send({
type: 'regtest-mine-blocks',
...options,
});
return null;
},
startBridge: async version => {
console.log('startBridge');
await controller.send({ type: 'bridge-start', version });
return null;
},
stopBridge: async () => {
const response = await controller.send({ type: 'bridge-stop' });
return null;
},
startEmu: async arg => {
const params = {
type: 'emulator-start',
version: process.env.FIRMWARE || '2-latest',
...arg,
};
await controller.send(params);
return params;
},
stopEmu: async () => {
await controller.send({ type: 'emulator-stop' });
return null;
},
wipeEmu: async () => {
await controller.send({ type: 'emulator-wipe' });
return null;
},
pressYes: async () => {
await controller.send({ type: 'emulator-press-yes' });
return null;
},
pressNo: async () => {
await controller.send({ type: 'emulator-press-no' });
return null;
},
swipeEmu: async direction => {
await controller.send({ type: 'emulator-swipe', direction });
return null;
},
inputEmu: async value => {
await controller.send({ type: 'emulator-input', value });
return null;
},
clickEmu: async options => {
await controller.send({ type: 'emulator-click', ...options });
return null;
},
resetDevice: async options => {
await controller.send({ type: 'emulator-reset-device', ...options });
return null;
},
readAndConfirmMnemonicEmu: async () => {
await controller.send({ type: 'emulator-read-and-confirm-mnemonic' });
return null;
},
readAndConfirmShamirMnemonicEmu: async options => {
await controller.send({
type: 'emulator-read-and-confirm-shamir-mnemonic',
...options,
});
return null;
},
applySettings: async options => {
await controller.send({
type: 'emulator-apply-settings',
...options,
});
return null;
},
selectNumOfWordsEmu: async num => {
await controller.send({ type: 'emulator-select-num-of-words', num });
return null;
},
logTestDetails: async text => {
await controller.send({ type: 'log', text });
return null;
},
trezorUserEnvConnect: async () => {
await controller.connect();
controller.on('firmwares', data => {
firmwares = data;
});
return null;
},
trezorUserEnvDisconnect: async () => {
await controller.disconnect();
return null;
},
});