-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aptos): introduce aptosKeys graphql query (#14729)
We want to support Aptos in core node, similar to eTHKeys and solanaKeys, we need aptosKeys that will be used by the operator ui to show a list os addresses. JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1152
- Loading branch information
1 parent
7b67985
commit 770d2bc
Showing
8 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": minor | ||
--- | ||
|
||
#added Introduce aptosKeys Graphql query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type AptosKey { | ||
id: ID! | ||
account: String! | ||
} | ||
|
||
type AptosKeysPayload { | ||
results: [AptosKey!]! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters