mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 09:50:01 +00:00
## Summary - Add zero address validation across all functions that accept address parameters to prevent misconfiguration - Fix race condition in `buildNewValidatorSetMessage()` that could cause reverts during validator deregistration - Refactor contract for improved readability and reduced code duplication - Update AVS metadata URL to point to the correct hosted JSON file ## Changes ### Security & Validation - Add `ZeroAddress` error and validate all address inputs in `initialize`, `setRewardsInitiator`, `setSnowbridgeGateway`, `addValidatorToAllowlist`, `registerOperator`, and `updateSolochainAddressForValidator` - Fix race condition: filter out zero solochain addresses in `buildNewValidatorSetMessage()` to prevent reverts when a validator is mid-deregistration ### Refactoring - Replace verbose `if/revert` patterns with `require` statements for consistency - Inline single-use internal functions (`_createDataHavenOperatorSets`, `_setRewardsInitiator`) - Consolidate duplicate error types into single `ZeroAddress` error - Rename `initialise` → `initialize` to maintain consistency with the transparent upgradability pattern - Optimize validator set message encoding by removing redundant wrapper function ### Observability - Add `SolochainAddressUpdated` event for tracking validator address changes ### Cleanup - Remove unused remappings from `foundry.toml` - Fix typo in metadata description --------- Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
25 lines
1.2 KiB
Solidity
25 lines
1.2 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity ^0.8.27;
|
|
|
|
import {Test} from "forge-std/Test.sol";
|
|
import {console} from "forge-std/console.sol";
|
|
import {DataHavenSnowbridgeMessages} from "../src/libraries/DataHavenSnowbridgeMessages.sol";
|
|
import {TestUtils} from "./utils/TestUtils.sol";
|
|
|
|
// This test is used to encode the receive validators message and print the hex string.
|
|
// Run forge test --match-test testEncodeReceiveValidatorsMessage -vvv to see the hex encoded bytes.
|
|
// Use the helper script in operator/scripts/test_message_encoding.sh to test the encoding/decoding full cycle.
|
|
contract MessageEncodingTest is Test {
|
|
function testEncodeReceiveValidatorsMessage() public pure {
|
|
// Use the utility function for consistency
|
|
address[] memory mockValidators = TestUtils.generateMockValidatorsAddresses(3);
|
|
|
|
DataHavenSnowbridgeMessages.NewValidatorSetPayload memory payload =
|
|
DataHavenSnowbridgeMessages.NewValidatorSetPayload({validators: mockValidators});
|
|
|
|
bytes memory encodedMessage =
|
|
DataHavenSnowbridgeMessages.scaleEncodeNewValidatorSetMessagePayload(payload);
|
|
|
|
console.logBytes(encodedMessage);
|
|
}
|
|
}
|