2018-03-13 14:13:31 +00:00
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const Embark = require('embark');
|
2018-03-13 23:35:30 +00:00
|
|
|
let EmbarkSpec = Embark.initTests();
|
2018-03-14 14:31:12 +00:00
|
|
|
// const web3 = EmbarkSpec.web3;
|
2018-03-01 20:07:32 +00:00
|
|
|
const TestUtils = require("../utils/testUtils.js");
|
2018-03-01 15:42:44 +00:00
|
|
|
const idUtils = require('../utils/identityUtils.js');
|
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
describe("Identity", function() {
|
|
|
|
this.timeout(0);
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
let accounts;
|
2018-02-21 21:17:38 +00:00
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
beforeEach( function(done) {
|
|
|
|
this.timeout(0);
|
|
|
|
|
2018-03-13 23:35:30 +00:00
|
|
|
EmbarkSpec = Embark.initTests();
|
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
EmbarkSpec.deployAll({
|
|
|
|
"Identity": {},
|
|
|
|
"TestContract": {}
|
|
|
|
}, (_accounts) => {
|
2018-03-13 14:13:31 +00:00
|
|
|
accounts = _accounts;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-11-15 07:24:10 +00:00
|
|
|
|
|
|
|
describe("Identity()", () => {
|
|
|
|
it("initialize with msg.sender as management key", async () => {
|
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.MANAGEMENT,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address + ".getKeyPurpose("+accounts[0]+") is not MANAGEMENT_KEY");
|
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("addKey(address _key, uint256 _type)", () => {
|
|
|
|
it("MANAGEMENT_KEY add a new address as ACTION_KEY", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS)
|
|
|
|
).send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.ACTION,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not ACTION_KEY");
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should not add key by non manager", async () => {
|
|
|
|
try {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[2]});
|
2018-03-01 15:42:44 +00:00
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
TestUtils.assertJump(error);
|
2017-11-15 07:24:10 +00:00
|
|
|
}
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.NONE,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct");
|
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
2018-03-01 15:42:44 +00:00
|
|
|
it("should not add key type 1 by actor", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
try {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-02 19:00:46 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[2]});
|
2018-03-02 19:00:46 +00:00
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
TestUtils.assertJump(error);
|
|
|
|
}
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.NONE,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyType("+accounts[1]+") is not correct");
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("fire KeyAdded(address indexed key, uint256 indexed type)", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
let receipt = await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
const keyAdded = TestUtils.eventValues(receipt, "KeyAdded");
|
2018-02-21 21:17:38 +00:00
|
|
|
assert(keyAdded.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct")
|
2018-03-01 15:42:44 +00:00
|
|
|
assert(keyAdded.keyType, idUtils.types.ADDRESS, "Type is not correct")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("removeKey(address _key, uint256 _type)", () => {
|
2018-03-01 15:42:44 +00:00
|
|
|
it("MANAGEMENT_KEY should remove a key", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.NONE,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not 0")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
it("other key should not remove a key", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-01 15:42:44 +00:00
|
|
|
try {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT))
|
|
|
|
.send({from: accounts[2]});
|
2018-03-01 15:42:44 +00:00
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
TestUtils.assertJump(error);
|
2017-11-15 07:24:10 +00:00
|
|
|
}
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.MANAGEMENT,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not 0")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("actor key should not remove key", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
try {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-02 19:00:46 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION))
|
|
|
|
.send({from: accounts[2]});
|
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
TestUtils.assertJump(error);
|
|
|
|
}
|
2017-11-15 07:24:10 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.ACTION,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyType("+accounts[1]+") is not 0")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("MANAGEMENT_KEY should not remove itself MANAGEMENT_KEY when there is no other MANAGEMENT_KEY", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.removeKey(accounts[0], idUtils.purposes.MANAGEMENT))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
2018-03-01 15:42:44 +00:00
|
|
|
idUtils.purposes.MANAGEMENT,
|
2018-03-13 14:13:31 +00:00
|
|
|
Identity.address+".getKeyType("+accounts[0]+") is not 1")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("fire KeyRemoved(address indexed key, uint256 indexed type)", async () => {
|
2018-03-13 14:13:31 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
let receipt = await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 15:42:44 +00:00
|
|
|
0,
|
2018-03-13 14:13:31 +00:00
|
|
|
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 15:42:44 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
const keyRemoved = TestUtils.eventValues(receipt, "KeyRemoved");
|
2018-03-01 15:42:44 +00:00
|
|
|
assert(keyRemoved.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct");
|
|
|
|
assert(keyRemoved.keyType, idUtils.types.ADDRESS, "Type is not correct");
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
|
2018-02-21 21:17:38 +00:00
|
|
|
describe("getKeyPurpose(address _key)", () => {
|
2017-11-15 07:24:10 +00:00
|
|
|
|
|
|
|
it("should start only with initializer as only key", async () => {
|
|
|
|
assert.equal(
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
|
2018-03-01 20:07:32 +00:00
|
|
|
idUtils.purposes.MANAGEMENT,
|
2018-03-14 14:31:12 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[0]+") is not correct")
|
2017-11-15 07:24:10 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 20:07:32 +00:00
|
|
|
idUtils.purposes.NONE,
|
2018-03-14 14:31:12 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should get type 2 after addKey type 2", async () => {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 20:07:32 +00:00
|
|
|
idUtils.purposes.ACTION,
|
2018-03-14 14:31:12 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
2018-03-01 20:07:32 +00:00
|
|
|
it("should get type 3 after addKey type 3", async () => {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.CLAIM_SIGNER, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
assert.equal(
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
|
2018-03-01 20:07:32 +00:00
|
|
|
idUtils.purposes.CLAIM_SIGNER,
|
2018-03-14 14:31:12 +00:00
|
|
|
Identity.address+".getKeyPurpose("+accounts[1]+") is not correct")
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-01 20:07:32 +00:00
|
|
|
/*
|
2017-11-15 07:24:10 +00:00
|
|
|
describe("getKeysByType(uint256 _type)", () => {
|
|
|
|
|
|
|
|
it("at initialization", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("after addKey", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("after removeKey", async () => {
|
|
|
|
|
|
|
|
});
|
2018-03-01 20:07:32 +00:00
|
|
|
});
|
2018-03-13 14:13:31 +00:00
|
|
|
*/
|
2018-03-14 14:31:12 +00:00
|
|
|
|
2018-03-01 20:07:32 +00:00
|
|
|
describe("execute(address _to, uint256 _value, bytes _data)", () => {
|
|
|
|
let functionPayload;
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-01 20:07:32 +00:00
|
|
|
it("Identity should receive ether", async() => {
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
const amountToSend = web3.utils.toWei('0.05', "ether");
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let idBalance0 = web3.eth.getBalance(Identity.address);
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
await web3.eth.sendTransaction({from:accounts[0], to:Identity.address, value: amountToSend})
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let idBalance1 = web3.eth.getBalance(Identity.address);
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
assert.equal(idBalance0.toNumber() + amountToSend, idBalance1.toNumber(), Identity.address + " did not receive ether");
|
2018-03-01 20:07:32 +00:00
|
|
|
});
|
2018-03-14 14:31:12 +00:00
|
|
|
/*
|
2017-11-15 07:24:10 +00:00
|
|
|
it("ACTOR_KEY execute arbitrary transaction", async () => {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
|
|
|
|
functionPayload = web3.eth.abi.encodeFunctionCall({
|
2018-03-01 20:07:32 +00:00
|
|
|
name: 'test',
|
|
|
|
type: 'function',
|
|
|
|
inputs: []
|
|
|
|
}, []);
|
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let receipt = await Identity.methods.execute(
|
|
|
|
TestContract.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
functionPayload)
|
|
|
|
.send({from: accounts[1]});
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
assert.notEqual(
|
|
|
|
await TestUtils.listenForEvent(TestContract.event.TestFunctionExecuted),
|
|
|
|
undefined,
|
|
|
|
"Test function was not executed");
|
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
2018-03-14 14:31:12 +00:00
|
|
|
*/
|
2018-03-02 19:00:46 +00:00
|
|
|
it("MANAGEMENT_KEY cannot execute arbitrary transaction", async () => {
|
|
|
|
try {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
TestContract.address,
|
2018-03-02 19:00:46 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
functionPayload)
|
|
|
|
.send({from: accounts[0]});
|
2018-03-02 19:00:46 +00:00
|
|
|
} catch(error) {
|
|
|
|
TestUtils.assertJump(error);
|
|
|
|
}
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Other keys NOT execute arbitrary transaction", async () => {
|
2018-03-01 20:07:32 +00:00
|
|
|
try {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
TestContract.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
functionPayload)
|
|
|
|
.send({from: accounts[3]});
|
2018-03-01 20:07:32 +00:00
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
TestUtils.assertJump(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-03-02 19:00:46 +00:00
|
|
|
it("ACTION_KEY should send ether from contract", async () => {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-02 19:00:46 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-01 20:07:32 +00:00
|
|
|
|
|
|
|
// Adding funds to contract
|
2018-03-14 14:31:12 +00:00
|
|
|
await web3.eth.sendTransaction({from:accounts[0], to:Identity.address, value: web3.utils.toWei('0.05', "ether")})
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
const amountToSend = web3.utils.toWei('0.01', "ether");
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let idBalance0 = web3.eth.getBalance(Identity.address);
|
2018-03-02 19:00:46 +00:00
|
|
|
let a2Balance0 = web3.eth.getBalance(accounts[2]);
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
2018-03-02 19:00:46 +00:00
|
|
|
accounts[2],
|
2018-03-01 20:07:32 +00:00
|
|
|
amountToSend,
|
2018-03-14 14:31:12 +00:00
|
|
|
'')
|
|
|
|
.send({from: accounts[1]});
|
2018-03-01 20:07:32 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let idBalance1 = web3.eth.getBalance(Identity.address);
|
2018-03-02 19:00:46 +00:00
|
|
|
let a2Balance1 = web3.eth.getBalance(accounts[2]);
|
2018-03-01 20:07:32 +00:00
|
|
|
|
|
|
|
assert(idBalance1.toNumber, idBalance0.toNumber - amountToSend, "Contract did not send ether");
|
2018-03-02 19:00:46 +00:00
|
|
|
assert(a2Balance1.toNumber, a2Balance0.toNumber + amountToSend, accounts[2] + " did not receive ether");
|
2018-03-01 20:07:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("fire ExecutionRequested(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-02 19:00:46 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-02 19:00:46 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let receipt = await Identity.methods.execute(
|
|
|
|
TestContract.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
functionPayload)
|
|
|
|
.send({from: accounts[1]});
|
|
|
|
|
|
|
|
const executionRequested = TestUtils.eventValues(receipt, "ExecutionRequested");
|
|
|
|
assert(executionRequested.to, TestContract.address, "To is not correct");
|
2018-03-01 20:07:32 +00:00
|
|
|
assert(executionRequested.value, 0, "Value is not correct");
|
|
|
|
assert(executionRequested.data, functionPayload, "Data is not correct");
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("fire Executed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data)", async () => {
|
2018-03-14 14:31:12 +00:00
|
|
|
await Identity.methods.execute(
|
|
|
|
Identity.address,
|
2018-03-02 19:00:46 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
|
|
|
|
.send({from: accounts[0]});
|
2018-03-02 19:00:46 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
let receipt = await Identity.methods.execute(
|
|
|
|
TestContract.address,
|
2018-03-01 20:07:32 +00:00
|
|
|
0,
|
2018-03-14 14:31:12 +00:00
|
|
|
functionPayload)
|
|
|
|
.send({from: accounts[1]});
|
2017-11-15 07:24:10 +00:00
|
|
|
|
2018-03-14 14:31:12 +00:00
|
|
|
const executed = TestUtils.eventValues(receipt, "Executed")
|
|
|
|
assert(executed.to, TestContract.address, "To is not correct");
|
2018-03-01 20:07:32 +00:00
|
|
|
assert(executed.value, 0, "Value is not correct");
|
|
|
|
assert(executed.data, functionPayload, "Data is not correct");
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-03-13 14:13:31 +00:00
|
|
|
/*
|
2018-03-02 19:00:46 +00:00
|
|
|
describe("setMinimumApprovalsByKeyPurpose(uint256 _type, uint8 _minimumApprovals)", () => {
|
2018-03-01 20:07:32 +00:00
|
|
|
it("MANAGEMENT_KEY should set minimum approvals for MANAGEMENT_KEYs", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("MANAGEMENT_KEY should set minimum approvals for ACTION_KEYs", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("ACTION_KEY should not be able to set minimum approvals", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Other keys should not be able to set minimum approvals", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
describe("approve(bytes32 _id, bool _approve)", () => {
|
|
|
|
|
|
|
|
it("MANAGEMENT_KEY should approve a claim", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("MANAGEMENT_KEY should approve a transaction", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-01 20:07:32 +00:00
|
|
|
it("2 out of 3 MANAGEMENT_KEY should approve a transaction and execute it", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
it("fire Approved(uint256 indexed executionId, bool approved)", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("getClaim(bytes32 _claimId)", () => {
|
|
|
|
|
|
|
|
it("Returns a claim by ID.", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("getClaimIdsByType(uint256 _claimType)", () => {
|
|
|
|
it("Returns an array of claim IDs by type.", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("addClaim(uint256 _claimType, address issuer, uint256 signatureType, bytes _signature, bytes _data, string _uri)", () => {
|
|
|
|
it("Requests the ADDITION of a claim from an issuer", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Requests the CHANGE of a claim from an issuer", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("removeClaim(bytes32 _claimId)", () => {
|
|
|
|
it("Requests the DELETION of a claim from an issuer", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Requests the DELETION of a claim from identity", async () => {
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2018-03-13 14:13:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-11-15 07:24:10 +00:00
|
|
|
});
|
2018-03-13 14:13:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|