Skip to content

Commit

Permalink
Merge branch 'master' into con-41-validate-queries-in-request-function
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanRHall authored Feb 14, 2025
2 parents 6eb8e6e + 3f672f2 commit 1507b6a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
5 changes: 5 additions & 0 deletions src/v2/DatabaseManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ contract DatabaseManager is
/// @notice Error thrown when attempting to register a query more than once
error QueryAlreadyRegistered();

/// @notice We disable initializers to prevent the initializer from being called directly on the implementation contract
constructor() {
_disableInitializers();
}

/// @notice Initializes the contract
function initialize(address initialOwner) public initializer {
__AccessControl_init();
Expand Down
32 changes: 30 additions & 2 deletions test/v2/DatabaseManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import {DatabaseManager} from "../../src/v2/DatabaseManager.sol";
import {BaseTest} from "./BaseTest.t.sol";

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {Initializable} from
"@openzeppelin-contracts-upgradeable-5.2.0/proxy/utils/Initializable.sol";
import {TransparentUpgradeableProxy} from
"@openzeppelin-contracts-5.2.0/proxy/transparent/TransparentUpgradeableProxy.sol";

contract DatabaseManagerTest is BaseTest {
DatabaseManager public implementation;
DatabaseManager public dbManager;
address public owner;
address public stranger;
Expand All @@ -20,8 +25,15 @@ contract DatabaseManagerTest is BaseTest {
owner = makeAddr("owner");
stranger = makeAddr("stranger");

dbManager = new DatabaseManager();
dbManager.initialize(owner);
implementation = new DatabaseManager();
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
address(implementation),
owner,
abi.encodeWithSelector(DatabaseManager.initialize.selector, owner)
);

// cast the proxy to as the DatabaseManager contract, the base test suite will do the rest!
dbManager = DatabaseManager(address(proxy));
}

function test_Constructor() public view {
Expand All @@ -33,6 +45,22 @@ contract DatabaseManagerTest is BaseTest {
assertFalse(dbManager.hasRole(keccak256("OWNER_ROLE"), stranger));
}

function test_Initialize_RevertsIf_DuplicateAttempt() public {
vm.expectRevert(
abi.encodeWithSelector(Initializable.InvalidInitialization.selector)
);
dbManager.initialize(stranger);
}

function test_Initialize_RevertsIf_CalledDirectlyOnImplementation()
public
{
vm.expectRevert(
abi.encodeWithSelector(Initializable.InvalidInitialization.selector)
);
implementation.initialize(stranger);
}

function test_RegisterTable_Success() public {
vm.prank(owner);

Expand Down
28 changes: 0 additions & 28 deletions test/v2/DatabaseManagerProxy.t.sol

This file was deleted.

0 comments on commit 1507b6a

Please sign in to comment.