-
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(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
a00d943
commit 88c5682
Showing
7 changed files
with
158 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
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,73 @@ | ||
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 StarkNetKey { | ||
id: ID! | ||
} | ||
|
||
type StarkNetKeysPayload { | ||
results: [StarkNetKey!]! | ||
} |