From c983304a5ce34c0310fc9fe91bdbe2005f0c9dff Mon Sep 17 00:00:00 2001 From: benk10 Date: Mon, 9 Mar 2020 11:31:51 +0100 Subject: [PATCH] Change A4R test (#715) * Change A4R test * Fix typo * Fix test * Delete migrations.js * update continuousLocking4Reputation test * externalLocking4rep test update * fixreputationallocation test update * globalconstraint test update * Update LockingEth4Reputation test * Update LockingToken4Reputation test * Update SignalScheme test * Update ReputationFromToken test * Update VoteInOrganization test * Update VMCallbacks test * Remove daoCreator Co-authored-by: Oren Sokolowsky --- contracts/schemes/Forwarder.sol | 50 - contracts/schemes/SignalScheme.sol | 2 +- contracts/utils/DaoCreator.sol | 200 ---- docs/generated_docs/controller/UController.md | 869 ------------------ .../universalSchemes/ControllerCreator.md | 31 - .../universalSchemes/DaoCreator.md | 140 --- migrations/2_deploy_organization.js | 85 -- mkdocs.yml | 1 - package-lock.json | 122 ++- test/.DS_Store | Bin 0 -> 14340 bytes test/auction4reputation.js | 67 +- test/continuouslockingtoken4reputation.js | 95 +- test/daocreator.js | 219 ----- test/externallocking4reputation.js | 88 +- test/fixreputationallocation.js | 65 +- test/forwarder.js | 141 --- test/globalconstraintregistrar.js | 75 +- test/helpers.js | 71 +- test/lockingeth4reputation.js | 71 +- test/lockingtoken4reputation.js | 73 +- test/migrations.js | 13 - test/reputationfromtoken.js | 85 +- test/signalscheme.js | 61 +- test/voteinorganization.js | 82 +- test/votingmachinecallbacks.js | 38 +- 25 files changed, 621 insertions(+), 2123 deletions(-) delete mode 100644 contracts/schemes/Forwarder.sol delete mode 100644 contracts/utils/DaoCreator.sol delete mode 100644 docs/generated_docs/controller/UController.md delete mode 100644 docs/generated_docs/universalSchemes/ControllerCreator.md delete mode 100644 docs/generated_docs/universalSchemes/DaoCreator.md delete mode 100644 migrations/2_deploy_organization.js create mode 100644 test/.DS_Store delete mode 100644 test/daocreator.js delete mode 100644 test/forwarder.js delete mode 100644 test/migrations.js diff --git a/contracts/schemes/Forwarder.sol b/contracts/schemes/Forwarder.sol deleted file mode 100644 index e9b6fd6e..00000000 --- a/contracts/schemes/Forwarder.sol +++ /dev/null @@ -1,50 +0,0 @@ -pragma solidity ^0.5.16; - -import "../controller/Controller.sol"; -import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol"; -import "@openzeppelin/upgrades/contracts/Initializable.sol"; - - -/** - * @title A scheme to forward a call to a dao. - * The scheme can unregister itself when its expirationTime reached. - */ -contract Forwarder is Initializable, Ownable { - - Avatar public avatar; - uint256 public expirationTime; - - /** - * @dev forwardCall forward a call to the dao controller - */ - // solhint-disable-next-line no-complex-fallback,payable-fallback - function () external onlyOwner { - // solhint-disable-next-line not-rely-on-time - require(expirationTime > now, "expirationTime > now"); - // solhint-disable-next-line avoid-low-level-calls - (bool result,) = avatar.owner().call(msg.data); - require(result); - } - - /** - * @dev initialize - * @param _avatar the avatar of the dao to forward the call to - * @param _expirationTime the expirationTime to forwardCall - */ - function initialize(Avatar _avatar, uint256 _expirationTime, address _owner) external initializer { - require(_avatar != Avatar(0), "avatar cannot be zero"); - avatar = _avatar; - expirationTime = _expirationTime; - Ownable.initialize(_owner); - } - - /** - * @dev unregisterSelf function - * @return bool - */ - function unregisterSelf() public returns(bool) { - // solhint-disable-next-line not-rely-on-time - require(expirationTime <= now, "expirationTime <= now"); - return Controller(avatar.owner()).unregisterSelf(); - } -} diff --git a/contracts/schemes/SignalScheme.sol b/contracts/schemes/SignalScheme.sol index 73e75cd7..68da22a8 100644 --- a/contracts/schemes/SignalScheme.sol +++ b/contracts/schemes/SignalScheme.sol @@ -8,7 +8,7 @@ import "@openzeppelin/upgrades/contracts/Initializable.sol"; /** - * @title A scheme for proposing a signal on behalkf of the daoCreator + * @title A scheme for proposing a signal on behalkf of the dao */ contract SignalScheme is VotingMachineCallbacks, ProposalExecuteInterface, Initializable { diff --git a/contracts/utils/DaoCreator.sol b/contracts/utils/DaoCreator.sol deleted file mode 100644 index 03bb6291..00000000 --- a/contracts/utils/DaoCreator.sol +++ /dev/null @@ -1,200 +0,0 @@ -pragma solidity ^0.5.16; - -import "../controller/Controller.sol"; - -/** - * @title ControllerCreator for creating a single controller. - */ -contract ControllerCreator { - - function create(Avatar _avatar) public returns(address) { - Controller controller = new Controller(); - controller.initialize(_avatar, address(this)); - controller.registerScheme(msg.sender, bytes4(0x0000001f)); - controller.unregisterScheme(address(this)); - return address(controller); - } -} - -/** - * @title Genesis Scheme that creates organizations - */ -contract DaoCreator { - - mapping(address=>address) public locks; - - event NewOrg (address _avatar); - event InitialSchemesSet (address _avatar); - - ControllerCreator private controllerCreator; - - constructor(ControllerCreator _controllerCreator) public { - require(_controllerCreator != ControllerCreator(0)); - controllerCreator = _controllerCreator; - } - - /** - * @dev addFounders add founders to the organization. - * this function can be called only after forgeOrg and before setSchemes - * @param _avatar the organization avatar - * @param _founders An array with the addresses of the founders of the organization - * @param _foundersTokenAmount An array of amount of tokens that the founders - * receive in the new organization - * @param _foundersReputationAmount An array of amount of reputation that the - * founders receive in the new organization - * @return bool true or false - */ - function addFounders ( - Avatar _avatar, - address[] calldata _founders, - uint[] calldata _foundersTokenAmount, - uint[] calldata _foundersReputationAmount - ) - external - returns(bool) - { - require(_founders.length == _foundersTokenAmount.length); - require(_founders.length == _foundersReputationAmount.length); - require(_founders.length > 0); - require(locks[address(_avatar)] == msg.sender); - // Mint token and reputation for founders: - for (uint256 i = 0; i < _founders.length; i++) { - require(_founders[i] != address(0)); - if (_foundersTokenAmount[i] > 0) { - Controller( - _avatar.owner()).mintTokens(_foundersTokenAmount[i], _founders[i]); - } - if (_foundersReputationAmount[i] > 0) { - Controller( - _avatar.owner()).mintReputation(_foundersReputationAmount[i], _founders[i]); - } - } - return true; - } - - /** - * @dev Create a new organization - * @param _orgName The name of the new organization - * @param _tokenName The name of the token associated with the organization - * @param _tokenSymbol The symbol of the token - * @param _founders An array with the addresses of the founders of the organization - * @param _foundersTokenAmount An array of amount of tokens that the founders - * receive in the new organization - * @param _foundersReputationAmount An array of amount of reputation that the - * founders receive in the new organization - * @param _cap token cap - 0 for no cap. - * @return The address of the avatar of the controller - */ - function forgeOrg ( - string calldata _orgName, - string calldata _tokenName, - string calldata _tokenSymbol, - address[] calldata _founders, - uint[] calldata _foundersTokenAmount, - uint[] calldata _foundersReputationAmount, - uint256 _cap - ) - external - returns(address) - { - //The call for the private function is needed to bypass a deep stack issues - return _forgeOrg( - _orgName, - _tokenName, - _tokenSymbol, - _founders, - _foundersTokenAmount, - _foundersReputationAmount, - _cap); - } - - /** - * @dev Set initial schemes for the organization. - * @param _avatar organization avatar (returns from forgeOrg) - * @param _schemes the schemes to register for the organization - * @param _permissions the schemes permissions. - * @param _metaData dao meta data hash - */ - function setSchemes ( - Avatar _avatar, - address[] calldata _schemes, - bytes4[] calldata _permissions, - string calldata _metaData - ) - external - { - // this action can only be executed by the account that holds the lock - // for this controller - require(locks[address(_avatar)] == msg.sender); - // register initial schemes: - Controller controller = Controller(_avatar.owner()); - for (uint256 i = 0; i < _schemes.length; i++) { - controller.registerScheme(_schemes[i], _permissions[i]); - } - controller.metaData(_metaData); - // Unregister self: - controller.unregisterScheme(address(this)); - // Remove lock: - delete locks[address(_avatar)]; - emit InitialSchemesSet(address(_avatar)); - } - - /** - * @dev Create a new organization - * @param _orgName The name of the new organization - * @param _tokenName The name of the token associated with the organization - * @param _tokenSymbol The symbol of the token - * @param _founders An array with the addresses of the founders of the organization - * @param _foundersTokenAmount An array of amount of tokens that the founders - * receive in the new organization - * @param _foundersReputationAmount An array of amount of reputation that the - * founders receive in the new organization - * @param _cap token cap - 0 for no cap. - * @return The address of the avatar of the controller - */ - function _forgeOrg ( - string memory _orgName, - string memory _tokenName, - string memory _tokenSymbol, - address[] memory _founders, - uint[] memory _foundersTokenAmount, - uint[] memory _foundersReputationAmount, - uint256 _cap - ) private returns(address) - { - // Create Token, Reputation and Avatar: - require(_founders.length == _foundersTokenAmount.length); - require(_founders.length == _foundersReputationAmount.length); - require(_founders.length > 0); - DAOToken nativeToken = new DAOToken(); - nativeToken.initialize(_tokenName, _tokenSymbol, _cap, address(this)); - Reputation nativeReputation = new Reputation(); - nativeReputation.initialize(address(this)); - Avatar avatar = new Avatar(); - avatar.initialize(_orgName, nativeToken, nativeReputation, address(this)); - - // Mint token and reputation for founders: - for (uint256 i = 0; i < _founders.length; i++) { - require(_founders[i] != address(0)); - if (_foundersTokenAmount[i] > 0) { - nativeToken.mint(_founders[i], _foundersTokenAmount[i]); - } - if (_foundersReputationAmount[i] > 0) { - nativeReputation.mint(_founders[i], _foundersReputationAmount[i]); - } - } - - // Create Controller: - Controller controller = Controller(controllerCreator.create(avatar)); - - // Transfer ownership: - avatar.transferOwnership(address(controller)); - nativeToken.transferOwnership(address(controller)); - nativeReputation.transferOwnership(address(controller)); - - locks[address(avatar)] = msg.sender; - - emit NewOrg (address(avatar)); - return (address(avatar)); - } -} diff --git a/docs/generated_docs/controller/UController.md b/docs/generated_docs/controller/UController.md deleted file mode 100644 index 758d0fab..00000000 --- a/docs/generated_docs/controller/UController.md +++ /dev/null @@ -1,869 +0,0 @@ -# UController -[see the source](https://github.com/daostack/arc/tree/master/contracts/controller/UController.sol) -> Universal Controller contract - - -**Execution cost**: less than 4240 gas - -**Deployment cost**: less than 3752800 gas - -**Combined cost**: less than 3757040 gas - -## Constructor - - - - -## Events -### ExternalTokenTransfer(address,address,address,uint256) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_externalToken** *of type `address`* -3. **_to** *of type `address`* -4. **_value** *of type `uint256`* - ---- -### MintReputation(address,address,uint256,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_to** *of type `address`* -3. **_amount** *of type `uint256`* -4. **_avatar** *of type `address`* - ---- -### AddGlobalConstraint(address,bytes32,uint8,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_globalConstraint** *of type `address`* -2. **_params** *of type `bytes32`* -3. **_when** *of type `uint8`* -4. **_avatar** *of type `address`* - ---- -### ExternalTokenDecreaseApproval(address,address,address,uint256) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_externalToken** *of type `address`* -3. **_spender** *of type `address`* -4. **_value** *of type `uint256`* - ---- -### ExternalTokenIncreaseApproval(address,address,address,uint256) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_externalToken** *of type `address`* -3. **_spender** *of type `address`* -4. **_value** *of type `uint256`* - ---- -### GenericAction(address,bytes32[]) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_params** *of type `bytes32[]`* - ---- -### ExternalTokenTransferFrom(address,address,address,address,uint256) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_externalToken** *of type `address`* -3. **_from** *of type `address`* -4. **_to** *of type `address`* -5. **_value** *of type `uint256`* - ---- -### BurnReputation(address,address,uint256,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_from** *of type `address`* -3. **_amount** *of type `uint256`* -4. **_avatar** *of type `address`* - ---- -### MintTokens(address,address,uint256,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_beneficiary** *of type `address`* -3. **_amount** *of type `uint256`* -4. **_avatar** *of type `address`* - ---- -### RegisterScheme(address,address,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_scheme** *of type `address`* -3. **_avatar** *of type `address`* - ---- -### RemoveGlobalConstraint(address,uint256,bool,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_globalConstraint** *of type `address`* -2. **_index** *of type `uint256`* -3. **_isPre** *of type `bool`* -4. **_avatar** *of type `address`* - ---- -### SendEther(address,uint256,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_amountInWei** *of type `uint256`* -3. **_to** *of type `address`* - ---- -### UnregisterScheme(address,address,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_sender** *of type `address`* -2. **_scheme** *of type `address`* -3. **_avatar** *of type `address`* - ---- -### UpgradeController(address,address,address) - - -**Execution cost**: No bound available - - -Params: - -1. **_oldController** *of type `address`* -2. **_newController** *of type `address`* -3. **_avatar** *of type `address`* - - -## Methods -### globalConstraintsCount(address) -> -> globalConstraintsCount return the global constraint pre and post count - - -**Execution cost**: less than 1192 gas - -**Attributes**: constant - - -Params: - -1. **_avatar** *of type `address`* - -Returns: - -> uint globalConstraintsPre count.uint globalConstraintsPost count. - -1. **output_0** *of type `uint256`* -2. **output_1** *of type `uint256`* - ---- -### externalTokenTransferFrom(address,address,address,uint256,address) -> -> transfer token "from" address "to" address One must to approve the amount of tokens which can be spend from the "from" account.This can be done using externalTokenApprove. - - -**Execution cost**: No bound available - - -Params: - -1. **_externalToken** *of type `address`* - - > the address of the Token Contract - -2. **_from** *of type `address`* - - > address of the account to send from - -3. **_to** *of type `address`* - - > address of the beneficiary - -4. **_value** *of type `uint256`* - - > the amount of ether (in Wei) to send - -5. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### addGlobalConstraint(address,bytes32,address) -> -> add or update Global Constraint - - -**Execution cost**: No bound available - - -Params: - -1. **_globalConstraint** *of type `address`* - - > the address of the global constraint to be added. - -2. **_params** *of type `bytes32`* - - > the constraint parameters hash. - -3. **_avatar** *of type `address`* - - > the avatar of the organization - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### externalTokenDecreaseApproval(address,address,uint256,address) -> -> decrease approval for the spender address to spend a specified amount of tokens on behalf of msg.sender. - - -**Execution cost**: No bound available - - -Params: - -1. **_externalToken** *of type `address`* - - > the address of the Token Contract - -2. **_spender** *of type `address`* - - > address - -3. **_subtractedValue** *of type `uint256`* - - > the amount of ether (in Wei) which the approval is referring to. - -4. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### externalTokenTransfer(address,address,uint256,address) -> -> send some amount of arbitrary ERC20 Tokens - - -**Execution cost**: No bound available - - -Params: - -1. **_externalToken** *of type `address`* - - > the address of the Token Contract - -2. **_to** *of type `address`* - - > address of the beneficiary - -3. **_value** *of type `uint256`* - - > the amount of ether (in Wei) to send - -4. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### burnReputation(uint256,address,address) -> -> Burns `_amount` of reputation from `_from` - - -**Execution cost**: No bound available - - -Params: - -1. **_amount** *of type `uint256`* - - > amount of reputation to burn - -2. **_from** *of type `address`* - - > The address that will lose the reputation - -3. **_avatar** *of type `address`* - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### externalTokenIncreaseApproval(address,address,uint256,address) -> -> increase approval for the spender address to spend a specified amount of tokens on behalf of msg.sender. - - -**Execution cost**: No bound available - - -Params: - -1. **_externalToken** *of type `address`* - - > the address of the Token Contract - -2. **_spender** *of type `address`* - - > address - -3. **_addedValue** *of type `uint256`* - - > the amount of ether (in Wei) which the approval is referring to. - -4. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### isSchemeRegistered(address,address) - - -**Execution cost**: less than 1217 gas - -**Attributes**: constant - - -Params: - -1. **_scheme** *of type `address`* -2. **_avatar** *of type `address`* - -Returns: - - -1. **output_0** *of type `bool`* - ---- -### genericAction(bytes32[],address) -> -> do a generic delegate call to the contract which called us. This function use delegatecall and might expose the organization to security risk. Use this function only if you really knows what you are doing. - - -**Execution cost**: No bound available - - -Params: - -1. **_params** *of type `bytes32[]`* - - > the params for the call. - -2. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents success - -1. **output_0** *of type `bool`* - ---- -### newOrganization(address) -> -> newOrganization set up a new organization with default daoCreator. - - -**Execution cost**: No bound available - - -Params: - -1. **_avatar** *of type `address`* - - > the organization avatar - - - ---- -### mintTokens(uint256,address,address) -> -> mint tokens . - - -**Execution cost**: No bound available - - -Params: - -1. **_amount** *of type `uint256`* - - > amount of token to mint - -2. **_beneficiary** *of type `address`* - - > beneficiary address - -3. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### isGlobalConstraintRegistered(address,address) - - -**Execution cost**: less than 1771 gas - -**Attributes**: constant - - -Params: - -1. **_globalConstraint** *of type `address`* -2. **_avatar** *of type `address`* - -Returns: - - -1. **output_0** *of type `bool`* - ---- -### mintReputation(uint256,address,address) -> -> Mint `_amount` of reputation that are assigned to `_to` . - - -**Execution cost**: No bound available - - -Params: - -1. **_amount** *of type `uint256`* - - > amount of reputation to mint - -2. **_to** *of type `address`* - - > beneficiary address - -3. **_avatar** *of type `address`* - - > the address of the organization's avatar - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### getSchemeParameters(address,address) - - -**Execution cost**: less than 811 gas - -**Attributes**: constant - - -Params: - -1. **_scheme** *of type `address`* -2. **_avatar** *of type `address`* - -Returns: - - -1. **output_0** *of type `bytes32`* - ---- -### getNativeReputation(address) -> -> getNativeReputation - - -**Execution cost**: less than 1062 gas - -**Attributes**: constant - - -Params: - -1. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> organization native reputation - -1. **output_0** *of type `address`* - ---- -### getSchemePermissions(address,address) - - -**Execution cost**: less than 1186 gas - -**Attributes**: constant - - -Params: - -1. **_scheme** *of type `address`* -2. **_avatar** *of type `address`* - -Returns: - - -1. **output_0** *of type `bytes4`* - ---- -### newControllers(address) - - -**Execution cost**: less than 846 gas - -**Attributes**: constant - - -Params: - -1. **param_0** *of type `address`* - -Returns: - - -1. **output_0** *of type `address`* - ---- -### organizations(address) - - -**Execution cost**: less than 1391 gas - -**Attributes**: constant - - -Params: - -1. **param_0** *of type `address`* - -Returns: - - -1. **nativeToken** *of type `address`* -2. **nativeReputation** *of type `address`* -3. **exist** *of type `bool`* - ---- -### registerScheme(address,bytes32,bytes4,address) -> -> register or update a scheme - - -**Execution cost**: No bound available - - -Params: - -1. **_scheme** *of type `address`* - - > the address of the scheme - -2. **_paramsHash** *of type `bytes32`* - - > a hashed configuration of the usage of the scheme - -3. **_permissions** *of type `bytes4`* - - > the permissions the new scheme will have - -4. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### removeGlobalConstraint(address,address) -> -> remove Global Constraint - - -**Execution cost**: No bound available - - -Params: - -1. **_globalConstraint** *of type `address`* - - > the address of the global constraint to be remove. - -2. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### reputations(address) - - -**Execution cost**: less than 617 gas - -**Attributes**: constant - - -Params: - -1. **param_0** *of type `address`* - -Returns: - - -1. **output_0** *of type `bool`* - ---- -### sendEther(uint256,address,address) -> -> send some ether - - -**Execution cost**: No bound available - - -Params: - -1. **_amountInWei** *of type `uint256`* - - > the amount of ether (in Wei) to send - -2. **_to** *of type `address`* - - > address of the beneficiary - -3. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### tokens(address) - - -**Execution cost**: less than 1057 gas - -**Attributes**: constant - - -Params: - -1. **param_0** *of type `address`* - -Returns: - - -1. **output_0** *of type `bool`* - ---- -### unregisterScheme(address,address) -> -> unregister a scheme - - -**Execution cost**: No bound available - - -Params: - -1. **_scheme** *of type `address`* - - > the address of the scheme - -2. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### unregisterSelf(address) -> -> unregister the caller's scheme - - -**Execution cost**: less than 28553 gas - - -Params: - -1. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - ---- -### upgradeController(address,address) -> -> upgrade the Controller The function will trigger an event 'UpgradeController'. - - -**Execution cost**: No bound available - - -Params: - -1. **_newController** *of type `address`* - - > the address of the new controller. - -2. **_avatar** *of type `address`* - - > the organization avatar. - - -Returns: - -> bool which represents a success - -1. **output_0** *of type `bool`* - -[Back to the top ↑](#ucontroller) diff --git a/docs/generated_docs/universalSchemes/ControllerCreator.md b/docs/generated_docs/universalSchemes/ControllerCreator.md deleted file mode 100644 index 309962c3..00000000 --- a/docs/generated_docs/universalSchemes/ControllerCreator.md +++ /dev/null @@ -1,31 +0,0 @@ -# ControllerCreator -[see the source](https://github.com/daostack/arc/tree/master/contracts/universalSchemes/DaoCreator.sol) -> ControllerCreator for creating a single controller. - - -**Execution cost**: less than 3320 gas - -**Deployment cost**: less than 3026600 gas - -**Combined cost**: less than 3029920 gas - - - - -## Methods -### create(address) - - -**Execution cost**: No bound available - - -Params: - -1. **_avatar** *of type `address`* - -Returns: - - -1. **output_0** *of type `address`* - -[Back to the top ↑](#controllercreator) diff --git a/docs/generated_docs/universalSchemes/DaoCreator.md b/docs/generated_docs/universalSchemes/DaoCreator.md deleted file mode 100644 index b2150097..00000000 --- a/docs/generated_docs/universalSchemes/DaoCreator.md +++ /dev/null @@ -1,140 +0,0 @@ -# DaoCreator -[see the source](https://github.com/daostack/arc/tree/master/contracts/universalSchemes/DaoCreator.sol) -> Genesis Scheme that creates organizations - - -**Execution cost**: less than 22864 gas - -**Deployment cost**: less than 2275200 gas - -**Combined cost**: less than 2298064 gas - -## Constructor - - - -Params: - -1. **_controllerCreator** *of type `address`* - -## Events -### InitialSchemesSet(address) - - -**Execution cost**: No bound available - - -Params: - -1. **_avatar** *of type `address`* - ---- -### NewOrg(address) - - -**Execution cost**: No bound available - - -Params: - -1. **_avatar** *of type `address`* - - -## Methods -### forgeOrg(bytes32,string,string,address[],uint256[],uint256[],address,uint256) -> -> Create a new organization - - -**Execution cost**: No bound available - - -Params: - -1. **_orgName** *of type `bytes32`* - - > The name of the new organization - -2. **_tokenName** *of type `string`* - - > The name of the token associated with the organization - -3. **_tokenSymbol** *of type `string`* - - > The symbol of the token - -4. **_founders** *of type `address[]`* - - > An array with the addresses of the founders of the organization - -5. **_foundersTokenAmount** *of type `uint256[]`* - - > An array of amount of tokens that the founders receive in the new organization - -6. **_foundersReputationAmount** *of type `uint256[]`* - - > An array of amount of reputation that the founders receive in the new organization - -7. **_uController** *of type `address`* - - > universal controller instance if _uController address equal to zero the organization will use none universal controller. - -8. **_cap** *of type `uint256`* - - > token cap - 0 for no cap. - - -Returns: - -> The address of the avatar of the controller - -1. **output_0** *of type `address`* - ---- -### locks(address) - - -**Execution cost**: less than 739 gas - -**Attributes**: constant - - -Params: - -1. **param_0** *of type `address`* - -Returns: - - -1. **output_0** *of type `address`* - ---- -### setSchemes(address,address[],bytes32[],bytes4[]) -> -> Set initial schemes for the organization. - - -**Execution cost**: No bound available - - -Params: - -1. **_avatar** *of type `address`* - - > organization avatar (returns from forgeOrg) - -2. **_schemes** *of type `address[]`* - - > the schemes to register for the organization - -3. **_params** *of type `bytes32[]`* - - > the schemes's params - -4. **_permissions** *of type `bytes4[]`* - - > the schemes permissions. - - - -[Back to the top ↑](#daocreator) diff --git a/migrations/2_deploy_organization.js b/migrations/2_deploy_organization.js deleted file mode 100644 index c363f9d7..00000000 --- a/migrations/2_deploy_organization.js +++ /dev/null @@ -1,85 +0,0 @@ -//this migration file is used only for testing purpose -var constants = require('../test/constants'); -var Avatar = artifacts.require('./Avatar.sol'); -var DaoCreator = artifacts.require('./DaoCreator.sol'); -var GlobalConstraintRegistrar = artifacts.require('./GlobalConstraintRegistrar.sol'); -var SchemeRegistrar = artifacts.require('./SchemeRegistrar.sol'); -var AbsoluteVote = artifacts.require('./AbsoluteVote.sol'); -var ContributionReward = artifacts.require('./ContributionReward.sol'); -var UpgradeScheme = artifacts.require('./UpgradeScheme.sol'); -var ControllerCreator = artifacts.require('./ControllerCreator.sol'); -const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; - - -// TEST_ORGANIZATION ORG parameters: -const orgName = "TEST_ORGANIZATION"; -const tokenName = "TestToken"; -const tokenSymbol = "TST"; -const founders = []; -const initRep = web3.utils.toWei("10"); -const initRepInWei = [initRep]; -const initToken = web3.utils.toWei("1000"); -const initTokenInWei = [initToken]; -const cap = web3.utils.toWei("100000000","ether"); - - - -// DAOstack parameters for universal schemes: - -const votePrec = 50; - -var accounts; - -//Deploy test organization with the following schemes: -//schemeRegistrar, upgradeScheme,globalConstraintRegistrar,simpleICO,contributionReward. -module.exports = async function(deployer) { - deployer.deploy(ControllerCreator, {gas: constants.ARC_GAS_LIMIT}).then(async function(){ - var controllerCreator = await ControllerCreator.deployed(); - await deployer.deploy(DaoCreator,controllerCreator.address, {gas: constants.ARC_GAS_LIMIT}); - var daoCreatorInst = await DaoCreator.deployed(controllerCreator.address,{gas: constants.ARC_GAS_LIMIT}); - // Create DAOstack: - - await web3.eth.getAccounts(function(err,res) { accounts = res; }); - founders[0] = accounts[0]; - var returnedParams = await daoCreatorInst.forgeOrg(orgName, tokenName, tokenSymbol, founders, - initTokenInWei, initRepInWei,cap,{gas: constants.ARC_GAS_LIMIT}); - var AvatarInst = await Avatar.at(returnedParams.logs[0].args._avatar); - await deployer.deploy(AbsoluteVote,{gas: constants.ARC_GAS_LIMIT}); - // Deploy AbsoluteVote: - var AbsoluteVoteInst = await AbsoluteVote.deployed(); - // Deploy SchemeRegistrar: - await deployer.deploy(SchemeRegistrar); - var schemeRegistrarInst = await SchemeRegistrar.deployed(); - // Deploy UniversalUpgrade: - await deployer.deploy(UpgradeScheme); - var upgradeSchemeInst = await UpgradeScheme.deployed(); - // Deploy UniversalGCScheme register: - await deployer.deploy(GlobalConstraintRegistrar); - var globalConstraintRegistrarInst = await GlobalConstraintRegistrar.deployed(); - - await deployer.deploy(ContributionReward); - var contributionRewardInst = await ContributionReward.deployed(); - - // Voting parameters and schemes params: - var voteParametersHash = await AbsoluteVoteInst.getParametersHash(votePrec, NULL_ADDRESS); - - await schemeRegistrarInst.initialize(AvatarInst.address,AbsoluteVoteInst.address,voteParametersHash, voteParametersHash, ); - await globalConstraintRegistrarInst.initialize(AvatarInst.address, AbsoluteVoteInst.address, voteParametersHash); - await upgradeSchemeInst.initialize(AvatarInst.address, AbsoluteVoteInst.address, voteParametersHash); - - await contributionRewardInst.initialize(AvatarInst.address, AbsoluteVoteInst.address, voteParametersHash); - - var schemesArray = [schemeRegistrarInst.address, - globalConstraintRegistrarInst.address, - upgradeSchemeInst.address, - contributionRewardInst.address]; - const permissionArray = ['0x0000001F', '0x00000005', '0x0000000a','0x00000001']; - - // set DAOstack initial schmes: - await daoCreatorInst.setSchemes( - AvatarInst.address, - schemesArray, - permissionArray, - "metaData"); - }); - }; diff --git a/mkdocs.yml b/mkdocs.yml index c2cd6152..a5f98264 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -59,7 +59,6 @@ pages: - TokenCapGC: 'generated_docs/globalConstraints/TokenCapGC.md' - 'Universal Schemes': - ContributionReward: 'generated_docs/universalSchemes/ContributionReward.md' - - DaoCreator: 'generated_docs/universalSchemes/DaoCreator.md' - ExecutableInterface: 'generated_docs/universalSchemes/ExecutableInterface.md' - GlobalConstraintRegistrar: 'generated_docs/universalSchemes/GlobalConstraintRegistrar.md' - OrganizationRegister: 'generated_docs/universalSchemes/OrganizationRegister.md' diff --git a/package-lock.json b/package-lock.json index 0290cc93..d13841c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -307,6 +307,21 @@ "minimalistic-assert": "^1.0.0" } }, + "scrypt-shim": { + "version": "github:web3-js/scrypt-shim#be5e616323a8b5e568788bf94d03c1b8410eac54", + "from": "github:web3-js/scrypt-shim#be5e616323a8b5e568788bf94d03c1b8410eac54", + "requires": { + "scryptsy": "^2.1.0", + "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + } + } + }, "setimmediate": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.4.tgz", @@ -491,7 +506,7 @@ "eth-lib": "0.2.7", "ethereumjs-common": "^1.3.2", "ethereumjs-tx": "^2.1.1", - "scrypt-shim": "github:web3-js/scrypt-shim#be5e616323a8b5e568788bf94d03c1b8410eac54", + "scrypt-shim": "github:web3-js/scrypt-shim", "underscore": "1.9.1", "uuid": "3.3.2", "web3-core": "1.2.2", @@ -500,6 +515,19 @@ "web3-utils": "1.2.2" }, "dependencies": { + "scrypt-shim": { + "version": "github:web3-js/scrypt-shim#be5e616323a8b5e568788bf94d03c1b8410eac54", + "from": "github:web3-js/scrypt-shim", + "requires": { + "scryptsy": "^2.1.0", + "semver": "^6.3.0" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" + }, "uuid": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", @@ -596,7 +624,20 @@ "requires": { "underscore": "1.9.1", "web3-core-helpers": "1.2.2", - "websocket": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e" + "websocket": "github:web3-js/WebSocket-Node#polyfill/globalThis" + }, + "dependencies": { + "websocket": { + "version": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e", + "from": "github:web3-js/WebSocket-Node#polyfill/globalThis", + "requires": { + "debug": "^2.2.0", + "es5-ext": "^0.10.50", + "nan": "^2.14.0", + "typedarray-to-buffer": "^3.1.5", + "yaeti": "^0.0.6" + } + } } }, "web3-shh": { @@ -624,6 +665,17 @@ "underscore": "1.9.1", "utf8": "3.0.0" } + }, + "websocket": { + "version": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e", + "from": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e", + "requires": { + "debug": "^2.2.0", + "es5-ext": "^0.10.50", + "nan": "^2.14.0", + "typedarray-to-buffer": "^3.1.5", + "yaeti": "^0.0.6" + } } } }, @@ -4420,7 +4472,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -4441,12 +4494,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4461,17 +4516,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -4588,7 +4646,8 @@ "inherits": { "version": "2.0.4", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -4600,6 +4659,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4614,6 +4674,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4621,12 +4682,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.9.0", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4645,6 +4708,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4734,7 +4798,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4746,6 +4811,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4831,7 +4897,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4867,6 +4934,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4886,6 +4954,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4929,12 +4998,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -8825,21 +8896,6 @@ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-2.0.3.tgz", "integrity": "sha1-uwBAvgMEPamgEqLOqfyfhSz8h9Q=" }, - "scrypt-shim": { - "version": "github:web3-js/scrypt-shim#be5e616323a8b5e568788bf94d03c1b8410eac54", - "from": "github:web3-js/scrypt-shim", - "requires": { - "scryptsy": "^2.1.0", - "semver": "^6.3.0" - }, - "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" - } - } - }, "scrypt.js": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/scrypt.js/-/scrypt.js-0.3.0.tgz", @@ -10896,10 +10952,16 @@ "resolved": "https://registry.npmjs.org/web3/-/web3-0.16.0.tgz", "integrity": "sha1-pFVBdc1GKUMDWx8dOUMvdBxrYBk=", "requires": { - "bignumber.js": "git+https://github.com/debris/bignumber.js.git#c7a38de919ed75e6fb6ba38051986e294b328df9", + "bignumber.js": "git+https://github.com/debris/bignumber.js.git#master", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xmlhttprequest": "*" + }, + "dependencies": { + "bignumber.js": { + "version": "git+https://github.com/debris/bignumber.js.git#c7a38de919ed75e6fb6ba38051986e294b328df9", + "from": "git+https://github.com/debris/bignumber.js.git#master" + } } } } @@ -10930,7 +10992,7 @@ "requires": { "underscore": "1.9.1", "web3-core-helpers": "1.2.1", - "websocket": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e" + "websocket": "github:web3-js/WebSocket-Node#polyfill/globalThis" } }, "web3-shh": { diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..99e914355d9772aabe456d96efc925cb2028d6be GIT binary patch literal 14340 zcmeI2&2JJx6u{qVO*Ab^Oxm=KCLBE5YI^X94SF(qXw<8e(uzeOu+)zeH~(#aZ)T^^ z!Y=GW%n)bE?7-~2*?GUb`FM{Jk?44M_Cn-PMDCL`FK==CBT~_P;?n1urmnk`M5H4U z-^(H$X-Z#O(vZPa?dgI$6si0MsVo=BPRcjrD<$7a&*hs8dhzM|;UMlWQrGliAO~`4 z+Psvy4CS1*>b&7VYSN{L;R*x-fj}S-2n7C50=o8c-QTo%xCa7(Kp=2UK<9@FN%Lxw zk8EzH4sN=I*XO#0Hy7XW158;Z$*V~|vbhmO#)y(z(I{~-A}daLMXQrnlYC@zD=v{0 zmneC2lz1qSc{_3yQ(dB}&BHwq2n41H>{Ijv-@A=Ze2RbE#xw5XB@ZOVldt2;cg(jY zbz0Y@{cE56UE-6!l@s}8o~zG(AfITZjn}RIyL#d^+KNdB@{!*fC79=*TUmX(*8EI+ zeYrF(y_OG@X=@ErQs+s7C$V`~%(vxqa&d;jTzLPkA*%gTf*RY1iDw+q)28&`qP>rK zrmS6j!&jC?ba4!G%ffE|7P}ZqmvHN>DZirnIEIDf;kW~_CL=>_t)Ez)j&L38jWx2r zym~lpx#ZwgVr1&9rSZZBW3(?<@bi6iX7}2$$f#v3W!AiO4uLK+_;~#J&SEFA@|*K( zx*m>BE;)E@vHsMFC^z}&+VheCy6`}u>$2a?r-kE_Lkd!R2`TFx=s%M>x9Tt5 zvDsak`eW)r47?vl#k6tc3P?jRT&p0kMZ>qYu*7qffoG@tPl4Ig3$>gV*ZeYFQ?6Ta&@uisAV z%zEhm%;>M9Ue})?EQYK(HcH^)S7RS=Jx9tab#z=;)~1<{Y}{3&t}P<5>cQIRpw7!b z7=L|sm%dx%_O&G~qJ`s_Lkd#63%#Q$KOyKluOhlQYPn@$SDIj_k*+qj<$o+cyVs6K zMlGZH8DpqR%trUrI-B+RzruI>C^6>Kdp*`XwHBIhCT)yoaNo5~@3GT3r3TtQ#iDiO zt6kfO%*}OdJy);gv~tvzXa%zSjGY#2XGMzF@n40a`Z$_}M literal 0 HcmV?d00001 diff --git a/test/auction4reputation.js b/test/auction4reputation.js index ced9e3e8..00f88fec 100644 --- a/test/auction4reputation.js +++ b/test/auction4reputation.js @@ -1,11 +1,13 @@ const helpers = require('./helpers'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); const constants = require('./constants'); const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); var Auction4Reputation = artifacts.require("./Auction4Reputation.sol"); +export class Auction4ReputationParams { + constructor() { + } +} const setup = async function (accounts, _auctionReputationReward = 100, @@ -13,36 +15,51 @@ const setup = async function (accounts, _auctionsEndTime = 3000, _numberOfAuctions = 3, _redeemEnableTime = 3000, - _agreementHash = helpers.SOME_HASH, - _initialize = true) { + _agreementHash = helpers.SOME_HASH) { var testSetup = new helpers.TestSetup(); + testSetup.proxyAdmin = accounts[5]; + var registration = await helpers.registerImplementation(); testSetup.biddingToken = await ERC20Mock.new(accounts[0], web3.utils.toWei('100', "ether")); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory( + testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000] + ); - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); testSetup.auctionsEndTime = (await web3.eth.getBlock("latest")).timestamp + _auctionsEndTime; testSetup.auctionsStartTime = (await web3.eth.getBlock("latest")).timestamp + _auctionsStartTime; testSetup.redeemEnableTime = (await web3.eth.getBlock("latest")).timestamp + _redeemEnableTime; testSetup.auction4Reputation = await Auction4Reputation.new(); testSetup.auctionPeriod = (testSetup.auctionsEndTime - testSetup.auctionsStartTime)/3; testSetup.agreementHash = _agreementHash; - if (_initialize === true ) { - await testSetup.auction4Reputation.initialize(testSetup.org.avatar.address, - _auctionReputationReward, - testSetup.auctionsStartTime, - testSetup.auctionPeriod, - _numberOfAuctions, - testSetup.redeemEnableTime, - testSetup.biddingToken.address, - testSetup.org.avatar.address, - testSetup.agreementHash, - {gas : constants.ARC_GAS_LIMIT}); - } + testSetup.auction4ReputationParams = new Auction4ReputationParams(); + testSetup.auction4ReputationParams.initdata = await new web3.eth.Contract(registration.auction4Reputation.abi) + .methods + .initialize(testSetup.org.avatar.address, + _auctionReputationReward, + testSetup.auctionsStartTime, + testSetup.auctionPeriod, + _numberOfAuctions, + testSetup.redeemEnableTime, + testSetup.biddingToken.address, + testSetup.org.avatar.address, + testSetup.agreementHash) + .encodeABI(); var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address,[testSetup.auction4Reputation.address],[permissions],"metaData"); + + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("Auction4Reputation")], + testSetup.auction4ReputationParams.initdata, + [helpers.getBytesLength(testSetup.auction4ReputationParams.initdata)], + [permissions], + "metaData",{from:testSetup.proxyAdmin}); + testSetup.auction4Reputation = await Auction4Reputation.at(tx.logs[1].args._scheme); await testSetup.biddingToken.approve(testSetup.auction4Reputation.address,web3.utils.toWei('100', "ether")); return testSetup; }; @@ -185,16 +202,6 @@ contract('Auction4Reputation', accounts => { }); - it("bid without initialize should fail", async () => { - let testSetup = await setup(accounts,100,0,3000,3,3000,helpers.SOME_HASH,false); - try { - await testSetup.auction4Reputation.bid(web3.utils.toWei('1', "ether"),0, testSetup.agreementHash); - assert(false, "bid without initialize should fail"); - } catch(error) { - helpers.assertVMException(error); - } - }); - it("bid with wrong agreementHash should fail", async () => { let testSetup = await setup(accounts); try { diff --git a/test/continuouslockingtoken4reputation.js b/test/continuouslockingtoken4reputation.js index 5aec24df..fb9ee7a6 100644 --- a/test/continuouslockingtoken4reputation.js +++ b/test/continuouslockingtoken4reputation.js @@ -1,12 +1,11 @@ const helpers = require('./helpers'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); - -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); const constants = require('./constants'); const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); var ContinuousLocking4Reputation = artifacts.require("./ContinuousLocking4Reputation.sol"); - - +export class ContinuousLocking4ReputationParams { + constructor() { + } +} const setup = async function (accounts, _initialize = true, _reputationReward = 850000, @@ -18,46 +17,68 @@ const setup = async function (accounts, _repRewardConstB = 900, _periodsCap = 100, _agreementHash = helpers.SOME_HASH - ) { + ) + { var testSetup = new helpers.TestSetup(); + testSetup.proxyAdmin = accounts[5]; + var registration = await helpers.registerImplementation(); testSetup.lockingToken = await ERC20Mock.new(accounts[0], web3.utils.toWei('100', "ether")); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); - testSetup.startTime = (await web3.eth.getBlock("latest")).timestamp + _startTime; - testSetup.redeemEnableTime = (await web3.eth.getBlock("latest")).timestamp + _redeemEnableTime; - testSetup.continuousLocking4Reputation = await ContinuousLocking4Reputation.new(); - testSetup.periodsUnit = _periodsUnit; - testSetup.agreementHash = _agreementHash; - testSetup.maxLockingPeriod = _maxLockingPeriod; - - testSetup.repRewardConstA = _repRewardConstA; - testSetup.repRewardConstB = _repRewardConstB; - testSetup.reputationReward = _reputationReward; - testSetup.periodsCap = _periodsCap; - if (_initialize === true ) { - await testSetup.continuousLocking4Reputation.initialize(testSetup.org.avatar.address, - testSetup.reputationReward, - testSetup.startTime, - testSetup.periodsUnit, - testSetup.redeemEnableTime, - testSetup.maxLockingPeriod, - testSetup.repRewardConstA, - testSetup.repRewardConstB, - testSetup.periodsCap, - testSetup.lockingToken.address, - testSetup.agreementHash, - {gas : constants.ARC_GAS_LIMIT}); - } + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory( + testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000] + ); + + + testSetup.startTime = (await web3.eth.getBlock("latest")).timestamp + _startTime; + testSetup.redeemEnableTime = (await web3.eth.getBlock("latest")).timestamp + _redeemEnableTime; + testSetup.continuousLocking4Reputation = await ContinuousLocking4Reputation.new(); + testSetup.periodsUnit = _periodsUnit; + testSetup.agreementHash = _agreementHash; + testSetup.maxLockingPeriod = _maxLockingPeriod; + testSetup.repRewardConstA = _repRewardConstA; + testSetup.repRewardConstB = _repRewardConstB; + testSetup.reputationReward = _reputationReward; + testSetup.periodsCap = _periodsCap; + + testSetup.continuousLocking4ReputationParams = new ContinuousLocking4ReputationParams(); + if (_initialize === true) { + testSetup.continuousLocking4ReputationParams.initdata = await new web3.eth.Contract(registration.continuousLocking4Reputation.abi) + .methods + .initialize(testSetup.org.avatar.address, + testSetup.reputationReward, + testSetup.startTime, + testSetup.periodsUnit, + testSetup.redeemEnableTime, + testSetup.maxLockingPeriod, + testSetup.repRewardConstA, + testSetup.repRewardConstB, + testSetup.periodsCap, + testSetup.lockingToken.address, + testSetup.agreementHash) + .encodeABI(); + } else { + testSetup.continuousLocking4ReputationParams.initdata = Buffer.from(''); + } var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address,[testSetup.continuousLocking4Reputation.address],[permissions],"metaData"); + + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("ContinuousLocking4Reputation")], + testSetup.continuousLocking4ReputationParams.initdata, + [helpers.getBytesLength(testSetup.continuousLocking4ReputationParams.initdata)], + [permissions], + "metaData",{from:testSetup.proxyAdmin}); + testSetup.continuousLocking4Reputation = await ContinuousLocking4Reputation.at(tx.logs[1].args._scheme); await testSetup.lockingToken.approve(testSetup.continuousLocking4Reputation.address,web3.utils.toWei('100', "ether")); return testSetup; }; + contract('ContinuousLocking4Reputation', accounts => { it("initialize", async () => { let testSetup = await setup(accounts); diff --git a/test/daocreator.js b/test/daocreator.js deleted file mode 100644 index 391812f0..00000000 --- a/test/daocreator.js +++ /dev/null @@ -1,219 +0,0 @@ -const helpers = require('./helpers'); -const constants = require('./constants'); -const DAOToken = artifacts.require("./DAOToken.sol"); -const Reputation = artifacts.require("./Reputation.sol"); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const Avatar = artifacts.require("./Avatar.sol"); -const Controller = artifacts.require("./Controller.sol"); -const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); -const SchemeMock = artifacts.require('./test/SchemeMock.sol'); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); - - -var avatar,token,reputation,daoCreator,controllerCreator; -const setup = async function (accounts,founderToken,founderReputation,cap=0) { - controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - var tx = await daoCreator.forgeOrg("testOrg","TEST","TST",[accounts[0]],[founderToken],[founderReputation],cap,{gas:constants.ARC_GAS_LIMIT}); - assert.equal(tx.logs.length, 1); - assert.equal(tx.logs[0].event, "NewOrg"); - var avatarAddress = tx.logs[0].args._avatar; - avatar = await Avatar.at(avatarAddress); - var tokenAddress = await avatar.nativeToken(); - token = await DAOToken.at(tokenAddress); - var reputationAddress = await avatar.nativeReputation(); - reputation = await Reputation.at(reputationAddress); -}; - -contract('DaoCreator', function(accounts) { - - it("forgeOrg check avatar", async function() { - await setup(accounts,10,10); - assert.equal(await avatar.orgName(),"testOrg"); - }); - - it("forgeOrg check reputations and tokens to founders", async function() { - await setup(accounts,10,10); - var founderBalance = await token.balanceOf(accounts[0]); - assert.equal(founderBalance,10); - var founderReputation = await reputation.balanceOf(accounts[0]); - assert.equal(founderReputation,10); - }); - - - it("forgeOrg check transfer ownership", async function() { - //check the forgeOrg transfer ownership to avatar ,reputation and token - //to the controller contract - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - var controllerAddress,controller; - controllerAddress = await avatar.owner(); - controller = await Controller.at(controllerAddress); - - var controllerAvatarAddress = await controller.avatar(); - assert.equal(controllerAvatarAddress,avatar.address); - var tokenAddress = await avatar.nativeToken(); - var token = await DAOToken.at(tokenAddress); - controllerAddress = await token.owner(); - controller = await Controller.at(controllerAddress); - var controllerTokenAddress = await controller.nativeToken(); - assert.equal(controllerTokenAddress,tokenAddress); - - var reputationAddress = await avatar.nativeReputation(); - var reputation = await Reputation.at(reputationAddress); - controllerAddress = await reputation.owner(); - controller = await Controller.at(controllerAddress); - var controllerReputationAddress = await controller.nativeReputation(); - assert.equal(controllerReputationAddress,reputationAddress); - }); - - it("setSchemes to none SchemeMock", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - var tx = await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData"); - assert.equal(tx.logs.length, 1); - assert.equal(tx.logs[0].event, "InitialSchemesSet"); - assert.equal(tx.logs[0].args._avatar, avatar.address); - }); - - it("setSchemes to SchemeMock", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - var universalSchemeMock = await SchemeMock.new(); - var tx = await daoCreator.setSchemes(avatar.address,[universalSchemeMock.address],["0x8000000F"],"metaData"); - assert.equal(tx.logs.length, 1); - assert.equal(tx.logs[0].event, "InitialSchemesSet"); - assert.equal(tx.logs[0].args._avatar, avatar.address); - }); - - it("setSchemes from account that does not hold the lock", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - try { - await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData",{ from: accounts[1]}); - assert(false,"should fail because accounts[1] does not hold the lock"); - } - catch(ex){ - helpers.assertVMException(ex); - } - }); - - it("setSchemes increase approval for scheme and register org in scheme", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - var standardTokenMock = await ERC20Mock.new(avatar.address, 100); - var universalSchemeMock = await SchemeMock.new(); - var allowance = await standardTokenMock.allowance(avatar.address,universalSchemeMock.address); - assert.equal(allowance,0); - await daoCreator.setSchemes(avatar.address,[universalSchemeMock.address],["0x8000000F"],"metaData"); - allowance = await standardTokenMock.allowance(avatar.address,universalSchemeMock.address); - assert.equal(allowance,0); - }); - - it("setSchemes increase approval for scheme without fee", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - var standardTokenMock = await ERC20Mock.new(accounts[0], 100); - var allowance = await standardTokenMock.allowance(avatar.address,accounts[1]); - assert.equal(allowance,0); - - await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData"); - allowance = await standardTokenMock.allowance(avatar.address,accounts[1]); - assert.equal(allowance,0); - }); - - it("setSchemes check register", async function() { - var amountToMint = 10; - var controllerAddress,controller; - await setup(accounts,amountToMint,amountToMint); - await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData"); - controllerAddress = await avatar.owner(); - controller = await Controller.at(controllerAddress); - var isSchemeRegistered = await controller.isSchemeRegistered(accounts[1]); - assert.equal(isSchemeRegistered,true); - }); - - it("setSchemes check unregisterSelf", async function() { - var amountToMint = 10; - var controllerAddress,controller; - await setup(accounts,amountToMint,amountToMint); - controllerAddress = await avatar.owner(); - controller = await Controller.at(controllerAddress); - var isSchemeRegistered = await controller.isSchemeRegistered(daoCreator.address); - assert.equal(isSchemeRegistered,true); - await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData"); - controllerAddress = await avatar.owner(); - controller = await Controller.at(controllerAddress); - isSchemeRegistered = await controller.isSchemeRegistered(daoCreator.address); - assert.equal(isSchemeRegistered,false); - }); - - it("setSchemes delete lock", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData"); - try { - await daoCreator.setSchemes(avatar.address,[accounts[1]],["0x0000000F"],"metaData",{ from: accounts[1]}); - assert(false,"should fail because lock for account[0] suppose to be deleted by the first call"); - } - catch(ex){ - helpers.assertVMException(ex); - } - }); - - it("forgeOrg with different params length should revert", async function() { - var amountToMint = 10; - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - try { - await daoCreator.forgeOrg("testOrg","TEST","TST",[accounts[0]],[amountToMint],[],helpers.NULL_ADDRESS,{gas:constants.ARC_GAS_LIMIT}); - assert(false,"should revert because reputation array size is 0"); - } - catch(ex){ - helpers.assertVMException(ex); - } - - try { - await daoCreator.forgeOrg("testOrg","TEST","TST",[accounts[0],helpers.NULL_ADDRESS],[amountToMint,amountToMint],[amountToMint,amountToMint],0,{gas:constants.ARC_GAS_LIMIT}); - assert(false,"should revert because account is 0"); - } - catch(ex){ - helpers.assertVMException(ex); - } - }); - it("setSchemes to none SchemeMock and addFounders", async function() { - var amountToMint = 10; - await setup(accounts,amountToMint,amountToMint); - var foundersArray = []; - var founderReputation = []; - var founderToken = []; - var i; - var numberOfFounders = 60; - for (i=0;i { - it("initialize", async () => { - let testSetup = await setup(accounts); - - assert.equal(await testSetup.forwarder.avatar(),testSetup.org.avatar.address); - assert.equal(await testSetup.forwarder.expirationTime(),testSetup.expirationTime); - }); - - it("cannot initialize twice", async () => { - let testSetup = await setup(accounts); - try { - await testSetup.forwarder.initialize(testSetup.org.avatar.address, - testSetup.expirationTime, - accounts[0]); - assert(false, "cannot initialize twice"); - } catch(error) { - helpers.assertVMException(error); - } - }); - - it("forwardCall (fallback)", async () => { - let testSetupA = await setup(accounts); - let testSetupB = await setup(accounts); - // transferOwnership of testSetupA.forwarder to testSetupB avatar - await testSetupA.forwarder.transferOwnership(testSetupB.org.avatar.address); - //do generic call from testSetupB controller to testSetupA controller to "registerScheme" - let controllerB = await Controller.at(await testSetupB.org.avatar.owner()); - let controllerA = await Controller.at(await testSetupA.org.avatar.owner()); - const encodeABI = await new web3.eth.Contract(controllerA.abi). - methods. - registerScheme(accounts[1],"0x0000001f"). - encodeABI(); - assert.equal(await controllerA.isSchemeRegistered(accounts[1]),false); - await controllerB.genericCall(testSetupA.forwarder.address,encodeABI,0); - //check that accounts[1] register as scheme at controllerA. - assert.equal(await controllerA.isSchemeRegistered(accounts[1]),true); - - }); - - it("forwardCall (fallback) -check expirationTime", async () => { - let testSetupA = await setup(accounts); - let testSetupB = await setup(accounts); - // transferOwnership of testSetupA.forwarder to testSetupB avatar - await testSetupA.forwarder.transferOwnership(testSetupB.org.avatar.address); - //do generic call from testSetupB controller to testSetupA controller to "registerScheme" - let controllerB = await Controller.at(await testSetupB.org.avatar.owner()); - let controllerA = await Controller.at(await testSetupA.org.avatar.owner()); - const encodeABI = await new web3.eth.Contract(controllerA.abi). - methods. - registerScheme(accounts[1],"0x0000001f"). - encodeABI(); - //expiered - await helpers.increaseTime(301); - - let tx = await controllerB.genericCall(testSetupA.forwarder.address,encodeABI,0); - await testSetupB.org.avatar.getPastEvents('GenericCall', { - fromBlock: tx.blockNumber, - toBlock: 'latest' - }) - .then(function(events){ - assert.equal(events[0].event,"GenericCall"); - assert.equal(events[0].args._success,false); - }); - - }); - - - it("forwardCall (fallback) is onlyOwner ", async () => { - let testSetupA = await setup(accounts); - let testSetupB = await setup(accounts); - //do generic call from testSetupB controller to testSetupA controller to "registerScheme" - let controllerB = await Controller.at(await testSetupB.org.avatar.owner()); - let controllerA = await Controller.at(await testSetupA.org.avatar.owner()); - const encodeABI = await new web3.eth.Contract(controllerA.abi). - methods. - registerScheme(accounts[1],"0x0000001f"). - encodeABI(); - let tx = await controllerB.genericCall(testSetupA.forwarder.address,encodeABI,0); - await testSetupB.org.avatar.getPastEvents('GenericCall', { - fromBlock: tx.blockNumber, - toBlock: 'latest' - }) - .then(function(events){ - assert.equal(events[0].event,"GenericCall"); - assert.equal(events[0].args._success,false); - }); - - }); - - it("unregisterSelf", async () => { - let testSetupA = await setup(accounts); - let testSetupB = await setup(accounts); - let controllerA = await Controller.at(await testSetupA.org.avatar.owner()); - // transferOwnership of testSetupA.forwarder to testSetupB avatar - await testSetupA.forwarder.transferOwnership(testSetupB.org.avatar.address); - assert.equal(await controllerA.isSchemeRegistered(testSetupA.forwarder.address),true); - try { - await testSetupA.forwarder.unregisterSelf(); - assert(false, "expirationTime did not passed"); - } catch(error) { - helpers.assertVMException(error); - } - assert.equal(await controllerA.isSchemeRegistered(testSetupA.forwarder.address),true); - await helpers.increaseTime(301); - await testSetupA.forwarder.unregisterSelf(); - assert.equal(await controllerA.isSchemeRegistered(testSetupA.forwarder.address),false); - - }); -}); diff --git a/test/globalconstraintregistrar.js b/test/globalconstraintregistrar.js index 53166988..93816266 100644 --- a/test/globalconstraintregistrar.js +++ b/test/globalconstraintregistrar.js @@ -1,22 +1,15 @@ import * as helpers from './helpers'; -const constants = require('./constants'); const GlobalConstraintRegistrar = artifacts.require("./GlobalConstraintRegistrar.sol"); const GlobalConstraintMock = artifacts.require('./test/GlobalConstraintMock.sol'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); const Controller = artifacts.require("./Controller.sol"); const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); - - - export class GlobalConstraintRegistrarParams { constructor() { } } - +var registration; const setupGlobalConstraintRegistrarParams = async function( - globalConstraintRegistrar, accounts, genesisProtocol, @@ -26,52 +19,62 @@ const setupGlobalConstraintRegistrarParams = async function( var globalConstraintRegistrarParams = new GlobalConstraintRegistrarParams(); if (genesisProtocol === true) { globalConstraintRegistrarParams.votingMachine = await helpers.setupGenesisProtocol(accounts,token,helpers.NULL_ADDRESS); - await globalConstraintRegistrar.initialize(avatarAddress, + globalConstraintRegistrarParams.initdata = await new web3.eth.Contract(registration.globalConstraintRegistrar.abi) + .methods + .initialize(avatarAddress, globalConstraintRegistrarParams.votingMachine.genesisProtocol.address, - globalConstraintRegistrarParams.votingMachine.params - ); + globalConstraintRegistrarParams.votingMachine.params) + .encodeABI(); } else { - globalConstraintRegistrarParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50,globalConstraintRegistrar.address); - await globalConstraintRegistrar.initialize( avatarAddress, - globalConstraintRegistrarParams.votingMachine.absoluteVote.address, - globalConstraintRegistrarParams.votingMachine.params, - ); + globalConstraintRegistrarParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50); + globalConstraintRegistrarParams.initdata = await new web3.eth.Contract(registration.globalConstraintRegistrar.abi) + .methods + .initialize(avatarAddress, + globalConstraintRegistrarParams.votingMachine.absoluteVote.address, + globalConstraintRegistrarParams.votingMachine.params) + .encodeABI(); } return globalConstraintRegistrarParams; }; const setup = async function (accounts,genesisProtocol = false,tokenAddress=0) { - var testSetup = new helpers.TestSetup(); - testSetup.fee = 10; - testSetup.globalConstraintRegistrar = await GlobalConstraintRegistrar.new(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); + var testSetup = new helpers.TestSetup(); + testSetup.standardTokenMock = await ERC20Mock.new(accounts[1],100000); + registration = await helpers.registerImplementation(); testSetup.reputationArray = [20,10,70]; - testSetup.org = await helpers.setupOrganizationWithArrays(testSetup.daoCreator,[accounts[0],accounts[1],accounts[2]],[1000,1000,1000],testSetup.reputationArray); + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0], + accounts[1], + accounts[2]], + [1000,0,0], + testSetup.reputationArray); + testSetup.globalConstraintRegistrarParams= await setupGlobalConstraintRegistrarParams(testSetup.globalConstraintRegistrar, accounts, genesisProtocol, tokenAddress, - testSetup.org.avatar.address); + testSetup.org.avatar.address); var permissions = "0x00000004"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address, - [testSetup.globalConstraintRegistrar.address], - [permissions],"metaData"); + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("GlobalConstraintRegistrar")], + testSetup.globalConstraintRegistrarParams.initdata, + [helpers.getBytesLength(testSetup.globalConstraintRegistrarParams.initdata)], + [permissions], + "metaData",{from:testSetup.proxyAdmin}); + + testSetup.globalConstraintRegistrar = await GlobalConstraintRegistrar.at(tx.logs[1].args._scheme); return testSetup; }; contract('GlobalConstraintRegistrar', accounts => { it("initialize", async ()=> { - var globalConstraintRegistrar = await GlobalConstraintRegistrar.new(); - var params = await setupGlobalConstraintRegistrarParams(globalConstraintRegistrar, - accounts, - false, - helpers.SOME_ADDRESS, - helpers.SOME_ADDRESS); - - assert.equal(await globalConstraintRegistrar.votingMachine(),params.votingMachine.absoluteVote.address); + var testSetup = await setup(accounts); + assert.equal(await testSetup.globalConstraintRegistrar.votingMachine(),testSetup.globalConstraintRegistrarParams.votingMachine.absoluteVote.address); }); it("proposeGlobalConstraint voteToRemoveParams", async function() { @@ -220,7 +223,7 @@ contract('GlobalConstraintRegistrar', accounts => { helpers.NULL_HASH); proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); var rep = await testSetup.org.reputation.balanceOf(accounts[2]); - await testSetup.globalConstraintRegistrarParams.votingMachine.genesisProtocol.vote(proposalId,1,0,helpers.NULL_ADDRESS,{gas: constants.ARC_GAS_LIMIT, from:accounts[2]}); + await testSetup.globalConstraintRegistrarParams.votingMachine.genesisProtocol.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]}); await helpers.checkVoteInfo(testSetup.globalConstraintRegistrarParams.votingMachine.genesisProtocol,proposalId,accounts[2],[1,rep.toNumber()]); }); diff --git a/test/helpers.js b/test/helpers.js index b602eda5..ba6da041 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -21,6 +21,18 @@ const ContributionRewardExt = artifacts.require("./ContributionRewardExt.sol"); const SchemeRegistrar = artifacts.require("./SchemeRegistrar.sol"); const GenericScheme = artifacts.require("./GenericScheme.sol"); const UpgradeScheme = artifacts.require("./UpgradeScheme.sol"); +const Auction4Reputation = artifacts.require("./Auction4Reputation.sol"); +const LockingEth4Reputation = artifacts.require("./LockingEth4Reputation.sol"); +const LockingToken4Reputation = artifacts.require("./LockingToken4Reputation.sol"); +const ContinuousLocking4Reputation = artifacts.require("./ContinuousLocking4Reputation.sol"); +const ExternalLocking4Reputation = artifacts.require("./ExternalLocking4Reputation.sol"); +const FixedReputationAllocation = artifacts.require("./FixedReputationAllocation.sol"); +const GlobalConstraintRegistrar = artifacts.require("./GlobalConstraintRegistrar.sol"); +const SignalScheme = artifacts.require("./SignalScheme.sol"); +const ReputationFromToken = artifacts.require("./ReputationFromToken.sol"); +const VoteInOrganization = artifacts.require("./VoteInOrganizationScheme.sol"); +const ARCVotingMachineCallbacksMock = artifacts.require("./ARCVotingMachineCallbacksMock.sol"); + export const MAX_UINT_256 = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; export const NULL_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000'; @@ -155,6 +167,19 @@ export const registrationAddVersionToPackege = async function (registration,vers registration.schemeRegistrar = await SchemeRegistrar.new(); registration.genericScheme = await GenericScheme.new(); registration.upgradeScheme = await UpgradeScheme.new(); + registration.auction4Reputation = await Auction4Reputation.new(); + registration.lockingEth4Reputation = await LockingEth4Reputation.new(); + registration.lockingToken4Reputation = await LockingToken4Reputation.new(); + registration.continuousLocking4Reputation = await ContinuousLocking4Reputation.new(); + registration.externalLocking4Reputation = await ExternalLocking4Reputation.new(); + registration.fixedReputationAllocation = await FixedReputationAllocation.new(); + registration.globalConstraintRegistrar = await GlobalConstraintRegistrar.new(); + registration.signalScheme = await SignalScheme.new(); + registration.reputationFromToken = await ReputationFromToken.new(); + registration.voteInOrganization = await VoteInOrganization.new(); + registration.arcVotingMachineCallbacksMock = await ARCVotingMachineCallbacksMock.new(); + + await implementationDirectory.setImplementation("DAOToken",registration.daoToken.address); await implementationDirectory.setImplementation("Reputation",registration.reputation.address); await implementationDirectory.setImplementation("Avatar",registration.avatar.address); @@ -167,8 +192,17 @@ export const registrationAddVersionToPackege = async function (registration,vers await implementationDirectory.setImplementation("SchemeRegistrar",registration.schemeRegistrar.address); await implementationDirectory.setImplementation("GenericScheme",registration.genericScheme.address); await implementationDirectory.setImplementation("UpgradeScheme",registration.upgradeScheme.address); - - + await implementationDirectory.setImplementation("Auction4Reputation",registration.auction4Reputation.address); + await implementationDirectory.setImplementation("LockingEth4Reputation",registration.lockingEth4Reputation.address); + await implementationDirectory.setImplementation("LockingToken4Reputation",registration.lockingToken4Reputation.address); + await implementationDirectory.setImplementation("ContinuousLocking4Reputation",registration.continuousLocking4Reputation.address); + await implementationDirectory.setImplementation("ExternalLocking4Reputation",registration.externalLocking4Reputation.address); + await implementationDirectory.setImplementation("FixedReputationAllocation",registration.fixedReputationAllocation.address); + await implementationDirectory.setImplementation("GlobalConstraintRegistrar",registration.globalConstraintRegistrar.address); + await implementationDirectory.setImplementation("SignalScheme",registration.signalScheme.address); + await implementationDirectory.setImplementation("ReputationFromToken",registration.reputationFromToken.address); + await implementationDirectory.setImplementation("VoteInOrganization",registration.voteInOrganization.address); + await implementationDirectory.setImplementation("ARCVotingMachineCallbacksMock",registration.arcVotingMachineCallbacksMock.address); return registration; }; @@ -241,24 +275,10 @@ export const setupGenesisProtocol = async function ( return votingMachine; }; -export const setupOrganizationWithArrays = async function (daoCreator,daoCreatorOwner,founderToken,founderReputation,cap=0) { - var org = new Organization(); - var tx = await daoCreator.forgeOrg("testOrg","TEST","TST",daoCreatorOwner,founderToken,founderReputation,cap,{gas: constants.ARC_GAS_LIMIT}); - assert.equal(tx.logs.length, 1); - assert.equal(tx.logs[0].event, "NewOrg"); - var avatarAddress = tx.logs[0].args._avatar; - org.avatar = await Avatar.at(avatarAddress); - var tokenAddress = await org.avatar.nativeToken(); - org.token = await DAOToken.at(tokenAddress); - var reputationAddress = await org.avatar.nativeReputation(); - org.reputation = await Reputation.at(reputationAddress); - return org; -}; - export const setupOrganizationWithArraysDAOFactory = async function (proxyAdmin, accounts, registration, - daoCreatorOwner, + daoFactoryOwner, founderToken, founderReputation, cap=0) { @@ -269,7 +289,7 @@ export const setupOrganizationWithArraysDAOFactory = async function (proxyAdmin, .encodeABI(); var tx = await registration.daoFactory.forgeOrg("testOrg", nativeTokenData, - daoCreatorOwner, + daoFactoryOwner, founderToken, founderReputation, [0,0,0], @@ -285,21 +305,6 @@ export const setupOrganizationWithArraysDAOFactory = async function (proxyAdmin, return org; }; -export const setupOrganization = async function (daoCreator,daoCreatorOwner,founderToken,founderReputation,cap=0) { - var org = new Organization(); - var tx = await daoCreator.forgeOrg("testOrg","TEST","TST",[daoCreatorOwner],[founderToken],[founderReputation],cap,{gas: constants.ARC_GAS_LIMIT}); - assert.equal(tx.logs.length, 1); - assert.equal(tx.logs[0].event, "NewOrg"); - var avatarAddress = tx.logs[0].args._avatar; - org.avatar = await Avatar.at(avatarAddress); - var tokenAddress = await org.avatar.nativeToken(); - org.token = await DAOToken.at(tokenAddress); - var reputationAddress = await org.avatar.nativeReputation(); - org.reputation = await Reputation.at(reputationAddress); - return org; -}; - - export const checkVoteInfo = async function(absoluteVote,proposalId, voterAddress, _voteInfo) { let voteInfo; voteInfo = await absoluteVote.voteInfo(proposalId, voterAddress); diff --git a/test/lockingeth4reputation.js b/test/lockingeth4reputation.js index 77da78e7..574d3cc4 100644 --- a/test/lockingeth4reputation.js +++ b/test/lockingeth4reputation.js @@ -1,42 +1,65 @@ const helpers = require('./helpers'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); - -const constants = require('./constants'); var LockingEth4Reputation = artifacts.require("./LockingEth4Reputation.sol"); +export class LockingEth4ReputationParams { + constructor() { + } +} + +var registration; + const setup = async function (accounts, _repAllocation = 100, _lockingStartTime = 0, _lockingEndTime = 3000, _redeemEnableTime = 3000, _maxLockingPeriod = 6000, - _agreementHash = helpers.SOME_HASH, - _initialize = true) { + _agreementHash = helpers.SOME_HASH) { var testSetup = new helpers.TestSetup(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); + registration = await helpers.registerImplementation(); - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000]); + testSetup.lockingEndTime = (await web3.eth.getBlock("latest")).timestamp + _lockingEndTime; testSetup.lockingStartTime = (await web3.eth.getBlock("latest")).timestamp + _lockingStartTime; testSetup.redeemEnableTime = (await web3.eth.getBlock("latest")).timestamp + _redeemEnableTime; testSetup.lockingEth4Reputation = await LockingEth4Reputation.new(); testSetup.agreementHash = _agreementHash; - if (_initialize === true) { - await testSetup.lockingEth4Reputation.initialize(testSetup.org.avatar.address, - _repAllocation, - testSetup.lockingStartTime, - testSetup.lockingEndTime, - testSetup.redeemEnableTime, - _maxLockingPeriod, - testSetup.agreementHash); - } + + testSetup.lockingEth4ReputationParams = new LockingEth4ReputationParams(); + + testSetup.lockingEth4ReputationParams.initdata = await new web3.eth.Contract(registration.lockingEth4Reputation.abi) + .methods + .initialize(testSetup.org.avatar.address, + _repAllocation, + testSetup.lockingStartTime, + testSetup.lockingEndTime, + testSetup.redeemEnableTime, + _maxLockingPeriod, + testSetup.agreementHash) + .encodeABI(); var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address,[testSetup.lockingEth4Reputation.address],[permissions],"metaData"); + + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("LockingEth4Reputation")], + testSetup.lockingEth4ReputationParams.initdata, + [helpers.getBytesLength(testSetup.lockingEth4ReputationParams.initdata)], + [permissions], + "metaData", + {from:testSetup.proxyAdmin}); + + testSetup.lockingEth4Reputation = await LockingEth4Reputation.at(tx.logs[1].args._scheme); + return testSetup; }; @@ -81,16 +104,6 @@ contract('LockingEth4Reputation', accounts => { }); - it("cannot lock without initialize", async () => { - let testSetup = await setup(accounts,100,0,3000,3000,6000,helpers.SOME_HASH,false); - try { - await testSetup.lockingEth4Reputation.lock(100,testSetup.agreementHash,{value:web3.utils.toWei('1', "ether")}); - assert(false, "cannot lock without initialize"); - } catch(error) { - helpers.assertVMException(error); - } - }); - it("cannot lock with wrong agreementHash", async () => { let testSetup = await setup(accounts); try { diff --git a/test/lockingtoken4reputation.js b/test/lockingtoken4reputation.js index 36401a9a..561ae34a 100644 --- a/test/lockingtoken4reputation.js +++ b/test/lockingtoken4reputation.js @@ -1,27 +1,37 @@ const helpers = require('./helpers'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); -const constants = require('./constants'); const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); var LockingToken4Reputation = artifacts.require("./LockingToken4Reputation.sol"); const PriceOracleMock = artifacts.require('./test/PriceOracleMock.sol'); +export class LockingToken4ReputationParams { + constructor() { + } +} + +var registration; + const setup = async function (accounts, _repAllocation = 100, _lockingStartTime = 0, _lockingEndTime = 3000, _redeemEnableTime = 3000, _maxLockingPeriod = 6000, - _agreementHash = helpers.SOME_HASH, - _initialize = true) { + _agreementHash = helpers.SOME_HASH) { var testSetup = new helpers.TestSetup(); + registration = await helpers.registerImplementation(); testSetup.lockingToken = await ERC20Mock.new(accounts[0], web3.utils.toWei('100', "ether")); testSetup.lockingToken2 = await ERC20Mock.new(accounts[0], web3.utils.toWei('100', "ether")); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); + + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000]); + testSetup.lockingEndTime = (await web3.eth.getBlock("latest")).timestamp + _lockingEndTime; testSetup.lockingStartTime = (await web3.eth.getBlock("latest")).timestamp + _lockingStartTime; testSetup.redeemEnableTime = (await web3.eth.getBlock("latest")).timestamp + _redeemEnableTime; @@ -33,19 +43,34 @@ const setup = async function (accounts, await testSetup.priceOracleMock.setTokenPrice(testSetup.lockingToken.address,100,4); await testSetup.priceOracleMock.setTokenPrice(testSetup.lockingToken2.address,200,4); - if (_initialize === true) { - await testSetup.lockingToken4Reputation.initialize(testSetup.org.avatar.address, - _repAllocation, - testSetup.lockingStartTime, - testSetup.lockingEndTime, - testSetup.redeemEnableTime, - _maxLockingPeriod, - testSetup.priceOracleMock.address, - testSetup.agreementHash); - } + testSetup.lockingToken4ReputationParams = new LockingToken4ReputationParams(); + + testSetup.lockingToken4ReputationParams.initdata = await new web3.eth.Contract(registration.lockingToken4Reputation.abi) + .methods + .initialize(testSetup.org.avatar.address, + _repAllocation, + testSetup.lockingStartTime, + testSetup.lockingEndTime, + testSetup.redeemEnableTime, + _maxLockingPeriod, + testSetup.priceOracleMock.address, + testSetup.agreementHash) + .encodeABI(); + var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address,[testSetup.lockingToken4Reputation.address],[permissions],"metaData"); + + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("LockingToken4Reputation")], + testSetup.lockingToken4ReputationParams.initdata, + [helpers.getBytesLength(testSetup.lockingToken4ReputationParams.initdata)], + [permissions], + "metaData", + {from:testSetup.proxyAdmin}); + + testSetup.lockingToken4Reputation = await LockingToken4Reputation.at(tx.logs[1].args._scheme); + await testSetup.lockingToken.approve(testSetup.lockingToken4Reputation.address,web3.utils.toWei('100', "ether")); return testSetup; }; @@ -103,16 +128,6 @@ contract('LockingToken4Reputation', accounts => { assert.equal(await testSetup.lockingToken4Reputation.totalScore(),2*100*web3.utils.toWei('1', "ether")*100/4); }); - it("cannot lock without initialize", async () => { - let testSetup = await setup(accounts,100,0,3000,3000,6000,helpers.SOME_HASH,false); - try { - await testSetup.lockingToken4Reputation.lock(web3.utils.toWei('1', "ether"),100,testSetup.lockingToken.address,testSetup.agreementHash); - assert(false, "cannot lock without initialize"); - } catch(error) { - helpers.assertVMException(error); - } - }); - it("cannot lock with wrong agreementHash", async () => { let testSetup = await setup(accounts); try { diff --git a/test/migrations.js b/test/migrations.js deleted file mode 100644 index 2a0da27c..00000000 --- a/test/migrations.js +++ /dev/null @@ -1,13 +0,0 @@ -const DaoCreator = artifacts.require('./DaoCreator.sol'); -const ContributionReward = artifacts.require('./ContributionReward.sol'); - -contract('Migrations', async function() { - - it('should have deployed entire DAOStack', async function() { - // 'deployed()' will throw an error if the contract is not found - // we test the first and last contract deployed in migrations - await DaoCreator.deployed(); - await ContributionReward.deployed(); - }); - -}); diff --git a/test/reputationfromtoken.js b/test/reputationfromtoken.js index 8c08ea15..9ee9669e 100644 --- a/test/reputationfromtoken.js +++ b/test/reputationfromtoken.js @@ -1,8 +1,5 @@ const helpers = require('./helpers'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); -const constants = require('./constants'); var ReputationFromToken = artifacts.require("./ReputationFromToken.sol"); var RepAllocation = artifacts.require("./RepAllocation.sol"); var PolkaCurve = artifacts.require("./PolkaCurve.sol"); @@ -11,12 +8,23 @@ var NectarRepAllocation = artifacts.require("./NectarRepAllocation.sol"); const NectarToken = artifacts.require('./Reputation.sol'); var ethereumjs = require('ethereumjs-abi'); +export class ReputationFromTokenParams { + constructor() { + } +} + +var registration; + const setupNectar = async function (accounts) { var testSetup = new helpers.TestSetup(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); + registration = await helpers.registerImplementation(); + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000]); testSetup.nectarToken = await NectarToken.new(); await testSetup.nectarToken.initialize(accounts[0]); await testSetup.nectarToken.mint(accounts[0],100); @@ -33,22 +41,40 @@ const setupNectar = async function (accounts) { testSetup.reputationFromToken = await ReputationFromToken.new(); testSetup.curve = helpers.NULL_ADDRESS; - await testSetup.reputationFromToken.initialize(testSetup.org.avatar.address, - testSetup.nectarRepAllocation.address, - helpers.NULL_ADDRESS); + + testSetup.reputationFromTokenParams = new ReputationFromTokenParams(); + testSetup.reputationFromTokenParams.initdata = await new web3.eth.Contract(registration.reputationFromToken.abi) + .methods + .initialize(testSetup.org.avatar.address, + testSetup.nectarRepAllocation.address, + helpers.NULL_ADDRESS) + .encodeABI(); var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address,[testSetup.reputationFromToken.address],[permissions],"metaData"); - return testSetup; + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("ReputationFromToken")], + testSetup.reputationFromTokenParams.initdata, + [helpers.getBytesLength(testSetup.reputationFromTokenParams.initdata)], + [permissions], + "metaData", + {from:testSetup.proxyAdmin}); + + testSetup.reputationFromToken = await ReputationFromToken.at(tx.logs[1].args._scheme); + return testSetup; }; -const setup = async function (accounts, _initialize = true) { +const setup = async function (accounts) { var testSetup = new helpers.TestSetup(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); + registration = await helpers.registerImplementation(); + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000]); testSetup.repAllocation = await RepAllocation.new(); await testSetup.repAllocation.initialize(accounts[0]); await testSetup.repAllocation.addBeneficiary(accounts[0],100); @@ -57,14 +83,27 @@ const setup = async function (accounts, _initialize = true) { testSetup.reputationFromToken = await ReputationFromToken.new(); testSetup.curve = await PolkaCurve.new(); - if (_initialize === true) { - await testSetup.reputationFromToken.initialize(testSetup.org.avatar.address, - testSetup.repAllocation.address, - testSetup.curve.address); - } + + testSetup.reputationFromTokenParams = new ReputationFromTokenParams(); + + testSetup.reputationFromTokenParams.initdata = await new web3.eth.Contract(registration.reputationFromToken.abi) + .methods + .initialize(testSetup.org.avatar.address, + testSetup.repAllocation.address, + testSetup.curve.address) + .encodeABI(); var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address,[testSetup.reputationFromToken.address],[permissions],"metaData"); + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("ReputationFromToken")], + testSetup.reputationFromTokenParams.initdata, + [helpers.getBytesLength(testSetup.reputationFromTokenParams.initdata)], + [permissions], + "metaData", + {from:testSetup.proxyAdmin}); + + testSetup.reputationFromToken = await ReputationFromToken.at(tx.logs[1].args._scheme); return testSetup; }; const signatureType = 1; diff --git a/test/signalscheme.js b/test/signalscheme.js index 343f0b12..a6ccd116 100644 --- a/test/signalscheme.js +++ b/test/signalscheme.js @@ -1,18 +1,15 @@ import * as helpers from './helpers'; -const constants = require('./constants'); const SignalScheme = artifacts.require("./SignalScheme.sol"); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); export class SignalSchemeParams { constructor() { } } +var registration; const setupSignalSchemeParam = async function( - signalScheme, accounts, genesisProtocol, avatar @@ -20,41 +17,59 @@ const setupSignalSchemeParam = async function( var signalSchemeParams = new SignalSchemeParams(); if (genesisProtocol === true) { signalSchemeParams.votingMachine = await helpers.setupGenesisProtocol(accounts,token,avatar,helpers.NULL_ADDRESS); - await signalScheme.initialize( avatar.address, - 1234, - setupSignalSchemeParam.votingMachine.params, - setupSignalSchemeParam.votingMachine.genesisProtocol.address); + signalSchemeParams.initdata = await new web3.eth.Contract(registration.signalScheme.abi) + .methods + .initialize( avatar.address, + 1234, + setupSignalSchemeParam.votingMachine.params, + setupSignalSchemeParam.votingMachine.genesisProtocol.address) + .encodeABI(); } else { - signalSchemeParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50,signalScheme.address); - await signalScheme.initialize( avatar.address, - 1234, - signalSchemeParams.votingMachine.params, - signalSchemeParams.votingMachine.absoluteVote.address); + signalSchemeParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50); + signalSchemeParams.initdata = await new web3.eth.Contract(registration.signalScheme.abi) + .methods + .initialize( avatar.address, + 1234, + signalSchemeParams.votingMachine.params, + signalSchemeParams.votingMachine.absoluteVote.address) + .encodeABI(); } return signalSchemeParams; }; const setup = async function (accounts,genesisProtocol = false) { var testSetup = new helpers.TestSetup(); - testSetup.signalScheme = await SignalScheme.new(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); + registration = await helpers.registerImplementation(); + if (genesisProtocol) { testSetup.reputationArray = [1000,100,0]; } else { testSetup.reputationArray = [2000,4000,7000]; } - testSetup.org = await helpers.setupOrganizationWithArrays(testSetup.daoCreator,[accounts[0],accounts[1],accounts[2]],[1000,0,0],testSetup.reputationArray); - testSetup.signalSchemeParams= await setupSignalSchemeParam( - testSetup.signalScheme, + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0], + accounts[1], + accounts[2]], + [1000,0,0], + testSetup.reputationArray); + + testSetup.signalSchemeParams= await setupSignalSchemeParam( accounts, genesisProtocol, testSetup.org.avatar); var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address, - [testSetup.signalScheme.address], - [permissions],"metaData"); + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("SignalScheme")], + testSetup.signalSchemeParams.initdata, + [helpers.getBytesLength(testSetup.signalSchemeParams.initdata)], + [permissions], + "metaData",{from:testSetup.proxyAdmin}); + + testSetup.signalScheme = await SignalScheme.at(tx.logs[1].args._scheme); return testSetup; }; contract('SignalScheme', accounts => { diff --git a/test/voteinorganization.js b/test/voteinorganization.js index 8a9e27de..0eab2e83 100644 --- a/test/voteinorganization.js +++ b/test/voteinorganization.js @@ -1,23 +1,18 @@ import * as helpers from './helpers'; -const constants = require('./constants'); -const AbsoluteVote = artifacts.require('./AbsoluteVote.sol'); -const VoteInOrganizationScheme = artifacts.require('./VoteInOrganizationScheme.sol'); +const VoteInOrganization = artifacts.require('./VoteInOrganizationScheme.sol'); const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); const AbsoluteVoteExecuteMock = artifacts.require("./AbsoluteVoteExecuteMock.sol"); const GenesisProtocolCallbacksMock = artifacts.require("./GenesisProtocolCallbacksMock.sol"); const Reputation = artifacts.require("./Reputation.sol"); -const Controller = artifacts.require("./Controller.sol"); export class VoteInOrganizationParams { constructor() { } } +var registration; const setupVoteInOrganizationParams = async function( - voteInOrganization, accounts, genesisProtocol = false, tokenAddress = 0, @@ -27,18 +22,21 @@ const setupVoteInOrganizationParams = async function( voteInOrganizationParams.paramsHash = helpers.NULL_HASH; if (genesisProtocol === true){ voteInOrganizationParams.votingMachine = await helpers.setupGenesisProtocol(accounts,tokenAddress,helpers.NULL_ADDRESS); - await voteInOrganization.initialize( avatarAddress, - voteInOrganizationParams.votingMachine.genesisProtocol.address, - voteInOrganizationParams.votingMachine.params - ); - + voteInOrganizationParams.initdata = await new web3.eth.Contract(registration.voteInOrganization.abi) + .methods + .initialize(avatarAddress, + voteInOrganizationParams.votingMachine.genesisProtocol.address, + voteInOrganizationParams.votingMachine.params) + .encodeABI(); } else { voteInOrganizationParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50); - await voteInOrganization.initialize(avatarAddress, - voteInOrganizationParams.votingMachine.absoluteVote.address, - voteInOrganizationParams.votingMachine.params - ); + voteInOrganizationParams.initdata = await new web3.eth.Contract(registration.voteInOrganization.abi) + .methods + .initialize(avatarAddress, + voteInOrganizationParams.votingMachine.absoluteVote.address, + voteInOrganizationParams.votingMachine.params) + .encodeABI(); } return voteInOrganizationParams; @@ -48,27 +46,41 @@ const setup = async function (accounts,reputationAccount=0,genesisProtocol = fal var testSetup = new helpers.TestSetup(); testSetup.fee = 10; testSetup.standardTokenMock = await ERC20Mock.new(accounts[1],100); - testSetup.voteInOrganization = await VoteInOrganizationScheme.new(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); + registration = await helpers.registerImplementation(); testSetup.reputationArray = [200,100,700]; + testSetup.proxyAdmin = accounts[5]; if (reputationAccount === 0) { - testSetup.org = await helpers.setupOrganizationWithArrays(testSetup.daoCreator,[accounts[0],accounts[1],accounts[2]],[1000,1000,1000],testSetup.reputationArray); + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0],accounts[1],accounts[2]], + [1000,1000,1000], + testSetup.reputationArray); } else { - testSetup.org = await helpers.setupOrganizationWithArrays(testSetup.daoCreator,[accounts[0],accounts[1],reputationAccount],[1000,1000,1000],testSetup.reputationArray); + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0],accounts[1],reputationAccount], + [1000,1000,1000], + testSetup.reputationArray); } - testSetup.voteInOrganizationParams= await setupVoteInOrganizationParams(testSetup.voteInOrganization, + testSetup.voteInOrganizationParams= await setupVoteInOrganizationParams( accounts, genesisProtocol, tokenAddress, testSetup.org.avatar.address); var permissions = "0x00000010"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address, - [testSetup.voteInOrganization.address,accounts[3]], - [permissions,permissions],"metaData"); + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("VoteInOrganization")], + testSetup.voteInOrganizationParams.initdata, + [helpers.getBytesLength(testSetup.voteInOrganizationParams.initdata)], + [permissions], + "metaData",{from:testSetup.proxyAdmin}); + + testSetup.voteInOrganization = await VoteInOrganization.at(tx.logs[1].args._scheme); return testSetup; }; @@ -77,20 +89,6 @@ contract('VoteInOrganizationScheme', accounts => { before(function() { helpers.etherForEveryone(accounts); }); - it("initialize", async() => { - var voteInOrganization = await VoteInOrganizationScheme.new(); - var absoluteVote = await AbsoluteVote.new(); - await voteInOrganization.initialize(helpers.SOME_ADDRESS,absoluteVote.address,"0x1234"); - - assert.equal(await voteInOrganization.votingMachine(),absoluteVote.address); - try { - await voteInOrganization.initialize(helpers.SOME_ADDRESS,absoluteVote.address,"0x1234"); - assert(false, "cannot initialize twice"); - } catch(error) { - helpers.assertVMException(error); - } - }); - it("proposeVote log", async function() { var testSetup = await setup(accounts); @@ -141,10 +139,8 @@ contract('VoteInOrganizationScheme', accounts => { it("execute proposeVote -positive decision - proposal data delete", async function() { var testSetup = await setup(accounts); - var anotherTestSetup = await setup(accounts); - var anotherController = await Controller.at(await anotherTestSetup.org.reputation.owner()); + var anotherTestSetup = await setup(accounts,testSetup.org.avatar.address); //mint reputation to avatar in the other dao. - await anotherController.mintReputation(10000,testSetup.org.avatar.address,{from:accounts[3]}); var absoluteVoteExecuteMock = await AbsoluteVoteExecuteMock.new(); await absoluteVoteExecuteMock.initialize(anotherTestSetup.org.reputation.address, anotherTestSetup.voteInOrganizationParams.votingMachine.absoluteVote.address); diff --git a/test/votingmachinecallbacks.js b/test/votingmachinecallbacks.js index 55a13ed8..38702b5e 100644 --- a/test/votingmachinecallbacks.js +++ b/test/votingmachinecallbacks.js @@ -1,26 +1,42 @@ import * as helpers from './helpers'; -const constants = require('./constants'); const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); -const DaoCreator = artifacts.require("./DaoCreator.sol"); -const ControllerCreator = artifacts.require("./ControllerCreator.sol"); const ARCVotingMachineCallbacksMock = artifacts.require("./ARCVotingMachineCallbacksMock.sol"); const proposalId = "0x1234000000000000000000000000000000000000000000000000000000000000"; + +export class SchemeParams { + constructor() { + } + } + + var registration; + const setup = async function (accounts) { var testSetup = new helpers.TestSetup(); - var controllerCreator = await ControllerCreator.new({gas: constants.ARC_GAS_LIMIT}); - - testSetup.daoCreator = await DaoCreator.new(controllerCreator.address,{gas:constants.ARC_GAS_LIMIT}); - testSetup.org = await helpers.setupOrganization(testSetup.daoCreator,accounts[0],1000,1000); + registration = await helpers.registerImplementation(); + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000]); testSetup.standardTokenMock = await ERC20Mock.new(testSetup.org.avatar.address,100); - testSetup.arcVotingMachineCallbacksMock = await ARCVotingMachineCallbacksMock.new(); var permissions = "0x00000000"; - await testSetup.daoCreator.setSchemes(testSetup.org.avatar.address, - [testSetup.arcVotingMachineCallbacksMock.address], - [permissions],"metaData"); + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("ARCVotingMachineCallbacksMock")], + '0x', + [0], + [permissions], + "metaData", + {from:testSetup.proxyAdmin}); + + testSetup.arcVotingMachineCallbacksMock = await ARCVotingMachineCallbacksMock.at(tx.logs[1].args._scheme); + await testSetup.arcVotingMachineCallbacksMock.propose(proposalId, testSetup.org.avatar.address, accounts[0]);