Skip to content

Commit 603ef8d

Browse files
Merge pull request #99 from smartcontractkit/ggoh/DPA-1333/tron-chain-config
[DPA-1333]: feat: create tron chain config support
2 parents 445b190 + 840b5aa commit 603ef8d

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

.changeset/brown-horses-give.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+
feat: create tron chain config

src/components/Form/ChainConfigurationForm.test.tsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ describe('ChainConfigurationForm', () => {
232232
solanaKeys: {
233233
results: [],
234234
},
235+
tronKeys: {
236+
results: [],
237+
},
235238
})
236239

237240
const chainType = getByRole('button', { name: 'EVM' })
@@ -334,6 +337,61 @@ describe('ChainConfigurationForm', () => {
334337
})
335338
})
336339

340+
test('should able to create Tron chain config', async () => {
341+
const handleSubmit = jest.fn()
342+
const initialValues = emptyFormValues()
343+
initialValues.chainType = ChainTypes.EVM
344+
initialValues.adminAddr = '0x1234567'
345+
346+
const { container } = renderChainConfigurationForm(
347+
initialValues,
348+
handleSubmit,
349+
)
350+
351+
const chainType = getByRole('button', { name: 'EVM' })
352+
userEvent.click(chainType)
353+
userEvent.click(getByRole('option', { name: 'TRON' }))
354+
await screen.findByRole('button', { name: 'TRON' })
355+
356+
await selectChainIdOnUI(container, '4444')
357+
358+
const address = container.querySelector('#select-accountAddr')
359+
expect(address).toBeInTheDocument()
360+
address && userEvent.click(address)
361+
userEvent.click(getByRole('option', { name: 'tron_xxxx' }))
362+
await screen.findByRole('button', { name: 'tron_xxxx' })
363+
364+
await userEvent.click(getByRole('button', { name: /submit/i }))
365+
366+
await waitFor(() => {
367+
expect(handleSubmit).toHaveBeenCalledWith({
368+
accountAddr: 'tron_xxxx',
369+
accountAddrPubKey: '',
370+
adminAddr: '0x1234567',
371+
chainID: '4444',
372+
chainType: 'TRON',
373+
fluxMonitorEnabled: false,
374+
ocr1Enabled: false,
375+
ocr1IsBootstrap: false,
376+
ocr1KeyBundleID: '',
377+
ocr1Multiaddr: '',
378+
ocr1P2PPeerID: '',
379+
ocr2CommitPluginEnabled: false,
380+
ocr2Enabled: false,
381+
ocr2ExecutePluginEnabled: false,
382+
ocr2ForwarderAddress: '',
383+
ocr2IsBootstrap: false,
384+
ocr2KeyBundleID: '',
385+
ocr2MedianPluginEnabled: false,
386+
ocr2MercuryPluginEnabled: false,
387+
ocr2Multiaddr: '',
388+
ocr2P2PPeerID: '',
389+
ocr2RebalancerPluginEnabled: false,
390+
})
391+
expect(handleSubmit).toHaveBeenCalledTimes(1)
392+
})
393+
})
394+
337395
test('should be able to select OCR2 Job Type with Key Bundle ID', async () => {
338396
const handleSubmit = jest.fn()
339397
const initialValues = emptyFormValues()
@@ -350,6 +408,9 @@ test('should be able to select OCR2 Job Type with Key Bundle ID', async () => {
350408
solanaKeys: {
351409
results: [],
352410
},
411+
tronKeys: {
412+
results: [],
413+
},
353414
},
354415
)
355416

@@ -410,6 +471,11 @@ function renderChainConfigurationForm(
410471
enabled: true,
411472
network: 'solana',
412473
},
474+
{
475+
id: '4444',
476+
enabled: true,
477+
network: 'tron',
478+
},
413479
],
414480
accountsNonEvm: FetchNonEvmKeys | undefined = {
415481
aptosKeys: {
@@ -418,6 +484,9 @@ function renderChainConfigurationForm(
418484
solanaKeys: {
419485
results: [{ id: 'solana_xxxx' }],
420486
},
487+
tronKeys: {
488+
results: [{ id: 'tron_xxxx' }],
489+
},
421490
},
422491
) {
423492
return render(

src/components/Form/ChainConfigurationForm.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ export const ChainConfigurationForm = withStyles(styles)(
260260
chainAccountAddresses =
261261
accountsNonEvm?.solanaKeys.results.map((acc) => acc.id) ?? []
262262
break
263+
case ChainTypes.TRON:
264+
chainAccountAddresses =
265+
accountsNonEvm?.tronKeys.results.map((acc) => acc.id) ?? []
266+
break
263267
default:
264268
chainAccountAddresses = []
265269
}
@@ -295,6 +299,9 @@ export const ChainConfigurationForm = withStyles(styles)(
295299
<MenuItem key={ChainTypes.SOLANA} value={ChainTypes.SOLANA}>
296300
SOLANA
297301
</MenuItem>
302+
<MenuItem key={ChainTypes.TRON} value={ChainTypes.TRON}>
303+
TRON
304+
</MenuItem>
298305
</Field>
299306
</Grid>
300307

src/components/Form/ChainTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const ChainTypes = {
44
SOLANA: 'SOLANA',
55
STARKNET: 'STARKNET',
66
COSMOS: 'COSMOS',
7+
TRON: 'TRON',
78
}

src/hooks/queries/useNonEvmAccountsQuery.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const mockData = {
1919
__typename: 'SolanaKeys',
2020
results: [{ __typename: 'SolanaKey', id: '3' }],
2121
},
22+
tronKeys: {
23+
__typename: 'TronKeys',
24+
results: [{ __typename: 'TronKey', id: '4' }],
25+
},
2226
},
2327
}
2428

@@ -51,6 +55,12 @@ const TestComponent: React.FC = () => {
5155
<p>Solana ID: {key.id}</p>
5256
</div>
5357
))}
58+
59+
{data?.tronKeys.results.map((key, i) => (
60+
<div key={i}>
61+
<p>Tron ID: {key.id}</p>
62+
</div>
63+
))}
5464
</div>
5565
)
5666
}
@@ -70,6 +80,7 @@ describe('useNonEvmAccountsQuery', () => {
7080
expect(screen.getByText('Aptos ID: 2')).toBeInTheDocument()
7181

7282
expect(screen.getByText('Solana ID: 3')).toBeInTheDocument()
83+
expect(screen.getByText('Tron ID: 4')).toBeInTheDocument()
7384
})
7485
})
7586
})

src/hooks/queries/useNonEvmAccountsQuery.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ export const SOLANA_KEYS_PAYLOAD__RESULTS_FIELDS = gql`
1313
}
1414
`
1515

16+
export const TRON_KEYS_PAYLOAD__RESULTS_FIELDS = gql`
17+
fragment TronKeysPayload_ResultsFields on TronKey {
18+
id
19+
}
20+
`
21+
1622
export const NON_EVM_KEYS_QUERY = gql`
1723
${APTOS_KEYS_PAYLOAD__RESULTS_FIELDS}
1824
${SOLANA_KEYS_PAYLOAD__RESULTS_FIELDS}
25+
${TRON_KEYS_PAYLOAD__RESULTS_FIELDS}
1926
query FetchNonEvmKeys {
2027
aptosKeys {
2128
results {
@@ -27,6 +34,11 @@ export const NON_EVM_KEYS_QUERY = gql`
2734
...SolanaKeysPayload_ResultsFields
2835
}
2936
}
37+
tronKeys {
38+
results {
39+
...TronKeysPayload_ResultsFields
40+
}
41+
}
3042
}
3143
`
3244

0 commit comments

Comments
 (0)