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-1152]: feat(aptos): introduce aptosKeys graphql query #14729

Merged
merged 1 commit into from
Oct 11, 2024
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/four-buses-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#added Introduce aptosKeys Graphql query
47 changes: 47 additions & 0 deletions core/web/resolver/aptos_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package resolver

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

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

type AptosKeyResolver struct {
key aptoskey.Key
}

func NewAptosKey(key aptoskey.Key) *AptosKeyResolver {
return &AptosKeyResolver{key: key}
}

func NewAptosKeys(keys []aptoskey.Key) []*AptosKeyResolver {
var resolvers []*AptosKeyResolver

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

return resolvers
}

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

func (r *AptosKeyResolver) Account() string {
return r.key.Account()
}

// -- GetAptosKeys Query --

type AptosKeysPayloadResolver struct {
keys []aptoskey.Key
}

func NewAptosKeysPayload(keys []aptoskey.Key) *AptosKeysPayloadResolver {
return &AptosKeysPayloadResolver{keys: keys}
}

func (r *AptosKeysPayloadResolver) Results() []*AptosKeyResolver {
return NewAptosKeys(r.keys)
}
76 changes: 76 additions & 0 deletions core/web/resolver/aptos_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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/aptoskey"
)

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

query := `
query GetAptosKeys {
aptosKeys {
results {
id
account
}
}
}`
k := aptoskey.MustNewInsecure(keystest.NewRandReaderFromSeed(1))
result := fmt.Sprintf(`
{
"aptosKeys": {
"results": [
{
"id": "%s",
"account": "%s"
}
]
}
}`, k.PublicKeyStr(), k.Account())
gError := errors.New("error")

testCases := []GQLTestCase{
unauthorizedTestCase(GQLTestCase{query: query}, "aptosKeys"),
{
name: "success",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.Mocks.aptos.On("GetAll").Return([]aptoskey.Key{k}, nil)
f.Mocks.keystore.On("Aptos").Return(f.Mocks.aptos)
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.aptos.On("GetAll").Return([]aptoskey.Key{}, gError)
f.Mocks.keystore.On("Aptos").Return(f.Mocks.aptos)
f.App.On("GetKeyStore").Return(f.Mocks.keystore)
},
query: query,
result: `null`,
errors: []*gqlerrors.QueryError{
{
Extensions: nil,
ResolverError: gError,
Path: []interface{}{"aptosKeys"},
Message: gError.Error(),
},
},
},
}

RunGQLTests(t, testCases)
}
13 changes: 13 additions & 0 deletions core/web/resolver/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,19 @@ func (r *Resolver) SolanaKeys(ctx context.Context) (*SolanaKeysPayloadResolver,
return NewSolanaKeysPayload(keys), nil
}

func (r *Resolver) AptosKeys(ctx context.Context) (*AptosKeysPayloadResolver, error) {
if err := authenticateUser(ctx); err != nil {
return nil, err
}

keys, err := r.App.GetKeyStore().Aptos().GetAll()
if err != nil {
return nil, err
}

return NewAptosKeysPayload(keys), nil
}

func (r *Resolver) SQLLogging(ctx context.Context) (*GetSQLLoggingPayloadResolver, error) {
if err := authenticateUser(ctx); err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions core/web/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type mocks struct {
p2p *keystoreMocks.P2P
vrf *keystoreMocks.VRF
solana *keystoreMocks.Solana
aptos *keystoreMocks.Aptos
chain *legacyEvmORMMocks.Chain
legacyEVMChains *legacyEvmORMMocks.LegacyChainContainer
relayerChainInterops *chainlinkMocks.FakeRelayerChainInteroperators
Expand Down Expand Up @@ -106,6 +107,7 @@ func setupFramework(t *testing.T) *gqlTestFramework {
p2p: keystoreMocks.NewP2P(t),
vrf: keystoreMocks.NewVRF(t),
solana: keystoreMocks.NewSolana(t),
aptos: keystoreMocks.NewAptos(t),
chain: legacyEvmORMMocks.NewChain(t),
legacyEVMChains: legacyEvmORMMocks.NewLegacyChainContainer(t),
relayerChainInterops: &chainlinkMocks.FakeRelayerChainInteroperators{},
Expand Down
1 change: 1 addition & 0 deletions core/web/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Query {
ocr2KeyBundles: OCR2KeyBundlesPayload!
p2pKeys: P2PKeysPayload!
solanaKeys: SolanaKeysPayload!
aptosKeys: AptosKeysPayload!
sqlLogging: GetSQLLoggingPayload!
vrfKey(id: ID!): VRFKeyPayload!
vrfKeys: VRFKeysPayload!
Expand Down
8 changes: 8 additions & 0 deletions core/web/schema/type/aptos_key.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type AptosKey {
id: ID!
account: String!
}

type AptosKeysPayload {
results: [AptosKey!]!
}
9 changes: 9 additions & 0 deletions integration-tests/web/sdk/internal/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Query {
ocr2KeyBundles: OCR2KeyBundlesPayload!
p2pKeys: P2PKeysPayload!
solanaKeys: SolanaKeysPayload!
aptosKeys: AptosKeysPayload!
sqlLogging: GetSQLLoggingPayload!
vrfKey(id: ID!): VRFKeyPayload!
vrfKeys: VRFKeysPayload!
Expand Down Expand Up @@ -99,6 +100,14 @@ type DeleteAPITokenSuccess {
}

union DeleteAPITokenPayload = DeleteAPITokenSuccess | InputErrors
type AptosKey {
id: ID!
account: String!
}

type AptosKeysPayload {
results: [AptosKey!]!
}
type Bridge {
id: ID!
name: String!
Expand Down
Loading