Commenting tests while they're updated for Embark and Web3 1.0.0

This commit is contained in:
Richard Ramos 2018-03-13 10:13:31 -04:00
parent 9c2cbe28f7
commit 3a0889237c
3 changed files with 118 additions and 110 deletions

View File

@ -1,3 +1,7 @@
/*
COMMENTED TEMPORARLY WHILE PROJECT IS MIGRATED TO EMBARK - @rramos
const TestUtils = require("../utils/testUtils.js")
const idUtils = require("../utils/identityUtils.js")
const web3EthAbi = require("web3-eth-abi");
@ -82,4 +86,6 @@ contract('IdentityFactory', function(accounts) {
})
});
});
});
*/

View File

@ -1,97 +1,102 @@
const assert = require('assert');
const Embark = require('embark');
const EmbarkSpec = Embark.initTests();
const web3 = EmbarkSpec.web3;
const TestUtils = require("../utils/testUtils.js");
const web3EthAbi = require("web3-eth-abi");
const idUtils = require('../utils/identityUtils.js');
const Identity = artifacts.require("./identity/Identity.sol");
const TestContract = artifacts.require("./test/TestContract.sol");
describe("Identity", function() {
this.timeout(0);
contract('Identity', function(accounts) {
let accounts;
let identity;
beforeEach(async () => {
identity = await Identity.new({from: accounts[0]})
})
beforeEach( function(done) {
this.timeout(0);
EmbarkSpec.deployAll({ "Identity": {}}, (_accounts) => {
accounts = _accounts;
done();
});
});
describe("Identity()", () => {
it("initialize with msg.sender as management key", async () => {
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
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)", () => {
it("MANAGEMENT_KEY add a new address as ACTION_KEY", async () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS)
).send({from: accounts[0]});
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
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 () => {
try {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
{from: accounts[2]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
.send({from: accounts[2]});
assert.fail('should have reverted before');
} catch(error) {
TestUtils.assertJump(error);
}
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
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 () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
.send({from: accounts[0]});
try {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
{from: accounts[2]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
.send({from: accounts[2]});
assert.fail('should have reverted before');
} catch(error) {
TestUtils.assertJump(error);
}
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
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 () => {
await identity.execute(
identity.address,
let receipt = await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
.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.keyType, idUtils.types.ADDRESS, "Type is not correct")
});
@ -100,121 +105,112 @@ contract('Identity', function(accounts) {
describe("removeKey(address _key, uint256 _type)", () => {
it("MANAGEMENT_KEY should remove a key", async () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
.send({from: accounts[0]});
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT),
{from: accounts[0]}
);
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT))
.send({from: accounts[0]});
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
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 () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.MANAGEMENT, idUtils.types.ADDRESS))
.send({from: accounts[0]});
try {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT),
{from: accounts[2]}
);
idUtils.encode.removeKey(accounts[1], idUtils.purposes.MANAGEMENT))
.send({from: accounts[2]});
assert.fail('should have reverted before');
} catch(error) {
TestUtils.assertJump(error);
}
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
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 () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
.send({from: accounts[0]});
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[2], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
.send({from: accounts[0]});
try {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION),
{from: accounts[2]}
);
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION))
.send({from: accounts[2]});
assert.fail('should have reverted before');
} catch(error) {
TestUtils.assertJump(error);
}
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[1])).call(),
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 () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.removeKey(accounts[0], idUtils.purposes.MANAGEMENT),
{from: accounts[0]}
);
idUtils.encode.removeKey(accounts[0], idUtils.purposes.MANAGEMENT))
.send({from: accounts[0]});
assert.equal(
await identity.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])),
await Identity.methods.getKeyPurpose(TestUtils.addressToBytes32(accounts[0])).call(),
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 () => {
await identity.execute(
identity.address,
await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS),
{from: accounts[0]}
);
idUtils.encode.addKey(accounts[1], idUtils.purposes.ACTION, idUtils.types.ADDRESS))
.send({from: accounts[0]});
await identity.execute(
identity.address,
let receipt = await Identity.methods.execute(
Identity.address,
0,
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION),
{from: accounts[0]}
);
idUtils.encode.removeKey(accounts[1], idUtils.purposes.ACTION))
.send({from: accounts[0]});
const keyRemoved = await TestUtils.listenForEvent(identity.KeyRemoved());
const keyRemoved = await TestUtils.eventValues(receipt, "KeyRemoved");
assert(keyRemoved.key, TestUtils.addressToBytes32(accounts[1]), "Key is not correct");
assert(keyRemoved.keyType, idUtils.types.ADDRESS, "Type is not correct");
});
});
/*
describe("getKeyPurpose(address _key)", () => {
it("should start only with initializer as only key", async () => {
@ -274,9 +270,8 @@ contract('Identity', function(accounts) {
});
});
*/
*/
/*
describe("execute(address _to, uint256 _value, bytes _data)", () => {
let testContractInstance;
let functionPayload;
@ -422,12 +417,10 @@ contract('Identity', function(accounts) {
assert(executed.value, 0, "Value is not correct");
assert(executed.data, functionPayload, "Data is not correct");
});
});
/*
/*
describe("setMinimumApprovalsByKeyPurpose(uint256 _type, uint8 _minimumApprovals)", () => {
it("MANAGEMENT_KEY should set minimum approvals for MANAGEMENT_KEYs", async () => {
@ -501,5 +494,10 @@ contract('Identity', function(accounts) {
});
});
*/
*/
});

View File

@ -1,3 +1,6 @@
/*
COMMENTED TEMPORARLY WHILE PROJECT IS MIGRATED TO EMBARK - @rramos
const TestUtils = require("../utils/testUtils.js")
var ethUtils = require('ethereumjs-util')
@ -62,3 +65,4 @@ contract('Identity - Extended Functionality', function(accounts) {
});
*/