Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
cfal committed Jul 20, 2023
1 parent 6af07c2 commit 0730b5b
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 450 deletions.
70 changes: 70 additions & 0 deletions integration-tests/common/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package common

import (
"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
}
nodeKeys, _, err := client.CreateNodeKeysBundle(nodes, chainName, chainId)
if err != nil {
return nil, err
}
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
}
110 changes: 66 additions & 44 deletions integration-tests/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,34 @@ const (
ChainBlockTimeSoak = "2s"
)

var (
observationSource = `
val [type="bridge" name="bridge-coinmetrics" requestData=<{"data": {"from":"LINK","to":"USD"}}>]
parse [type="jsonparse" path="result"]
val -> parse
`
juelsPerFeeCoinSource = `"""
sum [type="sum" values=<[451000]> ]
sum
"""
`
)

type Common struct {
P2PPort string
ChainName string
ChainId string
NodeCount int
TTL time.Duration
Testnet bool
RPCUrl 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
RPCUrl string
PrivateKey string
Account string
ObservationSource string
JuelsPerFeeCoinSource 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 +65,64 @@ 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(),
RPCUrl: getEnv("RPC_URL"),
PrivateKey: getEnv("PRIVATE_KEY"),
Account: getEnv("ACCOUNT"),
ObservationSource: observationSource,
JuelsPerFeeCoinSource: juelsPerFeeCoinSource,
}
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.RPCUrl != "" {
wasmdUrl = c.RPCUrl
}
baseTOML := fmt.Sprintf(`[[Cosmos]]
Enabled = true
Expand Down
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
}
105 changes: 105 additions & 0 deletions integration-tests/common/ocr2_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package common

import (
"math/big"
)

// OCR2Config Default config for OCR2 for starknet
// TODO: validate for cosmos
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

0 comments on commit 0730b5b

Please sign in to comment.