Skip to content

Commit

Permalink
Add error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ßingen committed Jun 3, 2020
1 parent e15b33e commit 8d13f5a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions contracts/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract Staking is Autopetrified, ERCStaking, ERCStakingHistory, IStakingLockin
string private constant ERROR_TOKEN_NOT_CONTRACT = "STAKING_TOKEN_NOT_CONTRACT";
string private constant ERROR_AMOUNT_ZERO = "STAKING_AMOUNT_ZERO";
string private constant ERROR_TOKEN_TRANSFER = "STAKING_TOKEN_TRANSFER";
string private constant ERROR_TOKEN_DEPOSIT = "STAKING_TOKEN_DEPOSIT";
string private constant ERROR_TOKEN_NOT_SENDER = "STAKING_TOKEN_NOT_SENDER";
string private constant ERROR_WRONG_TOKEN = "STAKING_WRONG_TOKEN";
string private constant ERROR_NOT_ENOUGH_BALANCE = "STAKING_NOT_ENOUGH_BALANCE";
Expand Down Expand Up @@ -441,7 +442,7 @@ contract Staking is Autopetrified, ERCStaking, ERCStakingHistory, IStakingLockin
_modifyTotalStaked(_amount, true);

// pull tokens into Staking contract
require(stakingToken.safeTransferFrom(_from, this, _amount), ERROR_TOKEN_TRANSFER);
require(stakingToken.safeTransferFrom(_from, this, _amount), ERROR_TOKEN_DEPOSIT);

emit Staked(_accountAddress, _amount, newStake, _data);
}
Expand All @@ -453,7 +454,8 @@ contract Staking is Autopetrified, ERCStaking, ERCStakingHistory, IStakingLockin
if (_increase) {
newStake = currentStake.add(_by);
} else {
newStake = currentStake.sub(_by);
require(currentStake >= _by, ERROR_NOT_ENOUGH_BALANCE);
newStake = currentStake - _by;
}

// add new value to account history
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/staking",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"author": "Aragon Institution MTU <contact@aragon.one>",
"license": "(GPL-3.0-or-later OR MIT)",
Expand Down
1 change: 1 addition & 0 deletions test/helpers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const STAKING_ERRORS = {
ERROR_TOKEN_NOT_CONTRACT: 'STAKING_TOKEN_NOT_CONTRACT',
ERROR_AMOUNT_ZERO: 'STAKING_AMOUNT_ZERO',
ERROR_TOKEN_TRANSFER: 'STAKING_TOKEN_TRANSFER',
ERROR_TOKEN_DEPOSIT: 'STAKING_TOKEN_DEPOSIT',
ERROR_TOKEN_NOT_SENDER: 'STAKING_TOKEN_NOT_SENDER',
ERROR_WRONG_TOKEN: 'STAKING_WRONG_TOKEN',
ERROR_NOT_ENOUGH_BALANCE: 'STAKING_NOT_ENOUGH_BALANCE',
Expand Down
6 changes: 3 additions & 3 deletions test/staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { bn, assertBn } = require('@aragon/contract-helpers-test/numbers')

const { deploy } = require('./helpers/deploy')(artifacts)
const { DEFAULT_STAKE_AMOUNT, EMPTY_DATA } = require('./helpers/constants')
const { STAKING_ERRORS, SAFE_MATH_ERRORS } = require('./helpers/errors')
const { STAKING_ERRORS } = require('./helpers/errors')

const StakingMock = artifacts.require('StakingMock')
const StandardTokenMock = artifacts.require('StandardTokenMock');
Expand Down Expand Up @@ -66,7 +66,7 @@ contract('Staking app', ([owner, other]) => {
const balance = await getTokenBalance(token, owner)
const amount = balance + 1
await token.approve(stakingAddress, amount)
await assertRevert(staking.stake(amount, EMPTY_DATA), STAKING_ERRORS.ERROR_TOKEN_TRANSFER)
await assertRevert(staking.stake(amount, EMPTY_DATA), STAKING_ERRORS.ERROR_TOKEN_DEPOSIT)
})

it('stakes for', async () => {
Expand Down Expand Up @@ -112,7 +112,7 @@ contract('Staking app', ([owner, other]) => {

it('fails unstaking more than staked', async () => {
await approveAndStake()
await assertRevert(staking.unstake(DEFAULT_STAKE_AMOUNT + 1, EMPTY_DATA), SAFE_MATH_ERRORS.ERROR_SUB_UNDERFLOW)
await assertRevert(staking.unstake(DEFAULT_STAKE_AMOUNT + 1, EMPTY_DATA), STAKING_ERRORS.ERROR_NOT_ENOUGH_BALANCE)
})

context('History', async () => {
Expand Down

0 comments on commit 8d13f5a

Please sign in to comment.