Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #349

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft

wip #349

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 integration-tests/common/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package common

import (
"fmt"

"github.com/smartcontractkit/chainlink-env/environment"
"github.com/smartcontractkit/chainlink/integration-tests/client"
)

type ChainlinkClient struct {
ChainlinkNodes []*client.Chainlink
NodeKeys []client.NodeKeysBundle
bTypeAttr *client.BridgeTypeAttributes
bootstrapPeers []client.P2PData
}

// CreateKeys Creates node keys and defines chain and nodes for each node
func NewChainlinkClient(env *environment.Environment, chainName string, chainId string, tendermintURL string) (*ChainlinkClient, error) {
nodes, err := client.ConnectChainlinkNodes(env)
if err != nil {
return nil, err
}
fmt.Println(nodes)
nodeKeys, _, err := client.CreateNodeKeysBundle(nodes, chainName, chainId)
if err != nil {
return nil, err
}
fmt.Println(nodeKeys)
for _, n := range nodes {
_, _, err = n.CreateCosmosChain(&client.CosmosChainAttributes{
ChainID: chainId,
Config: client.CosmosChainConfig{},
})
if err != nil {
return nil, err
}
_, _, err = n.CreateCosmosNode(&client.CosmosNodeAttributes{
Name: chainName,
CosmosChainID: chainId,
TendermintURL: tendermintURL,
})
if err != nil {
return nil, err
}
}

return &ChainlinkClient{
ChainlinkNodes: nodes,
NodeKeys: nodeKeys,
}, nil
}

func (cc *ChainlinkClient) LoadOCR2Config(accountAddresses []string) (*OCR2Config, error) {
var offChainKeys []string
var onChainKeys []string
var peerIds []string
var txKeys []string
var cfgKeys []string
for i, key := range cc.NodeKeys {
offChainKeys = append(offChainKeys, key.OCR2Key.Data.Attributes.OffChainPublicKey)
peerIds = append(peerIds, key.PeerID)
txKeys = append(txKeys, accountAddresses[i])
onChainKeys = append(onChainKeys, key.OCR2Key.Data.Attributes.OnChainPublicKey)
cfgKeys = append(cfgKeys, key.OCR2Key.Data.Attributes.ConfigPublicKey)
}

var payload = TestOCR2Config
payload.Signers = onChainKeys
payload.Transmitters = txKeys
payload.OffchainConfig.OffchainPublicKeys = offChainKeys
payload.OffchainConfig.PeerIds = peerIds
payload.OffchainConfig.ConfigPublicKeys = cfgKeys
return &payload, nil
}
97 changes: 53 additions & 44 deletions integration-tests/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ const (
)

type Common struct {
P2PPort string
ChainName string
ChainId string
NodeCount int
TTL time.Duration
Testnet bool
L2RPCUrl string
PrivateKey string
Account string
ClConfig map[string]any
K8Config *environment.Config
Env *environment.Environment
IsSoak bool
P2PPort string
ChainName string
ChainId string
NodeCount int
TTL time.Duration
NodeUrl string
Mnemonic string
Account string
ClConfig map[string]any
K8Config *environment.Config
Env *environment.Environment
}

// getEnv gets the environment variable if it exists and sets it for the remote runner
Expand All @@ -50,57 +50,62 @@ func getEnv(v string) string {
return val
}

func New() *Common {
var err error
c := &Common{
ChainName: chainName,
ChainId: chainID,
}
func getNodeCount() int {
// Checking if count of OCR nodes is defined in ENV
nodeCountSet := getEnv("NODE_COUNT")
if nodeCountSet != "" {
c.NodeCount, err = strconv.Atoi(nodeCountSet)
if err != nil {
panic(fmt.Sprintf("Please define a proper node count for the test: %v", err))
}
} else {
if nodeCountSet == "" {
panic("Please define NODE_COUNT")
}
nodeCount, err := strconv.Atoi(nodeCountSet)
if err != nil {
panic(fmt.Sprintf("Please define a proper node count for the test: %v", err))
}
return nodeCount
}

// Checking if TTL env var is set in ENV
func getTTL() time.Duration {
ttlValue := getEnv("TTL")
if ttlValue != "" {
duration, err := time.ParseDuration(ttlValue)
if err != nil {
panic(fmt.Sprintf("Please define a proper duration for the test: %v", err))
}
c.TTL, err = time.ParseDuration(*alias.ShortDur(duration))
if err != nil {
panic(fmt.Sprintf("Please define a proper duration for the test: %v", err))
}
} else {
if ttlValue == "" {
panic("Please define TTL of env")
}
duration, err := time.ParseDuration(ttlValue)
if err != nil {
panic(fmt.Sprintf("Please define a proper duration for the test: %v", err))
}
t, err := time.ParseDuration(*alias.ShortDur(duration))
if err != nil {
panic(fmt.Sprintf("Please define a proper duration for the test: %v", err))
}
return t
}

// Setting optional parameters
c.L2RPCUrl = getEnv("L2_RPC_URL") // Fetch L2 RPC url if defined
c.Testnet = c.L2RPCUrl != ""
c.PrivateKey = getEnv("PRIVATE_KEY")
c.Account = getEnv("ACCOUNT")

func NewCommon() *Common {
c := &Common{
IsSoak: getEnv("SOAK") != "",
ChainName: chainName,
ChainId: chainID,
NodeCount: getNodeCount(),
TTL: getTTL(),
NodeUrl: getEnv("NODE_URL"),
Mnemonic: getEnv("MNEMONIC"),
Account: getEnv("ACCOUNT"),
}
return c
}

func (c *Common) Default(t *testing.T) {
func (c *Common) SetDefaultEnvironment(t *testing.T) {
c.K8Config = &environment.Config{
NamespacePrefix: "cosmos-ocr",
TTL: c.TTL,
Test: t,
}
// These can be uncommented when toml configuration is supposrted for cosmos in the chainlink node
wasmdUrl := fmt.Sprintf("http://%s:%d", "tendermint-rpc", 26657)
if c.Testnet {
wasmdUrl = c.L2RPCUrl
//if c.Testnet {
//wasmdUrl = c.RPCUrl
//}
if c.NodeUrl != "" {
wasmdUrl = c.NodeUrl
}
baseTOML := fmt.Sprintf(`[[Cosmos]]
Enabled = true
Expand All @@ -124,9 +129,13 @@ ListenAddresses = ['0.0.0.0:6690']
"replicas": c.NodeCount,
"toml": baseTOML,
}
fmt.Println(c.ClConfig)
// replace this env with local docker
c.Env = environment.New(c.K8Config).
AddHelm(wasmd.New(nil)).
AddHelm(mockservercfg.New(nil)).
AddHelm(mockserver.New(nil)).
AddHelm(chainlink.New(0, c.ClConfig))

fmt.Println(c.Env)
}
24 changes: 24 additions & 0 deletions integration-tests/common/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

import (
"os"
"testing"

"github.com/rs/zerolog"
"github.com/stretchr/testify/require"

envConf "github.com/smartcontractkit/chainlink-env/config"
)

// GetTestLogger TODO: This is a duplicate of the same function in chainlink-testing-framework. We should replace this with a call to the ctf version when chainlink-starknet is updated to use the latest ctf version.
// GetTestLogger instantiates a logger that takes into account the test context and the log level
func GetTestLogger(t *testing.T) zerolog.Logger {
lvlStr := os.Getenv(envConf.EnvVarLogLevel)
if lvlStr == "" {
lvlStr = "info"
}
lvl, err := zerolog.ParseLevel(lvlStr)
require.NoError(t, err, "error parsing log level")
l := zerolog.New(zerolog.NewTestWriter(t)).Output(zerolog.ConsoleWriter{Out: os.Stderr}).Level(lvl).With().Timestamp().Logger()
return l
}
99 changes: 99 additions & 0 deletions integration-tests/common/ocr2_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package common

type OCR2Config struct {
F int `json:"f"`
Signers []string `json:"signers"`
Transmitters []string `json:"transmitters"`
OnchainConfig string `json:"onchainConfig"`
OffchainConfig *OffchainConfig `json:"offchainConfig"`
OffchainConfigVersion int `json:"offchainConfigVersion"`
Secret string `json:"secret"`
}

type OffchainConfig struct {
DeltaProgressNanoseconds int64 `json:"deltaProgressNanoseconds"`
DeltaResendNanoseconds int64 `json:"deltaResendNanoseconds"`
DeltaRoundNanoseconds int64 `json:"deltaRoundNanoseconds"`
DeltaGraceNanoseconds int `json:"deltaGraceNanoseconds"`
DeltaStageNanoseconds int64 `json:"deltaStageNanoseconds"`
RMax int `json:"rMax"`
S []int `json:"s"`
OffchainPublicKeys []string `json:"offchainPublicKeys"`
PeerIds []string `json:"peerIds"`
ReportingPluginConfig *ReportingPluginConfig `json:"reportingPluginConfig"`
MaxDurationQueryNanoseconds int `json:"maxDurationQueryNanoseconds"`
MaxDurationObservationNanoseconds int `json:"maxDurationObservationNanoseconds"`
MaxDurationReportNanoseconds int `json:"maxDurationReportNanoseconds"`
MaxDurationShouldAcceptFinalizedReportNanoseconds int `json:"maxDurationShouldAcceptFinalizedReportNanoseconds"`
MaxDurationShouldTransmitAcceptedReportNanoseconds int `json:"maxDurationShouldTransmitAcceptedReportNanoseconds"`
ConfigPublicKeys []string `json:"configPublicKeys"`
}

type ReportingPluginConfig struct {
AlphaReportInfinite bool `json:"alphaReportInfinite"`
AlphaReportPpb int `json:"alphaReportPpb"`
AlphaAcceptInfinite bool `json:"alphaAcceptInfinite"`
AlphaAcceptPpb int `json:"alphaAcceptPpb"`
DeltaCNanoseconds int `json:"deltaCNanoseconds"`
}

var TestOCR2Config = OCR2Config{
F: 1,
// Signers: onChainKeys, // user defined
// Transmitters: txKeys, // user defined
OnchainConfig: "",
OffchainConfig: &OffchainConfig{
DeltaProgressNanoseconds: 8000000000,
DeltaResendNanoseconds: 30000000000,
DeltaRoundNanoseconds: 3000000000,
DeltaGraceNanoseconds: 1000000000,
DeltaStageNanoseconds: 20000000000,
RMax: 5,
S: []int{1, 2},
// OffchainPublicKeys: offChainKeys, // user defined
// PeerIds: peerIds, // user defined
ReportingPluginConfig: &ReportingPluginConfig{
AlphaReportInfinite: false,
AlphaReportPpb: 0,
AlphaAcceptInfinite: false,
AlphaAcceptPpb: 0,
DeltaCNanoseconds: 1000000000,
},
MaxDurationQueryNanoseconds: 2000000000,
MaxDurationObservationNanoseconds: 1000000000,
MaxDurationReportNanoseconds: 2000000000,
MaxDurationShouldAcceptFinalizedReportNanoseconds: 2000000000,
MaxDurationShouldTransmitAcceptedReportNanoseconds: 2000000000,
// ConfigPublicKeys: cfgKeys, // user defined
},
OffchainConfigVersion: 2,
Secret: "awe accuse polygon tonic depart acuity onyx inform bound gilbert expire",
}

var TestOnKeys = []string{
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603730",
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603731",
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603732",
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603733",
}

var TestTxKeys = []string{
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603734",
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603735",
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603736",
"0x04cc1bfa99e282e434aef2815ca17337a923cd2c61cf0c7de5b326d7a8603737",
}

var TestOffKeys = []string{
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852090",
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852091",
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852092",
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852093",
}

var TestCfgKeys = []string{
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852094",
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852095",
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852096",
"af400004fa5d02cd5170b5261032e71f2847ead36159cf8dee68affc3c852097",
}
Loading