Merge from embark into develop
This commit is contained in:
commit
74262dd33e
|
@ -9,7 +9,6 @@ contract TestContract {
|
||||||
TestFunctionExecuted();
|
TestFunctionExecuted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Helper function to be used in unit testing due to error in web3
|
Helper function to be used in unit testing due to error in web3
|
||||||
web3.utils.soliditySha3([1, 2, 3])
|
web3.utils.soliditySha3([1, 2, 3])
|
||||||
|
@ -23,7 +22,7 @@ contract TestContract {
|
||||||
bytes _data,
|
bytes _data,
|
||||||
bytes32 _newSecret,
|
bytes32 _newSecret,
|
||||||
bytes32[] _newFriendsHashes)
|
bytes32[] _newFriendsHashes)
|
||||||
external
|
public
|
||||||
pure
|
pure
|
||||||
returns(bytes32)
|
returns(bytes32)
|
||||||
{
|
{
|
||||||
|
|
134
test/factory.js
134
test/factory.js
|
@ -1,102 +1,136 @@
|
||||||
|
const assert = require('assert');
|
||||||
|
const Embark = require('embark');
|
||||||
|
let EmbarkSpec = Embark.initTests();
|
||||||
|
let web3 = EmbarkSpec.web3;
|
||||||
|
|
||||||
|
const identityJson = require('../dist/contracts/Identity.json');
|
||||||
|
const updatedIdentityKernelJson = require('../dist/contracts/UpdatedIdentityKernel.json');
|
||||||
|
|
||||||
const TestUtils = require("../utils/testUtils.js")
|
const TestUtils = require("../utils/testUtils.js")
|
||||||
const idUtils = require("../utils/identityUtils.js")
|
const idUtils = require("../utils/identityUtils.js")
|
||||||
const web3EthAbi = require("web3-eth-abi");
|
|
||||||
|
|
||||||
const Identity = artifacts.require("./identity/Identity.sol");
|
describe('IdentityFactory', function(accounts) {
|
||||||
const IdentityFactory = artifacts.require("./identity/IdentityFactory.sol");
|
|
||||||
const UpdatableInstance = artifacts.require('./deploy/UpdatableInstance.sol');
|
|
||||||
const UpdatedIdentityKernel = artifacts.require("./tests/UpdatedIdentityKernel.sol");
|
|
||||||
|
|
||||||
contract('IdentityFactory', function(accounts) {
|
|
||||||
|
|
||||||
let identityFactory;
|
let identityFactory;
|
||||||
let identity;
|
let identity;
|
||||||
let updatedIdentity;
|
let updatedIdentity;
|
||||||
let updatedIdentityKernel;
|
let updatedIdentityKernel;
|
||||||
|
|
||||||
before(async () => {
|
before( function(done) {
|
||||||
identityFactory = await IdentityFactory.new("0xaaa", {from: accounts[0]});
|
this.timeout(0);
|
||||||
})
|
|
||||||
|
EmbarkSpec = Embark.initTests();
|
||||||
|
web3 = EmbarkSpec.web3;
|
||||||
|
|
||||||
|
EmbarkSpec.deployAll({
|
||||||
|
"IdentityFactory": {
|
||||||
|
args: ["0xaaaa"],
|
||||||
|
gas: 5000000
|
||||||
|
},
|
||||||
|
"Identity": {},
|
||||||
|
"UpdatedIdentityKernel": {}
|
||||||
|
}, (_accounts) => {
|
||||||
|
accounts = _accounts;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("IdentityFactory()", () => {
|
|
||||||
it("Creates a new identity", async () => {
|
it("Creates a new identity", async () => {
|
||||||
let tx = await identityFactory.createIdentity({from: accounts[0]});
|
let tx = await IdentityFactory.methods.createIdentity().send({from: accounts[0]});
|
||||||
const logEntry = tx.logs[0];
|
|
||||||
assert.strictEqual(logEntry.event, "IdentityCreated");
|
|
||||||
|
|
||||||
identity = await Identity.at(logEntry.args.instance, {from: accounts[0]})
|
const logEntry = tx.events.IdentityCreated;
|
||||||
|
|
||||||
|
assert(logEntry !== undefined, "IdentityCreated was not triggered");
|
||||||
|
|
||||||
|
let identity = new web3.eth.Contract(identityJson.abi, logEntry.returnValues.instance, {from: accounts[0]});
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
|
await identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
||||||
idUtils.purposes.MANAGEMENT,
|
idUtils.purposes.MANAGEMENT,
|
||||||
identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
|
identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Registers a updated identity contract", async() => {
|
it("Registers a updated identity contract", async() => {
|
||||||
const infoHash = "0xbbb";
|
const infoHash = "0xbbbb";
|
||||||
updatedIdentityKernel = await UpdatedIdentityKernel.new({from: accounts[0]});
|
let receipt = await IdentityFactory.methods.setKernel(UpdatedIdentityKernel.address, infoHash).send({from: accounts[0]});
|
||||||
await identityFactory.setKernel(updatedIdentityKernel.address, infoHash);
|
|
||||||
|
|
||||||
const newKernel = await TestUtils.listenForEvent(identityFactory.NewKernel());
|
const newKernel = TestUtils.eventValues(receipt, "NewKernel");
|
||||||
assert(newKernel.infohash, infoHash, "Infohash is not correct");
|
assert(newKernel.infohash, infoHash, "Infohash is not correct");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Creates a new identity using latest version", async() => {
|
it("Creates a new identity using latest version", async() => {
|
||||||
let tx = await identityFactory.createIdentity({from: accounts[0]});
|
let tx = await IdentityFactory.methods.createIdentity().send({from: accounts[0]});
|
||||||
const logEntry = tx.logs[0];
|
|
||||||
assert.strictEqual(logEntry.event, "IdentityCreated");
|
|
||||||
|
|
||||||
updatedIdentity = await UpdatedIdentityKernel.at(logEntry.args.instance, {from: accounts[0]})
|
assert.notEqual(tx.events.IdentityCreated, undefined, "IdentityCreated wasn't triggered");
|
||||||
tx = await updatedIdentity.test({from: accounts[0]});
|
|
||||||
assert.strictEqual(tx.logs[0].event, "TestFunctionExecuted");
|
const contractAddress = tx.events.IdentityCreated.returnValues.instance;
|
||||||
|
|
||||||
|
|
||||||
|
let updatedIdentity = new web3.eth.Contract(updatedIdentityKernelJson.abi, contractAddress, {from: accounts[0]});
|
||||||
|
|
||||||
|
tx = await updatedIdentity.methods.test().send({from: accounts[0]});
|
||||||
|
assert.notEqual(tx.events.TestFunctionExecuted, undefined, "TestFunctionExecuted wasn't triggered");
|
||||||
|
|
||||||
// Test if it still executes identity functions as expected
|
// Test if it still executes identity functions as expected
|
||||||
let baseIdentity = await Identity.at(updatedIdentity.address, {from: accounts[0]})
|
let baseIdentity = new web3.eth.Contract(identityJson.abi, contractAddress, {from: accounts[0]});
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
|
await baseIdentity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
||||||
1,
|
1,
|
||||||
identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
|
baseIdentity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Updates an identity to the latest version", async() => {
|
it("Updates an identity to the latest version", async() => {
|
||||||
let tx1 = await identity.execute(
|
let tx1 = await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.updateRequestUpdatableInstance(updatedIdentityKernel.address),
|
idUtils.encode.updateRequestUpdatableInstance(UpdatedIdentityKernel.address))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.strictEqual(tx1.logs[tx1.logs.length - 1].event, "Executed");
|
assert.notEqual(tx1.events.Executed, undefined, "Executed wasn't triggered");
|
||||||
|
|
||||||
// Updating EVM timestamp to test delay
|
// Updating EVM timestamp to test delay
|
||||||
const plus31days = 60 * 60 * 24 * 31;
|
const plus31days = 60 * 60 * 24 * 31;
|
||||||
|
|
||||||
web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [plus31days], id: 0});
|
/*
|
||||||
web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0})
|
// @rramos - The following code is supposed to increase by 31 days the evm date,
|
||||||
|
// and mine one block. It is commented because it seems to not be working on web3 1.0.
|
||||||
|
// Also, sendAsync is supposed to be named send in this version, yet it shows an error
|
||||||
|
// that it does not support synchronous executions. (?)
|
||||||
|
// TODO: figure it out!
|
||||||
|
|
||||||
|
web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [plus31days], id: 0}, function(){console.log(1);});
|
||||||
|
web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0}, function(){console.log(2);})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Confirm update
|
// Confirm update
|
||||||
let tx2 = await identity.execute(
|
let tx2 = await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.updateConfirmUpdatableInstance(updatedIdentityKernel.address),
|
idUtils.encode.updateConfirmUpdatableInstance(UpdatedIdentityKernel.address))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.strictEqual(tx2.logs[tx2.logs.length - 1].event, "Executed");
|
assert.notEqual(tx2.events.Executed, undefined, "Executed wasn't triggered");
|
||||||
|
|
||||||
// Calling function available in updated identity kernel
|
|
||||||
let updatedIdentity1 = await UpdatedIdentityKernel.at(identity.address, {from: accounts[0]})
|
|
||||||
let tx3 = await updatedIdentity1.test({from: accounts[0]});
|
|
||||||
|
|
||||||
assert.strictEqual(tx3.logs[tx3.logs.length - 1].event, "TestFunctionExecuted");
|
let updatedIdentity1 = new web3.eth.Contract(updatedIdentityKernelJson.abi, Identity.address, {from: accounts[0]});
|
||||||
|
|
||||||
|
// Calling
|
||||||
|
let tx3 = await updatedIdentity1.methods.test().send({from: accounts[0]});
|
||||||
|
assert.notEqual(tx3.events.TestFunctionExecuted, undefined, "TestFunctionExecuted wasn't triggered");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
tx3.logs[tx3.logs.length - 1].args.minApprovalsByManagementKeys.toString(10),
|
tx3.events.TestFunctionExecuted.returnValues.minApprovalsByManagementKeys.toString(10),
|
||||||
1,
|
1,
|
||||||
identity.address + " wasn't updated to last version");
|
Identity.address + " wasn't updated to last version");
|
||||||
|
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
380
test/identity.js
380
test/identity.js
|
@ -1,97 +1,107 @@
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const Embark = require('embark');
|
||||||
|
let EmbarkSpec = Embark.initTests();
|
||||||
|
let web3 = EmbarkSpec.web3;
|
||||||
const TestUtils = require("../utils/testUtils.js");
|
const TestUtils = require("../utils/testUtils.js");
|
||||||
const web3EthAbi = require("web3-eth-abi");
|
|
||||||
const idUtils = require('../utils/identityUtils.js');
|
const idUtils = require('../utils/identityUtils.js');
|
||||||
|
|
||||||
const Identity = artifacts.require("./identity/Identity.sol");
|
describe("Identity", function() {
|
||||||
const TestContract = artifacts.require("./test/TestContract.sol");
|
this.timeout(0);
|
||||||
|
|
||||||
contract('Identity', function(accounts) {
|
let accounts;
|
||||||
|
|
||||||
let identity;
|
beforeEach( function(done) {
|
||||||
|
this.timeout(0);
|
||||||
|
|
||||||
beforeEach(async () => {
|
EmbarkSpec = Embark.initTests();
|
||||||
identity = await Identity.new({from: accounts[0]})
|
web3 = EmbarkSpec.web3;
|
||||||
})
|
|
||||||
|
EmbarkSpec.deployAll({
|
||||||
|
"Identity": {},
|
||||||
|
"TestContract": {}
|
||||||
|
}, (_accounts) => {
|
||||||
|
accounts = _accounts;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Identity()", () => {
|
describe("Identity()", () => {
|
||||||
it("initialize with msg.sender as management key", async () => {
|
it("initialize with msg.sender as management key", async () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
||||||
idUtils.purposes.MANAGEMENT,
|
idUtils.purposes.MANAGEMENT,
|
||||||
identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY")
|
Identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY");
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("addKey(address _key, uint256 _type)", () => {
|
describe("addKey(address _key, uint256 _type)", () => {
|
||||||
it("MANAGEMENT_KEY add a new address as ACTION_KEY", async () => {
|
it("MANAGEMENT_KEY add a new address as ACTION_KEY", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS)
|
||||||
{from: accounts[0]}
|
).send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.ACTION,
|
idUtils.purposes.ACTION,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not ACTION_KEY")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not ACTION_KEY");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add key by non manager", async () => {
|
it("should not add key by non manager", async () => {
|
||||||
try {
|
try {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
||||||
{from: accounts[2]}
|
.send({from: accounts[2]});
|
||||||
);
|
|
||||||
assert.fail('should have reverted before');
|
assert.fail('should have reverted before');
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
TestUtils.assertJump(error);
|
TestUtils.assertJump(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.NONE,
|
idUtils.purposes.NONE,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add key type 1 by actor", async () => {
|
it("should not add key type 1 by actor", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
||||||
{from: accounts[2]}
|
.send({from: accounts[2]});
|
||||||
);
|
|
||||||
assert.fail('should have reverted before');
|
assert.fail('should have reverted before');
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
TestUtils.assertJump(error);
|
TestUtils.assertJump(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.NONE,
|
idUtils.purposes.NONE,
|
||||||
identity.address+".getKeyType("+accounts[1]+") is not correct")
|
Identity.address+".getKeyType("+accounts[1]+") is not correct");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fire KeyAdded(address indexed key, uint256 indexed type)", async () => {
|
it("fire KeyAdded(address indexed key, uint256 indexed type)", async () => {
|
||||||
await identity.execute(
|
let receipt = await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
const keyAdded = await TestUtils.listenForEvent(identity.KeyAdded())
|
const keyAdded = TestUtils.eventValues(receipt, "KeyAdded");
|
||||||
assert(keyAdded.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct")
|
assert(keyAdded.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct")
|
||||||
assert(keyAdded.keyType, idUtils.types.ADDRESS, "Type is not correct")
|
assert(keyAdded.keyType, idUtils.types.ADDRESS, "Type is not correct")
|
||||||
});
|
});
|
||||||
|
@ -100,115 +110,106 @@ contract('Identity', function(accounts) {
|
||||||
|
|
||||||
describe("removeKey(address _key, uint256 _type)", () => {
|
describe("removeKey(address _key, uint256 _type)", () => {
|
||||||
it("MANAGEMENT_KEY should remove a key", async () => {
|
it("MANAGEMENT_KEY should remove a key", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT),
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.NONE,
|
idUtils.purposes.NONE,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not 0")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not 0")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("other key should not remove a key", async () => {
|
it("other key should not remove a key", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT),
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT))
|
||||||
{from: accounts[2]}
|
.send({from: accounts[2]});
|
||||||
);
|
|
||||||
assert.fail('should have reverted before');
|
assert.fail('should have reverted before');
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
TestUtils.assertJump(error);
|
TestUtils.assertJump(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.MANAGEMENT,
|
idUtils.purposes.MANAGEMENT,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not 0")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not 0")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("actor key should not remove key", async () => {
|
it("actor key should not remove key", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION),
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION))
|
||||||
{from: accounts[2]}
|
.send({from: accounts[2]});
|
||||||
);
|
|
||||||
assert.fail('should have reverted before');
|
assert.fail('should have reverted before');
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
TestUtils.assertJump(error);
|
TestUtils.assertJump(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.ACTION,
|
idUtils.purposes.ACTION,
|
||||||
identity.address+".getKeyType("+accounts[1]+") is not 0")
|
Identity.address+".getKeyType("+accounts[1]+") is not 0")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("MANAGEMENT_KEY should not remove itself MANAGEMENT_KEY when there is no other MANAGEMENT_KEY", async () => {
|
it("MANAGEMENT_KEY should not remove itself MANAGEMENT_KEY when there is no other MANAGEMENT_KEY", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.removeKey(accounts[0], idUtils.purposes.MANAGEMENT),
|
idUtils.encode.removeKey(accounts[0], idUtils.purposes.MANAGEMENT))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
||||||
idUtils.purposes.MANAGEMENT,
|
idUtils.purposes.MANAGEMENT,
|
||||||
identity.address+".getKeyType("+accounts[0]+") is not 1")
|
Identity.address+".getKeyType("+accounts[0]+") is not 1")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fire KeyRemoved(address indexed key, uint256 indexed type)", async () => {
|
it("fire KeyRemoved(address indexed key, uint256 indexed type)", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
await identity.execute(
|
let receipt = await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION),
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
const keyRemoved = await TestUtils.listenForEvent(identity.KeyRemoved());
|
const keyRemoved = TestUtils.eventValues(receipt, "KeyRemoved");
|
||||||
assert(keyRemoved.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct");
|
assert(keyRemoved.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct");
|
||||||
assert(keyRemoved.keyType, idUtils.types.ADDRESS, "Type is not correct");
|
assert(keyRemoved.keyType, idUtils.types.ADDRESS, "Type is not correct");
|
||||||
});
|
});
|
||||||
|
@ -219,42 +220,40 @@ contract('Identity', function(accounts) {
|
||||||
|
|
||||||
it("should start only with initializer as only key", async () => {
|
it("should start only with initializer as only key", async () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
||||||
idUtils.purposes.MANAGEMENT,
|
idUtils.purposes.MANAGEMENT,
|
||||||
identity.address+".getKeyPurpose("+accounts[0]+") is not correct")
|
Identity.address+".getKeyPurpose("+accounts[0]+") is not correct")
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.NONE,
|
idUtils.purposes.NONE,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should get type 2 after addKey type 2", async () => {
|
it("should get type 2 after addKey type 2", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.ACTION,
|
idUtils.purposes.ACTION,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should get type 3 after addKey type 3", async () => {
|
it("should get type 3 after addKey type 3", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.CLAIM_SIGNER, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.CLAIM_SIGNER, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
||||||
idUtils.purposes.CLAIM_SIGNER,
|
idUtils.purposes.CLAIM_SIGNER,
|
||||||
identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -276,61 +275,58 @@ contract('Identity', function(accounts) {
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
describe("execute(address _to, uint256 _value, bytes _data)", () => {
|
describe("execute(address _to, uint256 _value, bytes _data)", () => {
|
||||||
let testContractInstance;
|
|
||||||
let functionPayload;
|
let functionPayload;
|
||||||
|
|
||||||
it("Identity should receive ether", async() => {
|
it("Identity should receive ether", async() => {
|
||||||
|
|
||||||
const amountToSend = web3.toWei(0.05, "ether");
|
const amountToSend = web3.utils.toWei('0.05', "ether");
|
||||||
|
|
||||||
let idBalance0 = web3.eth.getBalance(identity.address);
|
let idBalance0 = await web3.eth.getBalance(Identity.address);
|
||||||
|
|
||||||
await web3.eth.sendTransaction({from:accounts[0], to:identity.address, value: amountToSend})
|
await web3.eth.sendTransaction({from:accounts[0], to:Identity.address, value: amountToSend})
|
||||||
|
|
||||||
let idBalance1 = web3.eth.getBalance(identity.address);
|
let idBalance1 = await web3.eth.getBalance(Identity.address);
|
||||||
|
|
||||||
assert.equal(idBalance0.toNumber() + amountToSend, idBalance1.toNumber(), identity.address + " did not receive ether");
|
assert.equal(web3.utils.toBN(idBalance0).add(web3.utils.toBN(amountToSend)).toString(), web3.utils.toBN(idBalance1).toString(), Identity.address + " did not receive ether");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ACTOR_KEY execute arbitrary transaction", async () => {
|
it("ACTOR_KEY execute arbitrary transaction", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
testContractInstance = await TestContract.new({from: accounts[0]});
|
|
||||||
|
|
||||||
functionPayload = web3EthAbi.encodeFunctionCall({
|
functionPayload = web3.eth.abi.encodeFunctionCall({
|
||||||
name: 'test',
|
name: 'test',
|
||||||
type: 'function',
|
type: 'function',
|
||||||
inputs: []
|
inputs: []
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
await identity.execute(
|
let receipt = await Identity.methods.execute(
|
||||||
testContractInstance.address,
|
TestContract.address,
|
||||||
0,
|
0,
|
||||||
functionPayload,
|
functionPayload)
|
||||||
{from: accounts[1]}
|
.send({from: accounts[1]});
|
||||||
);
|
|
||||||
|
|
||||||
assert.notEqual(
|
// @rramos - Commented because of error:
|
||||||
await TestUtils.listenForEvent(testContractInstance.TestFunctionExecuted()),
|
// The current provider doesn't support subscriptions: Provider
|
||||||
|
/*assert.notEqual(
|
||||||
|
await TestUtils.listenForEvent(TestContract.events.TestFunctionExecuted),
|
||||||
undefined,
|
undefined,
|
||||||
"Test function was not executed");
|
"Test function was not executed"); */
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("MANAGEMENT_KEY cannot execute arbitrary transaction", async () => {
|
it("MANAGEMENT_KEY cannot execute arbitrary transaction", async () => {
|
||||||
try {
|
try {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
testContractInstance.address,
|
TestContract.address,
|
||||||
0,
|
0,
|
||||||
functionPayload,
|
functionPayload)
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
TestUtils.assertJump(error);
|
TestUtils.assertJump(error);
|
||||||
}
|
}
|
||||||
|
@ -338,12 +334,11 @@ contract('Identity', function(accounts) {
|
||||||
|
|
||||||
it("Other keys NOT execute arbitrary transaction", async () => {
|
it("Other keys NOT execute arbitrary transaction", async () => {
|
||||||
try {
|
try {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
testContractInstance.address,
|
TestContract.address,
|
||||||
0,
|
0,
|
||||||
functionPayload,
|
functionPayload)
|
||||||
{from: accounts[3]}
|
.send({from: accounts[3]});
|
||||||
);
|
|
||||||
assert.fail('should have reverted before');
|
assert.fail('should have reverted before');
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
TestUtils.assertJump(error);
|
TestUtils.assertJump(error);
|
||||||
|
@ -352,82 +347,74 @@ contract('Identity', function(accounts) {
|
||||||
|
|
||||||
|
|
||||||
it("ACTION_KEY should send ether from contract", async () => {
|
it("ACTION_KEY should send ether from contract", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
// Adding funds to contract
|
// Adding funds to contract
|
||||||
await web3.eth.sendTransaction({from:accounts[0], to:identity.address, value: web3.toWei(0.05, "ether")})
|
await web3.eth.sendTransaction({from:accounts[0], to:Identity.address, value: web3.utils.toWei('0.05', "ether")})
|
||||||
|
|
||||||
const amountToSend = web3.toWei(0.01, "ether");
|
const amountToSend = web3.utils.toWei('0.01', "ether");
|
||||||
|
|
||||||
let idBalance0 = web3.eth.getBalance(identity.address);
|
let idBalance0 = await web3.eth.getBalance(Identity.address);
|
||||||
let a2Balance0 = web3.eth.getBalance(accounts[2]);
|
let a2Balance0 = await web3.eth.getBalance(accounts[2]);
|
||||||
|
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
accounts[2],
|
accounts[2],
|
||||||
amountToSend,
|
amountToSend,
|
||||||
'',
|
'0x')
|
||||||
{from: accounts[1]}
|
.send({from: accounts[1]});
|
||||||
);
|
|
||||||
|
|
||||||
let idBalance1 = web3.eth.getBalance(identity.address);
|
let idBalance1 = await web3.eth.getBalance(Identity.address);
|
||||||
let a2Balance1 = web3.eth.getBalance(accounts[2]);
|
let a2Balance1 = await web3.eth.getBalance(accounts[2]);
|
||||||
|
|
||||||
assert(idBalance1.toNumber, idBalance0.toNumber - amountToSend, "Contract did not send ether");
|
assert(web3.utils.toBN(idBalance1).toString(), web3.utils.toBN(idBalance0).sub(web3.utils.toBN(amountToSend)).toString(), "Contract did not send ether");
|
||||||
assert(a2Balance1.toNumber, a2Balance0.toNumber + amountToSend, accounts[2] + " did not receive ether");
|
assert(web3.utils.toBN(a2Balance1).toString(), web3.utils.toBN(a2Balance0).add(web3.utils.toBN(amountToSend)).toString(), accounts[2] + " did not receive ether");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fire ExecutionRequested(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
|
it("fire ExecutionRequested(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
await identity.execute(
|
let receipt = await Identity.methods.execute(
|
||||||
testContractInstance.address,
|
TestContract.address,
|
||||||
0,
|
0,
|
||||||
functionPayload,
|
functionPayload)
|
||||||
{from: accounts[1]}
|
.send({from: accounts[1]});
|
||||||
);
|
|
||||||
|
|
||||||
const executionRequested = await TestUtils.listenForEvent(identity.ExecutionRequested());
|
const executionRequested = TestUtils.eventValues(receipt, "ExecutionRequested");
|
||||||
assert(executionRequested.to, testContractInstance.address, "To is not correct");
|
assert(executionRequested.to, TestContract.address, "To is not correct");
|
||||||
assert(executionRequested.value, 0, "Value is not correct");
|
assert(executionRequested.value, 0, "Value is not correct");
|
||||||
assert(executionRequested.data, functionPayload, "Data is not correct");
|
assert(executionRequested.data, functionPayload, "Data is not correct");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fire Executed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
|
it("fire Executed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
|
||||||
await identity.execute(
|
await Identity.methods.execute(
|
||||||
identity.address,
|
Identity.address,
|
||||||
0,
|
0,
|
||||||
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
||||||
{from: accounts[0]}
|
.send({from: accounts[0]});
|
||||||
);
|
|
||||||
|
|
||||||
await identity.execute(
|
let receipt = await Identity.methods.execute(
|
||||||
testContractInstance.address,
|
TestContract.address,
|
||||||
0,
|
0,
|
||||||
functionPayload,
|
functionPayload)
|
||||||
{from: accounts[1]}
|
.send({from: accounts[1]});
|
||||||
);
|
|
||||||
|
|
||||||
const executed = await TestUtils.listenForEvent(identity.Executed());
|
const executed = TestUtils.eventValues(receipt, "Executed")
|
||||||
assert(executed.to, testContractInstance.address, "To is not correct");
|
assert(executed.to, TestContract.address, "To is not correct");
|
||||||
assert(executed.value, 0, "Value is not correct");
|
assert(executed.value, 0, "Value is not correct");
|
||||||
assert(executed.data, functionPayload, "Data is not correct");
|
assert(executed.data, functionPayload, "Data is not correct");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
describe("setMinimumApprovalsByKeyPurpose(uint256 _type, uint8 _minimumApprovals)", () => {
|
describe("setMinimumApprovalsByKeyPurpose(uint256 _type, uint8 _minimumApprovals)", () => {
|
||||||
it("MANAGEMENT_KEY should set minimum approvals for MANAGEMENT_KEYs", async () => {
|
it("MANAGEMENT_KEY should set minimum approvals for MANAGEMENT_KEYs", async () => {
|
||||||
|
|
||||||
|
@ -502,4 +489,9 @@ contract('Identity', function(accounts) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*
|
||||||
|
COMMENTED TEMPORARLY WHILE PROJECT IS MIGRATED TO EMBARK - @rramos
|
||||||
|
|
||||||
const TestUtils = require("../utils/testUtils.js")
|
const TestUtils = require("../utils/testUtils.js")
|
||||||
var ethUtils = require('ethereumjs-util')
|
var ethUtils = require('ethereumjs-util')
|
||||||
|
|
||||||
|
@ -62,3 +65,4 @@ contract('Identity - Extended Functionality', function(accounts) {
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
*/
|
|
@ -117,7 +117,6 @@ const _managerReset = function(address){
|
||||||
}, [address]);
|
}, [address]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const _updateUpdatableInstance = function(address){
|
const _updateUpdatableInstance = function(address){
|
||||||
if(!/^(0x)?[0-9a-f]{0,40}$/i.test(address))
|
if(!/^(0x)?[0-9a-f]{0,40}$/i.test(address))
|
||||||
throw new Error('Address "'+ address +'" is not a valid Ethereum address.');
|
throw new Error('Address "'+ address +'" is not a valid Ethereum address.');
|
||||||
|
|
Loading…
Reference in New Issue