-
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.
- Loading branch information
Showing
7 changed files
with
133 additions
and
6 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 |
---|---|---|
@@ -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 |
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/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 | ||
|
||
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) | ||
} |
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/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) | ||
} |
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 TronKey { | ||
id: ID! | ||
} | ||
|
||
type TronKeysPayload { | ||
results: [TronKey!]! | ||
} |
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