Skip to content

Commit

Permalink
parameterize subnet specification
Browse files Browse the repository at this point in the history
addresses review comment ava-labs/icm-contracts#401 (comment)
  • Loading branch information
feuGeneA committed Jul 11, 2024
1 parent 579cccb commit 91126a6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
16 changes: 15 additions & 1 deletion tests/local/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,21 @@ func TestE2E(t *testing.T) {
// Define the Teleporter before and after suite functions.
var _ = ginkgo.BeforeSuite(func() {
// Create the local network instance
LocalNetworkInstance = NewLocalNetwork(warpGenesisTemplateFile)
LocalNetworkInstance = NewLocalNetwork(
warpGenesisTemplateFile,
[]SubnetSpec{
{
Name: "A",
EVMChainID: 12345,
NodeCount: 5,
},
{
Name: "B",
EVMChainID: 54321,
NodeCount: 5,
},
},
)

// Generate the Teleporter deployment values
teleporterDeployerTransaction, teleporterDeployerAddress, teleporterContractAddress, err :=
Expand Down
62 changes: 34 additions & 28 deletions tests/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ const (
timeout = 60 * time.Second
)

func NewLocalNetwork(warpGenesisTemplateFile string) *LocalNetwork {
type SubnetSpec struct {
Name string
EVMChainID uint64
NodeCount int
}

func NewLocalNetwork(warpGenesisTemplateFile string, subnetSpecs []SubnetSpec) *LocalNetwork {
ctx := context.Background()
var err error

// Declare 10 new validators (which should have BLS key registered)
subnetANodes := subnetEvmTestUtils.NewTmpnetNodes(5)
subnetBNodes := subnetEvmTestUtils.NewTmpnetNodes(5)
// and some extra nodes to be used to add more validators later:
// declare some extra nodes to be used to add more validators later:
extraNodes := subnetEvmTestUtils.NewTmpnetNodes(5)

f, err := os.CreateTemp(os.TempDir(), "config.json")
Expand All @@ -82,26 +85,30 @@ func NewLocalNetwork(warpGenesisTemplateFile string) *LocalNetwork {
Expect(err).Should(BeNil())
warpChainConfigPath := f.Name()

subnetA := subnetEvmTestUtils.NewTmpnetSubnet(
"A",
utils.InstantiateGenesisTemplate(warpGenesisTemplateFile, 12345),
subnetEvmTestUtils.DefaultChainConfig,
subnetANodes...,
)

subnetB := subnetEvmTestUtils.NewTmpnetSubnet(
"B",
utils.InstantiateGenesisTemplate(warpGenesisTemplateFile, 54321),
subnetEvmTestUtils.DefaultChainConfig,
subnetBNodes...,
)
allNodes := slices.Clone(extraNodes) // to be appended w/ subnet validators

var subnets []*tmpnet.Subnet
for _, subnetSpec := range subnetSpecs {
nodes := subnetEvmTestUtils.NewTmpnetNodes(subnetSpec.NodeCount)
allNodes = append(allNodes, nodes...)

subnet := subnetEvmTestUtils.NewTmpnetSubnet(
subnetSpec.Name,
utils.InstantiateGenesisTemplate(
warpGenesisTemplateFile,
subnetSpec.EVMChainID,
),
subnetEvmTestUtils.DefaultChainConfig,
nodes...,
)
subnets = append(subnets, subnet)
}

network := subnetEvmTestUtils.NewTmpnetNetwork(
"teleporter-test-local-network",
append(subnetANodes, append(subnetBNodes, extraNodes...)...),
allNodes,
tmpnet.FlagsMap{},
subnetA,
subnetB,
subnets...,
)
Expect(network).ShouldNot(BeNil())

Expand All @@ -123,12 +130,10 @@ func NewLocalNetwork(warpGenesisTemplateFile string) *LocalNetwork {
globalFundedKey, err := crypto.HexToECDSA(fundedKeyStr)
Expect(err).Should(BeNil())

subnetAID := network.GetSubnet("A").SubnetID
subnetBID := network.GetSubnet("B").SubnetID

// Issue transactions to activate the proposerVM fork on the chains
setupProposerVM(ctx, globalFundedKey, network, subnetAID)
setupProposerVM(ctx, globalFundedKey, network, subnetBID)
for _, subnet := range network.Subnets {
setupProposerVM(ctx, globalFundedKey, network, subnet.SubnetID)
}

res := &LocalNetwork{
primaryNetworkInfo: &interfaces.SubnetTestInfo{},
Expand All @@ -138,8 +143,9 @@ func NewLocalNetwork(warpGenesisTemplateFile string) *LocalNetwork {
tmpnet: network,
warpChainConfigPath: warpChainConfigPath,
}
res.setSubnetValues(subnetAID)
res.setSubnetValues(subnetBID)
for _, subnet := range network.Subnets {
res.setSubnetValues(subnet.SubnetID)
}
res.setPrimaryNetworkValues()
return res
}
Expand Down

0 comments on commit 91126a6

Please sign in to comment.