Skip to content

Commit

Permalink
Add contractName to SetupChainReaderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jun 25, 2024
1 parent caab3dc commit 908e585
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestChainReader(t *testing.T) {
},
}

d := helpers.SetupChainReaderTest[Chainreader](t, ctx, DeployChainreader, NewChainreader, cfg)
d := helpers.SetupChainReaderTest[Chainreader](t, ctx, DeployChainreader, NewChainreader, cfg, ContractNameAlias)
cr := *d.ChainReader

emitEvents(t, d, ctx) // Calls the contract to emit events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,76 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
capcfg "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_capability_configuration"
helpers "github.com/smartcontractkit/chainlink/v2/core/services/ocr3/plugins/ccip_integration_tests"
"github.com/smartcontractkit/libocr/commontypes"
libocrtypes "github.com/smartcontractkit/libocr/ragep2p/types"

evmtypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
"github.com/stretchr/testify/assert"
)

const (
chainID = 1337
chainA = ccipocr3.ChainSelector(1)
chainB = ccipocr3.ChainSelector(2)
chainC = ccipocr3.ChainSelector(3)
var (
chainA uint64 = 1
nodeAID uint8 = 1
fChainA uint8 = 1
oracleAID = commontypes.OracleID(nodeAID)
peerAID = "12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X"
p2pOracleAID = libocrtypes.PeerID{byte(nodeAID)}

chainB uint64 = 2
nodeBID uint8 = 2
fChainB uint8 = 2
oracleBID = commontypes.OracleID(nodeBID)
p2pOracleBID = libocrtypes.PeerID{byte(nodeBID)}

chainC uint64 = 3
nodeCID uint8 = 3
fChainC uint8 = 3
oracleCID = commontypes.OracleID(nodeCID)
p2pOracleCID = libocrtypes.PeerID{byte(nodeCID)}
)

func TestHomeChainReader(t *testing.T) {
deployFunc := func(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *capcfg.CCIPCapabilityConfiguration, error) {
return capcfg.DeployCCIPCapabilityConfiguration(auth, backend, common.Address{})
}
const (
ContractName = "CCIPCapabilityConfiguration"
FnGetChainConfigs = "getAllChainConfigs"
)
// Initialize chainReader
cfg := evmtypes.ChainReaderConfig{
Contracts: map[string]evmtypes.ChainContractReader{
"CCIPCapabilityConfiguration": {
ContractName: {
ContractABI: capcfg.CCIPCapabilityConfigurationMetaData.ABI,
Configs: map[string]*evmtypes.ChainReaderDefinition{
"ChainConfigSet": {
ChainSpecificName: "ChainConfigSet",
ReadType: evmtypes.Event,
ConfidenceConfirmations: map[string]int{"0.0": 0, "1.0": 0},
},
"getAllChainConfigs": {
ChainSpecificName: "getAllChainConfigs",
FnGetChainConfigs: {
ChainSpecificName: FnGetChainConfigs,
},
},
},
},
}

d := helpers.SetupChainReaderTest[capcfg.CCIPCapabilityConfiguration](t, context.Background(), deployFunc, capcfg.NewCCIPCapabilityConfiguration, cfg)
d := helpers.SetupChainReaderTest[capcfg.CCIPCapabilityConfiguration](t, context.Background(), deployFunc, capcfg.NewCCIPCapabilityConfiguration, cfg, ContractName)
chainReader := *d.ChainReader

// Apply chain configs to the contract
inputConfig := setupConfigInfo()
//[]capcfg.CCIPCapabilityConfigurationChainConfigInfo{
// setupConfigInfo(chainA, []uint8{nodeAID, nodeBID, nodeCID}, fChainA, []byte{}),
// setupConfigInfo(chainB, []uint8{nodeAID, nodeBID}, fChainB, []byte{}),
// setupConfigInfo(chainC, []uint8{nodeCID}, fChainC, []byte{}),
//setupConfigInfo(chainA, []byte{'a', 'b', 'c'}, fChainA, []byte{}),
//setupConfigInfo(chainB, []byte{'a', 'b'}, fChainB, []byte{}),
//setupConfigInfo(chainC, []byte{}, fChainC, []byte{}),
//}
_, err := d.Contract.ApplyChainConfigUpdates(d.Auth, nil, inputConfig)
d.SimulatedBE.Commit()
assert.NoError(t, err)
Expand All @@ -60,8 +86,8 @@ func TestHomeChainReader(t *testing.T) {
var allConfigs []capcfg.CCIPCapabilityConfigurationChainConfigInfo
err = chainReader.GetLatestValue(
context.Background(),
"CCIPCapabilityConfiguration",
"getAllChainConfigs",
ContractName,
FnGetChainConfigs,
map[string]interface{}{},
&allConfigs,
)
Expand All @@ -72,7 +98,7 @@ func TestHomeChainReader(t *testing.T) {
func setupConfigInfo() []capcfg.CCIPCapabilityConfigurationChainConfigInfo {
return []capcfg.CCIPCapabilityConfigurationChainConfigInfo{
{
ChainSelector: chainID,
ChainSelector: 1,
ChainConfig: capcfg.CCIPCapabilityConfigurationChainConfig{
Readers: [][32]byte{},
FChain: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type DeployFuncWithCapabilities[T any] func(auth *bind.TransactOpts, backend bin

type NewFunc[T any] func(address common.Address, backend bind.ContractBackend) (*T, error)

func SetupChainReaderTest[T any](t *testing.T, _ context.Context, deployFunc DeployFunc[T], newFunc NewFunc[T], chainReaderConfig evmtypes.ChainReaderConfig) *TestSetupData[T] {
func SetupChainReaderTest[T any](t *testing.T, _ context.Context, deployFunc DeployFunc[T], newFunc NewFunc[T], chainReaderConfig evmtypes.ChainReaderConfig, contractName string) *TestSetupData[T] {
// Generate a new key pair for the simulated account
privateKey, err := crypto.GenerateKey()
assert.NoError(t, err)
Expand Down Expand Up @@ -82,7 +82,7 @@ func SetupChainReaderTest[T any](t *testing.T, _ context.Context, deployFunc Dep
err = cr.Bind(context.Background(), []types2.BoundContract{
{
Address: address.String(),
Name: "CCIPCapabilityConfiguration",
Name: contractName,
Pending: false,
},
})
Expand Down

0 comments on commit 908e585

Please sign in to comment.