Skip to content

Commit e623f73

Browse files
feat(chainconfig): support aptos
Allow APTOS to be selected in the chainconfig modal instead of just EVM JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1155
1 parent b940c8d commit e623f73

File tree

10 files changed

+310
-117
lines changed

10 files changed

+310
-117
lines changed

.changeset/serious-turtles-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@smartcontractkit/operator-ui': minor
3+
---
4+
5+
Support APTOS in chain config
Lines changed: 138 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,25 @@
11
import * as React from 'react'
22

3-
import { render, screen } from 'support/test-utils'
43
import userEvent from '@testing-library/user-event'
4+
import { render, screen, waitFor } from 'support/test-utils'
55

66
import { ChainConfigurationForm, FormValues } from './ChainConfigurationForm'
7+
import { ChainTypes } from './ChainTypes'
78

89
const { getByRole, findByTestId } = screen
910

1011
describe('ChainConfigurationForm', () => {
1112
it('validates top level input', async () => {
1213
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()
3615

3716
render(
3817
<ChainConfigurationForm
3918
initialValues={initialValues}
4019
onSubmit={handleSubmit}
41-
accounts={[]}
42-
chainIDs={[]}
20+
accountsEVM={[]}
21+
accountsAptos={[]}
22+
chains={[]}
4323
p2pKeys={[]}
4424
ocrKeys={[]}
4525
ocr2Keys={[]}
@@ -62,37 +42,15 @@ describe('ChainConfigurationForm', () => {
6242

6343
it('validates OCR input', async () => {
6444
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()
8946

9047
render(
9148
<ChainConfigurationForm
9249
initialValues={initialValues}
9350
onSubmit={handleSubmit}
94-
accounts={[]}
95-
chainIDs={[]}
51+
accountsEVM={[]}
52+
accountsAptos={[]}
53+
chains={[]}
9654
p2pKeys={[]}
9755
ocrKeys={[]}
9856
ocr2Keys={[]}
@@ -123,37 +81,15 @@ describe('ChainConfigurationForm', () => {
12381

12482
it('validates OCR2 input', async () => {
12583
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()
15085

15186
render(
15287
<ChainConfigurationForm
15388
initialValues={initialValues}
15489
onSubmit={handleSubmit}
155-
accounts={[]}
156-
chainIDs={[]}
90+
accountsEVM={[]}
91+
accountsAptos={[]}
92+
chains={[]}
15793
p2pKeys={[]}
15894
ocrKeys={[]}
15995
ocr2Keys={[]}
@@ -185,4 +121,128 @@ describe('ChainConfigurationForm', () => {
185121
await findByTestId('ocr2P2PPeerID-helper-text'),
186122
).not.toHaveTextContent('Required')
187123
})
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: /submit/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+
})
188221
})
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

Comments
 (0)