Resolve some solhint errors and warnings

This commit is contained in:
Râu Cao 2023-08-07 23:05:15 +02:00
parent 0b593ec795
commit c61632d949
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
5 changed files with 18 additions and 20 deletions

View File

@ -4,6 +4,6 @@
"solhint:recommended" "solhint:recommended"
], ],
"rules": { "rules": {
"indent": "2" "max-line-length": "warn"
} }
} }

View File

@ -95,13 +95,13 @@ contract Contribution is Initializable {
// Balance is amount of ERC271 tokens, not amount of kredits // Balance is amount of ERC271 tokens, not amount of kredits
function balanceOf(address owner) public view returns (uint256) { function balanceOf(address owner) public view returns (uint256) {
require(owner != address(0)); require(owner != address(0), "Address invalid");
uint32 contributorId = getContributorIdByAddress(owner); uint32 contributorId = getContributorIdByAddress(owner);
return ownedContributions[contributorId].length; return ownedContributions[contributorId].length;
} }
function ownerOf(uint32 contributionId) public view returns (address) { function ownerOf(uint32 contributionId) public view returns (address) {
require(exists(contributionId)); require(exists(contributionId), "Contribution does not exist");
uint32 contributorId = contributions[contributionId].contributorId; uint32 contributorId = contributions[contributionId].contributorId;
return getContributorAddressById(contributorId); return getContributorAddressById(contributorId);
} }
@ -156,10 +156,8 @@ contract Contribution is Initializable {
} }
function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool vetoed) 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((confirmedAtBlock == 0 && vetoed == false) || migrationDone == false, "Extra arguments not allowed");
// TODO hubot neither has kredits nor a core account require(balanceOf(msg.sender) > 0 || contributorContract.addressIsCore(msg.sender), "Requires kredits or core status");
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];
@ -188,8 +186,8 @@ 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(block.number < c.confirmedAtBlock, 'VETO_PERIOD_ENDED'); require(block.number < c.confirmedAtBlock, "VETO_PERIOD_ENDED");
c.vetoed = true; c.vetoed = true;
emit ContributionVetoed(contributionId, msg.sender); emit ContributionVetoed(contributionId, msg.sender);

View File

@ -112,17 +112,17 @@ contract Contributor is Initializable {
emit ContributorAdded(_id, account); emit ContributorAdded(_id, account);
} }
function isCoreTeam(uint32 id) view public returns (bool) { function isCoreTeam(uint32 id) public view returns (bool) {
// TODO: for simplicity we simply define the first contributors as core // TODO: for simplicity we simply define the first contributors as core
// later this needs to be changed to something more dynamic // later this needs to be changed to something more dynamic
return id > 0 && id < 7; return id > 0 && id < 7;
} }
function exists(uint32 id) view public returns (bool) { function exists(uint32 id) public view returns (bool) {
return contributors[id].exists; return contributors[id].exists;
} }
function addressIsCore(address account) view public returns (bool) { function addressIsCore(address account) public view returns (bool) {
// the deployer is always core // the deployer is always core
if(account == deployer) { if(account == deployer) {
return true; return true;
@ -131,15 +131,15 @@ contract Contributor is Initializable {
return isCoreTeam(id); return isCoreTeam(id);
} }
function addressExists(address account) view public returns (bool) { function addressExists(address account) public view returns (bool) {
return getContributorByAddress(account).exists; return getContributorByAddress(account).exists;
} }
function getContributorIdByAddress(address account) view public returns (uint32) { function getContributorIdByAddress(address account) public view returns (uint32) {
return contributorIds[account]; return contributorIds[account];
} }
function getContributorAddressById(uint32 id) view public returns (address) { function getContributorAddressById(uint32 id) public view returns (address) {
return contributors[id].account; return contributors[id].account;
} }
@ -148,7 +148,7 @@ contract Contributor is Initializable {
return contributors[id]; return contributors[id];
} }
function getContributorById(uint32 _id) view public returns (uint32 id, address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, uint32 totalKreditsEarned, uint256 contributionsCount, bool exists, uint256 kreditsWithdrawn) { function getContributorById(uint32 _id) public view returns (uint32 id, address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, uint32 totalKreditsEarned, uint256 contributionsCount, bool exists, uint256 kreditsWithdrawn) {
id = _id; id = _id;
Contributor storage c = contributors[_id]; Contributor storage c = contributors[_id];
account = c.account; account = c.account;

View File

@ -101,8 +101,8 @@ contract Reimbursement is Initializable {
function veto(uint32 reimbursementId) public onlyCore { function veto(uint32 reimbursementId) public onlyCore {
ReimbursementData storage r = reimbursements[reimbursementId]; ReimbursementData storage r = reimbursements[reimbursementId];
require(r.exists, 'NOT_FOUND'); require(r.exists, "NOT_FOUND");
require(block.number < r.confirmedAtBlock, 'VETO_PERIOD_ENDED'); require(block.number < r.confirmedAtBlock, "VETO_PERIOD_ENDED");
r.vetoed = true; r.vetoed = true;
emit ReimbursementVetoed(reimbursementId, msg.sender); emit ReimbursementVetoed(reimbursementId, msg.sender);

View File

@ -67,7 +67,7 @@ describe("Contribution contract", async function () {
500, 1, 500, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f", "0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false 18, 32, 0, false
)).to.be.revertedWith("requires kredits or core status"); )).to.be.revertedWith("Requires kredits or core status");
expect(await Contribution.contributionsCount()).to.equal(0); expect(await Contribution.contributionsCount()).to.equal(0);
}); });
@ -76,7 +76,7 @@ describe("Contribution contract", async function () {
500, 1, 500, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f", "0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 23000, true 18, 32, 23000, true
)).to.be.revertedWith("extra arguments during migration only"); )).to.be.revertedWith("Extra arguments not allowed");
expect(await Contribution.contributionsCount()).to.equal(0); expect(await Contribution.contributionsCount()).to.equal(0);
}); });