-
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.
[DPA-1157]: feat: introduce cosmosKeys & starknetKeys graphql query (#…
…14764) * feat(cosmos): introduce cosmosKeys graphql query Similar to eTHKeys and solanaKeys, we need cosmosKeys that will be used by the operator ui to show a list of addresses. JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1157 * feat(starknet): introduce starknetKeys graphql query Similar to eTHKeys and solanaKeys, we need starknetKeys that will be used by the operator ui to show a list of addresses. JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1157
- Loading branch information
1 parent
a3b552f
commit 56d4b84
Showing
10 changed files
with
283 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 cosmosKeys and starknetKeys 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,43 @@ | ||
package resolver | ||
|
||
import ( | ||
"github.com/graph-gophers/graphql-go" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/cosmoskey" | ||
) | ||
|
||
type CosmosKeyResolver struct { | ||
key cosmoskey.Key | ||
} | ||
|
||
func NewCosmosKey(key cosmoskey.Key) *CosmosKeyResolver { | ||
return &CosmosKeyResolver{key: key} | ||
} | ||
|
||
func NewCosmosKeys(keys []cosmoskey.Key) []*CosmosKeyResolver { | ||
var resolvers []*CosmosKeyResolver | ||
|
||
for _, k := range keys { | ||
resolvers = append(resolvers, NewCosmosKey(k)) | ||
} | ||
|
||
return resolvers | ||
} | ||
|
||
func (r *CosmosKeyResolver) ID() graphql.ID { | ||
return graphql.ID(r.key.PublicKeyStr()) | ||
} | ||
|
||
// -- GetCosmosKeys Query -- | ||
|
||
type CosmosKeysPayloadResolver struct { | ||
keys []cosmoskey.Key | ||
} | ||
|
||
func NewCosmosKeysPayload(keys []cosmoskey.Key) *CosmosKeysPayloadResolver { | ||
return &CosmosKeysPayloadResolver{keys: keys} | ||
} | ||
|
||
func (r *CosmosKeysPayloadResolver) Results() []*CosmosKeyResolver { | ||
return NewCosmosKeys(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,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/cosmoskey" | ||
) | ||
|
||
func TestResolver_CosmosKeys(t *testing.T) { | ||
t.Parallel() | ||
|
||
query := ` | ||
query GetCosmosKeys { | ||
cosmosKeys { | ||
results { | ||
id | ||
} | ||
} | ||
}` | ||
k := cosmoskey.MustNewInsecure(keystest.NewRandReaderFromSeed(1)) | ||
result := fmt.Sprintf(` | ||
{ | ||
"cosmosKeys": { | ||
"results": [ | ||
{ | ||
"id": "%s" | ||
} | ||
] | ||
} | ||
}`, k.PublicKeyStr()) | ||
gError := errors.New("error") | ||
|
||
testCases := []GQLTestCase{ | ||
unauthorizedTestCase(GQLTestCase{query: query}, "cosmosKeys"), | ||
{ | ||
name: "success", | ||
authenticated: true, | ||
before: func(ctx context.Context, f *gqlTestFramework) { | ||
f.Mocks.cosmos.On("GetAll").Return([]cosmoskey.Key{k}, nil) | ||
f.Mocks.keystore.On("Cosmos").Return(f.Mocks.cosmos) | ||
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.cosmos.On("GetAll").Return([]cosmoskey.Key{}, gError) | ||
f.Mocks.keystore.On("Cosmos").Return(f.Mocks.cosmos) | ||
f.App.On("GetKeyStore").Return(f.Mocks.keystore) | ||
}, | ||
query: query, | ||
result: `null`, | ||
errors: []*gqlerrors.QueryError{ | ||
{ | ||
Extensions: nil, | ||
ResolverError: gError, | ||
Path: []interface{}{"cosmosKeys"}, | ||
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
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/starkkey" | ||
) | ||
|
||
type StarkNetKeyResolver struct { | ||
key starkkey.Key | ||
} | ||
|
||
func NewStarkNetKey(key starkkey.Key) *StarkNetKeyResolver { | ||
return &StarkNetKeyResolver{key: key} | ||
} | ||
|
||
func NewStarkNetKeys(keys []starkkey.Key) []*StarkNetKeyResolver { | ||
var resolvers []*StarkNetKeyResolver | ||
|
||
for _, k := range keys { | ||
resolvers = append(resolvers, NewStarkNetKey(k)) | ||
} | ||
|
||
return resolvers | ||
} | ||
|
||
func (r *StarkNetKeyResolver) ID() graphql.ID { | ||
return graphql.ID(r.key.StarkKeyStr()) | ||
} | ||
|
||
// -- GetStarkNetKeys Query -- | ||
|
||
type StarkNetKeysPayloadResolver struct { | ||
keys []starkkey.Key | ||
} | ||
|
||
func NewStarkNetKeysPayload(keys []starkkey.Key) *StarkNetKeysPayloadResolver { | ||
return &StarkNetKeysPayloadResolver{keys: keys} | ||
} | ||
|
||
func (r *StarkNetKeysPayloadResolver) Results() []*StarkNetKeyResolver { | ||
return NewStarkNetKeys(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,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/starkkey" | ||
) | ||
|
||
func TestResolver_StarkNetKeys(t *testing.T) { | ||
t.Parallel() | ||
|
||
query := ` | ||
query GetStarkNetKeys { | ||
starknetKeys { | ||
results { | ||
id | ||
} | ||
} | ||
}` | ||
k := starkkey.MustNewInsecure(keystest.NewRandReaderFromSeed(1)) | ||
result := fmt.Sprintf(` | ||
{ | ||
"starknetKeys": { | ||
"results": [ | ||
{ | ||
"id": "%s" | ||
} | ||
] | ||
} | ||
}`, k.StarkKeyStr()) | ||
gError := errors.New("error") | ||
|
||
testCases := []GQLTestCase{ | ||
unauthorizedTestCase(GQLTestCase{query: query}, "starknetKeys"), | ||
{ | ||
name: "success", | ||
authenticated: true, | ||
before: func(ctx context.Context, f *gqlTestFramework) { | ||
f.Mocks.starknet.On("GetAll").Return([]starkkey.Key{k}, nil) | ||
f.Mocks.keystore.On("StarkNet").Return(f.Mocks.starknet) | ||
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.starknet.On("GetAll").Return([]starkkey.Key{}, gError) | ||
f.Mocks.keystore.On("StarkNet").Return(f.Mocks.starknet) | ||
f.App.On("GetKeyStore").Return(f.Mocks.keystore) | ||
}, | ||
query: query, | ||
result: `null`, | ||
errors: []*gqlerrors.QueryError{ | ||
{ | ||
Extensions: nil, | ||
ResolverError: gError, | ||
Path: []interface{}{"starknetKeys"}, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type CosmosKey { | ||
id: ID! | ||
} | ||
|
||
type CosmosKeysPayload { | ||
results: [CosmosKey!]! | ||
} |
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,7 @@ | ||
type StarkNetKey { | ||
id: ID! | ||
} | ||
|
||
type StarkNetKeysPayload { | ||
results: [StarkNetKey!]! | ||
} |