Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions contracts/StakingToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
Expand All @@ -120,7 +120,7 @@ contract StakingToken is ERC20, Ownable {
public
{
(bool _isStakeholder, ) = isStakeholder(_stakeholder);
if(!_isStakeholder) stakeholders.push(_stakeholder);
if (!_isStakeholder) stakeholders.push(_stakeholder);
}

/**
Expand All @@ -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)
Expand All @@ -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.
*/
Expand All @@ -182,7 +182,7 @@ contract StakingToken is ERC20, Ownable {
/**
* @notice A method to distribute rewards to all stakeholders.
*/
function distributeRewards()
function distributeRewards()
public
onlyOwner
{
Expand All @@ -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];
Expand Down
5 changes: 3 additions & 2 deletions migrations/02_deploy_staking.js
Original file line number Diff line number Diff line change
@@ -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),
);
Expand Down
19 changes: 10 additions & 9 deletions test/StakingToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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);
});
Expand All @@ -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;
Expand All @@ -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);
});
Expand Down
2 changes: 0 additions & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const BigNumber = require('bignumber.js');

const itShouldThrow = (reason, fun, expectedMessage) => {
it(reason, async () => {
let error = false;
Expand Down