Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

test upgrade #1167

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions contracts/SkaleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,30 @@ import { ISchainsInternal } from "@skalenetwork/skale-manager-interfaces/ISchain
import { IWallets } from "@skalenetwork/skale-manager-interfaces/IWallets.sol";

import { Permissions } from "./Permissions.sol";

import { IGreeter } from "./interfaces/IGreeter.sol";
/**
* @title SkaleManager
* @dev Contract contains functions for node registration and exit, bounty
* management, and monitoring verdicts.
*/
contract SkaleManager is IERC777Recipient, ISkaleManager, Permissions {
contract SkaleManager is IERC777Recipient, ISkaleManager, Permissions, IGreeter {

IERC1820Registry private _erc1820;

bytes32 constant private _TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;

bytes32 constant public ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 constant public GREET_SETTER = keccak256("GREET_SETTER");
uint256 constant public HEADER_COSTS = 5310;
uint256 constant public CALL_PRICE = 21000;

string public version;

bytes32 public constant SCHAIN_REMOVAL_ROLE = keccak256("SCHAIN_REMOVAL_ROLE");

string public hello;

function initialize(address newContractsAddress) public override initializer {
Permissions.initialize(newContractsAddress);
_erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
Expand All @@ -71,6 +74,7 @@ contract SkaleManager is IERC777Recipient, ISkaleManager, Permissions {
);
}


function tokensReceived(
address, // operator
address from,
Expand Down Expand Up @@ -198,6 +202,11 @@ contract SkaleManager is IERC777Recipient, ISkaleManager, Permissions {
version = newVersion;
}

function setGreeting(string calldata newGreeting) external override {
require(hasRole(GREET_SETTER, msg.sender));
hello = newGreeting;
}

function _payBounty(uint256 bounty, uint256 validatorId) private {
IERC777 skaleToken = IERC777(contractManager.getContract("SkaleToken"));
IDistributor distributor = IDistributor(contractManager.getContract("Distributor"));
Expand Down
9 changes: 9 additions & 0 deletions contracts/interfaces/IGreeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-only

pragma solidity 0.8.17;



interface IGreeter {
function setGreeting(string calldata newGreeting) external;
}
10 changes: 6 additions & 4 deletions migrations/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async function timeHelpersWithDebugIsUsed(timeHelpersAddress: string) {
return storageLayout.find(storageItem => storageItem.label === "_timeShift") !== undefined;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function prepareContractsList(instance: Instance) {
// If skale-manager is deployed not in production mode
// the smart contract TimeHelpers is replaced
Expand All @@ -94,16 +95,17 @@ async function prepareContractsList(instance: Instance) {

async function main() {
const skaleManager = await getSkaleManagerInstance();
let contractsToUpgrade: string[] = [
const contractsToUpgrade: string[] = [
"SkaleManager"
];
if (process.env.UPGRADE_ALL) {
contractsToUpgrade = await prepareContractsList(skaleManager);
}

// cspell:ignore eduv
const upgrader = new SkaleManagerUpgrader(
"1.12.0",
skaleManager,
contractsToUpgrade
);

await upgrader.upgrade();
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
"@skalenetwork/marionette-interfaces": "^0.0.0-main.6",
"@skalenetwork/paymaster-interfaces": "^1.0.1",
"@skalenetwork/skale-manager-interfaces": "3.2.0",
"@skalenetwork/upgrade-tools": "3.0.0-develop.21",
"@skalenetwork/upgrade-tools": "3.0.0-develop.38",
"@typechain/hardhat": "^9.1.0",
"dotenv": "^16.4.5",
"ethereumjs-util": "^7.1.5",
"ethers": "^6.13.1",
"ethers": "^6.13.5",
"hardhat": "^2.22.8"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions test/SkaleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ describe("SkaleManager", () => {
await skaleManager.setVersion("good");
(await skaleManager.version()).should.be.equal("good");
});
it.only("should restrict access to setting greeting", async () => {
//no access yet
await skaleManager.setGreeting("This is a new Greeting").should.be.rejected;

await skaleManager.grantRole(await skaleManager.GREET_SETTER(), owner.address);
await skaleManager.setGreeting("This is a new Greeting");
await skaleManager.hello().should.be.eventually.equal("This is a new Greeting");
})

describe("when validator has delegated SKALE tokens", () => {
const validatorId = 1;
Expand Down
Loading
Loading