Skip to content

WIP: Fire events to track user and recipient registries independently #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
56 changes: 51 additions & 5 deletions contracts/contracts/ClrFundDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pragma solidity ^0.6.12;
import './MACIFactory.sol';
import './ClrFund.sol';
import './recipientRegistry/OptimisticRecipientRegistry.sol';
import './userRegistry/BrightIdUserRegistry.sol';

contract CloneFactory { // implementation of eip-1167 - see https://eips.ethereum.org/EIPS/eip-1167
function createClone(address target) internal returns (address result) {
Expand All @@ -40,16 +42,26 @@ contract ClrFundDeployer is CloneFactory {

address public template;
mapping (address => bool) public clrfunds;
mapping (address => bool) public recipientRegistries;
mapping (address => bool) public userRegistries;

uint clrId = 0;
uint recipientRegistryId = 0;
uint userId = 0;

ClrFund private clrfund; // funding factory contract

OptimisticRecipientRegistry private recipientRegistry; // recipient registry contract
BrightIdUserRegistry private userRegistry; // user registry contract

constructor(address _template) public {
template = _template;
}

event NewInstance(address indexed clrfund);
event Register(address indexed clrfund, string metadata);

event RegisterFund(address indexed clrfund, string metadata);
event RegisterOptimisticRecipientRegistry(address indexed recipientRegistry, string metadata);
event RegisterBrightIdUserRegistry(address indexed userRegistry, string metadata);

function deployFund(
MACIFactory _maciFactory
) public returns (address) {
Expand All @@ -64,7 +76,7 @@ contract ClrFundDeployer is CloneFactory {
return address(clrfund);
}

function registerInstance(
function registerFundInstance(
address _clrFundAddress,
string memory _metadata
) public returns (bool) {
Expand All @@ -76,7 +88,41 @@ contract ClrFundDeployer is CloneFactory {
clrfunds[_clrFundAddress] = true;

clrId = clrId + 1;
emit Register(_clrFundAddress, _metadata);
emit RegisterFund(_clrFundAddress, _metadata);
return true;

}

function registerRecipientRegistryInstance(
address _recipientRegistryAddress,
string memory _metadata
) public returns (bool) {

recipientRegistry = OptimisticRecipientRegistry(_recipientRegistryAddress);

require(recipientRegistries[_recipientRegistryAddress] == false, 'RecipientRegistry: metadata already registered');

recipientRegistries[_recipientRegistryAddress] = true;

recipientRegistryId = recipientRegistryId + 1;
emit RegisterOptimisticRecipientRegistry(_recipientRegistryAddress, _metadata);
return true;

}

function registerUserRegistryInstance(
address _userRegistryAddress,
string memory _metadata
) public returns (bool) {

userRegistry = BrightIdUserRegistry(_userRegistryAddress);

require(userRegistries[_userRegistryAddress] == false, 'UserRegistry: metadata already registered');

userRegistries[_userRegistryAddress] = true;

userId = userId + 1;
emit RegisterBrightIdUserRegistry(_userRegistryAddress, _metadata);
return true;

}
Expand Down
45 changes: 40 additions & 5 deletions contracts/tests/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,61 @@ describe('Clr fund deployer', () => {

it('can register with the subgraph', async () => {
await expect(
clrFundDeployer.registerInstance(
clrFundDeployer.registerFundInstance(
factory.address,
'{name:dead,title:beef}'
)
)
.to.emit(clrFundDeployer, 'Register')
.to.emit(clrFundDeployer, 'RegisterFund')
.withArgs(factory.address, '{name:dead,title:beef}')
})
//TODO: Test Optimistic Recipient Registry subgraph registration event is idempotent
it('can register Optimistic Recipient Registries with the subgraph', async () => {
await expect(
clrFundDeployer.registerRecipientRegistryInstance(
recipientRegistry.address,
'{name:dead,title:beef}'
)
)
.to.emit(clrFundDeployer, 'RegisterOptimisticRecipientRegistry')
.withArgs(recipientRegistry.address, '{name:dead,title:beef}')
})

//TODO: Test Bright ID User Registry subgraph registration event is idempotent
it('can register BrightId User Registries with the subgraph', async () => {
await expect(
clrFundDeployer.registerUserRegistryInstance(
userRegistry.address,
'{name:dead,title:beef}'
)
)
.to.emit(clrFundDeployer, 'RegisterBrightIdUserRegistry')
.withArgs(userRegistry.address, '{name:dead,title:beef}')
})

//TODO: Test brightId subgraph registration
it('can register fun instances with the subgraph', async () => {
await expect(
clrFundDeployer.registerFundInstance(
factory.address,
'{name:dead,title:beef}'
)
)
.to.emit(clrFundDeployer, 'RegisterFund')
.withArgs(factory.address, '{name:dead,title:beef}')
})

it('cannot register with the subgraph twice', async () => {
await expect(
clrFundDeployer.registerInstance(
clrFundDeployer.registerFundInstance(
factory.address,
'{name:dead,title:beef}'
)
)
.to.emit(clrFundDeployer, 'Register')
.to.emit(clrFundDeployer, 'RegisterFund')
.withArgs(factory.address, '{name:dead,title:beef}')
await expect(
clrFundDeployer.registerInstance(
clrFundDeployer.registerFundInstance(
factory.address,
'{name:dead,title:beef}'
)
Expand Down
Loading