Skip to content

Commit

Permalink
added initial testing for deployments and getting factory connected t…
Browse files Browse the repository at this point in the history
…o nextjs package
  • Loading branch information
JacobHomanics committed Nov 13, 2023
1 parent 990cf6d commit 2fb9eed
Show file tree
Hide file tree
Showing 8 changed files with 2,011 additions and 147 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
"lint-staged": "~13.2.2"
},
"packageManager": "yarn@3.2.3"
}
}
286 changes: 197 additions & 89 deletions packages/foundry/contracts/GivingCircle.sol

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions packages/foundry/contracts/GivingCircleStandalone.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./IGivingCircle.sol";
import "./KYCController.sol";
import "./partialIERC20.sol";
import "./Initialization.sol";
import "./Proposals.sol";
import {GivingCircle} from "./GivingCircle.sol";

contract GivingCircleStandalone is GivingCircle {
constructor(Initialization.GivingCircleInitialization memory init) {
initialize(init);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import "./Initialization.sol";
import "./Proposals.sol";
import "./Attendees.sol";

contract GivingCircleFactory is AccessControl {

contract GivingCirclesFactory is AccessControl {
uint256 public instancesCount;
mapping (uint256 => IGivingCircle) public instances;

address public implementation;
mapping(uint256 => IGivingCircle) public instances;

bytes32 public constant CIRCLE_CREATOR_ROLE = keccak256("CIRCLE_CREATOR_ROLE");
IGivingCircle public implementation;

bytes32 public constant CIRCLE_CREATOR_ROLE =
keccak256("CIRCLE_CREATOR_ROLE");

event CreatedNewCircle(address);

constructor(address[] memory admins) {

for (uint256 i = 0; i < admins.length; i++) {
_grantRole(DEFAULT_ADMIN_ROLE, admins[i]);
}
}

function createGivingCircle(Initialization.GivingCircleInitialization memory init) external onlyRole(CIRCLE_CREATOR_ROLE) {
function createGivingCircle(
Initialization.GivingCircleInitialization memory init
) external onlyRole(CIRCLE_CREATOR_ROLE) {
address clone = Clones.clone(address(implementation));
IGivingCircle newGivingCircle = IGivingCircle(clone);

Expand All @@ -39,14 +39,17 @@ contract GivingCircleFactory is AccessControl {
emit CreatedNewCircle(clone);
}

function setImplementation(address _implementation) external onlyRole(DEFAULT_ADMIN_ROLE) {
function setImplementation(
address _implementation
) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setImplementation(_implementation);
}

function _setImplementation(address _implementation) internal {
require(_implementation != address(0), "Address cannot be zero address!");
implementation = _implementation;
require(
_implementation != address(0),
"Address cannot be zero address!"
);
implementation = IGivingCircle(_implementation);
}

//End Circle Interaction Functions
}
}
2 changes: 1 addition & 1 deletion packages/foundry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"@types/prettier": "2",
"@types/qrcode": "1"
}
}
}
18 changes: 15 additions & 3 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "./DeployHelpers.s.sol";
import {GivingCirclesFactory} from "../contracts/GivingCirclesFactory.sol";
import {GivingCircle} from "../contracts/GivingCircle.sol";
import {Initialization} from "../contracts/Initialization.sol";
import {TestERC20} from "../contracts/TestERC20.sol";

contract DeployScript is ScaffoldETHDeploy {
error InvalidPrivateKey(string);
Expand All @@ -14,16 +18,24 @@ contract DeployScript is ScaffoldETHDeploy {
"You don't have a deployer account. Make sure you have set DEPLOYER_PRIVATE_KEY in .env or use `yarn generate` to generate a new random account"
);
}

address[] memory admins = new address[](1);
admins[0] = vm.addr(deployerPrivateKey);

vm.startBroadcast(deployerPrivateKey);
YourContract yourContract = new YourContract(
vm.addr(deployerPrivateKey)
);
GivingCirclesFactory yourContract = new GivingCirclesFactory(admins);
console.logString(
string.concat(
"YourContract deployed at: ",
vm.toString(address(yourContract))
)
);

GivingCircle implementation = new GivingCircle();
yourContract.setImplementation(address(implementation));

new TestERC20();

vm.stopBroadcast();

/**
Expand Down
64 changes: 64 additions & 0 deletions packages/foundry/test/GivingCircleFactory.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "../contracts/YourContract.sol";
import {GivingCirclesFactory} from "../contracts/GivingCirclesFactory.sol";
import {GivingCircle} from "../contracts/GivingCircle.sol";
import {Initialization} from "../contracts/Initialization.sol";
import {TestERC20} from "../contracts/TestERC20.sol";

contract YourContractTest is Test {
YourContract public yourContract;
GivingCirclesFactory public factory;

function setUp() public {
yourContract = new YourContract(vm.addr(1));
address[] memory admins = new address[](1);
admins[0] = vm.addr(1);

factory = new GivingCirclesFactory(admins);
}

function testMe() public view {
require(factory.hasRole(factory.DEFAULT_ADMIN_ROLE(), vm.addr(1)));
}

function testDeployCircle() public deployCircleAndSetAsImplementation {}

function testCreateCircle()
public
setCircleCreator(vm.addr(1))
deployCircleAndSetAsImplementation
{
vm.startPrank(vm.addr(1));

Initialization.GivingCircleInitialization memory init;
init.name = "Test Circle";
init.beansToDispursePerAttendee = 1;

address[] memory leaders = new address[](1);
leaders[0] = vm.addr(1);
init.circleLeaders = leaders;
factory.createGivingCircle(init);
vm.stopPrank();

require(factory.instancesCount() == 1);
}

modifier setCircleCreator(address addr) {
vm.startPrank(vm.addr(1));
factory.grantRole(factory.CIRCLE_CREATOR_ROLE(), addr);
vm.stopPrank();
_;
}

modifier deployCircleAndSetAsImplementation() {
vm.startPrank(vm.addr(1));
GivingCircle implementation = new GivingCircle();
factory.setImplementation(address(implementation));
vm.stopPrank();
require(address(factory.implementation()) == address(implementation));
_;
}
}
Loading

0 comments on commit 2fb9eed

Please sign in to comment.