Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPA-1333]: feat: create tron chain config support #99

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-horses-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@smartcontractkit/operator-ui': minor
---

feat: create tron chain config
69 changes: 69 additions & 0 deletions src/components/Form/ChainConfigurationForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ describe('ChainConfigurationForm', () => {
solanaKeys: {
results: [],
},
tronKeys: {
results: [],
},
})

const chainType = getByRole('button', { name: 'EVM' })
Expand Down Expand Up @@ -334,6 +337,61 @@ describe('ChainConfigurationForm', () => {
})
})

test('should able to create Tron chain config', async () => {
const handleSubmit = jest.fn()
const initialValues = emptyFormValues()
initialValues.chainType = ChainTypes.EVM
initialValues.adminAddr = '0x1234567'

const { container } = renderChainConfigurationForm(
initialValues,
handleSubmit,
)

const chainType = getByRole('button', { name: 'EVM' })
userEvent.click(chainType)
userEvent.click(getByRole('option', { name: 'TRON' }))
await screen.findByRole('button', { name: 'TRON' })

await selectChainIdOnUI(container, '4444')

const address = container.querySelector('#select-accountAddr')
expect(address).toBeInTheDocument()
address && userEvent.click(address)
userEvent.click(getByRole('option', { name: 'tron_xxxx' }))
await screen.findByRole('button', { name: 'tron_xxxx' })

await userEvent.click(getByRole('button', { name: /submit/i }))

await waitFor(() => {
expect(handleSubmit).toHaveBeenCalledWith({
accountAddr: 'tron_xxxx',
accountAddrPubKey: '',
adminAddr: '0x1234567',
chainID: '4444',
chainType: 'TRON',
fluxMonitorEnabled: false,
ocr1Enabled: false,
ocr1IsBootstrap: false,
ocr1KeyBundleID: '',
ocr1Multiaddr: '',
ocr1P2PPeerID: '',
ocr2CommitPluginEnabled: false,
ocr2Enabled: false,
ocr2ExecutePluginEnabled: false,
ocr2ForwarderAddress: '',
ocr2IsBootstrap: false,
ocr2KeyBundleID: '',
ocr2MedianPluginEnabled: false,
ocr2MercuryPluginEnabled: false,
ocr2Multiaddr: '',
ocr2P2PPeerID: '',
ocr2RebalancerPluginEnabled: false,
})
expect(handleSubmit).toHaveBeenCalledTimes(1)
})
})

test('should be able to select OCR2 Job Type with Key Bundle ID', async () => {
const handleSubmit = jest.fn()
const initialValues = emptyFormValues()
Expand All @@ -350,6 +408,9 @@ test('should be able to select OCR2 Job Type with Key Bundle ID', async () => {
solanaKeys: {
results: [],
},
tronKeys: {
results: [],
},
},
)

Expand Down Expand Up @@ -410,6 +471,11 @@ function renderChainConfigurationForm(
enabled: true,
network: 'solana',
},
{
id: '4444',
enabled: true,
network: 'tron',
},
],
accountsNonEvm: FetchNonEvmKeys | undefined = {
aptosKeys: {
Expand All @@ -418,6 +484,9 @@ function renderChainConfigurationForm(
solanaKeys: {
results: [{ id: 'solana_xxxx' }],
},
tronKeys: {
results: [{ id: 'tron_xxxx' }],
},
},
) {
return render(
Expand Down
7 changes: 7 additions & 0 deletions src/components/Form/ChainConfigurationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ export const ChainConfigurationForm = withStyles(styles)(
chainAccountAddresses =
accountsNonEvm?.solanaKeys.results.map((acc) => acc.id) ?? []
break
case ChainTypes.TRON:
chainAccountAddresses =
accountsNonEvm?.tronKeys.results.map((acc) => acc.id) ?? []
break
default:
chainAccountAddresses = []
}
Expand Down Expand Up @@ -295,6 +299,9 @@ export const ChainConfigurationForm = withStyles(styles)(
<MenuItem key={ChainTypes.SOLANA} value={ChainTypes.SOLANA}>
SOLANA
</MenuItem>
<MenuItem key={ChainTypes.TRON} value={ChainTypes.TRON}>
TRON
</MenuItem>
</Field>
</Grid>

Expand Down
1 change: 1 addition & 0 deletions src/components/Form/ChainTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const ChainTypes = {
SOLANA: 'SOLANA',
STARKNET: 'STARKNET',
COSMOS: 'COSMOS',
TRON: 'TRON',
}
11 changes: 11 additions & 0 deletions src/hooks/queries/useNonEvmAccountsQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const mockData = {
__typename: 'SolanaKeys',
results: [{ __typename: 'SolanaKey', id: '3' }],
},
tronKeys: {
__typename: 'TronKeys',
results: [{ __typename: 'TronKey', id: '4' }],
},
},
}

Expand Down Expand Up @@ -51,6 +55,12 @@ const TestComponent: React.FC = () => {
<p>Solana ID: {key.id}</p>
</div>
))}

{data?.tronKeys.results.map((key, i) => (
<div key={i}>
<p>Tron ID: {key.id}</p>
</div>
))}
</div>
)
}
Expand All @@ -70,6 +80,7 @@ describe('useNonEvmAccountsQuery', () => {
expect(screen.getByText('Aptos ID: 2')).toBeInTheDocument()

expect(screen.getByText('Solana ID: 3')).toBeInTheDocument()
expect(screen.getByText('Tron ID: 4')).toBeInTheDocument()
})
})
})
12 changes: 12 additions & 0 deletions src/hooks/queries/useNonEvmAccountsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ export const SOLANA_KEYS_PAYLOAD__RESULTS_FIELDS = gql`
}
`

export const TRON_KEYS_PAYLOAD__RESULTS_FIELDS = gql`
fragment TronKeysPayload_ResultsFields on TronKey {
id
}
`

export const NON_EVM_KEYS_QUERY = gql`
${APTOS_KEYS_PAYLOAD__RESULTS_FIELDS}
${SOLANA_KEYS_PAYLOAD__RESULTS_FIELDS}
${TRON_KEYS_PAYLOAD__RESULTS_FIELDS}
query FetchNonEvmKeys {
aptosKeys {
results {
Expand All @@ -27,6 +34,11 @@ export const NON_EVM_KEYS_QUERY = gql`
...SolanaKeysPayload_ResultsFields
}
}
tronKeys {
results {
...TronKeysPayload_ResultsFields
}
}
}
`

Expand Down
Loading