Skip to content

Commit

Permalink
add to graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
cfal committed Dec 18, 2024
1 parent 7add58e commit dcbbc27
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 6 deletions.
8 changes: 4 additions & 4 deletions core/config/docs/chains-tron.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[[Tron]]
# ChainID is the Tron chain ID.
ChainID = 'foobar' # Example
# FeederURL is required to get tx metadata (that the RPC can't)
FeederURL = 'http://feeder.url' # Example
# Enabled enables this chain.
Enabled = true # Default

[[Tron.Nodes]]
# Name is a unique (per-chain) identifier for this node.
Name = 'primary' # Example
# URL is the base HTTP(S) endpoint for this node.
URL = 'http://api.trongrid.io' # Example
# URL is the full node HTTP endpoint for this node.
URL = 'https://api.trongrid.io/wallet' # Example
# SolidityURL is the solidity node HTTP endpoint for this node.
SolidityURL = 'http://api.trongrid.io/wallet' # Example
2 changes: 2 additions & 0 deletions core/web/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type mocks struct {
aptos *keystoreMocks.Aptos
cosmos *keystoreMocks.Cosmos
starknet *keystoreMocks.StarkNet
tron *keystoreMocks.Tron
chain *legacyEvmORMMocks.Chain
legacyEVMChains *legacyEvmORMMocks.LegacyChainContainer
relayerChainInterops *chainlinkMocks.FakeRelayerChainInteroperators
Expand Down Expand Up @@ -112,6 +113,7 @@ func setupFramework(t *testing.T) *gqlTestFramework {
aptos: keystoreMocks.NewAptos(t),
cosmos: keystoreMocks.NewCosmos(t),
starknet: keystoreMocks.NewStarkNet(t),
tron: keystoreMocks.NewTron(t),
chain: legacyEvmORMMocks.NewChain(t),
legacyEVMChains: legacyEvmORMMocks.NewLegacyChainContainer(t),
relayerChainInterops: &chainlinkMocks.FakeRelayerChainInteroperators{},
Expand Down
43 changes: 43 additions & 0 deletions core/web/resolver/tron_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package resolver

import (
"github.com/graph-gophers/graphql-go"

"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/tronkey"
)

type TronKeyResolver struct {
key tronkey.Key
}

func NewTronKey(key tronkey.Key) *TronKeyResolver {
return &TronKeyResolver{key: key}
}

func NewTronKeys(keys []tronkey.Key) []*TronKeyResolver {
var resolvers []*TronKeyResolver

Check failure on line 18 in core/web/resolver/tron_key.go

View workflow job for this annotation

GitHub Actions / lint

Consider pre-allocating `resolvers` (prealloc)

for _, k := range keys {
resolvers = append(resolvers, NewTronKey(k))
}

return resolvers
}

func (r *TronKeyResolver) ID() graphql.ID {
return graphql.ID(r.key.ID())
}

// -- GetTronKeys Query --

type TronKeysPayloadResolver struct {
keys []tronkey.Key
}

func NewTronKeysPayload(keys []tronkey.Key) *TronKeysPayloadResolver {
return &TronKeysPayloadResolver{keys: keys}
}

func (r *TronKeysPayloadResolver) Results() []*TronKeyResolver {
return NewTronKeys(r.keys)
}
74 changes: 74 additions & 0 deletions core/web/resolver/tron_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package resolver

import (
"context"
"errors"
"fmt"
"testing"

gqlerrors "github.com/graph-gophers/graphql-go/errors"

"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/keystest"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/tronkey"
)

func TestResolver_TronKeys(t *testing.T) {
t.Parallel()

query := `
query GetTronKeys {
tronKeys {
results {
id
}
}
}`
k := tronkey.MustNewInsecure(keystest.NewRandReaderFromSeed(1))
result := fmt.Sprintf(`
{
"tronKeys": {
"results": [
{
"id": "%s"
}
]
}
}`, k.ID())
gError := errors.New("error")

testCases := []GQLTestCase{
unauthorizedTestCase(GQLTestCase{query: query}, "tronKeys"),
{
name: "success",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.Mocks.tron.On("GetAll").Return([]tronkey.Key{k}, nil)
f.Mocks.keystore.On("Tron").Return(f.Mocks.tron)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
},
query: query,
result: result,
},
{
name: "no keys returned by GetAll",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.Mocks.tron.On("GetAll").Return([]tronkey.Key{}, gError)
f.Mocks.keystore.On("Tron").Return(f.Mocks.tron)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
},
query: query,
result: `null`,
errors: []*gqlerrors.QueryError{
{
Extensions: nil,
ResolverError: gError,
Path: []interface{}{"tronKeys"},
Message: gError.Error(),
},
},
},
}

RunGQLTests(t, testCases)
}
1 change: 1 addition & 0 deletions core/web/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Query {
aptosKeys: AptosKeysPayload!
cosmosKeys: CosmosKeysPayload!
starknetKeys: StarkNetKeysPayload!
tronKeys: TronKeysPayload!
sqlLogging: GetSQLLoggingPayload!
vrfKey(id: ID!): VRFKeyPayload!
vrfKeys: VRFKeysPayload!
Expand Down
7 changes: 7 additions & 0 deletions core/web/schema/type/tron_key.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type TronKey {
id: ID!
}

type TronKeysPayload {
results: [TronKey!]!
}
4 changes: 2 additions & 2 deletions deployment/environment/nodeclient/chainlink_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ type TronChainConfig struct {

// TronChainAttributes is the model that represents the tron chain
type TronChainAttributes struct {
ChainID string `json:"chainID"`
ChainID string `json:"chainID"`
Config TronChainConfig `json:"config"`
}

Expand All @@ -549,7 +549,7 @@ type TronChainCreate struct {
type TronNodeAttributes struct {
Name string `json:"name"`
ChainID string `json:"chainId"`
Url string `json:"url"`
URL string `json:"url"`
}

// TronNode is the model that represents the tron node when read
Expand Down

0 comments on commit dcbbc27

Please sign in to comment.