Allow deployer to set a migration-done flag
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details

* Save deployer's address on contract initialization
* Add modifier for requiring tx sender to be deployer
* Add migrationDone flag and function to set it to finished status
This commit is contained in:
Râu Cao 2022-08-23 12:15:16 +01:00
parent 0fc4eed09a
commit de1574155c
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
5 changed files with 69 additions and 12 deletions

View File

@ -42,8 +42,15 @@ contract Contribution is Initializable {
mapping(uint32 => ContributionData) public contributions;
uint32 public contributionsCount;
// Confirmation veto period
uint32 public blocksToWait;
// The address that deployed the contract
address public deployer;
// Data migration flag
bool public migrationDone;
event ContributionAdded(uint32 id, uint32 indexed contributorId, uint32 amount);
event ContributionClaimed(uint32 id, uint32 indexed contributorId, uint32 amount);
event ContributionVetoed(uint32 id, address vetoedByAccount);
@ -53,10 +60,21 @@ contract Contribution is Initializable {
_;
}
modifier onlyDeployer {
require(msg.sender == deployer, "Deployer only");
_;
}
function initialize(uint32 blocksToWait_) public initializer {
deployer = msg.sender;
migrationDone = false;
blocksToWait = blocksToWait_;
}
function finishMigration() public onlyDeployer {
migrationDone = true;
}
function setTokenContract(address token) public {
require(address(tokenContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
tokenContract = IToken(token);

View File

@ -99,7 +99,7 @@ contract Contributor is Initializable {
function isCoreTeam(uint32 id) view public returns (bool) {
// TODO: for simplicity we simply define the first contributors as core
// later this needs to be changed to something more dynamic
return id > 0 && id < 7;
return id > 0 && id < 6;
}
function exists(uint32 id) view public returns (bool) {

View File

@ -1,6 +1,7 @@
require("@nomiclabs/hardhat-waffle");
require("hardhat-deploy");
require("hardhat-deploy-ethers");
require("@nomicfoundation/hardhat-chai-matchers");
require("@openzeppelin/hardhat-upgrades");
const Kredits = require("./lib/kredits");

18
package-lock.json generated
View File

@ -1216,6 +1216,12 @@
"dependencies": {
"@types/sinon-chai": "^3.2.3",
"@types/web3": "1.0.19"
},
"peerDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"ethereum-waffle": "^3.2.0",
"ethers": "^5.0.0",
"hardhat": "^2.0.0"
}
},
"node_modules/@openzeppelin/contracts-upgradeable": {
@ -1708,9 +1714,9 @@
}
},
"node_modules/@types/sinon": {
"version": "10.0.11",
"resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.11.tgz",
"integrity": "sha512-dmZsHlBsKUtBpHriNjlK0ndlvEh8dcb9uV9Afsbt89QIyydpC7NcR+nWlAhASfy3GHnxTl4FX/aKE7XZUt/B4g==",
"version": "10.0.13",
"resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.13.tgz",
"integrity": "sha512-UVjDqJblVNQYvVNUsj0PuYYw0ELRmgt1Nt5Vk0pT5f16ROGfcKJY8o1HVuMOJOpD727RrGB9EGvoaTQE5tgxZQ==",
"dev": true,
"dependencies": {
"@types/sinonjs__fake-timers": "*"
@ -21394,9 +21400,9 @@
}
},
"@types/sinon": {
"version": "10.0.11",
"resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.11.tgz",
"integrity": "sha512-dmZsHlBsKUtBpHriNjlK0ndlvEh8dcb9uV9Afsbt89QIyydpC7NcR+nWlAhASfy3GHnxTl4FX/aKE7XZUt/B4g==",
"version": "10.0.13",
"resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.13.tgz",
"integrity": "sha512-UVjDqJblVNQYvVNUsj0PuYYw0ELRmgt1Nt5Vk0pT5f16ROGfcKJY8o1HVuMOJOpD727RrGB9EGvoaTQE5tgxZQ==",
"dev": true,
"requires": {
"@types/sinonjs__fake-timers": "*"

View File

@ -1,18 +1,50 @@
const { expect } = require("chai");
const { ethers, upgrades } = require("hardhat");
let hardhatContribution;
let owner, addr1, addr2, addr3, addr4, addr5, addr6;
let Contribution, Contributor;
describe("Contribution contract", function () {
describe("Contribution contract", async function () {
before(async function () {
[owner, addr1, addr2, addr3, addr4, addr5, addr6] = await ethers.getSigners();
let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6];
const contributorFactory = await ethers.getContractFactory("Contributor");
Contributor = await upgrades.deployProxy(contributorFactory);
for (const account of accounts) {
await Contributor.addContributor(account.address, "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8", 18, 32);
}
});
describe("Deployment", function () {
before(async function () {
// const [owner] = await ethers.getSigners();
const Contribution = await ethers.getContractFactory("Contribution");
hardhatContribution = await upgrades.deployProxy(Contribution, [40321]);
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
});
it("sets the veto confirmation period", async function () {
expect(await hardhatContribution.blocksToWait()).to.equal(40321);
expect(await Contribution.blocksToWait()).to.equal(40321);
});
it("sets the data migration flag", async function () {
expect(await Contribution.migrationDone()).to.equal(false);
});
});
describe("Data migration", function () {
before(async function () {
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
await Contribution.setContributorContract(Contributor.address).then(res => res.wait())
});
it("does not allow random accounts to mark the migration as finished", async function () {
await expect(Contribution.connect(addr1).finishMigration()).to.be.revertedWith("Deployer only");
expect(await Contribution.migrationDone()).to.equal(false);
});
it("allows the deployer to mark the migration as finished", async function () {
await Contribution.finishMigration();
expect(await Contribution.migrationDone()).to.equal(true);
});
});