1
1
import * as React from 'react'
2
2
3
- import { render , screen } from 'support/test-utils'
4
3
import userEvent from '@testing-library/user-event'
4
+ import { render , screen , waitFor } from 'support/test-utils'
5
5
6
6
import { ChainConfigurationForm , FormValues } from './ChainConfigurationForm'
7
+ import { ChainTypes } from './ChainTypes'
7
8
8
9
const { getByRole, findByTestId } = screen
9
10
10
11
describe ( 'ChainConfigurationForm' , ( ) => {
11
12
it ( 'validates top level input' , async ( ) => {
12
13
const handleSubmit = jest . fn ( )
13
- const initialValues : FormValues = {
14
- chainID : '' ,
15
- chainType : '' ,
16
- accountAddr : '' ,
17
- adminAddr : '' ,
18
- fluxMonitorEnabled : false ,
19
- ocr1Enabled : false ,
20
- ocr1IsBootstrap : false ,
21
- ocr1Multiaddr : '' ,
22
- ocr1P2PPeerID : '' ,
23
- ocr1KeyBundleID : '' ,
24
- ocr2Enabled : false ,
25
- ocr2IsBootstrap : false ,
26
- ocr2Multiaddr : '' ,
27
- ocr2P2PPeerID : '' ,
28
- ocr2KeyBundleID : '' ,
29
- ocr2CommitPluginEnabled : false ,
30
- ocr2ExecutePluginEnabled : false ,
31
- ocr2MedianPluginEnabled : false ,
32
- ocr2MercuryPluginEnabled : false ,
33
- ocr2RebalancerPluginEnabled : false ,
34
- ocr2ForwarderAddress : '' ,
35
- }
14
+ const initialValues = emptyFormValues ( )
36
15
37
16
render (
38
17
< ChainConfigurationForm
39
18
initialValues = { initialValues }
40
19
onSubmit = { handleSubmit }
41
- accounts = { [ ] }
42
- chainIDs = { [ ] }
20
+ accountsEVM = { [ ] }
21
+ accountsAptos = { [ ] }
22
+ chains = { [ ] }
43
23
p2pKeys = { [ ] }
44
24
ocrKeys = { [ ] }
45
25
ocr2Keys = { [ ] }
@@ -62,37 +42,15 @@ describe('ChainConfigurationForm', () => {
62
42
63
43
it ( 'validates OCR input' , async ( ) => {
64
44
const handleSubmit = jest . fn ( )
65
- const initialValues : FormValues = {
66
- chainID : '' ,
67
- chainType : '' ,
68
- accountAddr : '' ,
69
- accountAddrPubKey : '' ,
70
- adminAddr : '' ,
71
- fluxMonitorEnabled : false ,
72
- ocr1Enabled : false ,
73
- ocr1IsBootstrap : false ,
74
- ocr1Multiaddr : '' ,
75
- ocr1P2PPeerID : '' ,
76
- ocr1KeyBundleID : '' ,
77
- ocr2Enabled : false ,
78
- ocr2IsBootstrap : false ,
79
- ocr2Multiaddr : '' ,
80
- ocr2P2PPeerID : '' ,
81
- ocr2KeyBundleID : '' ,
82
- ocr2CommitPluginEnabled : false ,
83
- ocr2ExecutePluginEnabled : false ,
84
- ocr2MedianPluginEnabled : false ,
85
- ocr2MercuryPluginEnabled : false ,
86
- ocr2RebalancerPluginEnabled : false ,
87
- ocr2ForwarderAddress : '' ,
88
- }
45
+ const initialValues = emptyFormValues ( )
89
46
90
47
render (
91
48
< ChainConfigurationForm
92
49
initialValues = { initialValues }
93
50
onSubmit = { handleSubmit }
94
- accounts = { [ ] }
95
- chainIDs = { [ ] }
51
+ accountsEVM = { [ ] }
52
+ accountsAptos = { [ ] }
53
+ chains = { [ ] }
96
54
p2pKeys = { [ ] }
97
55
ocrKeys = { [ ] }
98
56
ocr2Keys = { [ ] }
@@ -123,37 +81,15 @@ describe('ChainConfigurationForm', () => {
123
81
124
82
it ( 'validates OCR2 input' , async ( ) => {
125
83
const handleSubmit = jest . fn ( )
126
- const initialValues : FormValues = {
127
- chainID : '' ,
128
- chainType : '' ,
129
- accountAddr : '' ,
130
- accountAddrPubKey : '' ,
131
- adminAddr : '' ,
132
- fluxMonitorEnabled : false ,
133
- ocr1Enabled : false ,
134
- ocr1IsBootstrap : false ,
135
- ocr1Multiaddr : '' ,
136
- ocr1P2PPeerID : '' ,
137
- ocr1KeyBundleID : '' ,
138
- ocr2Enabled : false ,
139
- ocr2IsBootstrap : false ,
140
- ocr2Multiaddr : '' ,
141
- ocr2P2PPeerID : '' ,
142
- ocr2KeyBundleID : '' ,
143
- ocr2CommitPluginEnabled : false ,
144
- ocr2ExecutePluginEnabled : false ,
145
- ocr2MedianPluginEnabled : false ,
146
- ocr2MercuryPluginEnabled : false ,
147
- ocr2RebalancerPluginEnabled : false ,
148
- ocr2ForwarderAddress : '' ,
149
- }
84
+ const initialValues = emptyFormValues ( )
150
85
151
86
render (
152
87
< ChainConfigurationForm
153
88
initialValues = { initialValues }
154
89
onSubmit = { handleSubmit }
155
- accounts = { [ ] }
156
- chainIDs = { [ ] }
90
+ accountsEVM = { [ ] }
91
+ accountsAptos = { [ ] }
92
+ chains = { [ ] }
157
93
p2pKeys = { [ ] }
158
94
ocrKeys = { [ ] }
159
95
ocr2Keys = { [ ] }
@@ -185,4 +121,128 @@ describe('ChainConfigurationForm', () => {
185
121
await findByTestId ( 'ocr2P2PPeerID-helper-text' ) ,
186
122
) . not . toHaveTextContent ( 'Required' )
187
123
} )
124
+
125
+ test ( 'should able to create APTOS chain config' , async ( ) => {
126
+ const handleSubmit = jest . fn ( )
127
+ const initialValues = emptyFormValues ( )
128
+ initialValues . chainType = ChainTypes . EVM
129
+ initialValues . adminAddr = '0x1234567'
130
+
131
+ const { container } = render (
132
+ < ChainConfigurationForm
133
+ initialValues = { initialValues }
134
+ onSubmit = { ( x , _ ) => handleSubmit ( x ) }
135
+ accountsEVM = { [
136
+ {
137
+ address : '0x1111' ,
138
+ chain : {
139
+ id : '1111' ,
140
+ } ,
141
+ createdAt : '2021-10-06T00:00:00Z' ,
142
+ isDisabled : false ,
143
+ } ,
144
+ ] }
145
+ accountsAptos = { [
146
+ {
147
+ account : '0x123' ,
148
+ id : '2222' ,
149
+ } ,
150
+ ] }
151
+ chains = { [
152
+ {
153
+ id : '1111' ,
154
+ enabled : true ,
155
+ network : 'evm' ,
156
+ } ,
157
+ {
158
+ id : '2222' ,
159
+ enabled : true ,
160
+ network : 'aptos' ,
161
+ } ,
162
+ ] }
163
+ p2pKeys = { [ ] }
164
+ ocrKeys = { [ ] }
165
+ ocr2Keys = { [ ] }
166
+ showSubmit
167
+ /> ,
168
+ )
169
+
170
+ const chainType = getByRole ( 'button' , { name : 'EVM' } )
171
+ userEvent . click ( chainType )
172
+ userEvent . click ( getByRole ( 'option' , { name : 'APTOS' } ) )
173
+ await screen . findByRole ( 'button' , { name : 'APTOS' } )
174
+
175
+ // no easy way to use react testing framework to do what i want,
176
+ // had to resort to using #id and querySelector
177
+ // formik does not seem to work well with react testing framework
178
+ const chainId = container . querySelector ( '#select-chainID' )
179
+ expect ( chainId ) . toBeInTheDocument ( )
180
+ // workaround ts lint warning - unable to use chainId!
181
+ chainId && userEvent . click ( chainId )
182
+ userEvent . click ( getByRole ( 'option' , { name : '2222' } ) )
183
+ await screen . findByRole ( 'button' , { name : '2222' } )
184
+
185
+ const address = container . querySelector ( '#select-accountAddr' )
186
+ expect ( address ) . toBeInTheDocument ( )
187
+ address && userEvent . click ( address )
188
+ userEvent . click ( getByRole ( 'option' , { name : '0x123' } ) )
189
+ await screen . findByRole ( 'button' , { name : '0x123' } )
190
+
191
+ await userEvent . click ( getByRole ( 'button' , { name : / s u b m i t / i } ) )
192
+
193
+ await waitFor ( ( ) => {
194
+ expect ( handleSubmit ) . toHaveBeenCalledWith ( {
195
+ accountAddr : '0x123' ,
196
+ accountAddrPubKey : '' ,
197
+ adminAddr : '0x1234567' ,
198
+ chainID : '2222' ,
199
+ chainType : 'APTOS' ,
200
+ fluxMonitorEnabled : false ,
201
+ ocr1Enabled : false ,
202
+ ocr1IsBootstrap : false ,
203
+ ocr1KeyBundleID : '' ,
204
+ ocr1Multiaddr : '' ,
205
+ ocr1P2PPeerID : '' ,
206
+ ocr2CommitPluginEnabled : false ,
207
+ ocr2Enabled : false ,
208
+ ocr2ExecutePluginEnabled : false ,
209
+ ocr2ForwarderAddress : '' ,
210
+ ocr2IsBootstrap : false ,
211
+ ocr2KeyBundleID : '' ,
212
+ ocr2MedianPluginEnabled : false ,
213
+ ocr2MercuryPluginEnabled : false ,
214
+ ocr2Multiaddr : '' ,
215
+ ocr2P2PPeerID : '' ,
216
+ ocr2RebalancerPluginEnabled : false ,
217
+ } )
218
+ expect ( handleSubmit ) . toHaveBeenCalledTimes ( 1 )
219
+ } )
220
+ } )
188
221
} )
222
+
223
+ function emptyFormValues ( ) : FormValues {
224
+ return {
225
+ chainID : '' ,
226
+ chainType : '' ,
227
+ accountAddr : '' ,
228
+ accountAddrPubKey : '' ,
229
+ adminAddr : '' ,
230
+ fluxMonitorEnabled : false ,
231
+ ocr1Enabled : false ,
232
+ ocr1IsBootstrap : false ,
233
+ ocr1Multiaddr : '' ,
234
+ ocr1P2PPeerID : '' ,
235
+ ocr1KeyBundleID : '' ,
236
+ ocr2Enabled : false ,
237
+ ocr2IsBootstrap : false ,
238
+ ocr2Multiaddr : '' ,
239
+ ocr2P2PPeerID : '' ,
240
+ ocr2KeyBundleID : '' ,
241
+ ocr2CommitPluginEnabled : false ,
242
+ ocr2ExecutePluginEnabled : false ,
243
+ ocr2MedianPluginEnabled : false ,
244
+ ocr2MercuryPluginEnabled : false ,
245
+ ocr2RebalancerPluginEnabled : false ,
246
+ ocr2ForwarderAddress : '' ,
247
+ }
248
+ }
0 commit comments