-
Notifications
You must be signed in to change notification settings - Fork 2
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
add contracts for token and crowdsale, and solidity tests #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pragma solidity ^0.4.18; | ||
|
||
import "zeppelin-solidity/contracts/crowdsale/Crowdsale.sol"; | ||
import "zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol"; | ||
import "zeppelin-solidity/contracts/token/ERC20/MintableToken.sol"; | ||
|
||
contract SampleCrowdsale is MintedCrowdsale { | ||
function SampleCrowdsale( | ||
uint256 _rate, | ||
address _wallet, | ||
MintableToken _token | ||
) | ||
public | ||
Crowdsale(_rate, _wallet, _token) | ||
{ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
pragma solidity ^0.4.18; | ||
|
||
import "zeppelin-solidity/contracts/token/ERC20/MintableToken.sol"; | ||
import { Jurisdiction } from "./tpl-contracts/Jurisdiction.sol"; | ||
|
||
/** | ||
* @title SampleToken | ||
* @dev Mintable ERC20 Token. | ||
*/ | ||
contract SampleToken is MintableToken { | ||
|
||
Jurisdiction jurisdiction; | ||
|
||
string public constant name = "SampleToken"; | ||
string public constant symbol = "TPL"; | ||
uint8 public constant decimals = 18; | ||
|
||
function SampleToken(Jurisdiction _jurisdiction) public { | ||
jurisdiction = _jurisdiction; | ||
totalSupply_ = 0; | ||
} | ||
|
||
function mint(address _to, uint256 _amount) | ||
onlyOwner | ||
canMint | ||
public | ||
returns (bool) | ||
{ | ||
require(jurisdiction.hasAttribute(_to, 'VALID')); | ||
return super.mint(_to, _amount); | ||
} | ||
|
||
function transfer(address _to, uint256 _value) public returns (bool) { | ||
require(jurisdiction.hasAttribute(_to, 'VALID')); | ||
return super.transfer(_to, _value); | ||
} | ||
|
||
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | ||
require(jurisdiction.hasAttribute(_to, 'VALID')); | ||
return super.transferFrom(_from, _to, _value); | ||
} | ||
} |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-bignumber": "^2.0.2", | ||
"enzyme": "^3.3.0", | ||
"enzyme-adapter-react-16": "^1.1.1", | ||
"jsdom": "^11.7.0", | ||
|
@@ -31,7 +33,9 @@ | |
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "mocha --require babel-core/register --require test/setup.js", | ||
"test": "npm run test:react && npm run test:contracts", | ||
"test:contracts": "truffle test test/contracts/* --network unexisting", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this weird. If I didn't set network, or set it to some existing network, it would say that the contract couldn't be deployed because of gas. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that by default the test network will be the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. But then I had plenty of problems with deploying the contracts to geth, and I read something about a wrong constructor. I made many changes back and forth, until it started working, so I'm not sure what was wrong. |
||
"test:react": "mocha test/react --require babel-core/register --require test/react/setup.js", | ||
"eject": "react-scripts eject" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const Jurisdiction = artifacts.require('Jurisdiction'); | ||
const DummyValidator = artifacts.require('DummyValidator'); | ||
|
||
var should = require('chai').should(); | ||
|
||
contract('DummyValidator', function ([investor]) { | ||
|
||
beforeEach(async function () { | ||
this.jurisdiction = await Jurisdiction.new(); | ||
this.dummyValidator = await DummyValidator.new(this.jurisdiction.address); | ||
await this.jurisdiction.addValidator(this.dummyValidator.address); | ||
}); | ||
|
||
it('should validate', async function () { | ||
await this.dummyValidator.validate({from: investor}); | ||
(await this.jurisdiction.hasAttribute(investor, 'VALID')).should.be.true; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const Jurisdiction = artifacts.require('Jurisdiction'); | ||
const SampleToken = artifacts.require('SampleToken'); | ||
const SampleCrowdsale = artifacts.require('SampleCrowdsale'); | ||
|
||
const BigNumber = web3.BigNumber; | ||
|
||
var should = require('chai') | ||
.use(require('chai-as-promised')) | ||
.use(require('chai-bignumber')(BigNumber)) | ||
.should(); | ||
|
||
contract('SampleCrowdsale', function ([owner, wallet, investor]) { | ||
|
||
const RATE = new BigNumber(1); | ||
|
||
beforeEach(async function () { | ||
this.jurisdiction = await Jurisdiction.new(); | ||
await this.jurisdiction.addValidator(owner); | ||
|
||
this.token = await SampleToken.new(this.jurisdiction.address); | ||
this.crowdsale = await SampleCrowdsale.new( | ||
RATE, wallet, this.token.address); | ||
await this.token.transferOwnership(this.crowdsale.address); | ||
}); | ||
|
||
it('should create crowdsale with correct parameters', async function () { | ||
(await this.crowdsale.rate()).should.be.bignumber.equal(RATE); | ||
(await this.crowdsale.wallet()).should.be.equal(wallet); | ||
}); | ||
|
||
it('should not accept payment not validated', async function () { | ||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.crowdsale.buyTokens( | ||
investor, | ||
{ value: investmentAmount, from: investor } | ||
).should.be.rejectedWith('revert'); | ||
(await this.token.balanceOf(investor)) | ||
.should.be.bignumber.equal(0); | ||
(await this.token.totalSupply()) | ||
.should.be.bignumber.equal(0); | ||
}); | ||
|
||
it('should accept payment validated', async function () { | ||
await this.jurisdiction.addAttribute(investor, 'VALID', 1); | ||
|
||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.crowdsale.buyTokens( | ||
investor, | ||
{ value: investmentAmount, from: investor } | ||
).should.be.fulfilled; | ||
(await this.token.balanceOf(investor)) | ||
.should.be.bignumber.equal(investmentAmount); | ||
(await this.token.totalSupply()) | ||
.should.be.bignumber.equal(investmentAmount); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
const Jurisdiction = artifacts.require('Jurisdiction'); | ||
const SampleToken = artifacts.require('SampleToken'); | ||
|
||
const BigNumber = web3.BigNumber; | ||
|
||
var should = require('chai') | ||
.use(require('chai-as-promised')) | ||
.use(require('chai-bignumber')(BigNumber)) | ||
.should(); | ||
|
||
contract('SampleToken', function ([owner, investor1, investor2]) { | ||
|
||
beforeEach(async function () { | ||
this.jurisdiction = await Jurisdiction.new(); | ||
await this.jurisdiction.addValidator(owner); | ||
|
||
this.token = await SampleToken.new(this.jurisdiction.address); | ||
await this.token.transferOwnership(owner); | ||
}); | ||
|
||
it('should not accept not validated minting', async function () { | ||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.token.mint( | ||
investor1, investmentAmount, | ||
{ from: investor1 } | ||
).should.be.rejectedWith('revert'); | ||
(await this.token.balanceOf(investor1)) | ||
.should.be.bignumber.equal(0); | ||
(await this.token.totalSupply()) | ||
.should.be.bignumber.equal(0); | ||
}); | ||
|
||
it('should accept validated minting', async function () { | ||
await this.jurisdiction.addAttribute(investor1, 'VALID', 1); | ||
|
||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.token.mint( | ||
investor1, investmentAmount, | ||
{ from: owner } | ||
).should.be.fulfilled; | ||
(await this.token.balanceOf(investor1)) | ||
.should.be.bignumber.equal(investmentAmount); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're using await this.token.balanceOf(investor1).should.eventually.be.bignumber.equal(investmentAmount) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think that reads better? It's a lot longer than adding two parentheses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably doesn't read better. No strong feelings about this. |
||
(await this.token.totalSupply()) | ||
.should.be.bignumber.equal(investmentAmount); | ||
}); | ||
|
||
it('should not accept not validated transfer', async function () { | ||
await this.jurisdiction.addAttribute(investor1, 'VALID', 1); | ||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.token.mint( | ||
investor1, investmentAmount, | ||
{ from: owner } | ||
).should.be.fulfilled; | ||
|
||
await this.token.transfer( | ||
investor2, investmentAmount, | ||
{ from: investor1 } | ||
).should.be.rejectedWith('revert'); | ||
(await this.token.balanceOf(investor1)) | ||
.should.be.bignumber.equal(investmentAmount); | ||
(await this.token.balanceOf(investor2)) | ||
.should.be.bignumber.equal(0); | ||
}); | ||
|
||
it('should accept validated transfer', async function () { | ||
await this.jurisdiction.addAttribute(investor1, 'VALID', 1); | ||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.token.mint( | ||
investor1, investmentAmount, | ||
{ from: owner } | ||
).should.be.fulfilled; | ||
|
||
await this.jurisdiction.addAttribute(investor2, 'VALID', 1); | ||
await this.token.transfer( | ||
investor2, investmentAmount, | ||
{ from: investor1 } | ||
).should.be.fulfilled; | ||
(await this.token.balanceOf(investor1)) | ||
.should.be.bignumber.equal(0); | ||
(await this.token.balanceOf(investor2)) | ||
.should.be.bignumber.equal(investmentAmount); | ||
}); | ||
|
||
it('should not accept not validated transferFrom', async function () { | ||
await this.jurisdiction.addAttribute(investor1, 'VALID', 1); | ||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.token.mint( | ||
investor1, investmentAmount, | ||
{ from: owner } | ||
).should.be.fulfilled; | ||
await this.token.approve( | ||
owner, investmentAmount, | ||
{ from: investor1 } | ||
).should.be.fulfilled; | ||
|
||
await this.token.transferFrom( | ||
investor1, investor2, investmentAmount, | ||
{ from: owner } | ||
).should.be.rejectedWith('revert'); | ||
(await this.token.balanceOf(investor1)) | ||
.should.be.bignumber.equal(investmentAmount); | ||
(await this.token.balanceOf(investor2)) | ||
.should.be.bignumber.equal(0); | ||
}); | ||
|
||
it('should accept validated transferFrom', async function () { | ||
await this.jurisdiction.addAttribute(investor1, 'VALID', 1); | ||
const investmentAmount = new BigNumber(web3.toWei(1, 'ether')); | ||
await this.token.mint( | ||
investor1, investmentAmount, | ||
{ from: owner } | ||
).should.be.fulfilled; | ||
await this.token.approve( | ||
owner, investmentAmount, | ||
{ from: investor1 } | ||
).should.be.fulfilled; | ||
|
||
await this.jurisdiction.addAttribute(investor2, 'VALID', 1); | ||
await this.token.transferFrom( | ||
investor1, investor2, investmentAmount, | ||
{ from: owner } | ||
).should.be.fulfilled; | ||
(await this.token.balanceOf(investor1)) | ||
.should.be.bignumber.equal(0); | ||
(await this.token.balanceOf(investor2)) | ||
.should.be.bignumber.equal(investmentAmount); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be checked in
transfer
andtransferFrom
too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this!
I added the overwrites, and tests specific to the token.