|
8 | 8 | "github.com/stretchr/testify/suite"
|
9 | 9 | . "gopkg.in/check.v1"
|
10 | 10 |
|
| 11 | + "github.com/zeta-chain/node/testutil/sample" |
11 | 12 | "github.com/zeta-chain/node/x/observer/types"
|
12 | 13 | )
|
13 | 14 |
|
@@ -48,9 +49,105 @@ func TestUpdateChainParamsSuiteSuite(t *testing.T) {
|
48 | 49 | }
|
49 | 50 |
|
50 | 51 | func TestChainParamsEqual(t *testing.T) {
|
51 |
| - params := types.GetDefaultChainParams() |
52 |
| - require.True(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[0])) |
53 |
| - require.False(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[1])) |
| 52 | + params := sample.ChainParams(1) |
| 53 | + |
| 54 | + require.True(t, types.ChainParamsEqual(*params, *params)) |
| 55 | + |
| 56 | + // ChainId matters |
| 57 | + copy := copyParams(params) |
| 58 | + copy.ChainId = 2 |
| 59 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 60 | + |
| 61 | + // ConfirmationCount matters |
| 62 | + copy = copyParams(params) |
| 63 | + copy.ConfirmationCount = params.ConfirmationCount + 1 |
| 64 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 65 | + |
| 66 | + // GasPriceTicker matters |
| 67 | + copy = copyParams(params) |
| 68 | + copy.GasPriceTicker = params.GasPriceTicker + 1 |
| 69 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 70 | + |
| 71 | + // InboundTicker matters |
| 72 | + copy = copyParams(params) |
| 73 | + copy.InboundTicker = params.InboundTicker + 1 |
| 74 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 75 | + |
| 76 | + // OutboundTicker matters |
| 77 | + copy = copyParams(params) |
| 78 | + copy.OutboundTicker = params.OutboundTicker + 1 |
| 79 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 80 | + |
| 81 | + // WatchUtxoTicker matters |
| 82 | + copy = copyParams(params) |
| 83 | + copy.WatchUtxoTicker = params.WatchUtxoTicker + 1 |
| 84 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 85 | + |
| 86 | + // ZetaTokenContractAddress matters |
| 87 | + copy = copyParams(params) |
| 88 | + copy.ZetaTokenContractAddress = "0x_something_else" |
| 89 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 90 | + |
| 91 | + // ConnectorContractAddress matters |
| 92 | + copy = copyParams(params) |
| 93 | + copy.ConnectorContractAddress = "0x_something_else" |
| 94 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 95 | + |
| 96 | + // Erc20CustodyContractAddress matters |
| 97 | + copy = copyParams(params) |
| 98 | + copy.Erc20CustodyContractAddress = "0x_something_else" |
| 99 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 100 | + |
| 101 | + // OutboundScheduleInterval matters |
| 102 | + copy = copyParams(params) |
| 103 | + copy.OutboundScheduleInterval = params.OutboundScheduleInterval + 1 |
| 104 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 105 | + |
| 106 | + // OutboundScheduleLookahead matters |
| 107 | + copy = copyParams(params) |
| 108 | + copy.OutboundScheduleLookahead = params.OutboundScheduleLookahead + 1 |
| 109 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 110 | + |
| 111 | + // BallotThreshold matters |
| 112 | + copy = copyParams(params) |
| 113 | + copy.BallotThreshold = params.BallotThreshold.Add(sdkmath.LegacySmallestDec()) |
| 114 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 115 | + |
| 116 | + // MinObserverDelegation matters |
| 117 | + copy = copyParams(params) |
| 118 | + copy.MinObserverDelegation = params.MinObserverDelegation.Add(sdkmath.LegacySmallestDec()) |
| 119 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 120 | + |
| 121 | + // IsSupported matters |
| 122 | + copy = copyParams(params) |
| 123 | + copy.IsSupported = !params.IsSupported |
| 124 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 125 | + |
| 126 | + // GatewayAddress matters |
| 127 | + copy = copyParams(params) |
| 128 | + copy.GatewayAddress = "0x_something_else" |
| 129 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 130 | + |
| 131 | + // ConfirmationParams matters |
| 132 | + copy = copyParams(params) |
| 133 | + copy.ConfirmationParams = nil |
| 134 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 135 | + |
| 136 | + copy = copyParams(params) |
| 137 | + copy.ConfirmationParams.SafeInboundCount = params.ConfirmationParams.SafeInboundCount + 1 |
| 138 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 139 | + |
| 140 | + copy = copyParams(params) |
| 141 | + copy.ConfirmationParams.FastInboundCount = params.ConfirmationParams.FastInboundCount + 1 |
| 142 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 143 | + |
| 144 | + copy = copyParams(params) |
| 145 | + copy.ConfirmationParams.SafeOutboundCount = params.ConfirmationParams.SafeOutboundCount + 1 |
| 146 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
| 147 | + |
| 148 | + copy = copyParams(params) |
| 149 | + copy.ConfirmationParams.FastOutboundCount = params.ConfirmationParams.FastOutboundCount + 1 |
| 150 | + require.False(t, types.ChainParamsEqual(*params, *copy)) |
54 | 151 | }
|
55 | 152 |
|
56 | 153 | func (s *UpdateChainParamsSuite) SetupTest() {
|
@@ -171,6 +268,58 @@ func (s *UpdateChainParamsSuite) TestCoreContractAddresses() {
|
171 | 268 | require.NotNil(s.T(), err)
|
172 | 269 | }
|
173 | 270 |
|
| 271 | +func Test_InboundConfirmationSafe(t *testing.T) { |
| 272 | + cp := sample.ChainParams(1) |
| 273 | + |
| 274 | + // set and check safe inbound count |
| 275 | + cp.ConfirmationParams.SafeInboundCount = 10 |
| 276 | + require.Equal(t, uint64(10), cp.InboundConfirmationSafe()) |
| 277 | +} |
| 278 | + |
| 279 | +func Test_OutboundConfirmationSafe(t *testing.T) { |
| 280 | + cp := sample.ChainParams(1) |
| 281 | + |
| 282 | + // set and check safe outbound count |
| 283 | + cp.ConfirmationParams.SafeOutboundCount = 10 |
| 284 | + require.Equal(t, uint64(10), cp.OutboundConfirmationSafe()) |
| 285 | +} |
| 286 | + |
| 287 | +func Test_InboundConfirmationFast(t *testing.T) { |
| 288 | + t.Run("should return fast inbound confirmation count if enabled", func(t *testing.T) { |
| 289 | + cp := sample.ChainParams(1) |
| 290 | + cp.ConfirmationParams.SafeInboundCount = 2 |
| 291 | + cp.ConfirmationParams.FastInboundCount = 1 |
| 292 | + confirmation := cp.InboundConfirmationFast() |
| 293 | + require.Equal(t, uint64(1), confirmation) |
| 294 | + }) |
| 295 | + |
| 296 | + t.Run("should fallback to safe inbound confirmation count if fast confirmation is disabled", func(t *testing.T) { |
| 297 | + cp := sample.ChainParams(1) |
| 298 | + cp.ConfirmationParams.SafeInboundCount = 2 |
| 299 | + cp.ConfirmationParams.FastInboundCount = 0 |
| 300 | + confirmation := cp.InboundConfirmationFast() |
| 301 | + require.Equal(t, uint64(2), confirmation) |
| 302 | + }) |
| 303 | +} |
| 304 | + |
| 305 | +func Test_OutboundConfirmationFast(t *testing.T) { |
| 306 | + t.Run("should return fast outbound confirmation count if enabled", func(t *testing.T) { |
| 307 | + cp := sample.ChainParams(1) |
| 308 | + cp.ConfirmationParams.SafeOutboundCount = 2 |
| 309 | + cp.ConfirmationParams.FastOutboundCount = 1 |
| 310 | + confirmation := cp.OutboundConfirmationFast() |
| 311 | + require.Equal(t, uint64(1), confirmation) |
| 312 | + }) |
| 313 | + |
| 314 | + t.Run("should fallback to safe outbound confirmation count if fast confirmation is disabled", func(t *testing.T) { |
| 315 | + cp := sample.ChainParams(1) |
| 316 | + cp.ConfirmationParams.SafeOutboundCount = 2 |
| 317 | + cp.ConfirmationParams.FastOutboundCount = 0 |
| 318 | + confirmation := cp.OutboundConfirmationFast() |
| 319 | + require.Equal(t, uint64(2), confirmation) |
| 320 | + }) |
| 321 | +} |
| 322 | + |
174 | 323 | func (s *UpdateChainParamsSuite) Validate(params *types.ChainParams) {
|
175 | 324 | copy := copyParams(params)
|
176 | 325 | copy.ConfirmationCount = 0
|
|
0 commit comments