|
4 | 4 | "bytes"
|
5 | 5 | "testing"
|
6 | 6 |
|
| 7 | + "github.com/BurntSushi/toml" |
7 | 8 | "github.com/stretchr/testify/assert"
|
8 | 9 | "github.com/stretchr/testify/require"
|
9 | 10 |
|
@@ -33,3 +34,104 @@ func TestConfigWriteRead(t *testing.T) {
|
33 | 34 | })
|
34 | 35 | }
|
35 | 36 | }
|
| 37 | + |
| 38 | +// TestUpdateConfig tests that updating an outdated config |
| 39 | +// using a new default config applies the correct values and |
| 40 | +// preserves old custom values. |
| 41 | +func TestUpdateConfig(t *testing.T) { |
| 42 | + cfg := new(Config) |
| 43 | + _, err := toml.Decode(outdatedConfig, cfg) |
| 44 | + require.NoError(t, err) |
| 45 | + |
| 46 | + newCfg := DefaultConfig(node.Light) |
| 47 | + // ensure this config field is not filled in the outdated config |
| 48 | + require.NotEqual(t, newCfg.Share.PeerManagerParams, cfg.Share.PeerManagerParams) |
| 49 | + |
| 50 | + cfg, err = updateConfig(cfg, newCfg) |
| 51 | + require.NoError(t, err) |
| 52 | + // ensure this config field is now set after updating the config |
| 53 | + require.Equal(t, newCfg.Share.PeerManagerParams, cfg.Share.PeerManagerParams) |
| 54 | + // ensure old custom values were not changed |
| 55 | + require.Equal(t, "thisshouldnthavechanged", cfg.State.KeyringAccName) |
| 56 | + require.Equal(t, "7979", cfg.RPC.Port) |
| 57 | + require.True(t, cfg.Gateway.Enabled) |
| 58 | +} |
| 59 | + |
| 60 | +// outdatedConfig is an outdated config from a light node |
| 61 | +var outdatedConfig = ` |
| 62 | +[Core] |
| 63 | + IP = "0.0.0.0" |
| 64 | + RPCPort = "0" |
| 65 | + GRPCPort = "0" |
| 66 | +
|
| 67 | +[State] |
| 68 | + KeyringAccName = "thisshouldnthavechanged" |
| 69 | + KeyringBackend = "test" |
| 70 | +
|
| 71 | +[P2P] |
| 72 | + ListenAddresses = ["/ip4/0.0.0.0/udp/2121/quic-v1", "/ip6/::/udp/2121/quic-v1", "/ip4/0.0.0.0/tcp/2121", |
| 73 | +"/ip6/::/tcp/2121"] |
| 74 | + AnnounceAddresses = [] |
| 75 | + NoAnnounceAddresses = ["/ip4/0.0.0.0/udp/2121/quic-v1", "/ip4/127.0.0.1/udp/2121/quic-v1", "/ip6/::/udp/2121/quic-v1", |
| 76 | +"/ip4/0.0.0.0/tcp/2121", "/ip4/127.0.0.1/tcp/2121", "/ip6/::/tcp/2121"] |
| 77 | + MutualPeers = [] |
| 78 | + PeerExchange = false |
| 79 | + RoutingTableRefreshPeriod = "1m0s" |
| 80 | + [P2P.ConnManager] |
| 81 | + Low = 50 |
| 82 | + High = 100 |
| 83 | + GracePeriod = "1m0s" |
| 84 | + [P2P.Metrics] |
| 85 | + PrometheusAgentPort = "8890" |
| 86 | +
|
| 87 | +[RPC] |
| 88 | + Address = "0.0.0.0" |
| 89 | + Port = "7979" |
| 90 | +
|
| 91 | +[Gateway] |
| 92 | + Address = "0.0.0.0" |
| 93 | + Port = "26659" |
| 94 | + Enabled = true |
| 95 | +
|
| 96 | +[Share] |
| 97 | + PeersLimit = 5 |
| 98 | + DiscoveryInterval = "30s" |
| 99 | + AdvertiseInterval = "30s" |
| 100 | + UseShareExchange = true |
| 101 | + [Share.ShrExEDSParams] |
| 102 | + ServerReadTimeout = "5s" |
| 103 | + ServerWriteTimeout = "1m0s" |
| 104 | + HandleRequestTimeout = "1m0s" |
| 105 | + ConcurrencyLimit = 10 |
| 106 | + BufferSize = 32768 |
| 107 | + [Share.ShrExNDParams] |
| 108 | + ServerReadTimeout = "5s" |
| 109 | + ServerWriteTimeout = "2m35s" |
| 110 | + HandleRequestTimeout = "1m0s" |
| 111 | + ConcurrencyLimit = 10 |
| 112 | +
|
| 113 | +[Header] |
| 114 | + TrustedHash = "" |
| 115 | + TrustedPeers = [] |
| 116 | + [Header.Store] |
| 117 | + StoreCacheSize = 4096 |
| 118 | + IndexCacheSize = 16384 |
| 119 | + WriteBatchSize = 2048 |
| 120 | + [Header.Syncer] |
| 121 | + TrustingPeriod = "168h0m0s" |
| 122 | + [Header.Server] |
| 123 | + WriteDeadline = "8s" |
| 124 | + ReadDeadline = "1m0s" |
| 125 | + RangeRequestTimeout = "10s" |
| 126 | + [Header.Client] |
| 127 | + MaxHeadersPerRangeRequest = 64 |
| 128 | + RangeRequestTimeout = "8s" |
| 129 | + TrustedPeersRequestTimeout = "300ms" |
| 130 | +
|
| 131 | +[DASer] |
| 132 | + SamplingRange = 100 |
| 133 | + ConcurrencyLimit = 16 |
| 134 | + BackgroundStoreInterval = "10m0s" |
| 135 | + SampleFrom = 1 |
| 136 | + SampleTimeout = "4m0s" |
| 137 | +` |
0 commit comments