Compare commits
6 Commits
v7.0.1
...
8ef6fc06ce
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ef6fc06ce | |||
|
|
093273f15b
|
||
|
|
1dc54eccea
|
||
|
|
bb662e377c
|
||
|
|
d6bbc441f8
|
||
|
|
46090b3740
|
30
README.md
30
README.md
@@ -1,4 +1,5 @@
|
||||
[](https://www.npmjs.com/package/@kredits/contracts)
|
||||
[](https://drone.kosmos.org/kredits/contracts)
|
||||
|
||||
# Kredits Contracts
|
||||
|
||||
@@ -26,27 +27,27 @@ To run a local development chain run:
|
||||
|
||||
### Bootstrap
|
||||
|
||||
1. Run an Ethereum node and ipfs
|
||||
1. Run an EVM node and ipfs
|
||||
|
||||
$ npm run devchain
|
||||
$ ipfs daemon
|
||||
|
||||
2. Compile contracts and build ABIs
|
||||
2. Compile contracts and build ABIs
|
||||
|
||||
(compiled artifacts will be in `/artifacts`)
|
||||
$ npm run build
|
||||
|
||||
3. Deploy new upgradable contract proxies
|
||||
3. Deploy new upgradable contract proxies
|
||||
|
||||
$ npm run deploy:dao
|
||||
|
||||
4. Execute seeds to create demo contributors, contributions, etc. (optional)
|
||||
4. Execute seeds to create demo contributors, contributions, etc. (optional)
|
||||
|
||||
$ npm run seeds
|
||||
|
||||
**Step 2-4 is also summarized in `npm run bootstrap`**
|
||||
|
||||
5. Show contract addresses
|
||||
5. Show contract addresses
|
||||
|
||||
$ cat lib/addresses.json
|
||||
|
||||
@@ -56,6 +57,16 @@ If you need to fund development accounts with devchain coins:
|
||||
|
||||
$ npm run fund # or hardhat fund --network localhost
|
||||
|
||||
## Specs / Testing
|
||||
|
||||
With a local development chain running:
|
||||
|
||||
$ hardhat test
|
||||
|
||||
If you add or change contract code, please make sure to add and/or adapt tests
|
||||
accordingly. Don't worry, it's easy! You can use existing tests as a template
|
||||
for new ones.
|
||||
|
||||
## Contract architecture
|
||||
|
||||
We use the [OpenZeppelin hardhat
|
||||
@@ -145,12 +156,3 @@ To run the console on one of the non localhost networks you can also just pass
|
||||
on the --network argument.
|
||||
|
||||
$ hardhat console --network rsk
|
||||
|
||||
|
||||
## Known Issues
|
||||
|
||||
When resetting ganache Metamask might have an invalid transaction nonce and
|
||||
transactions get rejected. Nonces in Ethereum must be incrementing and have no
|
||||
gap.
|
||||
|
||||
To solve this reset the metamask account (Account -> Settings -> Reset Account)
|
||||
|
||||
@@ -15,7 +15,7 @@ const contractCalls = [
|
||||
name: 'raucao',
|
||||
kind: 'person',
|
||||
url: '',
|
||||
github_username: 'skddc',
|
||||
github_username: 'raucao',
|
||||
github_uid: 842,
|
||||
gitea_username: 'raucao',
|
||||
wiki_username: 'Basti',
|
||||
|
||||
@@ -13,6 +13,7 @@ interface IContributionBalance {
|
||||
|
||||
contract Contributor is Initializable {
|
||||
address public deployer;
|
||||
address public profileManager;
|
||||
IContributionBalance public contributionContract;
|
||||
IToken public tokenContract;
|
||||
|
||||
@@ -43,8 +44,9 @@ contract Contributor is Initializable {
|
||||
_;
|
||||
}
|
||||
|
||||
function initialize() public initializer {
|
||||
function initialize(address profileManagerAddress) public initializer {
|
||||
deployer = msg.sender;
|
||||
profileManager = profileManagerAddress;
|
||||
}
|
||||
|
||||
function setContributionContract(address contribution) public onlyCore {
|
||||
@@ -87,8 +89,9 @@ contract Contributor is Initializable {
|
||||
ContributorProfileUpdated(id, oldHashDigest, c.hashDigest);
|
||||
}
|
||||
|
||||
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public onlyCore {
|
||||
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public {
|
||||
require(!addressExists(account), "Address already in use");
|
||||
require((msg.sender == profileManager) || addressIsCore(msg.sender), "Only core and profile manager");
|
||||
uint32 _id = contributorsCount + 1;
|
||||
assert(!contributors[_id].exists); // this can not be acually
|
||||
Contributor storage c = contributors[_id];
|
||||
|
||||
@@ -16,6 +16,7 @@ contract Reimbursement is Initializable {
|
||||
struct ReimbursementData {
|
||||
uint32 recipientId;
|
||||
uint256 amount;
|
||||
// TODO remove token entirely
|
||||
address token;
|
||||
bytes32 hashDigest;
|
||||
uint8 hashFunction;
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "kredits-contracts",
|
||||
"name": "@kredits/contracts",
|
||||
"version": "7.0.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kredits-contracts",
|
||||
"name": "@kredits/contracts",
|
||||
"version": "7.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
@@ -9,7 +9,7 @@ describe("Contribution contract", 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);
|
||||
Contributor = await upgrades.deployProxy(contributorFactory, ["0x2946fFfd31096435cb0fc927D306E1C006C5D1aF"]);
|
||||
for (const account of accounts) {
|
||||
await Contributor.addContributor(account.address, "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8", 18, 32);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
const { expect } = require("chai");
|
||||
const { ethers, upgrades } = require("hardhat");
|
||||
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7;
|
||||
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8;
|
||||
let Contribution, Contributor, Token;
|
||||
|
||||
describe("Contributor contract", async function () {
|
||||
before(async function () {
|
||||
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
|
||||
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8] = await ethers.getSigners();
|
||||
|
||||
const contributorFactory = await ethers.getContractFactory("Contributor");
|
||||
Contributor = await upgrades.deployProxy(contributorFactory);
|
||||
Contributor = await upgrades.deployProxy(contributorFactory, [addr8.address]);
|
||||
const contributionFactory = await ethers.getContractFactory("Contribution");
|
||||
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
|
||||
const tokenFactory = await ethers.getContractFactory("Token");
|
||||
@@ -30,6 +30,10 @@ describe("Contributor contract", async function () {
|
||||
expect(await Contributor.deployer()).to.equal(owner.address);
|
||||
expect(await Contributor.deployer()).to.not.equal(addr1.address);
|
||||
});
|
||||
|
||||
it("sets a profile manager address", async function () {
|
||||
expect(await Contributor.profileManager()).to.equal(addr8.address);
|
||||
});
|
||||
});
|
||||
|
||||
describe("add()", function () {
|
||||
@@ -38,7 +42,7 @@ describe("Contributor contract", async function () {
|
||||
"0x608FD4b95116Ea616990Aaeb1d4f1ce07612f261",
|
||||
"0x1d9de6de5c72eedca6d7a5e8a9159e2f5fe676506aece3000acefcc821723429",
|
||||
18, 32
|
||||
)).to.be.revertedWith("Core only");
|
||||
)).to.be.revertedWith("Only core and profile manager");
|
||||
expect(await Contributor.contributorsCount()).to.equal(8);
|
||||
});
|
||||
|
||||
@@ -70,6 +74,18 @@ describe("Contributor contract", async function () {
|
||||
18, 32
|
||||
)).to.emit(Contributor, "ContributorAdded").withArgs(10, "0x765E88b4F9a59C3a3b300C6eFF9E6E9fDDf9FbD9");
|
||||
});
|
||||
|
||||
it("allows the profile manager account to create a contributor profile", async function () {
|
||||
await Contributor.connect(addr8).addContributor(
|
||||
"0x954712B8703Df5255A219B139ba7BFC256E72a15",
|
||||
"0x1d9de6de5c72eedca6d7a5e8a9159e2f5fe676506aece3000acefcc821723429",
|
||||
18, 32
|
||||
);
|
||||
expect(await Contributor.contributorsCount()).to.equal(11);
|
||||
const c = await Contributor.getContributorById(11);
|
||||
expect(c['account']).to.equal("0x954712B8703Df5255A219B139ba7BFC256E72a15");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("withdraw()", function () {
|
||||
|
||||
Reference in New Issue
Block a user