Skip to content

Commit

Permalink
Remove the factory libraries to fix 0.9.0 deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 authored Oct 26, 2022
1 parent 222f983 commit 2f9485c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion contracts/CollectiveGovernanceFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import "../contracts/CollectiveGovernance.sol";
* CollectiveGovernance in the Builder. The GovernanceBuilder should be preferred for creating a new
* instance of the contract.
*/
library CollectiveGovernanceFactory {
contract CollectiveGovernanceFactory {
/// @notice create a new collective governance contract
/// @dev this should be invoked through the GovernanceBuilder
/// @param _supervisorList the list of supervisors for this project
Expand Down
10 changes: 8 additions & 2 deletions contracts/GovernanceBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ contract GovernanceBuilder is GovernanceCreator, ERC165 {
/// @dev implement the null object pattern requring voter class to be valid
VoterClass private immutable _voterClassNull;

StorageFactory private immutable _storageFactory;

CollectiveGovernanceFactory private immutable _governanceFactory;

mapping(address => bool) public _governanceContractRegistered;

constructor() {
_voterClassNull = new VoterClassNullObject();
_storageFactory = new StorageFactory();
_governanceFactory = new CollectiveGovernanceFactory();
}

/// @notice initialize and create a new builder context for this sender
Expand Down Expand Up @@ -189,7 +195,7 @@ contract GovernanceBuilder is GovernanceCreator, ERC165 {
GovernanceProperties storage _properties = _buildMap[_creator];
Storage _storage = createStorage(_properties);
TimeLocker _timeLock = createTimelock(_storage);
Governance _governance = CollectiveGovernanceFactory.create(
Governance _governance = _governanceFactory.create(
_properties.supervisorList,
_properties.class,
_storage,
Expand Down Expand Up @@ -258,7 +264,7 @@ contract GovernanceBuilder is GovernanceCreator, ERC165 {
function createStorage(GovernanceProperties storage _properties) private returns (Storage) {
require(address(_properties.class) != address(_voterClassNull), "Voter class required");
require(_properties.minimumVoteDuration >= Constant.MINIMUM_VOTE_DURATION, "Longer minimum duration required");
Storage _storage = StorageFactory.create(
Storage _storage = _storageFactory.create(
_properties.class,
_properties.minimumProjectQuorum,
_properties.minimumVoteDelay,
Expand Down
3 changes: 2 additions & 1 deletion contracts/StorageFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import "../contracts/GovernanceStorage.sol";
/**
* @title CollectiveStorage creational contract
*/
library StorageFactory {
contract StorageFactory {
event StorageCreated(address _storage, address _owner);

/// @notice create a new storage object with VoterClass as the voting population
Expand All @@ -64,6 +64,7 @@ library StorageFactory {
uint256 _minimumDuration
) external returns (Storage) {
GovernanceStorage _storage = new GovernanceStorage(_class, _minimumQuorum, _minimumDelay, _minimumDuration);
_storage.transferOwnership(msg.sender);
emit StorageCreated(address(_storage), msg.sender);
return _storage;
}
Expand Down
18 changes: 10 additions & 8 deletions test/CollectiveGovernanceFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ contract CollectiveGovernanceFactoryTest is Test {
Storage private _storage;
TimeLocker private _timeLock;
address[] private _supervisorList;
CollectiveGovernanceFactory private _governanceFactory;

function setUp() public {
VoterClassCreator _vcCreator = new VoterClassFactory();
address vcAddress = _vcCreator.createOpenVote(1);
_class = VoterClass(vcAddress);
_storage = StorageFactory.create(
_storage = new StorageFactory().create(
_class,
Constant.MINIMUM_PROJECT_QUORUM,
Constant.MINIMUM_VOTE_DELAY,
Expand All @@ -33,10 +34,11 @@ contract CollectiveGovernanceFactoryTest is Test {
_timeLock = new TimeLock(Constant.TIMELOCK_MINIMUM_DELAY);
_supervisorList = new address[](1);
_supervisorList[0] = _OWNER;
_governanceFactory = new CollectiveGovernanceFactory();
}

function testFailUrlTooLarge() public {
CollectiveGovernanceFactory.create(
_governanceFactory.create(
_supervisorList,
_class,
_storage,
Expand All @@ -50,7 +52,7 @@ contract CollectiveGovernanceFactoryTest is Test {
}

function testFailDescriptionTooLarge() public {
CollectiveGovernanceFactory.create(
_governanceFactory.create(
_supervisorList,
_class,
_storage,
Expand All @@ -64,7 +66,7 @@ contract CollectiveGovernanceFactoryTest is Test {
}

function testFailSupervisorListIsEmpty() public {
CollectiveGovernanceFactory.create(
_governanceFactory.create(
new address[](0),
_class,
_storage,
Expand All @@ -78,7 +80,7 @@ contract CollectiveGovernanceFactoryTest is Test {
}

function testFailGasUsedTooLow() public {
CollectiveGovernanceFactory.create(
_governanceFactory.create(
_supervisorList,
_class,
_storage,
Expand All @@ -92,7 +94,7 @@ contract CollectiveGovernanceFactoryTest is Test {
}

function testFailBaseFeeTooLow() public {
CollectiveGovernanceFactory.create(
_governanceFactory.create(
_supervisorList,
_class,
_storage,
Expand All @@ -106,7 +108,7 @@ contract CollectiveGovernanceFactoryTest is Test {
}

function testCreateNewGovernance() public {
Governance governance = CollectiveGovernanceFactory.create(
Governance governance = _governanceFactory.create(
_supervisorList,
_class,
_storage,
Expand All @@ -121,7 +123,7 @@ contract CollectiveGovernanceFactoryTest is Test {
}

function testCreateNewGovernanceGasRebate() public {
Governance governance = CollectiveGovernanceFactory.create(
Governance governance = _governanceFactory.create(
_supervisorList,
_class,
_storage,
Expand Down
10 changes: 6 additions & 4 deletions test/GovernanceStorage.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ contract GovernanceStorageTest is Test {

address private immutable _cognate = address(this);

StorageFactory private _storageFactory;
Storage private _storage;
VoteStrategy private _strategy;

function setUp() public {
vm.clearMockedCalls();
_storageFactory = new StorageFactory();
VoterClassVoterPool _voterClass = new VoterClassVoterPool(1);
_voterClass.addVoter(_VOTER1);
_voterClass.addVoter(_VOTER2);
_voterClass.addVoter(_VOTER3);
_voterClass.makeFinal();
_storage = StorageFactory.create(
_storage = _storageFactory.create(
_voterClass,
Constant.MINIMUM_PROJECT_QUORUM,
Constant.MINIMUM_VOTE_DELAY,
Expand All @@ -56,23 +58,23 @@ contract GovernanceStorageTest is Test {
VoterClassVoterPool _voterClass = new VoterClassVoterPool(1);
_voterClass.addVoter(_VOTER1);
_voterClass.makeFinal();
_storage = StorageFactory.create(_voterClass, Constant.MINIMUM_PROJECT_QUORUM, 333, Constant.MINIMUM_VOTE_DURATION);
_storage = _storageFactory.create(_voterClass, Constant.MINIMUM_PROJECT_QUORUM, 333, Constant.MINIMUM_VOTE_DURATION);
assertEq(_storage.minimumVoteDelay(), 333);
}

function testMinimumVoteDuration() public {
VoterClassVoterPool _voterClass = new VoterClassVoterPool(1);
_voterClass.addVoter(_VOTER1);
_voterClass.makeFinal();
_storage = StorageFactory.create(_voterClass, Constant.MINIMUM_PROJECT_QUORUM, Constant.MINIMUM_VOTE_DELAY, 22 days);
_storage = _storageFactory.create(_voterClass, Constant.MINIMUM_PROJECT_QUORUM, Constant.MINIMUM_VOTE_DELAY, 22 days);
assertEq(_storage.minimumVoteDuration(), 22 days);
}

function testMinimumProjectQuorum() public {
VoterClassVoterPool _voterClass = new VoterClassVoterPool(1);
_voterClass.addVoter(_VOTER1);
_voterClass.makeFinal();
_storage = StorageFactory.create(_voterClass, 11111, Constant.MINIMUM_VOTE_DELAY, Constant.MINIMUM_VOTE_DURATION);
_storage = _storageFactory.create(_voterClass, 11111, Constant.MINIMUM_VOTE_DELAY, Constant.MINIMUM_VOTE_DURATION);
assertEq(_storage.minimumProjectQuorum(), 11111);
}

Expand Down
6 changes: 4 additions & 2 deletions test/StorageFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import "../contracts/VoterClassFactory.sol";

contract StorageFactoryTest is Test {
VoterClass private _class;
StorageFactory private _storageFactory;

function setUp() public {
VoterClassCreator _vcCreator = new VoterClassFactory();
address vcAddress = _vcCreator.createOpenVote(1);
_class = VoterClass(vcAddress);
_storageFactory = new StorageFactory();
}

function testSetupNewStorage() public {
Storage _storage = StorageFactory.create(
Storage _storage = _storageFactory.create(
_class,
Constant.MINIMUM_PROJECT_QUORUM,
Constant.MINIMUM_VOTE_DELAY,
Expand All @@ -29,7 +31,7 @@ contract StorageFactoryTest is Test {
}

function testIsStorageOwner() public {
Storage _storage = StorageFactory.create(
Storage _storage = _storageFactory.create(
_class,
Constant.MINIMUM_PROJECT_QUORUM,
Constant.MINIMUM_VOTE_DELAY,
Expand Down

0 comments on commit 2f9485c

Please sign in to comment.