From be84c6a19a90b5ad33c8e7f8460647602385d1b1 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Tue, 3 Mar 2020 17:24:12 +0200 Subject: [PATCH 1/2] SKALE-2164 removed contract DelegationService --- .openzeppelin/project.json | 1 - contracts/SkaleManager.sol | 1 - contracts/delegation/DelegationController.sol | 2 +- contracts/delegation/DelegationService.sol | 128 ------------------ contracts/delegation/ValidatorService.sol | 46 +++++-- migrations/1_deploy_skale_manager_system.js | 1 - test/NodesFunctionality.ts | 2 +- test/SchainsFunctionality.ts | 6 +- test/SkaleDKG.ts | 8 +- test/SkaleManager.ts | 8 +- test/SkaleVerifier.ts | 2 +- test/delegation/Delegation.ts | 20 +-- test/delegation/DelegationRequest.ts | 10 +- test/delegation/TokenLaunch.ts | 8 +- test/delegation/TokenState.ts | 6 +- test/delegation/ValidatorService.ts | 61 +++++---- .../deploy/delegation/delegationService.ts | 34 ----- test/utils/deploy/skaleManager.ts | 2 - 18 files changed, 85 insertions(+), 261 deletions(-) delete mode 100644 contracts/delegation/DelegationService.sol delete mode 100644 test/utils/deploy/delegation/delegationService.ts diff --git a/.openzeppelin/project.json b/.openzeppelin/project.json index 8d4055ca9..2bf259c90 100644 --- a/.openzeppelin/project.json +++ b/.openzeppelin/project.json @@ -3,7 +3,6 @@ "contracts": { "DelegationController": "DelegationController", "DelegationPeriodManager": "DelegationPeriodManager", - "DelegationService": "DelegationService", "Distributor": "Distributor", "TimeHelpers": "TimeHelpers", "TokenLaunchManager": "TokenLaunchManager", diff --git a/contracts/SkaleManager.sol b/contracts/SkaleManager.sol index 8d83b6d0d..26ca4449b 100644 --- a/contracts/SkaleManager.sol +++ b/contracts/SkaleManager.sol @@ -26,7 +26,6 @@ import "./interfaces/ISkaleToken.sol"; import "./interfaces/INodesFunctionality.sol"; import "./interfaces/ISchainsFunctionality.sol"; import "./interfaces/IManagerData.sol"; -import "./delegation/DelegationService.sol"; import "./delegation/Distributor.sol"; import "./delegation/ValidatorService.sol"; import "./MonitorsFunctionality.sol"; diff --git a/contracts/delegation/DelegationController.sol b/contracts/delegation/DelegationController.sol index 9d516663c..63b3aa76c 100644 --- a/contracts/delegation/DelegationController.sol +++ b/contracts/delegation/DelegationController.sol @@ -165,7 +165,7 @@ contract DelegationController is Permissions, ILocker { return delegations[delegationId]; } - function getAndUpdateDelegatedToValidatorNow(uint validatorId) external allow("ValidatorService") returns (uint) { + function getAndUpdateDelegatedToValidatorNow(uint validatorId) external returns (uint) { return getAndUpdateDelegatedToValidator(validatorId, getCurrentMonth()); } diff --git a/contracts/delegation/DelegationService.sol b/contracts/delegation/DelegationService.sol deleted file mode 100644 index 0bcc9dd40..000000000 --- a/contracts/delegation/DelegationService.sol +++ /dev/null @@ -1,128 +0,0 @@ -/* - DelegationService.sol - SKALE Manager - Copyright (C) 2019-Present SKALE Labs - @author Dmytro Stebaiev - - SKALE Manager is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - SKALE Manager is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with SKALE Manager. If not, see . -*/ - -pragma solidity ^0.5.3; -pragma experimental ABIEncoderV2; - -import "../Permissions.sol"; -import "./ValidatorService.sol"; -import "./DelegationController.sol"; -import "./Distributor.sol"; -import "./TokenState.sol"; -import "./TimeHelpers.sol"; - - -contract DelegationService is Permissions { - - event ValidatorRegistered( - uint validatorId - ); - - function requestUndelegation(uint delegationId) external { - DelegationController delegationController = DelegationController(contractManager.getContract("DelegationController")); - - require( - delegationController.getDelegation(delegationId).holder == msg.sender, - "Can't request undelegation because sender is not a holder"); - - delegationController.requestUndelegation(delegationId); - } - - function setMinimumDelegationAmount(uint /* amount */) external pure { - revert("Not implemented"); - } - - /// @notice Returns amount of delegated token of the validator - function getDelegatedAmount(uint validatorId) external returns (uint) { - DelegationController delegationController = DelegationController(contractManager.getContract("DelegationController")); - return delegationController.getAndUpdateDelegatedToValidatorNow(validatorId); - } - - /// @notice Register new as validator - function registerValidator( - string calldata name, - string calldata description, - uint feeRate, - uint minimumDelegationAmount - ) - external returns (uint validatorId) - { - ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService")); - validatorId = validatorService.registerValidator( - name, - msg.sender, - description, - feeRate, - minimumDelegationAmount - ); - emit ValidatorRegistered(validatorId); - } - - function linkNodeAddress(address nodeAddress) external { - ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService")); - validatorService.linkNodeAddress(msg.sender, nodeAddress); - } - - function unlinkNodeAddress(address nodeAddress) external { - ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService")); - validatorService.unlinkNodeAddress(msg.sender, nodeAddress); - } - - function unregisterValidator(uint /* validatorId */) external pure { - revert("Not implemented"); - } - - /// @notice return how many of validator funds are locked in SkaleManager - function getBondAmount(uint /* validatorId */) external pure returns (uint) { - revert("Not implemented"); - } - - function setValidatorName(string calldata /* newName */) external pure { - revert("Not implemented"); - } - - function setValidatorDescription(string calldata /* description */) external pure { - revert("Not implemented"); - } - - function requestForNewAddress(address newAddress) external { - ValidatorService(contractManager.getContract("ValidatorService")).requestForNewAddress(msg.sender, newAddress); - } - - function confirmNewAddress(uint validatorId) external { - ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService")); - ValidatorService.Validator memory validator = validatorService.getValidator(validatorId); - - require( - validator.requestedAddress == msg.sender, - "The validator cannot be changed because it isn't the actual owner" - ); - - validatorService.confirmNewAddress(msg.sender, validatorId); - } - - /// @notice removes node from system - function deleteNode(uint /* nodeIndex */) external pure { - revert("Not implemented"); - } - - function initialize(address _contractsAddress) public initializer { - Permissions.initialize(_contractsAddress); - } -} diff --git a/contracts/delegation/ValidatorService.sol b/contracts/delegation/ValidatorService.sol index 382dca55c..45c6648d2 100644 --- a/contracts/delegation/ValidatorService.sol +++ b/contracts/delegation/ValidatorService.sol @@ -56,22 +56,20 @@ contract ValidatorService is Permissions { function registerValidator( string calldata name, - address validatorAddress, string calldata description, uint feeRate, uint minimumDelegationAmount ) external - allow("DelegationService") returns (uint validatorId) { - require(_validatorAddressToId[validatorAddress] == 0, "Validator with such address already exists"); + require(_validatorAddressToId[msg.sender] == 0, "Validator with such address already exists"); require(feeRate < 1000, "Fee rate of validator should be lower than 100%"); uint[] memory epmtyArray = new uint[](0); validatorId = ++numberOfValidators; validators[validatorId] = Validator( name, - validatorAddress, + msg.sender, address(0), description, feeRate, @@ -79,7 +77,7 @@ contract ValidatorService is Permissions { minimumDelegationAmount, epmtyArray ); - setValidatorAddress(validatorId, validatorAddress); + setValidatorAddress(validatorId, msg.sender); } function enableValidator(uint validatorId) external checkValidatorExists(validatorId) onlyOwner { @@ -107,31 +105,34 @@ contract ValidatorService is Permissions { return whitelist; } - function requestForNewAddress(address oldValidatorAddress, address newValidatorAddress) external allow("DelegationService") { + function requestForNewAddress(address newValidatorAddress) external { require(newValidatorAddress != address(0), "New address cannot be null"); - uint validatorId = getValidatorId(oldValidatorAddress); + uint validatorId = getValidatorId(msg.sender); validators[validatorId].requestedAddress = newValidatorAddress; } - function confirmNewAddress(address newValidatorAddress, uint validatorId) + function confirmNewAddress(uint validatorId) external checkValidatorExists(validatorId) - allow("DelegationService") { + require( + getValidator(validatorId).requestedAddress == msg.sender, + "The validator cannot be changed because it isn't the actual owner" + ); deleteValidatorAddress(validatorId, validators[validatorId].validatorAddress); - validators[validatorId].validatorAddress = newValidatorAddress; + validators[validatorId].validatorAddress = msg.sender; validators[validatorId].requestedAddress = address(0); setValidatorAddress(validatorId, validators[validatorId].validatorAddress); } - function linkNodeAddress(address validatorAddress, address nodeAddress) external allow("DelegationService") { - uint validatorId = getValidatorId(validatorAddress); + function linkNodeAddress(address nodeAddress) external { + uint validatorId = getValidatorId(msg.sender); setValidatorAddress(validatorId, nodeAddress); } - function unlinkNodeAddress(address validatorAddress, address nodeAddress) external allow("DelegationService") { - uint validatorId = getValidatorId(validatorAddress); - require(validators[validatorId].validatorAddress == validatorAddress, "Such address hasn't permissions to unlink node"); + function unlinkNodeAddress(address nodeAddress) external { + uint validatorId = getValidatorId(msg.sender); + require(validators[validatorId].validatorAddress == msg.sender, "Such address hasn't permissions to unlink node"); deleteValidatorAddress(validatorId, nodeAddress); } @@ -194,6 +195,21 @@ contract ValidatorService is Permissions { return position.add(1).mul(msr) <= delegationsTotal; } + function setValidatorName(string calldata name) external { + uint validatorId = getValidatorId(msg.sender); + validators[validatorId].name = name; + } + + function setValidatorDescription(string calldata description) external { + uint validatorId = getValidatorId(msg.sender); + validators[validatorId].description = description; + } + + function setValidatorMDA(uint minimumDelegationAmount) external { + uint validatorId = getValidatorId(msg.sender); + validators[validatorId].minimumDelegationAmount = minimumDelegationAmount; + } + function getMyAddresses() external view returns (address[] memory) { return getValidatorAddresses(getValidatorId(msg.sender)); } diff --git a/migrations/1_deploy_skale_manager_system.js b/migrations/1_deploy_skale_manager_system.js index 8bed57de4..f7634f99f 100644 --- a/migrations/1_deploy_skale_manager_system.js +++ b/migrations/1_deploy_skale_manager_system.js @@ -76,7 +76,6 @@ async function deploy(deployer, networkName, accounts) { "DelegationController", "DelegationPeriodManager", - "DelegationService", "Distributor", "Punisher", "SlashingTable", diff --git a/test/NodesFunctionality.ts b/test/NodesFunctionality.ts index a6800959f..08eb1501f 100644 --- a/test/NodesFunctionality.ts +++ b/test/NodesFunctionality.ts @@ -27,7 +27,7 @@ contract("NodesFunctionality", ([owner, validator]) => { nodesFunctionality = await deployNodesFunctionality(contractManager); validatorService = await deployValidatorService(contractManager); - await validatorService.registerValidator("Validator", validator, "D2", 0, 0); + await validatorService.registerValidator("Validator", "D2", 0, 0, {from: validator}); }); it("should fail to create node if ip is zero", async () => { diff --git a/test/SchainsFunctionality.ts b/test/SchainsFunctionality.ts index 13e35f2a9..1b40b7392 100644 --- a/test/SchainsFunctionality.ts +++ b/test/SchainsFunctionality.ts @@ -45,7 +45,7 @@ contract("SchainsFunctionality", ([owner, holder, validator]) => { validatorService = await deployValidatorService(contractManager); skaleManager = await deploySkaleManager(contractManager); - validatorService.registerValidator("D2", validator, "D2 is even", 0, 0); + validatorService.registerValidator("D2", "D2 is even", 0, 0, {from: validator}); }); describe("should add schain", async () => { @@ -450,10 +450,6 @@ contract("SchainsFunctionality", ([owner, holder, validator]) => { obtainedSchainName.should.be.equal("d2"); obtainedSchainOwner.should.be.equal(holder); - console.log(obtainedPart.toString()); - console.log(obtainedLifetime.toString()); - console.log(obtainedDeposit.toString()); - console.log(deposit.toString()); expect(obtainedPart.eq(web3.utils.toBN(1))).be.true; expect(obtainedLifetime.eq(web3.utils.toBN(5))).be.true; expect(obtainedDeposit.eq(web3.utils.toBN(deposit))).be.true; diff --git a/test/SkaleDKG.ts b/test/SkaleDKG.ts index 80f79ac0f..4aa6582cf 100644 --- a/test/SkaleDKG.ts +++ b/test/SkaleDKG.ts @@ -2,7 +2,6 @@ import * as chai from "chai"; import * as chaiAsPromised from "chai-as-promised"; import { ContractManagerInstance, DelegationControllerInstance, - DelegationServiceInstance, NodesFunctionalityInstance, SchainsDataInstance, SchainsFunctionalityInstance, @@ -16,7 +15,6 @@ import { skipTime } from "./utils/time"; import BigNumber from "bignumber.js"; import { deployContractManager } from "./utils/deploy/contractManager"; import { deployDelegationController } from "./utils/deploy/delegation/delegationController"; -import { deployDelegationService } from "./utils/deploy/delegation/delegationService"; import { deployValidatorService } from "./utils/deploy/delegation/validatorService"; import { deployNodesFunctionality } from "./utils/deploy/nodesFunctionality"; import { deploySchainsData } from "./utils/deploy/schainsData"; @@ -61,7 +59,6 @@ contract("SkaleDKG", ([owner, validator1, validator2]) => { let schainsData: SchainsDataInstance; let schainsFunctionality: SchainsFunctionalityInstance; let skaleDKG: SkaleDKGInstance; - let delegationService: DelegationServiceInstance; let skaleToken: SkaleTokenInstance; let validatorService: ValidatorServiceInstance; let slashingTable: SlashingTableInstance; @@ -74,7 +71,6 @@ contract("SkaleDKG", ([owner, validator1, validator2]) => { schainsData = await deploySchainsData(contractManager); schainsFunctionality = await deploySchainsFunctionality(contractManager); skaleDKG = await deploySkaleDKG(contractManager); - delegationService = await deployDelegationService(contractManager); skaleToken = await deploySkaleToken(contractManager); validatorService = await deployValidatorService(contractManager); slashingTable = await deploySlashingTable(contractManager); @@ -170,9 +166,9 @@ contract("SkaleDKG", ([owner, validator1, validator2]) => { let schainName = ""; beforeEach(async () => { - await delegationService.registerValidator("Validator1", "D2 is even", 0, 0, {from: validator1}); + await validatorService.registerValidator("Validator1", "D2 is even", 0, 0, {from: validator1}); const validator1Id = 1; - await delegationService.registerValidator("Validator2", "D2 is even more even", 0, 0, {from: validator2}); + await validatorService.registerValidator("Validator2", "D2 is even more even", 0, 0, {from: validator2}); const validator2Id = 2; await skaleToken.mint(owner, validator1, 1000, "0x", "0x"); await skaleToken.mint(owner, validator2, 1000, "0x", "0x"); diff --git a/test/SkaleManager.ts b/test/SkaleManager.ts index 34a651584..bf0467d7c 100644 --- a/test/SkaleManager.ts +++ b/test/SkaleManager.ts @@ -3,7 +3,6 @@ import * as chaiAsPromised from "chai-as-promised"; import { ConstantsHolderInstance, ContractManagerInstance, DelegationControllerInstance, - DelegationServiceInstance, DistributorInstance, MonitorsDataInstance, NodesDataInstance, @@ -16,7 +15,6 @@ import { ConstantsHolderInstance, import { deployConstantsHolder } from "./utils/deploy/constantsHolder"; import { deployContractManager } from "./utils/deploy/contractManager"; import { deployDelegationController } from "./utils/deploy/delegation/delegationController"; -import { deployDelegationService } from "./utils/deploy/delegation/delegationService"; import { deployDistributor } from "./utils/deploy/delegation/distributor"; import { deployValidatorService } from "./utils/deploy/delegation/validatorService"; import { deployMonitorsData } from "./utils/deploy/monitorsData"; @@ -39,7 +37,6 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => { let monitorsData: MonitorsDataInstance; let schainsData: SchainsDataInstance; let schainsFunctionality: SchainsFunctionalityInstance; - let delegationService: DelegationServiceInstance; let validatorService: ValidatorServiceInstance; let delegationController: DelegationControllerInstance; let distributor: DistributorInstance; @@ -54,7 +51,6 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => { schainsData = await deploySchainsData(contractManager); schainsFunctionality = await deploySchainsFunctionality(contractManager); skaleManager = await deploySkaleManager(contractManager); - delegationService = await deployDelegationService(contractManager); validatorService = await deployValidatorService(contractManager); delegationController = await deployDelegationController(contractManager); distributor = await deployDistributor(contractManager); @@ -85,7 +81,7 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => { const month = 60 * 60 * 24 * 31; beforeEach(async () => { - await delegationService.registerValidator("D2", "D2 is even", 150, 0, {from: validator}); + await validatorService.registerValidator("D2", "D2 is even", 150, 0, {from: validator}); await skaleToken.transfer(validator, "0x410D586A20A4C00000", {from: owner}); await validatorService.enableValidator(validatorId, {from: owner}); @@ -333,7 +329,7 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => { it("should fail to create schain if validator doesn't meet MSR", async () => { await constantsHolder.setMSR(6); const newValidatorId = 2; - await delegationService.registerValidator("D2", "D2 is even", 150, 0, {from: developer}); + await validatorService.registerValidator("D2", "D2 is even", 150, 0, {from: developer}); await validatorService.enableValidator(newValidatorId, {from: owner}); await skaleManager.createNode( diff --git a/test/SkaleVerifier.ts b/test/SkaleVerifier.ts index 741be4755..9c93aa2de 100644 --- a/test/SkaleVerifier.ts +++ b/test/SkaleVerifier.ts @@ -33,7 +33,7 @@ contract("SkaleVerifier", ([validator1, owner, developer, hacker]) => { schainsFunctionality = await deploySchainsFunctionality(contractManager); skaleVerifier = await deploySkaleVerifier(contractManager); - validatorService.registerValidator("D2", validator1, "D2 is even", 0, 0); + validatorService.registerValidator("D2", "D2 is even", 0, 0, {from: validator1}); }); describe("when skaleVerifier contract is activated", async () => { diff --git a/test/delegation/Delegation.ts b/test/delegation/Delegation.ts index 8e5801961..7b1171d0e 100644 --- a/test/delegation/Delegation.ts +++ b/test/delegation/Delegation.ts @@ -2,7 +2,6 @@ import { ConstantsHolderInstance, ContractManagerInstance, DelegationControllerInstance, DelegationPeriodManagerInstance, - DelegationServiceInstance, DistributorInstance, PunisherInstance, SkaleManagerMockContract, @@ -22,7 +21,6 @@ import { deployConstantsHolder } from "../utils/deploy/constantsHolder"; import { deployContractManager } from "../utils/deploy/contractManager"; import { deployDelegationController } from "../utils/deploy/delegation/delegationController"; import { deployDelegationPeriodManager } from "../utils/deploy/delegation/delegationPeriodManager"; -import { deployDelegationService } from "../utils/deploy/delegation/delegationService"; import { deployDistributor } from "../utils/deploy/delegation/distributor"; import { deployPunisher } from "../utils/deploy/delegation/punisher"; import { deployTokenState } from "../utils/deploy/delegation/tokenState"; @@ -43,7 +41,6 @@ contract("Delegation", ([owner, bountyAddress]) => { let contractManager: ContractManagerInstance; let skaleToken: SkaleTokenInstance; - let delegationService: DelegationServiceInstance; let delegationController: DelegationControllerInstance; let delegationPeriodManager: DelegationPeriodManagerInstance; let skaleManagerMock: SkaleManagerMockInstance; @@ -63,7 +60,6 @@ contract("Delegation", ([owner, await contractManager.setContractsAddress("SkaleManager", skaleManagerMock.address); skaleToken = await deploySkaleToken(contractManager); - delegationService = await deployDelegationService(contractManager); delegationController = await deployDelegationController(contractManager); delegationPeriodManager = await deployDelegationPeriodManager(contractManager); validatorService = await deployValidatorService(contractManager); @@ -79,13 +75,13 @@ contract("Delegation", ([owner, describe("when holders have tokens and validator is registered", async () => { let validatorId: number; beforeEach(async () => { + validatorId = 1; await skaleToken.mint(owner, holder1, defaultAmount.toString(), "0x", "0x"); await skaleToken.mint(owner, holder2, defaultAmount.toString(), "0x", "0x"); await skaleToken.mint(owner, holder3, defaultAmount.toString(), "0x", "0x"); await skaleToken.mint(owner, skaleManagerMock.address, defaultAmount.toString(), "0x", "0x"); - const { logs } = await delegationService.registerValidator( + await validatorService.registerValidator( "First validator", "Super-pooper validator", 150, 0, {from: validator}); - validatorId = logs[0].args.validatorId.toNumber(); await validatorService.enableValidator(validatorId, {from: owner}); }); @@ -148,8 +144,6 @@ contract("Delegation", ([owner, it("should accept delegation request", async () => { await delegationController.acceptPendingDelegation(requestId, {from: validator}); - - // await delegationService.listDelegationRequests().should.be.eventually.empty; }); it("should unlock token if validator does not accept delegation request", async () => { @@ -183,7 +177,7 @@ contract("Delegation", ([owner, await skaleToken.send(holder2, 1, "0x", {from: holder1}) .should.be.eventually.rejectedWith("Token should be unlocked for transferring"); - await delegationService.requestUndelegation(requestId, {from: holder1}); + await delegationController.requestUndelegation(requestId, {from: holder1}); await skipTimeToDate(web3, 27, (11 + delegationPeriod + delegationPeriod - 1) % 12); @@ -460,7 +454,7 @@ contract("Delegation", ([owner, // describe("when validator is registered", async () => { // beforeEach(async () => { - // await delegationService.registerValidator( + // await validatorService.registerValidator( // "First validator", "Super-pooper validator", 150, 0, {from: validator}); // }); @@ -520,8 +514,8 @@ contract("Delegation", ([owner, // await skipTimeToDate(web3, 1, 0); - // await delegationService.requestUndelegation(requestId1, {from: holder1}); - // await delegationService.requestUndelegation(requestId2, {from: holder2}); + // await delegationController.requestUndelegation(requestId1, {from: holder1}); + // await delegationController.requestUndelegation(requestId2, {from: holder2}); // // get bounty // await skipTimeToDate(web3, 1, 1); @@ -653,7 +647,7 @@ contract("Delegation", ([owner, // const requestId = response.logs[0].args.id; // await delegationService.accept(requestId, {from: validator}); - // await delegationService.requestUndelegation(requestId, {from: holder3}); + // await delegationController.requestUndelegation(requestId, {from: holder3}); // // spin up node diff --git a/test/delegation/DelegationRequest.ts b/test/delegation/DelegationRequest.ts index 3b22954f6..e56bfb530 100644 --- a/test/delegation/DelegationRequest.ts +++ b/test/delegation/DelegationRequest.ts @@ -1,6 +1,5 @@ import { ContractManagerInstance, DelegationControllerInstance, - DelegationServiceInstance, SkaleTokenInstance, TokenStateInstance, ValidatorServiceInstance } from "../../types/truffle-contracts"; @@ -11,7 +10,6 @@ import * as chai from "chai"; import * as chaiAsPromised from "chai-as-promised"; import { deployContractManager } from "../utils/deploy/contractManager"; import { deployDelegationController } from "../utils/deploy/delegation/delegationController"; -import { deployDelegationService } from "../utils/deploy/delegation/delegationService"; import { deployTokenState } from "../utils/deploy/delegation/tokenState"; import { deployValidatorService } from "../utils/deploy/delegation/validatorService"; import { deploySkaleToken } from "../utils/deploy/skaleToken"; @@ -22,7 +20,6 @@ chai.use(chaiAsPromised); contract("DelegationController", ([owner, holder1, holder2, validator, validator2]) => { let contractManager: ContractManagerInstance; let skaleToken: SkaleTokenInstance; - let delegationService: DelegationServiceInstance; let delegationController: DelegationControllerInstance; let tokenState: TokenStateInstance; let validatorService: ValidatorServiceInstance; @@ -34,7 +31,6 @@ contract("DelegationController", ([owner, holder1, holder2, validator, validator contractManager = await deployContractManager(); skaleToken = await deploySkaleToken(contractManager); - delegationService = await deployDelegationService(contractManager); delegationController = await deployDelegationController(contractManager); tokenState = await deployTokenState(contractManager); validatorService = await deployValidatorService(contractManager); @@ -51,7 +47,7 @@ contract("DelegationController", ([owner, holder1, holder2, validator, validator amount = 100; delegationPeriod = 3; info = "VERY NICE"; - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, @@ -162,7 +158,7 @@ contract("DelegationController", ([owner, holder1, holder2, validator, validator }); it("should reject accepting request if validator tried to accept request not assigned to him", async () => { - delegationService.registerValidator( + validatorService.registerValidator( "ValidatorName", "Really good validator", 500, @@ -192,7 +188,7 @@ contract("DelegationController", ([owner, holder1, holder2, validator, validator await delegationController.requestUndelegation(delegationId, {from: holder2}) .should.be.eventually.rejectedWith("Permission denied to request undelegation"); - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, diff --git a/test/delegation/TokenLaunch.ts b/test/delegation/TokenLaunch.ts index 3a860d9d7..f32190e60 100644 --- a/test/delegation/TokenLaunch.ts +++ b/test/delegation/TokenLaunch.ts @@ -1,6 +1,5 @@ import { ContractManagerInstance, DelegationControllerInstance, - DelegationServiceInstance, PunisherInstance, SkaleTokenInstance, TokenLaunchManagerInstance, @@ -12,7 +11,6 @@ import * as chai from "chai"; import * as chaiAsPromised from "chai-as-promised"; import { deployContractManager } from "../utils/deploy/contractManager"; import { deployDelegationController } from "../utils/deploy/delegation/delegationController"; -import { deployDelegationService } from "../utils/deploy/delegation/delegationService"; import { deployPunisher } from "../utils/deploy/delegation/punisher"; import { deployTokenLaunchManager } from "../utils/deploy/delegation/tokenLaunchManager"; import { deployValidatorService } from "../utils/deploy/delegation/validatorService"; @@ -25,7 +23,6 @@ contract("TokenLaunchManager", ([owner, holder, delegation, validator, seller, h let contractManager: ContractManagerInstance; let skaleToken: SkaleTokenInstance; let TokenLaunchManager: TokenLaunchManagerInstance; - let delegationService: DelegationServiceInstance; let validatorService: ValidatorServiceInstance; let delegationController: DelegationControllerInstance; let punisher: PunisherInstance; @@ -34,7 +31,6 @@ contract("TokenLaunchManager", ([owner, holder, delegation, validator, seller, h contractManager = await deployContractManager(); skaleToken = await deploySkaleToken(contractManager); TokenLaunchManager = await deployTokenLaunchManager(contractManager); - delegationService = await deployDelegationService(contractManager); validatorService = await deployValidatorService(contractManager); delegationController = await deployDelegationController(contractManager); punisher = await deployPunisher(contractManager); @@ -42,7 +38,7 @@ contract("TokenLaunchManager", ([owner, holder, delegation, validator, seller, h // each test will start from Nov 10 await skipTimeToDate(web3, 10, 11); await skaleToken.mint(owner, TokenLaunchManager.address, 1000, "0x", "0x"); - await delegationService.registerValidator("Validator", "D2 is even", 150, 0, {from: validator}); + await validatorService.registerValidator("Validator", "D2 is even", 150, 0, {from: validator}); await validatorService.enableValidator(1, {from: owner}); }); @@ -136,7 +132,7 @@ contract("TokenLaunchManager", ([owner, holder, delegation, validator, seller, h skipTime(web3, month); - await delegationService.requestUndelegation(delegationId, {from: holder}); + await delegationController.requestUndelegation(delegationId, {from: holder}); skipTime(web3, month * delegationPeriod); diff --git a/test/delegation/TokenState.ts b/test/delegation/TokenState.ts index 310664070..8e3ff8059 100644 --- a/test/delegation/TokenState.ts +++ b/test/delegation/TokenState.ts @@ -1,6 +1,5 @@ import { ContractManagerInstance, DelegationControllerInstance, - DelegationServiceInstance, SkaleTokenInstance, TokenStateInstance, ValidatorServiceInstance} from "../../types/truffle-contracts"; @@ -11,7 +10,6 @@ import { currentTime, skipTime } from "../utils/time"; import * as chai from "chai"; import * as chaiAsPromised from "chai-as-promised"; import { deployDelegationController } from "../utils/deploy/delegation/delegationController"; -import { deployDelegationService } from "../utils/deploy/delegation/delegationService"; import { deployTokenState } from "../utils/deploy/delegation/tokenState"; import { deployValidatorService } from "../utils/deploy/delegation/validatorService"; import { deploySkaleToken } from "../utils/deploy/skaleToken"; @@ -24,7 +22,6 @@ contract("DelegationController", ([owner, holder, validator]) => { let delegationController: DelegationControllerInstance; let tokenState: TokenStateInstance; let validatorService: ValidatorServiceInstance; - let delegationService: DelegationServiceInstance; let skaleToken: SkaleTokenInstance; let validatorId: number; @@ -35,10 +32,9 @@ contract("DelegationController", ([owner, holder, validator]) => { delegationController = await deployDelegationController(contractManager); tokenState = await deployTokenState(contractManager); validatorService = await deployValidatorService(contractManager); - delegationService = await deployDelegationService(contractManager); skaleToken = await deploySkaleToken(contractManager); - await delegationService.registerValidator("Validator", "D2 is even", 150, 0, {from: validator}); + await validatorService.registerValidator("Validator", "D2 is even", 150, 0, {from: validator}); validatorId = 1; await validatorService.enableValidator(validatorId, {from: owner}); await skaleToken.mint(owner, holder, 1000, "0x", "0x"); diff --git a/test/delegation/ValidatorService.ts b/test/delegation/ValidatorService.ts index 786971ec4..87f19c93a 100644 --- a/test/delegation/ValidatorService.ts +++ b/test/delegation/ValidatorService.ts @@ -1,7 +1,6 @@ import { ConstantsHolderInstance, ContractManagerInstance, DelegationControllerInstance, - DelegationServiceInstance, SkaleTokenInstance, ValidatorServiceInstance} from "../../types/truffle-contracts"; @@ -13,7 +12,6 @@ import * as chaiAsPromised from "chai-as-promised"; import { deployConstantsHolder } from "../utils/deploy/constantsHolder"; import { deployContractManager } from "../utils/deploy/contractManager"; import { deployDelegationController } from "../utils/deploy/delegation/delegationController"; -import { deployDelegationService } from "../utils/deploy/delegation/delegationService"; import { deployValidatorService } from "../utils/deploy/delegation/validatorService"; import { deploySkaleToken } from "../utils/deploy/skaleToken"; chai.should(); @@ -41,7 +39,6 @@ class Validator { contract("ValidatorService", ([owner, holder, validator1, validator2, validator3, nodeAddress]) => { let contractManager: ContractManagerInstance; - let delegationService: DelegationServiceInstance; let validatorService: ValidatorServiceInstance; let constantsHolder: ConstantsHolderInstance; let skaleToken: SkaleTokenInstance; @@ -54,21 +51,18 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 constantsHolder = await deployConstantsHolder(contractManager); skaleToken = await deploySkaleToken(contractManager); - delegationService = await deployDelegationService(contractManager); validatorService = await deployValidatorService(contractManager); delegationController = await deployDelegationController(contractManager); }); it("should register new validator", async () => { - const { logs } = await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, 100, {from: validator1}); - assert.equal(logs.length, 1, "No ValidatorRegistered Event emitted"); - assert.equal(logs[0].event, "ValidatorRegistered"); - const validatorId = logs[0].args.validatorId; + const validatorId = await validatorService.getValidatorId(validator1); const validator: Validator = new Validator( await validatorService.validators(validatorId)); assert.equal(validator.name, "ValidatorName"); @@ -80,7 +74,7 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 }); it("should reject if validator tried to register with a fee rate higher than 100 percent", async () => { - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 1500, @@ -91,7 +85,7 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 describe("when validator registered", async () => { beforeEach(async () => { - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, @@ -99,7 +93,7 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 {from: validator1}); }); it("should reject when validator tried to register new one with the same address", async () => { - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, @@ -109,29 +103,40 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 }); + it("should reset name, description, minimum delegation amount", async () => { + const validatorId = 1; + await validatorService.setValidatorName("Validator", {from: validator1}); + await validatorService.setValidatorDescription("Good", {from: validator1}); + await validatorService.setValidatorMDA(1, {from: validator1}); + const validator = await validatorService.getValidator(validatorId); + assert.equal(validator.name, "Validator"); + assert.equal(validator.description, "Good"); + assert.equal(validator.minimumDelegationAmount, new BigNumber(1)); + }); + it("should link new node address for validator", async () => { const validatorId = 1; - await delegationService.linkNodeAddress(nodeAddress, {from: validator1}); + await validatorService.linkNodeAddress(nodeAddress, {from: validator1}); const id = new BigNumber(await validatorService.getValidatorId(nodeAddress, {from: validator1})).toNumber(); assert.equal(id, validatorId); }); it("should reject if linked node address tried to unlink validator address", async () => { - await delegationService.linkNodeAddress(nodeAddress, {from: validator1}); - await delegationService.unlinkNodeAddress(validator1, {from: nodeAddress}) + await validatorService.linkNodeAddress(nodeAddress, {from: validator1}); + await validatorService.unlinkNodeAddress(validator1, {from: nodeAddress}) .should.be.eventually.rejectedWith("Such address hasn't permissions to unlink node"); }); it("should reject if validator tried to override node address of another validator", async () => { const validatorId = 1; - await delegationService.registerValidator( + await validatorService.registerValidator( "Second Validator", "Bad validator", 500, 100, {from: validator2}); - await delegationService.linkNodeAddress(nodeAddress, {from: validator1}); - await delegationService.linkNodeAddress(nodeAddress, {from: validator2}) + await validatorService.linkNodeAddress(nodeAddress, {from: validator1}); + await validatorService.linkNodeAddress(nodeAddress, {from: validator2}) .should.be.eventually.rejectedWith("Validator cannot override node address"); const id = new BigNumber(await validatorService.getValidatorId(nodeAddress, {from: validator1})).toNumber(); assert.equal(id, validatorId); @@ -139,38 +144,38 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 it("should unlink node address for validator", async () => { const validatorId = 1; - await delegationService.linkNodeAddress(nodeAddress, {from: validator1}); - await delegationService.registerValidator( + await validatorService.linkNodeAddress(nodeAddress, {from: validator1}); + await validatorService.registerValidator( "Second Validator", "Not bad validator", 500, 100, {from: validator2}); - await delegationService.unlinkNodeAddress(nodeAddress, {from: validator2}) + await validatorService.unlinkNodeAddress(nodeAddress, {from: validator2}) .should.be.eventually.rejectedWith("Validator hasn't permissions to unlink node"); const id = new BigNumber(await validatorService.getValidatorId(nodeAddress, {from: validator1})).toNumber(); assert.equal(id, validatorId); - await delegationService.unlinkNodeAddress(nodeAddress, {from: validator1}); + await validatorService.unlinkNodeAddress(nodeAddress, {from: validator1}); await validatorService.getValidatorId(nodeAddress, {from: validator1}) .should.be.eventually.rejectedWith("Validator with such address doesn't exist"); }); describe("when validator requests for a new address", async () => { beforeEach(async () => { - await delegationService.requestForNewAddress(validator3, {from: validator1}); + await validatorService.requestForNewAddress(validator3, {from: validator1}); }); it("should reject when hacker tries to change validator address", async () => { const validatorId = 1; - await delegationService.confirmNewAddress(validatorId, {from: validator2}) + await validatorService.confirmNewAddress(validatorId, {from: validator2}) .should.be.eventually.rejectedWith("The validator cannot be changed because it isn't the actual owner"); }); it("should set new address for validator", async () => { const validatorId = new BigNumber(1); assert.deepEqual(validatorId, new BigNumber(await validatorService.getValidatorId(validator1))); - await delegationService.confirmNewAddress(validatorId, {from: validator3}); + await validatorService.confirmNewAddress(validatorId, {from: validator3}); assert.deepEqual(validatorId, new BigNumber(await validatorService.getValidatorId(validator3))); await validatorService.getValidatorId(validator1) .should.be.eventually.rejectedWith("Validator with such address doesn't exist"); @@ -179,25 +184,25 @@ contract("ValidatorService", ([owner, holder, validator1, validator2, validator3 }); it("should reject when someone tries to set new address for validator that doesn't exist", async () => { - await delegationService.requestForNewAddress(validator2) + await validatorService.requestForNewAddress(validator2) .should.be.eventually.rejectedWith("Validator with such address doesn't exist"); }); it("should reject if validator tries to set new address as null", async () => { - await delegationService.requestForNewAddress("0x0000000000000000000000000000000000000000") + await validatorService.requestForNewAddress("0x0000000000000000000000000000000000000000") .should.be.eventually.rejectedWith("New address cannot be null"); }); it("should return list of trusted validators", async () => { const validatorId1 = 1; const validatorId3 = 3; - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, 100, {from: validator2}); - await delegationService.registerValidator( + await validatorService.registerValidator( "ValidatorName", "Really good validator", 500, diff --git a/test/utils/deploy/delegation/delegationService.ts b/test/utils/deploy/delegation/delegationService.ts deleted file mode 100644 index 114fef597..000000000 --- a/test/utils/deploy/delegation/delegationService.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ContractManagerInstance, DelegationServiceContract } from "../../../../types/truffle-contracts"; -import { deploySkaleToken } from "../skaleToken"; -import { deployDelegationController } from "./delegationController"; -import { deployDistributor } from "./distributor"; -import { deployTokenState } from "./tokenState"; -import { deployValidatorService } from "./validatorService"; - -const DelegationService: DelegationServiceContract = artifacts.require("./DelegationService"); -const name = "DelegationService"; - -async function deploy(contractManager: ContractManagerInstance) { - const instance = await DelegationService.new(); - await instance.initialize(contractManager.address); - await contractManager.setContractsAddress(name, instance.address); - return instance; -} - -async function deployDependencies(contractManager: ContractManagerInstance) { - await deployTokenState(contractManager); - await deployDelegationController(contractManager); - await deployValidatorService(contractManager); - await deployDistributor(contractManager); - await deploySkaleToken(contractManager); -} - -export async function deployDelegationService(contractManager: ContractManagerInstance) { - try { - return DelegationService.at(await contractManager.getContract(name)); - } catch (e) { - const instance = await deploy(contractManager); - await deployDependencies(contractManager); - return instance; - } -} diff --git a/test/utils/deploy/skaleManager.ts b/test/utils/deploy/skaleManager.ts index edb52fd15..85eed2860 100644 --- a/test/utils/deploy/skaleManager.ts +++ b/test/utils/deploy/skaleManager.ts @@ -1,6 +1,5 @@ import { ContractManagerInstance, SkaleManagerInstance } from "../../../types/truffle-contracts"; import { deployConstantsHolder } from "./constantsHolder"; -import { deployDelegationService } from "./delegation/delegationService"; import { deployDistributor } from "./delegation/distributor"; import { deployValidatorService } from "./delegation/validatorService"; import { deployFunctionFactory } from "./factory"; @@ -22,7 +21,6 @@ const deploySkaleManager: (contractManager: ContractManagerInstance) => Promise< await deployConstantsHolder(contractManager); await deployManagerData(contractManager); await deploySkaleToken(contractManager); - await deployDelegationService(contractManager); await deployDistributor(contractManager); }); From 1145cfc10840330b98daa65e84a46d3bb7d63961 Mon Sep 17 00:00:00 2001 From: Vadim Yavorsky Date: Tue, 3 Mar 2020 17:39:35 +0200 Subject: [PATCH 2/2] SKALE-2164 removed setters for validator --- contracts/delegation/ValidatorService.sol | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/contracts/delegation/ValidatorService.sol b/contracts/delegation/ValidatorService.sol index 45c6648d2..01b4ab756 100644 --- a/contracts/delegation/ValidatorService.sol +++ b/contracts/delegation/ValidatorService.sol @@ -195,16 +195,6 @@ contract ValidatorService is Permissions { return position.add(1).mul(msr) <= delegationsTotal; } - function setValidatorName(string calldata name) external { - uint validatorId = getValidatorId(msg.sender); - validators[validatorId].name = name; - } - - function setValidatorDescription(string calldata description) external { - uint validatorId = getValidatorId(msg.sender); - validators[validatorId].description = description; - } - function setValidatorMDA(uint minimumDelegationAmount) external { uint validatorId = getValidatorId(msg.sender); validators[validatorId].minimumDelegationAmount = minimumDelegationAmount;