|
| 1 | +// Copyright 2026 Circle Internet Group, Inc. All rights reserved. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +import { expect } from 'chai' |
| 18 | +import { schemaProtocolConfig } from '../../scripts/genesis/ProtocolConfig' |
| 19 | + |
| 20 | +const proxyAdmin = '0x0000000000000000000000000000000000000001' |
| 21 | +const owner = '0x0000000000000000000000000000000000000002' |
| 22 | +const controller = '0x0000000000000000000000000000000000000003' |
| 23 | +const pauser = '0x0000000000000000000000000000000000000004' |
| 24 | + |
| 25 | +const validConsensusParams = { |
| 26 | + timeoutProposeMs: 3000n, |
| 27 | + timeoutProposeDeltaMs: 500n, |
| 28 | + timeoutPrevoteMs: 1000n, |
| 29 | + timeoutPrevoteDeltaMs: 500n, |
| 30 | + timeoutPrecommitMs: 1000n, |
| 31 | + timeoutPrecommitDeltaMs: 500n, |
| 32 | + timeoutRebroadcastMs: 2000n, |
| 33 | + targetBlockTimeMs: 1000n, |
| 34 | +} |
| 35 | + |
| 36 | +const baseConfig = { |
| 37 | + proxy: { |
| 38 | + admin: proxyAdmin, |
| 39 | + }, |
| 40 | + owner, |
| 41 | + controller, |
| 42 | + pauser, |
| 43 | + feeParams: { |
| 44 | + alpha: 1n, |
| 45 | + kRate: 1n, |
| 46 | + inverseElasticityMultiplier: 1n, |
| 47 | + minBaseFee: 0n, |
| 48 | + maxBaseFee: 1_000_000n, |
| 49 | + blockGasLimit: 30_000_000n, |
| 50 | + }, |
| 51 | + consensusParams: validConsensusParams, |
| 52 | +} |
| 53 | + |
| 54 | +describe('ProtocolConfig genesis schema', () => { |
| 55 | + it('accepts a valid config', () => { |
| 56 | + expect(() => schemaProtocolConfig.parse(baseConfig)).to.not.throw() |
| 57 | + }) |
| 58 | + |
| 59 | + it('rejects zero consensus timeouts that updateConsensusParams also rejects', () => { |
| 60 | + const timeoutKeys = [ |
| 61 | + 'timeoutProposeMs', |
| 62 | + 'timeoutProposeDeltaMs', |
| 63 | + 'timeoutPrevoteMs', |
| 64 | + 'timeoutPrevoteDeltaMs', |
| 65 | + 'timeoutPrecommitMs', |
| 66 | + 'timeoutPrecommitDeltaMs', |
| 67 | + 'timeoutRebroadcastMs', |
| 68 | + ] as const |
| 69 | + |
| 70 | + for (const key of timeoutKeys) { |
| 71 | + expect( |
| 72 | + () => |
| 73 | + schemaProtocolConfig.parse({ |
| 74 | + ...baseConfig, |
| 75 | + consensusParams: { |
| 76 | + ...validConsensusParams, |
| 77 | + [key]: 0n, |
| 78 | + }, |
| 79 | + }), |
| 80 | + `${key} should reject 0`, |
| 81 | + ).to.throw() |
| 82 | + } |
| 83 | + }) |
| 84 | + |
| 85 | + it('rejects consensus params above uint16 max to prevent packed-slot overflow', () => { |
| 86 | + expect(() => |
| 87 | + schemaProtocolConfig.parse({ |
| 88 | + ...baseConfig, |
| 89 | + consensusParams: { |
| 90 | + ...validConsensusParams, |
| 91 | + timeoutProposeMs: 65536n, |
| 92 | + }, |
| 93 | + }), |
| 94 | + ).to.throw() |
| 95 | + }) |
| 96 | + |
| 97 | + it('rejects minBaseFee greater than maxBaseFee', () => { |
| 98 | + expect(() => |
| 99 | + schemaProtocolConfig.parse({ |
| 100 | + ...baseConfig, |
| 101 | + feeParams: { |
| 102 | + ...baseConfig.feeParams, |
| 103 | + minBaseFee: 1000n, |
| 104 | + maxBaseFee: 1n, |
| 105 | + }, |
| 106 | + }), |
| 107 | + ).to.throw() |
| 108 | + }) |
| 109 | +}) |
0 commit comments