Skip to content
Draft
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
74 changes: 74 additions & 0 deletions framework/clclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sync"
"time"

aptossdk "github.com/aptos-labs/aptos-go-sdk"
"github.com/avast/retry-go/v4"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -857,6 +858,79 @@ func (c *ChainlinkClient) ReadTxKeys(chain string) (*TxKeys, *http.Response, err
return txKeys, resp.RawResponse, err
}

// ReadAptosKeys reads all Aptos keys from the Chainlink node.
func (c *ChainlinkClient) ReadAptosKeys() (*AptosKeys, *http.Response, error) {
aptosKeys := &AptosKeys{}
framework.L.Info().Str(NodeURL, c.Config.URL).Msg("Reading Aptos Keys")
resp, err := c.APIClient.R().
SetResult(aptosKeys).
Get("/v2/keys/aptos")
if err != nil {
return nil, nil, err
}
return aptosKeys, resp.RawResponse, err
}

// MustReadAptosKeys reads all Aptos keys from the Chainlink node and returns error if the request is unsuccessful.
func (c *ChainlinkClient) MustReadAptosKeys() (*AptosKeys, error) {
aptosKeys, resp, err := c.ReadAptosKeys()
if err != nil {
return nil, err
}
if err := VerifyStatusCode(resp.StatusCode, http.StatusOK); err != nil {
return nil, err
}
if len(aptosKeys.Data) == 0 {
framework.L.Warn().Str(NodeURL, c.Config.URL).Msg("Found no Aptos Keys on the node")
}
return aptosKeys, nil
}

// MustReadAptosAccounts reads and normalizes all Aptos accounts from the Chainlink node.
func (c *ChainlinkClient) MustReadAptosAccounts() ([]string, error) {
aptosKeys, err := c.MustReadAptosKeys()
if err != nil {
return nil, err
}
return normalizeAptosAccounts(aptosKeys)
}

func normalizeAptosAccounts(keys *AptosKeys) ([]string, error) {
if keys == nil {
return nil, errors.New("aptos keys payload is nil")
}

seen := make(map[string]struct{})
out := make([]string, 0, len(keys.Data))
add := func(raw string) {
s := strings.TrimSpace(raw)
if s == "" {
return
}
var addr aptossdk.AccountAddress
if err := addr.ParseStringRelaxed(s); err != nil {
return
}
normalized := addr.StringLong()
if _, ok := seen[normalized]; ok {
return
}
seen[normalized] = struct{}{}
out = append(out, normalized)
}

for _, entry := range keys.Data {
add(entry.Attributes.Account)
add(entry.Attributes.Address)
}

if len(out) == 0 {
return nil, errors.New("no valid aptos accounts found")
}

return out, nil
}

// DeleteTxKey deletes an tx key based on the provided ID
func (c *ChainlinkClient) DeleteTxKey(chain string, id string) (*http.Response, error) {
framework.L.Info().Str(NodeURL, c.Config.URL).Str("ID", id).Msg("Deleting Tx Key")
Expand Down
42 changes: 42 additions & 0 deletions framework/clclient/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package clclient

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestNormalizeAptosAccounts(t *testing.T) {
keys := &AptosKeys{
Data: []AptosKeyData{
{
Attributes: AptosKeyAttributes{
Account: "0xa",
Address: " 0xA ",
},
},
{
Attributes: AptosKeyAttributes{
Account: "0xB",
},
},
{
Attributes: AptosKeyAttributes{
Account: "not-an-account",
},
},
},
}

accounts, err := normalizeAptosAccounts(keys)
require.NoError(t, err)
require.Equal(t, []string{
"0x000000000000000000000000000000000000000000000000000000000000000a",
"0x000000000000000000000000000000000000000000000000000000000000000b",
}, accounts)
}

func TestNormalizeAptosAccounts_ErrorsOnEmpty(t *testing.T) {
_, err := normalizeAptosAccounts(&AptosKeys{})
require.Error(t, err)
}
23 changes: 23 additions & 0 deletions framework/clclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,29 @@ type TxKeyAttributes struct {
StarkKey string `json:"starkPubKey,omitempty"`
}

// AptosKeys is the model that represents the created Aptos keys when read.
type AptosKeys struct {
Data []AptosKeyData `json:"data"`
}

// AptosKey is the model that represents the created Aptos key when read.
type AptosKey struct {
Data AptosKeyData `json:"data"`
}

// AptosKeyData is the model that represents the created Aptos keys when read.
type AptosKeyData struct {
Type string `json:"type"`
ID string `json:"id"`
Attributes AptosKeyAttributes `json:"attributes"`
}

// AptosKeyAttributes is the model that represents the attributes of an Aptos key.
type AptosKeyAttributes struct {
Account string `json:"account"`
Address string `json:"address"`
}

type SingleTransactionDataWrapper struct {
Data TransactionData `json:"data"`
}
Expand Down
5 changes: 5 additions & 0 deletions framework/components/blockchain/aptos.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func newAptos(ctx context.Context, in *Input) (*Output, error) {
Type: in.Type,
Family: FamilyAptos,
ContainerName: containerName,
NetworkSpecificData: &NetworkSpecificData{
AptosNetwork: &AptosNetworkInfo{
FaucetURL: fmt.Sprintf("http://%s:%s", host, DefaultAptosFaucetPort),
},
},
Nodes: []*Node{
{
ExternalHTTPUrl: fmt.Sprintf("http://%s:%s", host, exposedAPIPort),
Expand Down
5 changes: 5 additions & 0 deletions framework/components/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ type Output struct {
}

type NetworkSpecificData struct {
AptosNetwork *AptosNetworkInfo `toml:"aptos_network" comment:"Aptos network info"`
SuiAccount *SuiWalletInfo `toml:"sui_account" comment:"Sui network account info"`
CantonData *CantonData `toml:"canton_data" comment:"Canton network data"`
StellarNetwork *StellarNetworkInfo `toml:"stellar_network" comment:"Stellar network info"`
}

type AptosNetworkInfo struct {
FaucetURL string `toml:"faucet_url" comment:"Aptos faucet URL for funding accounts"`
}

// Node represents blockchain node output, URLs required for connection locally and inside docker network
type Node struct {
ExternalWSUrl string `toml:"ws_url" comment:"External blockchain node WebSocket URL"`
Expand Down
26 changes: 15 additions & 11 deletions framework/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
dario.cat/mergo v1.0.1
github.com/Khan/genqlient v0.8.1
github.com/Masterminds/semver/v3 v3.4.0
github.com/aptos-labs/aptos-go-sdk v1.12.0
github.com/avast/retry-go/v4 v4.6.1
github.com/block-vision/sui-go-sdk v1.0.6
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
Expand Down Expand Up @@ -40,7 +41,7 @@ require (
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/trace v1.35.0
go.uber.org/multierr v1.11.0
golang.org/x/sync v0.16.0
golang.org/x/sync v0.19.0
google.golang.org/grpc v1.71.0
gopkg.in/guregu/null.v4 v4.0.0
k8s.io/api v0.32.3
Expand All @@ -53,6 +54,7 @@ require (
cloud.google.com/go/auth v0.14.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
filippo.io/edwards25519 v1.1.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
Expand Down Expand Up @@ -81,7 +83,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/coder/websocket v1.8.12 // indirect
github.com/coder/websocket v1.8.14 // indirect
github.com/consensys/bavard v0.1.22 // indirect
github.com/consensys/gnark-crypto v0.14.0 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
Expand All @@ -95,7 +97,7 @@ require (
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
Expand Down Expand Up @@ -168,6 +170,8 @@ require (
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/memberlist v0.5.2 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/hasura/go-graphql-client v0.15.1 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/holiman/uint256 v1.3.2 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down Expand Up @@ -246,7 +250,7 @@ require (
github.com/smartcontractkit/chainlink-testing-framework/lib/grafana v1.50.0 // indirect
github.com/sony/gobreaker/v2 v2.1.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
Expand Down Expand Up @@ -285,16 +289,16 @@ require (
go.uber.org/zap v1.27.0 // indirect
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/mod v0.30.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/oauth2 v0.32.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/term v0.34.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.10.0 // indirect
golang.org/x/tools v0.36.0 // indirect
golang.org/x/tools v0.39.0 // indirect
google.golang.org/api v0.221.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250124145028-65684f501c47 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect
Expand Down
Loading
Loading