Compare commits
24 Commits
v7.0.0-bet
...
796ccebd84
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
796ccebd84
|
||
|
|
d72413eb66
|
||
|
|
9dd9d298cc
|
||
|
|
67add71a22
|
||
|
|
cd07313679
|
||
|
|
90172071fa
|
||
|
|
de1574155c
|
||
|
|
0fc4eed09a
|
||
|
|
55877897be
|
||
|
|
59bda71f97
|
||
|
|
1521e272f9
|
||
|
|
990e2a9649
|
||
|
|
883f9adb96
|
||
|
|
550bc2b9f4
|
||
| 2fca436fa8 | |||
| 2b05be1897 | |||
|
|
46b1bbfbf2
|
||
|
|
98348dc544
|
||
|
|
fd93993a1b
|
||
|
|
0d6702fd2b
|
||
|
|
51e50e7c46
|
||
| 793642c238 | |||
|
|
c55593d46f
|
||
|
|
2b314556ad
|
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.openzeppelin
|
||||||
|
artifacts
|
||||||
|
cache
|
||||||
|
deployments
|
||||||
|
gitno
|
||||||
|
node_modules
|
||||||
40
.drone.yml
Normal file
40
.drone.yml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: setup
|
||||||
|
image: gitea.kosmos.org/kredits/docker-ci:latest
|
||||||
|
commands:
|
||||||
|
- cp -r /app/node_modules /drone/src/node_modules
|
||||||
|
- chown -R drone:drone /drone/src
|
||||||
|
- su drone -c 'npm install'
|
||||||
|
- name: lint js
|
||||||
|
image: gitea.kosmos.org/kredits/docker-ci:latest
|
||||||
|
commands:
|
||||||
|
- su drone -c 'npm run lint:wrapper'
|
||||||
|
depends_on:
|
||||||
|
- setup
|
||||||
|
# - name: lint contracts
|
||||||
|
# image: gitea.kosmos.org/kredits/docker-ci:latest
|
||||||
|
# commands:
|
||||||
|
# - su drone -c 'npm run lint:contracts'
|
||||||
|
# depends_on:
|
||||||
|
# - setup
|
||||||
|
- name: build contracts
|
||||||
|
image: gitea.kosmos.org/kredits/docker-ci:latest
|
||||||
|
commands:
|
||||||
|
- su drone -c 'npm run devchain -- --silent' &
|
||||||
|
- sleep 5
|
||||||
|
- su drone -c 'npm run build'
|
||||||
|
depends_on:
|
||||||
|
- setup
|
||||||
|
- name: test
|
||||||
|
image: gitea.kosmos.org/kredits/docker-ci:latest
|
||||||
|
commands:
|
||||||
|
- su drone -c 'npm run devchain -- --silent' &
|
||||||
|
- sleep 5
|
||||||
|
- su drone -c 'npm test'
|
||||||
|
depends_on:
|
||||||
|
- setup
|
||||||
|
- build contracts
|
||||||
@@ -1 +1,2 @@
|
|||||||
/scripts/
|
/scripts/
|
||||||
|
/test/
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,8 @@ node_modules
|
|||||||
yarn-error.log
|
yarn-error.log
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
data
|
||||||
|
|
||||||
cache
|
cache
|
||||||
artifacts
|
artifacts
|
||||||
.openzeppelin
|
.openzeppelin
|
||||||
|
|||||||
38
.travis.yml
38
.travis.yml
@@ -1,38 +0,0 @@
|
|||||||
---
|
|
||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "12"
|
|
||||||
|
|
||||||
sudo: false
|
|
||||||
dist: xenial
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- node_modules
|
|
||||||
- apps/contribution/node_modules
|
|
||||||
- apps/contributor/node_modules
|
|
||||||
- apps/proposal/node_modules
|
|
||||||
- apps/token/node_modules
|
|
||||||
- apps/vault/node_modules
|
|
||||||
|
|
||||||
install:
|
|
||||||
- npm install -g @aragon/cli
|
|
||||||
- npm install -g truffle
|
|
||||||
- npm install
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- npm run devchain &
|
|
||||||
- sleep 10
|
|
||||||
|
|
||||||
script:
|
|
||||||
- npm run lint:wrapper
|
|
||||||
- npm run lint:contract-tests
|
|
||||||
# FIXME Fix tests
|
|
||||||
# - npm run test:token
|
|
||||||
# - npm run test:contributor
|
|
||||||
# - npm run test:contribution
|
|
||||||
# - npm run test:proposal
|
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM node:16.16
|
||||||
|
#ENV NODE_ENV=production
|
||||||
|
|
||||||
|
RUN useradd -ms /bin/bash drone
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ["package.json", "package-lock.json*", "./"]
|
||||||
|
RUN chown -R drone:drone /app
|
||||||
|
USER drone
|
||||||
|
RUN npm install
|
||||||
|
USER root
|
||||||
@@ -42,8 +42,15 @@ contract Contribution is Initializable {
|
|||||||
mapping(uint32 => ContributionData) public contributions;
|
mapping(uint32 => ContributionData) public contributions;
|
||||||
uint32 public contributionsCount;
|
uint32 public contributionsCount;
|
||||||
|
|
||||||
|
// Confirmation veto period
|
||||||
uint32 public blocksToWait;
|
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 ContributionAdded(uint32 id, uint32 indexed contributorId, uint32 amount);
|
||||||
event ContributionClaimed(uint32 id, uint32 indexed contributorId, uint32 amount);
|
event ContributionClaimed(uint32 id, uint32 indexed contributorId, uint32 amount);
|
||||||
event ContributionVetoed(uint32 id, address vetoedByAccount);
|
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 {
|
function initialize(uint32 blocksToWait_) public initializer {
|
||||||
|
deployer = msg.sender;
|
||||||
|
migrationDone = false;
|
||||||
blocksToWait = blocksToWait_;
|
blocksToWait = blocksToWait_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function finishMigration() public onlyDeployer {
|
||||||
|
migrationDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
function setTokenContract(address token) public {
|
function setTokenContract(address token) public {
|
||||||
require(address(tokenContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
|
require(address(tokenContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
|
||||||
tokenContract = IToken(token);
|
tokenContract = IToken(token);
|
||||||
@@ -150,9 +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');
|
// require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint32[](0)), 'nope');
|
||||||
require(balanceOf(msg.sender) > 0 || contributorContract.addressIsCore(msg.sender), 'must have kredits or core');
|
// 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;
|
uint32 contributionId = contributionsCount + 1;
|
||||||
ContributionData storage c = contributions[contributionId];
|
ContributionData storage c = contributions[contributionId];
|
||||||
c.exists = true;
|
c.exists = true;
|
||||||
@@ -162,12 +183,15 @@ contract Contribution is Initializable {
|
|||||||
c.hashDigest = hashDigest;
|
c.hashDigest = hashDigest;
|
||||||
c.hashFunction = hashFunction;
|
c.hashFunction = hashFunction;
|
||||||
c.hashSize = hashSize;
|
c.hashSize = hashSize;
|
||||||
if (contributionId < 10) {
|
|
||||||
c.confirmedAtBlock = block.number;
|
if (confirmedAtBlock > 0) {
|
||||||
|
c.confirmedAtBlock = confirmedAtBlock;
|
||||||
} else {
|
} else {
|
||||||
c.confirmedAtBlock = block.number + 1 + blocksToWait;
|
c.confirmedAtBlock = block.number + 1 + blocksToWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vetoed) { c.vetoed = true; }
|
||||||
|
|
||||||
contributionsCount++;
|
contributionsCount++;
|
||||||
|
|
||||||
contributionOwner[contributionId] = contributorId;
|
contributionOwner[contributionId] = contributorId;
|
||||||
@@ -177,7 +201,6 @@ contract Contribution is Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function veto(uint32 contributionId) public onlyCore {
|
function veto(uint32 contributionId) public onlyCore {
|
||||||
|
|
||||||
ContributionData storage c = contributions[contributionId];
|
ContributionData storage c = contributions[contributionId];
|
||||||
require(c.exists, 'NOT_FOUND');
|
require(c.exists, 'NOT_FOUND');
|
||||||
require(!c.claimed, 'ALREADY_CLAIMED');
|
require(!c.claimed, 'ALREADY_CLAIMED');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
require("@nomiclabs/hardhat-waffle");
|
require("@nomiclabs/hardhat-waffle");
|
||||||
require("hardhat-deploy");
|
require("hardhat-deploy");
|
||||||
require("hardhat-deploy-ethers");
|
require("hardhat-deploy-ethers");
|
||||||
|
require("@nomicfoundation/hardhat-chai-matchers");
|
||||||
require("@openzeppelin/hardhat-upgrades");
|
require("@openzeppelin/hardhat-upgrades");
|
||||||
const Kredits = require("./lib/kredits");
|
const Kredits = require("./lib/kredits");
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"1337": {
|
"1337": {
|
||||||
"Contributor": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
|
"Contributor": "0xCc66f9A3cA2670972938FAD91d0865c4a62DFB25",
|
||||||
"Contribution": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
|
"Contribution": "0x8999CaBc43E28202c5A2257f2a95A45b1F8A62BD",
|
||||||
"Token": "0x0165878A594ca255338adfa4d48449f69242Eb8F",
|
"Token": "0xe082678eCF749982e33Ea6839852a8cd989aEDE2",
|
||||||
"Reimbursement": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
|
"Reimbursement": "0x984f797d26d3da2E9b9f8Ae4eeFEACC60fCAA90C"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ class Contribution extends Record {
|
|||||||
ipfsHashAttr.hashSize,
|
ipfsHashAttr.hashSize,
|
||||||
];
|
];
|
||||||
|
|
||||||
return this.contract.add(...contribution, callOptions);
|
return this.contract.add(...contribution, 0, false, callOptions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
870
package-lock.json
generated
870
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@
|
|||||||
"lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"",
|
"lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"",
|
||||||
"lint:contract-tests": "eslint apps/*/test",
|
"lint:contract-tests": "eslint apps/*/test",
|
||||||
"lint:wrapper": "eslint lib/",
|
"lint:wrapper": "eslint lib/",
|
||||||
"test": "npm run test:token && npm run test:contributor && npm run test:contribution && npm run test:proposal",
|
"test": "hardhat test",
|
||||||
"test:token": "cd apps/token && npm run test",
|
"test:token": "cd apps/token && npm run test",
|
||||||
"test:contributor": "cd apps/contributor && npm run test",
|
"test:contributor": "cd apps/contributor && npm run test",
|
||||||
"test:contribution": "cd apps/contribution && npm run test",
|
"test:contribution": "cd apps/contribution && npm run test",
|
||||||
@@ -39,11 +39,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/67P/kredits-contracts#readme",
|
"homepage": "https://github.com/67P/kredits-contracts#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nomicfoundation/hardhat-chai-matchers": "^1.0.3",
|
||||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||||
"@openzeppelin/contracts-upgradeable": "^4.3.2",
|
"@openzeppelin/contracts-upgradeable": "^4.3.2",
|
||||||
"@openzeppelin/hardhat-upgrades": "^1.10.0",
|
"@openzeppelin/hardhat-upgrades": "^1.10.0",
|
||||||
"async-each-series": "^1.1.0",
|
"async-each-series": "^1.1.0",
|
||||||
|
"chai": "^4.3.6",
|
||||||
"cli-table": "^0.3.1",
|
"cli-table": "^0.3.1",
|
||||||
"colors": "^1.0.3",
|
"colors": "^1.0.3",
|
||||||
"eslint": "^8.14.0",
|
"eslint": "^8.14.0",
|
||||||
@@ -57,6 +59,7 @@
|
|||||||
"hardhat-deploy": "^0.11.4",
|
"hardhat-deploy": "^0.11.4",
|
||||||
"hardhat-deploy-ethers": "^0.3.0-beta.10",
|
"hardhat-deploy-ethers": "^0.3.0-beta.10",
|
||||||
"homedir": "^0.6.0",
|
"homedir": "^0.6.0",
|
||||||
|
"mocha": "^10.0.0",
|
||||||
"promptly": "^3.0.3",
|
"promptly": "^3.0.3",
|
||||||
"solhint": "^3.3.7",
|
"solhint": "^3.3.7",
|
||||||
"truffle-hdwallet-provider": "^1.0.17",
|
"truffle-hdwallet-provider": "^1.0.17",
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
const { ethers, upgrades } = require("hardhat"); const path = require("path"); const fileInject = require("./helpers/file_inject.js");
|
const { ethers, upgrades } = require("hardhat");
|
||||||
|
const path = require("path");
|
||||||
|
const fileInject = require("./helpers/file_inject.js");
|
||||||
|
|
||||||
function handleError(error) {
|
function handleError(error) {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
|
|||||||
42
scripts/export/contributions.js
Normal file
42
scripts/export/contributions.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
|
||||||
|
await kredits.init();
|
||||||
|
|
||||||
|
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
|
||||||
|
|
||||||
|
const count = await kredits.Contribution.count;
|
||||||
|
const currentBlockHeight = await XMLHttpRequest.ethers.provider.getBlockNumber();
|
||||||
|
|
||||||
|
const backup = {};
|
||||||
|
const promises = [];
|
||||||
|
for (let i = 1; i <= count; i++) {
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log(`Loading contribution #${i}`);
|
||||||
|
await kredits.Contribution.contract.getContribution(i).then(contractData => {
|
||||||
|
backup[i] = {
|
||||||
|
amount: contractData.amount,
|
||||||
|
contributorId: contractData.contributorId,
|
||||||
|
hashDigest: contractData.hashDigest,
|
||||||
|
hashFunction: contractData.hashFunction,
|
||||||
|
hashSize: contractData.hashSize,
|
||||||
|
confirmedAtBlock: contractData.confirmedAtBlock,
|
||||||
|
confirmed: contractData.confirmedAtBlock <= currentBlockHeight,
|
||||||
|
vetoed: contractData.vetoed,
|
||||||
|
id: contractData.id,
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}, 100 * i);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises).then(() => {
|
||||||
|
fs.writeFileSync("./data/contributions.json", JSON.stringify(backup, null, 2));
|
||||||
|
console.log("Exported");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
38
scripts/export/contributors.js
Normal file
38
scripts/export/contributors.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
|
||||||
|
await kredits.init();
|
||||||
|
|
||||||
|
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
|
||||||
|
|
||||||
|
const count = await kredits.Contributor.count;
|
||||||
|
|
||||||
|
const backup = {};
|
||||||
|
const promises = [];
|
||||||
|
for (let i = 1; i <= count; i++) {
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log(`Loading contributor #${i}`);
|
||||||
|
await kredits.Contributor.contract.getContributorById(i).then(contractData => {
|
||||||
|
backup[i] = {
|
||||||
|
account: contractData.account,
|
||||||
|
hashDigest: contractData.hashDigest,
|
||||||
|
hashFunction: contractData.hashFunction,
|
||||||
|
hashSize: contractData.hashSize,
|
||||||
|
id: contractData.id,
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}, 100 * i);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises).then(() => {
|
||||||
|
fs.writeFileSync("./data/contributors.json", JSON.stringify(backup, null, 2));
|
||||||
|
console.log("Exported");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
33
scripts/import/contributors.js
Normal file
33
scripts/import/contributors.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
|
||||||
|
await kredits.init();
|
||||||
|
|
||||||
|
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = fs.readFileSync("./data/contributors.json");
|
||||||
|
const contributors = JSON.parse(data);
|
||||||
|
const ids = Object.keys(contributors)
|
||||||
|
.map(k => parseInt(k))
|
||||||
|
.sort(function(a, b){return a-b});
|
||||||
|
|
||||||
|
for (const contributorId of ids) {
|
||||||
|
const contributor = contributors[contributorId.toString()];
|
||||||
|
const result = await kredits.Contributor.contract.addContributor(
|
||||||
|
contributor.account,
|
||||||
|
contributor.hashDigest,
|
||||||
|
contributor.hashFunction,
|
||||||
|
contributor.hashSize,
|
||||||
|
);
|
||||||
|
// await result.wait();
|
||||||
|
console.log(`Added contributor #${contributorId}: ${result.hash}`);
|
||||||
|
};
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
157
test/contracts/Contribution.js
Normal file
157
test/contracts/Contribution.js
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
const { expect } = require("chai");
|
||||||
|
const { ethers, upgrades } = require("hardhat");
|
||||||
|
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
|
||||||
|
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7;
|
||||||
|
let Contribution, Contributor;
|
||||||
|
|
||||||
|
describe("Contribution contract", async function () {
|
||||||
|
before(async function () {
|
||||||
|
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
|
||||||
|
let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7];
|
||||||
|
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("initialize()", function () {
|
||||||
|
before(async function () {
|
||||||
|
// const [owner] = await ethers.getSigners();
|
||||||
|
const contributionFactory = await ethers.getContractFactory("Contribution");
|
||||||
|
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets the veto confirmation period", async function () {
|
||||||
|
expect(await Contribution.blocksToWait()).to.equal(40321);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets the data migration flag", async function () {
|
||||||
|
expect(await Contribution.migrationDone()).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets the deployer address", async function () {
|
||||||
|
expect(await Contribution.deployer()).to.equal(owner.address);
|
||||||
|
expect(await Contribution.deployer()).to.not.equal(addr1.address);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("finishMigration()", 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.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows the deployer to mark the migration as finished", async function () {
|
||||||
|
await Contribution.finishMigration();
|
||||||
|
expect(await Contribution.migrationDone()).to.equal(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("add()", 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())
|
||||||
|
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, 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, 0, false
|
||||||
|
);
|
||||||
|
expect(await Contribution.contributionsCount()).to.equal(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows contributors to add a contribution", async function () {
|
||||||
|
// Issue some kredits for new contributor #8 (addr7)
|
||||||
|
await Contribution.connect(addr1).add(
|
||||||
|
5000, 8,
|
||||||
|
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||||
|
18, 32, 0, false
|
||||||
|
);
|
||||||
|
await Contribution.connect(addr7).add(
|
||||||
|
1500, 1,
|
||||||
|
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||||
|
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, 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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
30
test/contracts/Contributor.js
Normal file
30
test/contracts/Contributor.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const { expect } = require("chai");
|
||||||
|
const { ethers, upgrades } = require("hardhat");
|
||||||
|
// const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
|
||||||
|
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7;
|
||||||
|
let Contribution, Contributor;
|
||||||
|
|
||||||
|
describe("Contributor contract", async function () {
|
||||||
|
before(async function () {
|
||||||
|
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
|
||||||
|
// let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7];
|
||||||
|
// 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("initialize()", function () {
|
||||||
|
before(async function () {
|
||||||
|
// const [owner] = await ethers.getSigners();
|
||||||
|
const contributorFactory = await ethers.getContractFactory("Contributor");
|
||||||
|
Contributor = await upgrades.deployProxy(contributorFactory);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets the deployer address", async function () {
|
||||||
|
expect(await Contributor.deployer()).to.equal(owner.address);
|
||||||
|
expect(await Contributor.deployer()).to.not.equal(addr1.address);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user