Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "../library/SafeMath.sol";

contract ProxySafeMath {

using SafeMath for uint256;

function testadd(uint256 a, uint256 b) public pure returns (uint256 ){
return a.add(b);
}

function testsub(uint256 a, uint256 b) public pure returns (uint256 ){
return a.sub(b);
}

function testmul(uint256 a, uint256 b) public pure returns (uint256 ){
return a.mul(b);
}

function testdiv(uint256 a, uint256 b) public pure returns (uint256 ){
return a.div(b);
}

function testmod(uint256 a, uint256 b) public pure returns (uint256 ){
return a.mod(b);
}


}
52 changes: 52 additions & 0 deletions modules/challenges/token_challenge/06/test/SafeMathProxyTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const truffleAssert = require('truffle-assertions');
const SafeMath = artifacts.require("SafeMath");
const SimpleCrowdfund = artifacts.require("SimpleCrowdfund");
const SimpleToken = artifacts.require("SimpleToken");
const ProxySafeMath = artifacts.require("ProxySafeMath");

contract("contractProxySafeMath",(accounts)=>{
let contractProxySafeMath = null;
let trace = false;
let contractSafeMath = null;
let contractSimpleToken = null;
let contractSimpleCrowdfund = null;
beforeEach(async () => {
contractSafeMath = await SafeMath.new({from: accounts[0]});
if(trace) console.log('SUCESSO: SafeMath.new({from: accounts[0]}');
SimpleToken.link("SafeMath",contractSafeMath.address);
contractSimpleToken = await SimpleToken.new({from: accounts[0]});
if(trace) console.log('SUCESSO: SimpleToken.new({from: accounts[0]}');
contractSimpleCrowdfund = await SimpleCrowdfund.new(1000,9,{from:accounts[0]});
if(trace) console.log('SUCESSO: SimpleCrowdfund.new(1000,9,{from:accounts[0]}');
ProxySafeMath.link('SafeMath', contractSafeMath.address);
contractProxySafeMath = await ProxySafeMath.new({ from: accounts[0] });
});

it('Should execute testadd(uint256,uint256)', async () => {
let result = await contractProxySafeMath.testadd(749, 9,{from: accounts[0]});
});
it('Should execute testsub(uint256,uint256) WHEN b<=a', async () => {
let result = await contractProxySafeMath.testsub(1999, 499,{from: accounts[0]});
});
it('Should fail testsub(uint256,uint256) when NOT comply with: b <= a', async () => {
let result = await truffleAssert.fails(contractProxySafeMath.testsub(1999, 2000,{from: accounts[0]}),'revert');
});
it('Should execute testmul(uint256,uint256) WHEN a==0', async () => {
let result = await contractProxySafeMath.testmul(0, 7,{from: accounts[0]});
});
it('Should execute testmul(uint256,uint256) WHEN a!=0', async () => {
let result = await contractProxySafeMath.testmul(7, 999,{from: accounts[0]});
});
it('Should execute testdiv(uint256,uint256) WHEN b>0', async () => {
let result = await contractProxySafeMath.testdiv(18, 7,{from: accounts[0]});
});
it('Should fail testdiv(uint256,uint256) when NOT comply with: b > 0', async () => {
let result = await truffleAssert.fails(contractProxySafeMath.testdiv(18, 0,{from: accounts[0]}),'revert');
});
it('Should execute testmod(uint256,uint256) WHEN b!=0', async () => {
let result = await contractProxySafeMath.testmod(5, 750,{from: accounts[0]});
});
it('Should fail testmod(uint256,uint256) when NOT comply with: b != 0', async () => {
let result = await truffleAssert.fails(contractProxySafeMath.testmod(5, 0,{from: accounts[0]}),'revert');
});
});
31 changes: 31 additions & 0 deletions modules/challenges/token_challenge/06/test/SimpleCrowdfundTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const truffleAssert = require('truffle-assertions');
const SafeMath = artifacts.require("SafeMath");
const SimpleCrowdfund = artifacts.require("SimpleCrowdfund");
const SimpleToken = artifacts.require("SimpleToken");
const ProxySafeMath = artifacts.require("ProxySafeMath");

contract("SimpleCrowdfund",(accounts)=>{
let trace = false;
let contractSafeMath = null;
let contractSimpleToken = null;
let contractSimpleCrowdfund = null;
beforeEach(async () => {
contractSafeMath = await SafeMath.new({from: accounts[0]});
if(trace) console.log('SUCESSO: SafeMath.new({from: accounts[0]}');
SimpleToken.link("SafeMath",contractSafeMath.address);
contractSimpleToken = await SimpleToken.new({from: accounts[0]});
if(trace) console.log('SUCESSO: SimpleToken.new({from: accounts[0]}');
contractSimpleCrowdfund = await SimpleCrowdfund.new(1000,9,{from:accounts[0]});
if(trace) console.log('SUCESSO: SimpleCrowdfund.new(1000,9,{from:accounts[0]}');
});

it('Should execute buyTokens(address)', async () => {
let result = await contractSimpleCrowdfund.buyTokens(accounts[3],{from: accounts[0]});
});
it('Should execute getRate()', async () => {
let result = await contractSimpleCrowdfund.getRate({from: accounts[0]});
});
it('Should execute fallback()', async () => {
let result = await contractSimpleCrowdfund.sendTransaction({from: accounts[0],value:6});
});
});
67 changes: 67 additions & 0 deletions modules/challenges/token_challenge/06/test/SimpleTokenTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const truffleAssert = require('truffle-assertions');
const SafeMath = artifacts.require("SafeMath");
const SimpleCrowdfund = artifacts.require("SimpleCrowdfund");
const SimpleToken = artifacts.require("SimpleToken");
const ProxySafeMath = artifacts.require("ProxySafeMath");

contract("SimpleToken",(accounts)=>{
let trace = false;
let contractSafeMath = null;
let contractSimpleToken = null;
let contractSimpleCrowdfund = null;
beforeEach(async () => {
contractSafeMath = await SafeMath.new({from: accounts[0]});
if(trace) console.log('SUCESSO: SafeMath.new({from: accounts[0]}');
SimpleToken.link("SafeMath",contractSafeMath.address);
contractSimpleToken = await SimpleToken.new({from: accounts[0]});
if(trace) console.log('SUCESSO: SimpleToken.new({from: accounts[0]}');
contractSimpleCrowdfund = await SimpleCrowdfund.new(1000,9,{from:accounts[0]});
if(trace) console.log('SUCESSO: SimpleCrowdfund.new(1000,9,{from:accounts[0]}');
});

it('Should execute transferFrom(address,address,uint256)', async () => {
let result = await contractSimpleToken.transferFrom(accounts[7], accounts[8], 500,{from: accounts[0]});
});
it('Should execute approve(address,uint256)', async () => {
let result = await contractSimpleToken.approve(accounts[8], 2001,{from: accounts[0]});
});
it('Should execute allowance(address,address)', async () => {
let result = await contractSimpleToken.allowance(accounts[4], accounts[9],{from: accounts[0]});
});
it('Should execute balanceOf(address)', async () => {
let result = await contractSimpleToken.balanceOf(accounts[7],{from: accounts[0]});
});
it('Should execute transfer(address,uint256) WHEN _to!=0x0000000000000000000000000000000000000000,_value<=balances', async () => {
let result = await contractSimpleToken.transfer(accounts[6], 0,{from: accounts[0]});
});
it('Should fail transfer(address,uint256) when NOT comply with: _to != 0x0000000000000000000000000000000000000000', async () => {
let result = await truffleAssert.fails(contractSimpleToken.transfer("0x0000000000000000000000000000000000000000", 0,{from: accounts[0]}),'revert');
});
it('Should execute mint(address,uint256) WHEN msg.sender==_owner,totalSupply<maxSupply', async () => {
let result = await contractSimpleToken.mint(accounts[3], 6,{from: accounts[0]});
});
it('Should fail mint(address,uint256) when NOT comply with: msg.sender == _owner', async () => {
let result = await truffleAssert.fails(contractSimpleToken.mint(accounts[3], 6,{from: accounts[9]}),'revert');
});
it('Should execute owner()', async () => {
let result = await contractSimpleToken.owner({from: accounts[0]});
});
it('Should execute isOwner()', async () => {
let result = await contractSimpleToken.isOwner({from: accounts[0]});
});
it('Should execute renounceOwnership() WHEN msg.sender==_owner', async () => {
let result = await contractSimpleToken.renounceOwnership({from: accounts[0]});
});
it('Should fail renounceOwnership() when NOT comply with: msg.sender == _owner', async () => {
let result = await truffleAssert.fails(contractSimpleToken.renounceOwnership({from: accounts[9]}),'revert');
});
it('Should execute transferOwnership(address) WHEN msg.sender==_owner,newOwner!=0x0000000000000000000000000000000000000000', async () => {
let result = await contractSimpleToken.transferOwnership(accounts[0],{from: accounts[0]});
});
it('Should fail transferOwnership(address) when NOT comply with: msg.sender == _owner', async () => {
let result = await truffleAssert.fails(contractSimpleToken.transferOwnership(accounts[0],{from: accounts[9]}),'revert');
});
it('Should fail transferOwnership(address) when NOT comply with: newOwner != 0x0000000000000000000000000000000000000000', async () => {
let result = await truffleAssert.fails(contractSimpleToken.transferOwnership("0x0000000000000000000000000000000000000000",{from: accounts[0]}),'revert');
});
});