WIP Remove claims, add withdrawals
This commit is contained in:
@@ -128,7 +128,7 @@ describe("Contribution contract", 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())
|
||||
await Contribution.setContributorContract(Contributor.address);
|
||||
});
|
||||
|
||||
it("allows to add a contribution with custom confirmedAtBlock", async function () {
|
||||
|
||||
@@ -1,19 +1,31 @@
|
||||
const { expect } = require("chai");
|
||||
const { ethers, upgrades } = require("hardhat");
|
||||
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7;
|
||||
let Contribution, Contributor;
|
||||
let Contribution, Contributor, Token;
|
||||
|
||||
describe("Contributor contract", async function () {
|
||||
before(async function () {
|
||||
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
|
||||
|
||||
const contributorFactory = await ethers.getContractFactory("Contributor");
|
||||
Contributor = await upgrades.deployProxy(contributorFactory);
|
||||
const contributionFactory = await ethers.getContractFactory("Contribution");
|
||||
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
|
||||
const tokenFactory = await ethers.getContractFactory("Token");
|
||||
Token = await upgrades.deployProxy(tokenFactory);
|
||||
|
||||
await Contributor.setTokenContract(Token.address);
|
||||
await Contributor.setContributionContract(Contribution.address);
|
||||
await Contribution.setContributorContract(Contributor.address);
|
||||
await Token.setContributorContract(Contributor.address);
|
||||
|
||||
let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7];
|
||||
for (const account of accounts) {
|
||||
await Contributor.addContributor(account.address, "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8", 18, 32);
|
||||
}
|
||||
});
|
||||
|
||||
describe("initialize()", function () {
|
||||
before(async function () {
|
||||
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);
|
||||
@@ -21,16 +33,6 @@ describe("Contributor contract", async function () {
|
||||
});
|
||||
|
||||
describe("add()", function () {
|
||||
before(async function () {
|
||||
const contributorFactory = await ethers.getContractFactory("Contributor");
|
||||
Contributor = await upgrades.deployProxy(contributorFactory);
|
||||
|
||||
let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7];
|
||||
for (const account of accounts) {
|
||||
await Contributor.addContributor(account.address, "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8", 18, 32);
|
||||
}
|
||||
});
|
||||
|
||||
it("does not allow random accounts to create a contributor profile", async function () {
|
||||
await expect(Contributor.connect(addr7).addContributor(
|
||||
"0x608FD4b95116Ea616990Aaeb1d4f1ce07612f261",
|
||||
@@ -45,8 +47,11 @@ describe("Contributor contract", async function () {
|
||||
"0x608FD4b95116Ea616990Aaeb1d4f1ce07612f261",
|
||||
"0x1d9de6de5c72eedca6d7a5e8a9159e2f5fe676506aece3000acefcc821723429",
|
||||
18, 32
|
||||
)
|
||||
);
|
||||
expect(await Contributor.contributorsCount()).to.equal(9);
|
||||
const c = await Contributor.getContributorById(9);
|
||||
expect(c['account']).to.equal("0x608FD4b95116Ea616990Aaeb1d4f1ce07612f261");
|
||||
expect(c['kreditsWithdrawn']).to.equal(0);
|
||||
});
|
||||
|
||||
it("does not allow to create accounts with an existing address", async function () {
|
||||
@@ -66,4 +71,36 @@ describe("Contributor contract", async function () {
|
||||
)).to.emit(Contributor, "ContributorAdded").withArgs(10, "0x765E88b4F9a59C3a3b300C6eFF9E6E9fDDf9FbD9");
|
||||
});
|
||||
});
|
||||
|
||||
describe("withdraw()", function () {
|
||||
before(async function () {
|
||||
// Add some pre-confirmed contributions (confirmedAtBlock 1)
|
||||
await Contribution.add(
|
||||
1500, 2, "0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32, 1, false
|
||||
);
|
||||
await Contribution.add(
|
||||
5000, 2, "0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
|
||||
18, 32, 1, false
|
||||
);
|
||||
await Contribution.finishMigration();
|
||||
});
|
||||
|
||||
it("requires the transaction sender to be a contributor", async function () {
|
||||
await expect(Contributor.withdraw()).to.be.revertedWith("Contributors only");
|
||||
});
|
||||
|
||||
it("executes a withdrawal of all available ERC20 kredits", async function () {
|
||||
let c = await Contributor.getContributorById(2);
|
||||
expect(c['balance']).to.equal(0);
|
||||
await Contributor.connect(addr1).withdraw();
|
||||
c = await Contributor.getContributorById(2);
|
||||
// TODO Are we required to use Wei for ERC20 tokens?
|
||||
expect(c['balance'].toString()).to.equal("6500000000000000000000");
|
||||
});
|
||||
|
||||
it("requires the withdrawable amount to be larger than 0", async function () {
|
||||
await expect(Contributor.connect(addr1).withdraw()).to.be.revertedWith("No kredits available");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user