Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vms/platformvm] Cleanup execution config tests #3137

Merged
merged 10 commits into from
Jun 24, 2024
127 changes: 37 additions & 90 deletions vms/platformvm/config/execution_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
package config

import (
"encoding/json"
"errors"
"fmt"
"reflect"
"testing"
"time"

Expand All @@ -12,6 +16,31 @@
"github.com/ava-labs/avalanchego/vms/platformvm/network"
)

// Errors if all values in a struct are not initialized
dhrubabasu marked this conversation as resolved.
Show resolved Hide resolved
func VerifyInitializedStruct(s interface{}) error {
dhrubabasu marked this conversation as resolved.
Show resolved Hide resolved
dhrubabasu marked this conversation as resolved.
Show resolved Hide resolved
structType := reflect.TypeOf(s)
if structType.Kind() != reflect.Struct {
return fmt.Errorf("expected struct, got %s", structType.Kind())
}

v := reflect.ValueOf(s)
log := ""
for i := 0; i < v.NumField(); i++ {

Check failure on line 28 in vms/platformvm/config/execution_config_test.go

View workflow job for this annotation

GitHub Actions / Lint

empty-lines: extra empty line at the end of a block (revive)
field := v.Field(i)
isSet := field.IsValid() && !field.IsZero()
if !isSet {
log = fmt.Sprintf("%v%s not set; ", log, structType.Field(i).Name)
}

}

Check failure on line 35 in vms/platformvm/config/execution_config_test.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary trailing newline (whitespace)

if len(log) > 0 {
return errors.New(log)
}

return nil
}

func TestExecutionConfigUnmarshal(t *testing.T) {
t.Run("default values from empty json", func(t *testing.T) {
require := require.New(t)
Expand Down Expand Up @@ -41,39 +70,7 @@

t.Run("all values extracted from json", func(t *testing.T) {
require := require.New(t)
b := []byte(`{
"network": {
"max-validator-set-staleness": 1,
"target-gossip-size": 2,
"push-gossip-percent-stake": 0.3,
"push-gossip-num-validators": 4,
"push-gossip-num-peers": 5,
"push-regossip-num-validators": 6,
"push-regossip-num-peers": 7,
"push-gossip-discarded-cache-size": 8,
"push-gossip-max-regossip-frequency": 9,
"push-gossip-frequency": 10,
"pull-gossip-poll-size": 11,
"pull-gossip-frequency": 12,
"pull-gossip-throttling-period": 13,
"pull-gossip-throttling-limit": 14,
"expected-bloom-filter-elements": 15,
"expected-bloom-filter-false-positive-probability": 16,
"max-bloom-filter-false-positive-probability": 17
},
"block-cache-size": 1,
"tx-cache-size": 2,
"transformed-subnet-tx-cache-size": 3,
"reward-utxos-cache-size": 5,
"chain-cache-size": 6,
"chain-db-cache-size": 7,
"block-id-cache-size": 8,
"fx-owner-cache-size": 9,
"checksums-enabled": true,
"mempool-prune-frequency": 60000000000
}`)
ec, err := GetExecutionConfig(b)
require.NoError(err)

expected := &ExecutionConfig{
Network: network.Config{
MaxValidatorSetStaleness: 1,
Expand Down Expand Up @@ -105,64 +102,14 @@
ChecksumsEnabled: true,
MempoolPruneFrequency: time.Minute,
}
require.Equal(expected, ec)
})
require.NoError(VerifyInitializedStruct(*expected))
require.NoError(VerifyInitializedStruct(expected.Network))

t.Run("default values applied correctly", func(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not really doing anything more than the "mix default and extracted values from json" test earlier

require := require.New(t)
b := []byte(`{
"network": {
"max-validator-set-staleness": 1,
"target-gossip-size": 2,
"push-gossip-discarded-cache-size": 1024,
"push-gossip-max-regossip-frequency": 10000000000,
"pull-gossip-poll-size": 3,
"pull-gossip-frequency": 4,
"pull-gossip-throttling-period": 5
},
"block-cache-size": 1,
"tx-cache-size": 2,
"transformed-subnet-tx-cache-size": 3,
"reward-utxos-cache-size": 5,
"chain-cache-size": 6,
"chain-db-cache-size": 7,
"block-id-cache-size": 8,
"fx-owner-cache-size": 9,
"checksums-enabled": true
}`)
ec, err := GetExecutionConfig(b)
b, err := json.Marshal(expected)
require.NoError(err)
expected := &ExecutionConfig{
Network: network.Config{
MaxValidatorSetStaleness: 1,
TargetGossipSize: 2,
PushGossipPercentStake: DefaultExecutionConfig.Network.PushGossipPercentStake,
PushGossipNumValidators: DefaultExecutionConfig.Network.PushGossipNumValidators,
PushGossipNumPeers: DefaultExecutionConfig.Network.PushGossipNumPeers,
PushRegossipNumValidators: DefaultExecutionConfig.Network.PushRegossipNumValidators,
PushRegossipNumPeers: DefaultExecutionConfig.Network.PushRegossipNumPeers,
PushGossipDiscardedCacheSize: 1024,
PushGossipMaxRegossipFrequency: 10 * time.Second,
PushGossipFrequency: DefaultExecutionConfig.Network.PushGossipFrequency,
PullGossipPollSize: 3,
PullGossipFrequency: 4,
PullGossipThrottlingPeriod: 5,
PullGossipThrottlingLimit: DefaultExecutionConfig.Network.PullGossipThrottlingLimit,
ExpectedBloomFilterElements: DefaultExecutionConfig.Network.ExpectedBloomFilterElements,
ExpectedBloomFilterFalsePositiveProbability: DefaultExecutionConfig.Network.ExpectedBloomFilterFalsePositiveProbability,
MaxBloomFilterFalsePositiveProbability: DefaultExecutionConfig.Network.MaxBloomFilterFalsePositiveProbability,
},
BlockCacheSize: 1,
TxCacheSize: 2,
TransformedSubnetTxCacheSize: 3,
RewardUTXOsCacheSize: 5,
ChainCacheSize: 6,
ChainDBCacheSize: 7,
BlockIDCacheSize: 8,
FxOwnerCacheSize: 9,
ChecksumsEnabled: true,
MempoolPruneFrequency: 30 * time.Minute,
}
require.Equal(expected, ec)

actual, err := GetExecutionConfig(b)
require.NoError(err)
require.Equal(expected, actual)
})
}
Loading