Allow setting confirmedAtBlock and vetoed during migration
This commit is contained in:
parent
67add71a22
commit
9dd9d298cc
@ -168,10 +168,12 @@ contract Contribution is Initializable {
|
||||
);
|
||||
}
|
||||
|
||||
function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public {
|
||||
function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool vetoed) public {
|
||||
// require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint32[](0)), 'nope');
|
||||
// TODO hubot neither has kredits nor a core account
|
||||
require((confirmedAtBlock == 0 && vetoed == false) || migrationDone == false, 'extra arguments during migration only');
|
||||
require(balanceOf(msg.sender) > 0 || contributorContract.addressIsCore(msg.sender), 'requires kredits or core status');
|
||||
|
||||
uint32 contributionId = contributionsCount + 1;
|
||||
ContributionData storage c = contributions[contributionId];
|
||||
c.exists = true;
|
||||
@ -181,12 +183,15 @@ contract Contribution is Initializable {
|
||||
c.hashDigest = hashDigest;
|
||||
c.hashFunction = hashFunction;
|
||||
c.hashSize = hashSize;
|
||||
if (contributionId < 10) {
|
||||
c.confirmedAtBlock = block.number;
|
||||
|
||||
if (confirmedAtBlock > 0) {
|
||||
c.confirmedAtBlock = confirmedAtBlock;
|
||||
} else {
|
||||
c.confirmedAtBlock = block.number + 1 + blocksToWait;
|
||||
}
|
||||
|
||||
if (vetoed) { c.vetoed = true; }
|
||||
|
||||
contributionsCount++;
|
||||
|
||||
contributionOwner[contributionId] = contributorId;
|
||||
@ -196,7 +201,6 @@ contract Contribution is Initializable {
|
||||
}
|
||||
|
||||
function veto(uint32 contributionId) public onlyCore {
|
||||
|
||||
ContributionData storage c = contributions[contributionId];
|
||||
require(c.exists, 'NOT_FOUND');
|
||||
require(!c.claimed, 'ALREADY_CLAIMED');
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,8 +1,8 @@
|
||||
{
|
||||
"1337": {
|
||||
"Contributor": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
|
||||
"Contribution": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
|
||||
"Token": "0x0165878A594ca255338adfa4d48449f69242Eb8F",
|
||||
"Reimbursement": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
|
||||
"Contributor": "0xCc66f9A3cA2670972938FAD91d0865c4a62DFB25",
|
||||
"Contribution": "0x8999CaBc43E28202c5A2257f2a95A45b1F8A62BD",
|
||||
"Token": "0xe082678eCF749982e33Ea6839852a8cd989aEDE2",
|
||||
"Reimbursement": "0x984f797d26d3da2E9b9f8Ae4eeFEACC60fCAA90C"
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ class Contribution extends Record {
|
||||
ipfsHashAttr.hashSize,
|
||||
];
|
||||
|
||||
return this.contract.add(...contribution, callOptions);
|
||||
return this.contract.add(...contribution, 0, false, callOptions);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ describe("Contribution contract", async function () {
|
||||
});
|
||||
|
||||
it("sets the data migration flag", async function () {
|
||||
expect(await Contribution.migrationDone()).to.equal(false);
|
||||
expect(await Contribution.migrationDone()).to.be.false;
|
||||
});
|
||||
|
||||
it("sets the deployer address", async function () {
|
||||
@ -45,7 +45,7 @@ describe("Contribution contract", async function () {
|
||||
|
||||
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);
|
||||
expect(await Contribution.migrationDone()).to.be.false;
|
||||
});
|
||||
|
||||
it("allows the deployer to mark the migration as finished", async function () {
|
||||
@ -59,22 +59,32 @@ describe("Contribution contract", async function () {
|
||||
const contributionFactory = await ethers.getContractFactory("Contribution");
|
||||
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
|
||||
await Contribution.setContributorContract(Contributor.address).then(res => res.wait())
|
||||
await Contribution.finishMigration();
|
||||
});
|
||||
|
||||
it("does not allow non-contributors to add a contribution", async function () {
|
||||
await expect(Contribution.connect(addr7).add(
|
||||
500, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32
|
||||
18, 32, 0, false
|
||||
)).to.be.revertedWith("requires kredits or core status");
|
||||
expect(await Contribution.contributionsCount()).to.equal(0);
|
||||
});
|
||||
|
||||
it("does not allow special arguments outside of a migration", async function () {
|
||||
await expect(Contribution.connect(addr7).add(
|
||||
500, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32, 23000, true
|
||||
)).to.be.revertedWith("extra arguments during migration only");
|
||||
expect(await Contribution.contributionsCount()).to.equal(0);
|
||||
});
|
||||
|
||||
it("allows core contributors to add a contribution", async function () {
|
||||
await Contribution.connect(addr2).add(
|
||||
2001, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32
|
||||
18, 32, 0, false
|
||||
);
|
||||
expect(await Contribution.contributionsCount()).to.equal(1);
|
||||
});
|
||||
@ -84,23 +94,65 @@ describe("Contribution contract", async function () {
|
||||
await Contribution.connect(addr1).add(
|
||||
5000, 8,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32
|
||||
18, 32, 0, false
|
||||
);
|
||||
await Contribution.connect(addr7).add(
|
||||
1500, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32
|
||||
18, 32, 0, false
|
||||
);
|
||||
expect(await Contribution.contributionsCount()).to.equal(3);
|
||||
});
|
||||
|
||||
it("sets confirmedAtBlock to current block plus blocksToWait", async function () {
|
||||
await Contribution.connect(addr1).add(
|
||||
500, 3,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32, 0, false
|
||||
);
|
||||
expect(await Contribution.contributionsCount()).to.equal(4);
|
||||
const c = await Contribution.getContribution(4);
|
||||
const currentBlockNumber = await kredits.provider.getBlockNumber();
|
||||
expect(c['confirmedAtBlock']).to.equal(currentBlockNumber + 1 + 40321);
|
||||
});
|
||||
|
||||
it("emits a ContributionAdded event", async function () {
|
||||
await expect(Contribution.connect(addr1).add(
|
||||
2001, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32
|
||||
18, 32, 0, false
|
||||
)).to.emit(Contribution, "ContributionAdded").withArgs(anyValue, 1, 2001);
|
||||
});
|
||||
|
||||
describe("with extra arguments during migration", async 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("allows to add a contribution with custom confirmedAtBlock", async function () {
|
||||
await Contribution.connect(addr2).add(
|
||||
2001, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32, 23000, false
|
||||
);
|
||||
expect(await Contribution.contributionsCount()).to.equal(1);
|
||||
const c = await Contribution.getContribution(1);
|
||||
expect(c['confirmedAtBlock'].toNumber()).to.equal(23000);
|
||||
});
|
||||
|
||||
it("allows to add a vetoed contribution", async function () {
|
||||
await Contribution.connect(addr2).add(
|
||||
2001, 1,
|
||||
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32, 23000, true
|
||||
);
|
||||
expect(await Contribution.contributionsCount()).to.equal(2);
|
||||
const c = await Contribution.getContribution(2);
|
||||
expect(c['vetoed']).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user