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
117 changes: 27 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,8 @@
package config

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

Expand All @@ -12,6 +14,23 @@ import (
"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(tb testing.TB, s interface{}) {
tb.Helper()

require := require.New(tb)

structType := reflect.TypeOf(s)
require.Equal(reflect.Struct, structType.Kind())

v := reflect.ValueOf(s)
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
require.True(field.IsValid(), "invalid field: ", structType.Field(i).Name)
require.False(field.IsZero(), "zero field: ", structType.Field(i).Name)
}
}

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 +60,7 @@ func TestExecutionConfigUnmarshal(t *testing.T) {

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 +92,14 @@ func TestExecutionConfigUnmarshal(t *testing.T) {
ChecksumsEnabled: true,
MempoolPruneFrequency: time.Minute,
}
require.Equal(expected, ec)
})
verifyInitializedStruct(t, *expected)
verifyInitializedStruct(t, 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