Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fast-chefs-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink-deployments-framework": minor
---

feat(engine): allow configuration for SUI chain in test engine
16 changes: 16 additions & 0 deletions engine/test/environment/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
newAptosContainerLoader = onchain.NewAptosContainerLoader
newSolanaContainerLoader = onchain.NewSolanaContainerLoader
newSuiContainerLoader = onchain.NewSuiContainerLoader
newSuiContainerLoaderWithConfig = onchain.NewSuiContainerLoaderWithConfig
newTonContainerLoader = onchain.NewTonContainerLoader
newTonContainerLoaderWithConfig = onchain.NewTonContainerLoaderWithConfig
newTronContainerLoader = onchain.NewTronContainerLoader
Expand Down Expand Up @@ -170,13 +171,28 @@ func WithSuiContainer(t *testing.T, selectors []uint64) LoadOpt {
return withChainLoader(t, newSuiContainerLoader(), selectors)
}

// WithSuiContainerWithConfig loads Sui blockchain container instances with custom configuration
// for specified chain selectors.
func WithSuiContainerWithConfig(t *testing.T, selectors []uint64, cfg onchain.SuiContainerConfig) LoadOpt {
t.Helper()

return withChainLoader(t, newSuiContainerLoaderWithConfig(cfg), selectors)
}

// WithSuiContainerN loads n Sui blockchain container instances.
func WithSuiContainerN(t *testing.T, n int) LoadOpt {
t.Helper()

return withChainLoaderN(t, newSuiContainerLoader(), n)
}

// WithSuiContainerNWithConfig loads n Sui blockchain container instances with custom configuration.
func WithSuiContainerNWithConfig(t *testing.T, n int, cfg onchain.SuiContainerConfig) LoadOpt {
t.Helper()

return withChainLoaderN(t, newSuiContainerLoaderWithConfig(cfg), n)
}

// WithLogger sets the logger for the environment.
func WithLogger(lggr logger.Logger) LoadOpt {
return func(cmps *components) error {
Expand Down
15 changes: 15 additions & 0 deletions engine/test/onchain/sui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
suiprov "github.com/smartcontractkit/chainlink-deployments-framework/chain/sui/provider"
)

// SuiContainerConfig is the configuration for the Sui container loader.
type SuiContainerConfig = suiprov.CTFChainProviderConfig

// NewSuiContainerLoader creates a new Sui chain loader with default configuration using CTF.
func NewSuiContainerLoader() *ChainLoader {
// Generate a random Sui Ed25519 private key for testing
Expand All @@ -34,6 +37,18 @@ func NewSuiContainerLoader() *ChainLoader {
}
}

// NewSuiContainerLoaderWithConfig creates a new Sui chain loader with the given configuration using CTF.
func NewSuiContainerLoaderWithConfig(cfg SuiContainerConfig) *ChainLoader {
return &ChainLoader{
selectors: getTestSelectorsByFamily(chainselectors.FamilySui),
factory: func(t *testing.T, selector uint64) (fchain.BlockChain, error) {
t.Helper()

return suiprov.NewCTFChainProvider(t, selector, cfg).Initialize(t.Context())
},
}
}

// randomSeed generates a random seed for the Sui Ed25519 private key.
func suiRandomSeed() []byte {
seed := make([]byte, ed25519.SeedSize)
Expand Down
37 changes: 37 additions & 0 deletions engine/test/onchain/sui_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package onchain

import (
"crypto/ed25519"
"crypto/rand"
"encoding/hex"
"sync"
"testing"

chainselectors "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

suiprov "github.com/smartcontractkit/chainlink-deployments-framework/chain/sui/provider"
)

func Test_NewSuiContainerLoader(t *testing.T) {
Expand All @@ -23,3 +29,34 @@ func Test_NewSuiContainerLoader(t *testing.T) {
// but we can verify it exists.
require.NotNil(t, loader.factory)
}

func Test_NewSuiContainerLoaderWithConfig(t *testing.T) {
t.Parallel()

// Generate a test private key
seed := make([]byte, ed25519.SeedSize)
_, err := rand.Read(seed)
require.NoError(t, err)

seeded := ed25519.NewKeyFromSeed(seed)
seedBytes := seeded[:32]
testPrivateKey := hex.EncodeToString(seedBytes)

var once sync.Once

config := suiprov.CTFChainProviderConfig{
Once: &once,
DeployerSignerGen: suiprov.AccountGenPrivateKey(testPrivateKey),
}

loader := NewSuiContainerLoaderWithConfig(config)
require.NotNil(t, loader)

// Should have the same selectors as getTestSelectorsByFamily returns
require.NotNil(t, loader.selectors)
wantSelectors := getTestSelectorsByFamily(chainselectors.FamilySui)
assert.Equal(t, wantSelectors, loader.selectors)

// Factory should be configured with the provided config
require.NotNil(t, loader.factory)
}