Skip to content

Commit 0a320ef

Browse files
[CLD-1032]: feat(engine): allow configuration for SUI chain in test engine (#670)
SUI teams wants to be able to specify docker image used for the sui container. This commit exposes the provider configuration on the test engine layer. JIRA: https://smartcontract-it.atlassian.net/browse/CLD-1032
1 parent ff9c85a commit 0a320ef

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

.changeset/fast-chefs-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
feat(engine): allow configuration for SUI chain in test engine

engine/test/environment/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
newAptosContainerLoader = onchain.NewAptosContainerLoader
1818
newSolanaContainerLoader = onchain.NewSolanaContainerLoader
1919
newSuiContainerLoader = onchain.NewSuiContainerLoader
20+
newSuiContainerLoaderWithConfig = onchain.NewSuiContainerLoaderWithConfig
2021
newTonContainerLoader = onchain.NewTonContainerLoader
2122
newTonContainerLoaderWithConfig = onchain.NewTonContainerLoaderWithConfig
2223
newTronContainerLoader = onchain.NewTronContainerLoader
@@ -170,13 +171,28 @@ func WithSuiContainer(t *testing.T, selectors []uint64) LoadOpt {
170171
return withChainLoader(t, newSuiContainerLoader(), selectors)
171172
}
172173

174+
// WithSuiContainerWithConfig loads Sui blockchain container instances with custom configuration
175+
// for specified chain selectors.
176+
func WithSuiContainerWithConfig(t *testing.T, selectors []uint64, cfg onchain.SuiContainerConfig) LoadOpt {
177+
t.Helper()
178+
179+
return withChainLoader(t, newSuiContainerLoaderWithConfig(cfg), selectors)
180+
}
181+
173182
// WithSuiContainerN loads n Sui blockchain container instances.
174183
func WithSuiContainerN(t *testing.T, n int) LoadOpt {
175184
t.Helper()
176185

177186
return withChainLoaderN(t, newSuiContainerLoader(), n)
178187
}
179188

189+
// WithSuiContainerNWithConfig loads n Sui blockchain container instances with custom configuration.
190+
func WithSuiContainerNWithConfig(t *testing.T, n int, cfg onchain.SuiContainerConfig) LoadOpt {
191+
t.Helper()
192+
193+
return withChainLoaderN(t, newSuiContainerLoaderWithConfig(cfg), n)
194+
}
195+
180196
// WithLogger sets the logger for the environment.
181197
func WithLogger(lggr logger.Logger) LoadOpt {
182198
return func(cmps *components) error {

engine/test/onchain/sui.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
suiprov "github.com/smartcontractkit/chainlink-deployments-framework/chain/sui/provider"
1515
)
1616

17+
// SuiContainerConfig is the configuration for the Sui container loader.
18+
type SuiContainerConfig = suiprov.CTFChainProviderConfig
19+
1720
// NewSuiContainerLoader creates a new Sui chain loader with default configuration using CTF.
1821
func NewSuiContainerLoader() *ChainLoader {
1922
// Generate a random Sui Ed25519 private key for testing
@@ -34,6 +37,18 @@ func NewSuiContainerLoader() *ChainLoader {
3437
}
3538
}
3639

40+
// NewSuiContainerLoaderWithConfig creates a new Sui chain loader with the given configuration using CTF.
41+
func NewSuiContainerLoaderWithConfig(cfg SuiContainerConfig) *ChainLoader {
42+
return &ChainLoader{
43+
selectors: getTestSelectorsByFamily(chainselectors.FamilySui),
44+
factory: func(t *testing.T, selector uint64) (fchain.BlockChain, error) {
45+
t.Helper()
46+
47+
return suiprov.NewCTFChainProvider(t, selector, cfg).Initialize(t.Context())
48+
},
49+
}
50+
}
51+
3752
// randomSeed generates a random seed for the Sui Ed25519 private key.
3853
func suiRandomSeed() []byte {
3954
seed := make([]byte, ed25519.SeedSize)

engine/test/onchain/sui_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package onchain
22

33
import (
4+
"crypto/ed25519"
5+
"crypto/rand"
6+
"encoding/hex"
7+
"sync"
48
"testing"
59

610
chainselectors "github.com/smartcontractkit/chain-selectors"
711
"github.com/stretchr/testify/assert"
812
"github.com/stretchr/testify/require"
13+
14+
suiprov "github.com/smartcontractkit/chainlink-deployments-framework/chain/sui/provider"
915
)
1016

1117
func Test_NewSuiContainerLoader(t *testing.T) {
@@ -23,3 +29,34 @@ func Test_NewSuiContainerLoader(t *testing.T) {
2329
// but we can verify it exists.
2430
require.NotNil(t, loader.factory)
2531
}
32+
33+
func Test_NewSuiContainerLoaderWithConfig(t *testing.T) {
34+
t.Parallel()
35+
36+
// Generate a test private key
37+
seed := make([]byte, ed25519.SeedSize)
38+
_, err := rand.Read(seed)
39+
require.NoError(t, err)
40+
41+
seeded := ed25519.NewKeyFromSeed(seed)
42+
seedBytes := seeded[:32]
43+
testPrivateKey := hex.EncodeToString(seedBytes)
44+
45+
var once sync.Once
46+
47+
config := suiprov.CTFChainProviderConfig{
48+
Once: &once,
49+
DeployerSignerGen: suiprov.AccountGenPrivateKey(testPrivateKey),
50+
}
51+
52+
loader := NewSuiContainerLoaderWithConfig(config)
53+
require.NotNil(t, loader)
54+
55+
// Should have the same selectors as getTestSelectorsByFamily returns
56+
require.NotNil(t, loader.selectors)
57+
wantSelectors := getTestSelectorsByFamily(chainselectors.FamilySui)
58+
assert.Equal(t, wantSelectors, loader.selectors)
59+
60+
// Factory should be configured with the provided config
61+
require.NotNil(t, loader.factory)
62+
}

0 commit comments

Comments
 (0)