Skip to content

Commit 8ccb4dc

Browse files
Merge pull request #36 from ava-labs/add-subnet-check
Add subnet check
2 parents c74b518 + b3b4a8b commit 8ccb4dc

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

subnet/add_validator_subnet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAddValidatorDeploy(_ *testing.T) {
2121
// like logging, metrics preferences, etc
2222
baseApp := avalanche.New(avalanche.DefaultLeveledLogger)
2323
subnetParams := SubnetParams{
24-
SubnetEVM: SubnetEVMParams{
24+
SubnetEVM: &SubnetEVMParams{
2525
EvmChainID: 1234567,
2626
EvmDefaults: true,
2727
EnableWarp: true,

subnet/subnet.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ type SubnetParams struct {
3737

3838
// Subnet-EVM parameters to use
3939
// Do not set SubnetEVM value if you are using Custom VM
40-
SubnetEVM SubnetEVMParams
40+
SubnetEVM *SubnetEVMParams
4141

4242
// Custom VM parameters to use
4343
// Do not set CustomVM value if you are using Subnet-EVM
44-
CustomVM CustomVMParams
44+
CustomVM *CustomVMParams
4545

4646
Name string
4747
}
@@ -72,7 +72,7 @@ type SubnetEVMParams struct {
7272
// information on AWM Relayer
7373
EnableRelayer bool
7474

75-
GenesisParams EVMGenesisParams
75+
GenesisParams *EVMGenesisParams
7676
}
7777

7878
type CustomVMParams struct {
@@ -129,6 +129,12 @@ type EVMGenesisParams struct {
129129
}
130130

131131
func New(client *avalanche.BaseApp, subnetParams *SubnetParams) (*Subnet, error) {
132+
if subnetParams.GenesisFilePath != "" && (subnetParams.CustomVM != nil || subnetParams.SubnetEVM != nil) {
133+
return nil, fmt.Errorf("genesis file path cannot be non-empty if either CustomVM params or SubnetEVM params is not empty")
134+
}
135+
if subnetParams.SubnetEVM == nil && subnetParams.CustomVM != nil {
136+
return nil, fmt.Errorf("SubnetEVM params and CustomVM params cannot both be non-empty")
137+
}
132138
genesisBytes, err := createEvmGenesis(
133139
subnetParams.SubnetEVM.EvmChainID,
134140
subnetParams.SubnetEVM.GenesisParams,
@@ -146,7 +152,7 @@ func New(client *avalanche.BaseApp, subnetParams *SubnetParams) (*Subnet, error)
146152
// removed usewarp from argument, to use warp add it manualluy to precompile
147153
func createEvmGenesis(
148154
chainID uint64,
149-
genesisParams EVMGenesisParams,
155+
genesisParams *EVMGenesisParams,
150156
) ([]byte, error) {
151157
genesis := core.Genesis{}
152158
genesis.Timestamp = *utils.TimeToNewUint64(time.Now())

subnet/subnet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestSubnetDeploy(_ *testing.T) {
2020
// like logging, metrics preferences, etc
2121
baseApp := avalanche.New(avalanche.DefaultLeveledLogger)
2222
subnetParams := SubnetParams{
23-
SubnetEVM: SubnetEVMParams{
23+
SubnetEVM: &SubnetEVMParams{
2424
EvmChainID: 1234567,
2525
EvmDefaults: true,
2626
EnableWarp: true,

0 commit comments

Comments
 (0)