Skip to content

Commit

Permalink
fix interface
Browse files Browse the repository at this point in the history
  • Loading branch information
0x3bfc committed May 18, 2020
1 parent b65fc6d commit 652ae35
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 155 deletions.
4 changes: 2 additions & 2 deletions contracts/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pragma solidity ^0.5.7;
// Code is Apache-2.0 and docs are CC-BY-4.0

import './utils/Deployer.sol';

import './interfaces/IEREC20Template.sol';
/**
* @title Factory contract
* @dev Contract for creation of Ocean Data Tokens
*/
contract Factory is Deployer {
contract Factory is IEREC20Template, Deployer {

address private feeManager;
address private tokenTemplate;
Expand Down
17 changes: 0 additions & 17 deletions contracts/interfaces/IDataTokenERC20.sol

This file was deleted.

23 changes: 23 additions & 0 deletions contracts/interfaces/IEREC20Template.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity >=0.5.0;

interface IEREC20Template {
function initialize(
string calldata name,
string calldata symbol,
address minter,
uint256 cap,
address payable feeManager
) external;
function mint(address account, uint256 value)
external payable;
function pause() external;
function unpause() external;
function setMinter(address minter) external;
function name() external view returns(string memory);
function symbol() external view returns(string memory);
function decimals() external view returns(uint256);
function cap() external view returns (uint256);
function isMinter(address account) external view returns(bool);
function isInitialized() external view returns(bool);
function isPaused() external view returns(bool);
}
10 changes: 6 additions & 4 deletions contracts/templates/ERC20Template.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ contract ERC20Template is ERC20Pausable {
address payable feeManager
) private {
require(
feeManager != address(0),
'ERC20Template: Invalid feeManager, address(0)'
minter != address(0),
'ERC20Template: Invalid minter, zero address'
);

require(
minter != address(0),
'ERC20Template: Invalid minter, address(0)'
feeManager != address(0),
'ERC20Template: Invalid feeManager, zero address'
);

require(
_minter == address(0),
'ERC20Template: Invalid minter, access denied'
Expand Down
161 changes: 161 additions & 0 deletions test/unit/ERC20Template.Test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
const Template = artifacts.require('ERC20Template')
const FeeManager = artifacts.require('FeeManager')
const Factory = artifacts.require('Factory')
const Token = artifacts.require('ERC20Template')
const testUtils = require('../helpers/utils')
const truffleAssert = require('truffle-assertions')
const BigNumber = require('bn.js')


contract('ERC20Template', async (accounts) => {
let cap
let name
let symbol
let decimals
let factory
let template
let token
let feeManager
let ethValue
let tokenAddress
let minter
let newMinter
let reciever
let metadataRef

beforeEach('init contracts for each test', async () => {
symbol = 'EDT1'
name = 'ERC20DataToken'
decimals = 0
minter = accounts[0]
reciever = accounts[1]
newMinter = accounts[2]
feeManager = await FeeManager.new()
cap = new BigNumber('1400000000')
template = await Template.new('Template', 'TEMPLATE', minter, cap, feeManager.address)
factory = await Factory.new(template.address, feeManager.address)
metadataRef = 'https://example.com/dataset-1'
const trxReceipt = await factory.createToken(name, symbol, cap, metadataRef, minter)
const TokenCreatedEventArgs = testUtils.getEventArgsFromTx(trxReceipt, 'TokenCreated')
tokenAddress = TokenCreatedEventArgs.newTokenAddress
token = await Token.at(tokenAddress)
ethValue = new BigNumber('100000000000000000')
})

it('should check that the token contract is initialized', async () => {
const isInitialized = await token.isInitialized()
assert.strictEqual(
isInitialized === true,
'Contract was not initialized correctly!'
)
})

// it('should fail to re-initialize the contracts', async () => {
// truffleAssert.fails(token.initialize('NewName', 'NN', reciever, cap, feeManager.address),
// truffleAssert.ErrorType.REVERT,
// 'ERC20Template: token instance already initialized')
// })

// it('should check that the token is not paused', async () => {
// const isPaused = await token.isPaused()
// console.log('isPaused: ', isPaused)
// // assert(isPaused === false)
// })

// it('should pause the contract', async () => {
// await token.pause({ from: minter })
// const isPaused = await token.isPaused()
// assert(isPaused === true)
// })

// it('should fail to unpause the contract', async () => {
// truffleAssert.fails(token.unpause({ from: minter }))
// })

// it('should unpause the contract', async () => {
// await token.pause({ from: minter })
// await token.unpause({ from: minter })
// const isPaused = await token.isPaused()
// assert(isPaused === false)
// })

// it('should set a new minter', async () => {
// await token.setMinter(newMinter)
// const isMinter = await token.isMinter(newMinter)
// assert(isMinter === true)
// })

// it('should not mint the tokens due to zero message value', async () => {
// truffleAssert.fails(token.mint(reciever, 10, { from: minter }),
// truffleAssert.ErrorType.REVERT,
// 'ERC20Template: invalid data token minting fee')
// })

// it('should not mint the tokens due to the cap limit', async () => {
// ethValue = new BigNumber('100000000000000000')
// const one = new BigNumber('1')
// const tokenCap = cap.add(one)

// truffleAssert.fails(token.mint(reciever, tokenCap, { value: ethValue, from: minter }),
// truffleAssert.ErrorType.REVERT,
// 'ERC20Template: cap exceeded')
// })

// it('should not mint the tokens because of the paused contract', async () => {
// await token.pause()
// truffleAssert.fails(token.mint(reciever, 10, { value: ethValue, from: minter }),
// truffleAssert.ErrorType.REVERT,
// 'ERC20Pausable: this token contract is paused')
// })

// it('should mint the tokens', async () => {
// truffleAssert.passes(await token.mint(reciever, 10, { value: ethValue, from: minter }))
// const feeBalance = await web3.eth.getBalance(feeManager.address)
// assert(feeBalance.toString() === ethValue.toString())
// })

// it('should get the token name', async () => {
// const tokenName = await token.name()
// assert(tokenName === name)
// })

// it('should get the token symbol', async () => {
// const tokenSymbol = await token.symbol()
// assert(tokenSymbol === symbol)
// })

// it('should get the token decimals', async () => {
// const tokenDecimals = await token.decimals()
// assert(tokenDecimals.toNumber() === decimals)
// })

// it('should get the token cap', async () => {
// const tokenCap = await token.cap()
// assert(tokenCap.toString() === cap.toString())
// })

// it('should approve token spending', async () => {
// truffleAssert.passes(await token.approve(reciever, 10, { from: minter }))
// })

// it('should increase token allowance', async () => {
// truffleAssert.passes(await token.approve(reciever, 10, { from: minter }))
// truffleAssert.passes(await token.increaseAllowance(reciever, 1, { from: minter }))
// })

// it('should decrease token allowance', async () => {
// truffleAssert.passes(await token.approve(reciever, 10, { from: minter }))
// truffleAssert.passes(await token.decreaseAllowance(reciever, 1, { from: minter }))
// })

// it('should transfer token tokens to another address', async () => {
// truffleAssert.passes(await token.mint(minter, 10, { value: ethValue, from: minter }))
// truffleAssert.passes(await token.transfer(reciever, 1, { from: minter }))
// })

// it('should transfer token tokens to another address', async () => {
// truffleAssert.passes(await token.mint(minter, 10, { value: ethValue, from: minter }))
// truffleAssert.passes(await token.approve(reciever, 10, { from: minter }))
// truffleAssert.passes(await token.transferFrom(minter, reciever, 1, { from: reciever }))
// })
})
4 changes: 2 additions & 2 deletions test/unit/Factory.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ contract('Factory test', async accounts => {
it('should fail on zero minter address initialization', async () => {
truffleAssert.fails(Template.new('Zero address minter contract', 'ZERO', zeroAddress, cap, feeManager.address),
truffleAssert.ErrorType.REVERT,
'ERC20Template: Invalid minter, address(0)'
'ERC20Template: Invalid minter, zero address'
)
})

it('should fail on zero feeManager address initialization', async () => {
truffleAssert.fails(Template.new('Zero address minter contract', 'ZERO', minter, cap, zeroAddress),
truffleAssert.ErrorType.REVERT,
'ERC20Template: Invalid minter, address(0)'
'ERC20Template: Invalid minter, zero address'
)
})
})
Loading

0 comments on commit 652ae35

Please sign in to comment.