2018-08-08 07:02:03 -03:00
|
|
|
|
const utils = require("../utils/testUtils")
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
const DelegationFactory = require('Embark/contracts/DelegationFactory');
|
2019-03-25 05:15:23 -03:00
|
|
|
|
const DelegationBase = require('Embark/contracts/DelegationBase');
|
2018-08-08 07:02:03 -03:00
|
|
|
|
|
|
|
|
|
config({
|
|
|
|
|
contracts: {
|
2019-02-26 01:30:02 -03:00
|
|
|
|
"DelegationBase": {
|
2019-02-27 07:47:53 -03:00
|
|
|
|
"args": [ utils.zeroAddress ]
|
|
|
|
|
},
|
|
|
|
|
"DelegationInit": {
|
2018-08-08 07:02:03 -03:00
|
|
|
|
},
|
2019-02-27 07:47:53 -03:00
|
|
|
|
"DelegationFactory": {
|
|
|
|
|
"args": ["$DelegationBase", "$DelegationInit", utils.zeroAddress]
|
2018-08-08 07:02:03 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-20 22:01:06 -03:00
|
|
|
|
/**
|
|
|
|
|
* Delegations: Root, Sticker Market, ENS Usernames, Version Listings
|
|
|
|
|
* Functions:
|
|
|
|
|
* - Root
|
|
|
|
|
* - Sticker Market
|
|
|
|
|
* - change controller : Absolute Majority
|
|
|
|
|
* - change rates : Simple Majority
|
|
|
|
|
* - purgconte pack : Simple Majority
|
|
|
|
|
* - ENS Usernames
|
|
|
|
|
* - change controller : Simple Majority
|
|
|
|
|
* - migrate registry :
|
|
|
|
|
* - change price
|
|
|
|
|
* - Version Listing
|
|
|
|
|
* - change developer address
|
|
|
|
|
* - remove version
|
|
|
|
|
* - add release category (android,ios,linux,etc)
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-26 01:30:02 -03:00
|
|
|
|
contract("DelegationBase", function() {
|
2018-08-08 07:02:03 -03:00
|
|
|
|
this.timeout(0);
|
2019-02-27 07:47:53 -03:00
|
|
|
|
var defaultDelegate;
|
2018-08-08 07:02:03 -03:00
|
|
|
|
var accounts;
|
2019-02-27 07:47:53 -03:00
|
|
|
|
var RootDelegation;
|
|
|
|
|
var ChildDelegation;
|
2018-08-08 07:02:03 -03:00
|
|
|
|
before(function(done) {
|
|
|
|
|
web3.eth.getAccounts().then(function (res) {
|
|
|
|
|
accounts = res;
|
2019-03-25 06:31:04 -03:00
|
|
|
|
defaultDelegate = accounts[5];
|
2018-08-08 07:02:03 -03:00
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
it("creates headless delegation", async function () {
|
2019-03-28 19:12:31 -03:00
|
|
|
|
let result = await DelegationFactory.methods.createDelegation(utils.zeroAddress).send();
|
2019-03-25 05:15:23 -03:00
|
|
|
|
var NoDefaultDelegation = new web3.eth.Contract(DelegationBase._jsonInterface, result.events.InstanceCreated.returnValues[0]);
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await NoDefaultDelegation.methods.delegatedTo(accounts[0]).call()
|
2019-03-25 06:31:04 -03:00
|
|
|
|
assert.equal(result, utils.zeroAddress)
|
|
|
|
|
result = await NoDefaultDelegation.methods.delegatedTo(utils.zeroAddress).call()
|
|
|
|
|
assert.equal(result, utils.zeroAddress)
|
2019-02-27 07:47:53 -03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("creates root delegation", async function () {
|
2019-03-28 19:12:31 -03:00
|
|
|
|
let result = await DelegationFactory.methods.createDelegation(utils.zeroAddress,defaultDelegate,defaultDelegate).send();
|
2019-03-25 05:15:23 -03:00
|
|
|
|
RootDelegation = new web3.eth.Contract(DelegationBase._jsonInterface, result.events.InstanceCreated.returnValues[0]);
|
2019-03-25 06:31:04 -03:00
|
|
|
|
result = await RootDelegation.methods.delegatedTo(utils.zeroAddress).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
|
|
|
|
result = await RootDelegation.methods.delegate(defaultDelegate).send({from: defaultDelegate})
|
|
|
|
|
|
2018-08-08 07:02:03 -03:00
|
|
|
|
})
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
it("starts with default delegate", async function () {
|
|
|
|
|
let result = await RootDelegation.methods.delegatedTo(accounts[0]).call()
|
2019-03-25 06:31:04 -03:00
|
|
|
|
assert.equal(result, utils.zeroAddress)
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[0]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
})
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
it("a0 delegates to a1", async function () {
|
|
|
|
|
result = await RootDelegation.methods.delegate(accounts[1]).send({from: accounts[0]})
|
2018-08-08 07:02:03 -03:00
|
|
|
|
const delegateArgs = result.events.Delegate.returnValues;
|
|
|
|
|
assert.equal(delegateArgs.who, accounts[0])
|
|
|
|
|
assert.equal(delegateArgs.to, accounts[1])
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegatedTo(accounts[0]).call()
|
2018-08-08 07:02:03 -03:00
|
|
|
|
assert.equal(result, accounts[1])
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[0]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("a1 delegate to a2", async function () {
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegate(accounts[2]).send({from: accounts[1]})
|
2018-08-08 07:02:03 -03:00
|
|
|
|
const delegateArgs = result.events.Delegate.returnValues;
|
|
|
|
|
assert.equal(delegateArgs.who, accounts[1])
|
|
|
|
|
assert.equal(delegateArgs.to, accounts[2])
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegatedTo(accounts[1]).call()
|
2018-08-08 07:02:03 -03:00
|
|
|
|
assert.equal(result, accounts[2])
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[0]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[1]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("a2 delegate to a3", async function () {
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegate(accounts[3]).send({from: accounts[2]})
|
2018-08-08 07:02:03 -03:00
|
|
|
|
const delegateArgs = result.events.Delegate.returnValues;
|
|
|
|
|
assert.equal(delegateArgs.who, accounts[2])
|
|
|
|
|
assert.equal(delegateArgs.to, accounts[3])
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegatedTo(accounts[2]).call()
|
2018-08-08 07:02:03 -03:00
|
|
|
|
assert.equal(result, accounts[3])
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[0]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[1]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
|
|
|
|
result = await RootDelegation.methods.delegationOf(accounts[2]).call()
|
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2019-02-27 07:47:53 -03:00
|
|
|
|
it("creates child delegation", async function () {
|
|
|
|
|
let result = await DelegationFactory.methods.createDelegation(RootDelegation._address).send();
|
2019-03-25 05:15:23 -03:00
|
|
|
|
ChildDelegation = new web3.eth.Contract(DelegationBase._jsonInterface, result.events.InstanceCreated.returnValues[0]);
|
2019-02-27 07:47:53 -03:00
|
|
|
|
})
|
|
|
|
|
|
2018-08-08 07:02:03 -03:00
|
|
|
|
it("Child Delegate to Default", async function () {
|
|
|
|
|
result = await ChildDelegation.methods.delegatedTo(accounts[2]).call()
|
|
|
|
|
assert.equal(result, accounts[3])
|
|
|
|
|
|
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[0]).call()
|
2019-02-27 07:47:53 -03:00
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[1]).call()
|
2019-02-27 07:47:53 -03:00
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[2]).call()
|
2019-02-27 07:47:53 -03:00
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("Child a2 delegate to a4", async function () {
|
2019-03-20 22:01:06 -03:00
|
|
|
|
|
2018-08-08 07:02:03 -03:00
|
|
|
|
result = await ChildDelegation.methods.delegate(accounts[4]).send({from: accounts[2]})
|
|
|
|
|
const delegateArgs = result.events.Delegate.returnValues;
|
|
|
|
|
assert.equal(delegateArgs.who, accounts[2])
|
|
|
|
|
assert.equal(delegateArgs.to, accounts[4])
|
|
|
|
|
|
|
|
|
|
result = await ChildDelegation.methods.delegatedTo(accounts[2]).call()
|
|
|
|
|
assert.equal(result, accounts[4])
|
|
|
|
|
|
2019-03-20 22:01:06 -03:00
|
|
|
|
|
2018-08-08 07:02:03 -03:00
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[0]).call()
|
2019-02-27 07:47:53 -03:00
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[1]).call()
|
2019-02-27 07:47:53 -03:00
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[2]).call()
|
2019-02-27 07:47:53 -03:00
|
|
|
|
assert.equal(result, defaultDelegate)
|
2018-08-08 07:02:03 -03:00
|
|
|
|
|
2019-03-20 22:01:06 -03:00
|
|
|
|
|
2018-08-08 07:02:03 -03:00
|
|
|
|
})
|
|
|
|
|
|
2019-03-20 22:01:06 -03:00
|
|
|
|
it("default delegate should be able to delegate", async function () {
|
|
|
|
|
await ChildDelegation.methods.delegate(accounts[6]).send({from: accounts[6]})
|
|
|
|
|
newDelegate = await ChildDelegation.methods.delegationOf(accounts[6]).call()
|
|
|
|
|
result = await ChildDelegation.methods.delegate(accounts[6]).send({from: defaultDelegate})
|
|
|
|
|
const delegateArgs = result.events.Delegate.returnValues;
|
|
|
|
|
assert.equal(delegateArgs.who, defaultDelegate)
|
|
|
|
|
assert.equal(delegateArgs.to, accounts[6])
|
|
|
|
|
|
|
|
|
|
result = await ChildDelegation.methods.delegatedTo(defaultDelegate).call()
|
|
|
|
|
assert.equal(result, accounts[6])
|
|
|
|
|
|
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[0]).call()
|
|
|
|
|
assert.equal(result, newDelegate)
|
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[1]).call()
|
|
|
|
|
assert.equal(result, newDelegate)
|
|
|
|
|
result = await ChildDelegation.methods.delegationOf(accounts[2]).call()
|
|
|
|
|
assert.equal(result, newDelegate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
2018-08-08 07:02:03 -03:00
|
|
|
|
})
|