Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0x3bfc committed May 15, 2020
1 parent 53b6deb commit 05aed9d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 45 deletions.
3 changes: 2 additions & 1 deletion contracts/fee/FeeCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pragma solidity ^0.5.7;
// Code is Apache-2.0 and docs are CC-BY-4.0

contract FeeCollector {

function() external payable{
}
}
32 changes: 0 additions & 32 deletions contracts/fee/FeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,4 @@ import 'openzeppelin-solidity/contracts/math/SafeMath.sol';

contract FeeManager {
using SafeMath for uint256;

uint256 public constant DIVIDENT = 90;
uint256 public constant DIVIDER = 100;

function getFee(
uint256 _startGas,
uint256 _tokenAmount
)
public
view
returns(uint256)
{

uint256 txPrice = _getTxPrice(_startGas);
return ((_tokenAmount.mul(txPrice)).mul(DIVIDENT)).div(DIVIDER);
}


function _getTxPrice(
uint256 _startGas
)
private
view
returns(uint256)
{
uint256 usedGas = _startGas.sub(gasleft());
return usedGas.mul(tx.gasprice);
}

function() external payable{

}
}
24 changes: 12 additions & 12 deletions test/unit/FeeManager.Test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const FeeManager = artifacts.require('FeeManager')
const BigNumber = require('bn.js')
// const FeeManager = artifacts.require('FeeManager')
// const BigNumber = require('bn.js')

/* eslint-env mocha */
/* global artifacts, contract, it, beforeEach, assert */
// /* eslint-env mocha */
/* global contract, it, beforeEach */

contract('FeeManager test', async accounts => {
let feeManager
let serviceFee
// let feeManager
// let serviceFee

beforeEach('init contracts for each test', async function() {
feeManager = await FeeManager.new()
serviceFee = '74167032591041'
// feeManager = await FeeManager.new()
// serviceFee = '74167032591041'
})

it('calculate fee', async () => {
const gas = new BigNumber('100000000000000')
const tokens = new BigNumber('1')
const fee = await feeManager.getFee(gas, tokens)
assert(fee.toString() === serviceFee)
// const gas = new BigNumber('100000000000000')
// const tokens = new BigNumber('1')
// const fee = await feeManager.getFee(gas, tokens)
// assert(fee.toString() === serviceFee)
})
})

0 comments on commit 05aed9d

Please sign in to comment.