Skip to content

Commit

Permalink
load test, have transaction, need to use event watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAustinWang committed Dec 18, 2024
1 parent 8c01cc2 commit 44152cb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
18 changes: 16 additions & 2 deletions deployment/environment/crib/env.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package crib

import "fmt"

const (
AddressBookFileName = "ccip-v2-scripts-address-book.json"
NodesDetailsFileName = "ccip-v2-scripts-nodes-details.json"
Expand All @@ -16,15 +18,27 @@ func NewDevspaceEnvFromStateDir(envStateDir string) CRIBEnv {
}
}

func (c CRIBEnv) GetConfig() DeployOutput {
func (c CRIBEnv) GetConfig(deployerKeys map[uint64]string) (DeployOutput, error) {
reader := NewOutputReader(c.envStateDir)
nodesDetails := reader.ReadNodesDetails()
chainConfigs := reader.ReadChainConfigs()
for i, chain := range chainConfigs {
key, ok := deployerKeys[chain.ChainID]
if !ok {
return DeployOutput{}, fmt.Errorf("could not find deployer key for %s", key)
}
err := chain.SetDeployerKey(&key)
if err != nil {
return DeployOutput{}, err
}
chainConfigs[i] = chain
}

return DeployOutput{
AddressBook: reader.ReadAddressBook(),
NodeIDs: nodesDetails.NodeIDs,
Chains: chainConfigs,
}
}, nil
}

type RPC struct {
Expand Down
1 change: 0 additions & 1 deletion deployment/environment/devenv/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (c *ChainConfig) SetDeployerKey(pvtKeyStr *string) error {
if err != nil {
return fmt.Errorf("failed to create transactor: %w", err)
}
fmt.Printf("Deployer Address: %s for chain id %d\n", deployer.From.Hex(), c.ChainID)
c.DeployerKey = deployer
return nil
}
Expand Down
23 changes: 17 additions & 6 deletions integration-tests/load/ccip/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ var (
"branch": "ccip_load_crib",
"commit": "ccip_load_crib",
}
wg sync.WaitGroup
wg sync.WaitGroup
SIM_CHAIN_PRIVATE_KEYS = map[uint64]string{
1337: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
2337: "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
}
)

const CRIB_DIRECTORY = "/Users/austin.wang/ccip-core/repos/crib/deployments/ccip-v2/.tmp"
Expand All @@ -44,7 +48,8 @@ func TestCCIPLoad_RPS(t *testing.T) {

cribEnv := crib.NewDevspaceEnvFromStateDir(CRIB_DIRECTORY)

cribDeployOutput := cribEnv.GetConfig()
cribDeployOutput, err := cribEnv.GetConfig(SIM_CHAIN_PRIVATE_KEYS)
require.NoError(t, err)
env, err := crib.NewDeployEnvironmentFromCribOutput(lggr, cribDeployOutput)
require.NoError(t, err)
require.NotNil(t, env)
Expand All @@ -71,8 +76,8 @@ func TestCCIPLoad_RPS(t *testing.T) {
T: t,
GenName: "ccipLoad",
LoadType: wasp.RPS,
CallTimeout: 20 * time.Second,
Schedule: wasp.Plain(1, 20*time.Second),
CallTimeout: 5 * time.Second,
Schedule: wasp.Plain(1, 5*time.Second),
// will need to be divided by number of chains
// this schedule is per generator
// in this example, it would be 1 request per 10seconds per generator (dest chain)
Expand All @@ -91,6 +96,8 @@ func TestCCIPLoad_RPS(t *testing.T) {
wg.Add(1)
go func(chainSelector uint64, startBlock *uint64) {
defer wg.Done()
lggr.Infow("Starting to query for events on ", "chainSelector", chainSelector, "startblock", startBlock)

filterOpts := &bind.FilterOpts{
Start: *startBlock,
End: nil, // To the latest block
Expand All @@ -102,6 +109,8 @@ func TestCCIPLoad_RPS(t *testing.T) {
commitIterator, err := offRamp.FilterCommitReportAccepted(filterOpts)
require.NoError(t, err)

fmt.Printf("Events on commitIterator %+v", commitIterator)

for commitIterator.Next() {
event := commitIterator.Event
fmt.Printf("CommitReportAccepted event: %+v\n", event)
Expand All @@ -112,7 +121,8 @@ func TestCCIPLoad_RPS(t *testing.T) {
timestamp := time.Unix(int64(header.Time), 0)

for _, root := range event.MerkleRoots {
lokiLabels = setLokiLabels(root.SourceChainSelector, chainSelector)
lokiLabels, err = setLokiLabels(root.SourceChainSelector, chainSelector)
require.NoError(t, err)

for i := root.MinSeqNr; i <= root.MaxSeqNr; i++ {
// todo: push loki calls to channel?
Expand All @@ -138,7 +148,8 @@ func TestCCIPLoad_RPS(t *testing.T) {
timestamp := time.Unix(int64(header.Time), 0)

// todo: push loki calls to channel?
lokiLabels = setLokiLabels(execIterator.Event.SourceChainSelector, chainSelector)
lokiLabels, err = setLokiLabels(execIterator.Event.SourceChainSelector, chainSelector)
require.NoError(t, err)
SendMetricsToLoki(lggr, loki, lokiLabels, &LokiMetric{
EventType: executed,
Timestamp: timestamp,
Expand Down
12 changes: 9 additions & 3 deletions integration-tests/load/ccip/destination_gun.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,29 @@ func (m *DestinationGun) Call(_ *wasp.Generator) *wasp.Response {
}

fee, err := r.GetFee(
&bind.CallOpts{Context: context.Background()}, src, msg)
&bind.CallOpts{Context: context.Background()}, m.chainSelector, msg)
if err != nil {
m.l.Errorw("could not get fee ", "dstChainSelector", m.chainSelector, "msg", msg, "fee", fee)
return &wasp.Response{Error: err.Error(), Group: waspGroup, Failed: true}
}
m.l.Debugw("setting fee for ", "srcChain", src, "dstChain", m.chainSelector, "fee", fee, "msg", msg)
if msg.FeeToken == common.HexToAddress("0x0") {
m.env.Chains[src].DeployerKey.Value = fee
defer func() { m.env.Chains[src].DeployerKey.Value = nil }()
}
_, err = r.CcipSend(
tx, err := r.CcipSend(
m.env.Chains[src].DeployerKey,
m.chainSelector,
msg)
if err != nil {
m.l.Errorw("execution reverted from ", "sourceChain", src, "destchain", m.chainSelector, "err", err, "tx", tx)
return &wasp.Response{Error: err.Error(), Group: waspGroup, Failed: true}
}

lokiLabels := setLokiLabels(src, m.chainSelector)
lokiLabels, err := setLokiLabels(src, m.chainSelector)
if err != nil {
m.l.Errorw("Failed setting loki labels", "error", err)
}
SendMetricsToLoki(m.l, m.loki, lokiLabels, &LokiMetric{
EventType: transmitted,
Timestamp: time.Now(),
Expand Down
17 changes: 13 additions & 4 deletions integration-tests/load/ccip/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
chainselectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-testing-framework/wasp"
"github.com/smartcontractkit/chainlink/deployment"
Expand Down Expand Up @@ -41,13 +42,21 @@ func SendMetricsToLoki(l logger.Logger, lc *wasp.LokiClient, updatedLabels map[s
}
}

func setLokiLabels(src, dst uint64) map[string]string {
func setLokiLabels(src, dst uint64) (map[string]string, error) {
srcChainId, err := chainselectors.GetChainIDFromSelector(src)
if err != nil {
return nil, err
}
dstChainId, err := chainselectors.GetChainIDFromSelector(dst)
if err != nil {
return nil, err
}
return map[string]string{
"sourceEvmChainId": fmt.Sprintf("%d", src),
"destEvmChainId": fmt.Sprintf("%d", src),
"sourceEvmChainId": fmt.Sprintf("%s", srcChainId),
"destEvmChainId": fmt.Sprintf("%s", dstChainId),
"destinationSelector": fmt.Sprintf("%d", dst),
"testType": LokiLoadLabel,
}
}, nil
}

func readFile(filePath string) []byte {
Expand Down

0 comments on commit 44152cb

Please sign in to comment.