Commit a7568f1f authored by Alex Puig's avatar Alex Puig
Browse files

Merge branch 'id-factory' into 'master'

New Id Factory contract

See merge request caelum-tech/caelum-identity!20
parents cef754c3 2e5d4123
Pipeline #75989832 passed with stage
in 3 minutes and 2 seconds
This diff is collapsed.
This diff is collapsed.
pragma solidity ^0.5.4;
import "./Identity.sol";
contract IdFactory {
address public owner;
uint32 public numIdentifiers = 0;
struct Identifier {
address did; // person delegated to
uint version; // index of the voted proposal
}
mapping(bytes32=>Identifier) identifiers;
constructor(address _owner) public {
owner = _owner;
}
function createIdentity(bytes32 handler, address _owner) public {
assert(identifiers[handler].version == 0);
address newId = address(new Identity(_owner));
identifiers[handler] = Identifier({
did: newId,
version: 1
});
numIdentifiers++;
// emit new Identity
}
/**
* Returns the address associated with an ENS node.
* @param handler The NS handler to query.
* @return The associated address.
*/
function resolve(bytes32 handler) public view returns (address) {
return identifiers[handler].did;
}
}
\ No newline at end of file
{
"name": "@caelum-tech/identity",
"version": "1.2.2",
"version": "1.3.0",
"description": "Caelum Identity library",
"main": "index.js",
"scripts": {
......
const ethers = require('ethers')
const expect = require('chai').expect
const expectThrow = require('./helpers/expectThrow.js')
const Identity = artifacts.require('./contracts/Identity.sol')
const IdFactory = artifacts.require('./contracts/IdFactory.sol')
contract('IdFactory', (accounts) => {
const owner = accounts[1]
const idOwner = accounts[2]
// const rando = accounts[3]
// const mintee = accounts[4]
let factory
const handler = ethers.utils.formatBytes32String('test')
const handler2 = ethers.utils.formatBytes32String('test2')
it('Should Deploy the Factory Contract', async () => {
factory = await IdFactory.new(owner)
expect(await factory.owner()).to.be.equal(owner)
})
it('Should Add a new Identity', async () => {
await factory.createIdentity(handler, idOwner)
expect(Number(await factory.numIdentifiers())).to.be.equal(1)
let newId = await factory.resolve(handler)
let identifier = await Identity.at(newId)
expect(await identifier.owner()).to.be.equal(idOwner)
})
it('Should Add another Identity', async () => {
await factory.createIdentity(handler2, idOwner)
expect(Number(await factory.numIdentifiers())).to.be.equal(2)
})
it('Should Not duplicate handlers', async () => {
await expectThrow(factory.createIdentity(handler2, idOwner))
})
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment