Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions scripts/genesis/ProtocolConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const PROTOCOL_CONFIG_CONTROLLER_STORAGE_LOCATION = 0x958f8fec699b51a1249f513ece
const PAUSABLE_STORAGE_LOCATION = 0x0642d7922329a434cf4fd17a3c95eb692c24fd95f9f94d0b55420a5d895f4a00n

const maxUint64 = 18446744073709551615n
const maxUint16 = 65535n
const schemaUint16 = schemaBigInt.min(0n).max(maxUint16)

export const schemaProtocolConfig = z
.object({
Expand Down Expand Up @@ -75,14 +77,14 @@ export const schemaProtocolConfig = z
}),
consensusParams: z
.object({
timeoutProposeMs: schemaBigInt,
timeoutProposeDeltaMs: schemaBigInt,
timeoutPrevoteMs: schemaBigInt,
timeoutPrevoteDeltaMs: schemaBigInt,
timeoutPrecommitMs: schemaBigInt,
timeoutPrecommitDeltaMs: schemaBigInt,
timeoutRebroadcastMs: schemaBigInt,
targetBlockTimeMs: schemaBigInt,
timeoutProposeMs: schemaUint16,
timeoutProposeDeltaMs: schemaUint16,
timeoutPrevoteMs: schemaUint16,
timeoutPrevoteDeltaMs: schemaUint16,
timeoutPrecommitMs: schemaUint16,
timeoutPrecommitDeltaMs: schemaUint16,
timeoutRebroadcastMs: schemaUint16,
targetBlockTimeMs: schemaUint16,
})
.optional(),
})
Expand Down
82 changes: 82 additions & 0 deletions tests/unit/protocol-config-genesis.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2026 Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { expect } from 'chai'
import { schemaProtocolConfig } from '../../scripts/genesis/ProtocolConfig'

const proxyAdmin = '0x0000000000000000000000000000000000000001'
const owner = '0x0000000000000000000000000000000000000002'
const controller = '0x0000000000000000000000000000000000000003'
const pauser = '0x0000000000000000000000000000000000000004'

const validConsensusParams = {
timeoutProposeMs: 3000n,
timeoutProposeDeltaMs: 500n,
timeoutPrevoteMs: 1000n,
timeoutPrevoteDeltaMs: 500n,
timeoutPrecommitMs: 1000n,
timeoutPrecommitDeltaMs: 500n,
timeoutRebroadcastMs: 2000n,
targetBlockTimeMs: 1000n,
}

const protocolConfig = {
proxy: {
admin: proxyAdmin,
},
owner,
controller,
pauser,
feeParams: {
alpha: 1n,
kRate: 1n,
inverseElasticityMultiplier: 1n,
minBaseFee: 0n,
maxBaseFee: 1_000_000n,
blockGasLimit: 30_000_000n,
},
consensusParams: validConsensusParams,
}

describe('ProtocolConfig genesis schema', () => {
it('accepts consensusParams at the uint16 upper bound', () => {
expect(() =>
schemaProtocolConfig.parse({
...protocolConfig,
consensusParams: {
...validConsensusParams,
timeoutProposeMs: 65535n,
},
}),
).to.not.throw()
})

it('rejects consensusParams values above the uint16 upper bound', () => {
for (const key of Object.keys(validConsensusParams) as Array<keyof typeof validConsensusParams>) {
expect(
() =>
schemaProtocolConfig.parse({
...protocolConfig,
consensusParams: {
...validConsensusParams,
[key]: 65536n,
},
}),
`${key} should reject 65536`,
).to.throw()
}
})
})