From 15cdcd8c29814d51d59826ed420acd7bfd7d02a2 Mon Sep 17 00:00:00 2001 From: Dusan Perisic Date: Wed, 9 Dec 2020 09:03:35 +0100 Subject: [PATCH 1/2] refactor: fix sol lint issues --- contracts/StakingToken.sol | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contracts/StakingToken.sol b/contracts/StakingToken.sol index 216af96..cdb64e7 100644 --- a/contracts/StakingToken.sol +++ b/contracts/StakingToken.sol @@ -32,9 +32,9 @@ contract StakingToken is ERC20, Ownable { * @param _owner The address to receive all tokens on construction. * @param _supply The amount of tokens to mint on construction. */ - constructor(address _owner, uint256 _supply) + constructor(address _owner, uint256 _supply) public - { + { _mint(_owner, _supply); } @@ -48,7 +48,7 @@ contract StakingToken is ERC20, Ownable { public { _burn(msg.sender, _stake); - if(stakes[msg.sender] == 0) addStakeholder(msg.sender); + if (stakes[msg.sender] == 0) addStakeholder(msg.sender); stakes[msg.sender] = stakes[msg.sender].add(_stake); } @@ -60,7 +60,7 @@ contract StakingToken is ERC20, Ownable { public { stakes[msg.sender] = stakes[msg.sender].sub(_stake); - if(stakes[msg.sender] == 0) removeStakeholder(msg.sender); + if (stakes[msg.sender] == 0) removeStakeholder(msg.sender); _mint(msg.sender, _stake); } @@ -98,7 +98,7 @@ contract StakingToken is ERC20, Ownable { /** * @notice A method to check if an address is a stakeholder. * @param _address The address to verify. - * @return bool, uint256 Whether the address is a stakeholder, + * @return bool, uint256 Whether the address is a stakeholder, * and if so its position in the stakeholders array. */ function isStakeholder(address _address) @@ -120,7 +120,7 @@ contract StakingToken is ERC20, Ownable { public { (bool _isStakeholder, ) = isStakeholder(_stakeholder); - if(!_isStakeholder) stakeholders.push(_stakeholder); + if (!_isStakeholder) stakeholders.push(_stakeholder); } /** @@ -131,19 +131,19 @@ contract StakingToken is ERC20, Ownable { public { (bool _isStakeholder, uint256 s) = isStakeholder(_stakeholder); - if(_isStakeholder){ + if (_isStakeholder){ stakeholders[s] = stakeholders[stakeholders.length - 1]; stakeholders.pop(); - } + } } // ---------- REWARDS ---------- - + /** * @notice A method to allow a stakeholder to check his rewards. * @param _stakeholder The stakeholder to check rewards for. */ - function rewardOf(address _stakeholder) + function rewardOf(address _stakeholder) public view returns(uint256) @@ -167,7 +167,7 @@ contract StakingToken is ERC20, Ownable { return _totalRewards; } - /** + /** * @notice A simple method that calculates the rewards for each stakeholder. * @param _stakeholder The stakeholder to calculate rewards for. */ @@ -182,7 +182,7 @@ contract StakingToken is ERC20, Ownable { /** * @notice A method to distribute rewards to all stakeholders. */ - function distributeRewards() + function distributeRewards() public onlyOwner { @@ -196,7 +196,7 @@ contract StakingToken is ERC20, Ownable { /** * @notice A method to allow a stakeholder to withdraw his rewards. */ - function withdrawReward() + function withdrawReward() public { uint256 reward = rewards[msg.sender]; From 7304dcc50c4b2fd824b180affe10092db5a1933c Mon Sep 17 00:00:00 2001 From: Dusan Perisic Date: Wed, 9 Dec 2020 09:06:44 +0100 Subject: [PATCH 2/2] refactor: fix js related lint issues --- migrations/02_deploy_staking.js | 5 +++-- test/StakingToken.js | 19 ++++++++++--------- test/utils.js | 2 -- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/migrations/02_deploy_staking.js b/migrations/02_deploy_staking.js index 7cd0c30..2292e63 100644 --- a/migrations/02_deploy_staking.js +++ b/migrations/02_deploy_staking.js @@ -1,9 +1,10 @@ const BigNumber = require('bignumber.js'); + const StakingToken = artifacts.require('./StakingToken.sol'); -module.exports = function(deployer, network, accounts) { +module.exports = (deployer, network, accounts) => { deployer.deploy( - StakingToken, + StakingToken, accounts[1], new BigNumber(10).pow(18).multipliedBy(525).toString(10), ); diff --git a/test/StakingToken.js b/test/StakingToken.js index f65fb6b..c0258a7 100644 --- a/test/StakingToken.js +++ b/test/StakingToken.js @@ -20,13 +20,13 @@ contract('StakingToken', (accounts) => { beforeEach(async () => { stakingToken = await StakingToken.new( owner, - manyTokens.toString(10) + manyTokens.toString(10), ); }); itShouldThrow( 'createStake requires a StakingToken balance equal or above the stake.', - async () => { + async () => { await stakingToken.createStake(1, { from: user }); }, 'revert', @@ -45,13 +45,13 @@ contract('StakingToken', (accounts) => { it('createStake adds a stakeholder.', async () => { await stakingToken.transfer(user, 3, { from: owner }); await stakingToken.createStake(1, { from: user }); - + assert.isTrue((await stakingToken.isStakeholder(user))[0]); }); itShouldThrow( 'removeStake requires a stake equal or above the amount to remove.', - async () => { + async () => { await stakingToken.removeStake(1, { from: user }); }, 'revert', @@ -78,7 +78,7 @@ contract('StakingToken', (accounts) => { itShouldThrow( 'rewards can only be distributed by the contract owner.', - async () => { + async () => { await stakingToken.distributeRewards({ from: user }); }, 'revert', @@ -88,7 +88,7 @@ contract('StakingToken', (accounts) => { await stakingToken.transfer(user, 100, { from: owner }); await stakingToken.createStake(100, { from: user }); await stakingToken.distributeRewards({ from: owner }); - + assert.equal(await stakingToken.rewardOf(user), 1); assert.equal(await stakingToken.totalRewards(), 1); }); @@ -98,7 +98,7 @@ contract('StakingToken', (accounts) => { await stakingToken.createStake(100, { from: user }); await stakingToken.distributeRewards({ from: owner }); await stakingToken.withdrawReward({ from: user }); - + const initialSupply = manyTokens; const existingStakes = 100; const mintedAndWithdrawn = 1; @@ -107,8 +107,9 @@ contract('StakingToken', (accounts) => { assert.equal(await stakingToken.stakeOf(user), 100); assert.equal(await stakingToken.rewardOf(user), 0); assert.equal( - await stakingToken.totalSupply(), - initialSupply.minus(existingStakes).plus(mintedAndWithdrawn).toString(10)); + await stakingToken.totalSupply(), + initialSupply.minus(existingStakes).plus(mintedAndWithdrawn).toString(10), + ); assert.equal(await stakingToken.totalStakes(), 100); assert.equal(await stakingToken.totalRewards(), 0); }); diff --git a/test/utils.js b/test/utils.js index 83e7eeb..d19a4f3 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,5 +1,3 @@ -const BigNumber = require('bignumber.js'); - const itShouldThrow = (reason, fun, expectedMessage) => { it(reason, async () => { let error = false;