diff --git a/modules/challenges/token_challenge/06/contracts/proxy4tests/SafeMath.sol b/modules/challenges/token_challenge/06/contracts/proxy4tests/SafeMath.sol new file mode 100644 index 0000000..57bbd38 --- /dev/null +++ b/modules/challenges/token_challenge/06/contracts/proxy4tests/SafeMath.sol @@ -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); + } + + +} \ No newline at end of file diff --git a/modules/challenges/token_challenge/06/test/SafeMathProxyTest.js b/modules/challenges/token_challenge/06/test/SafeMathProxyTest.js new file mode 100644 index 0000000..33c3a1c --- /dev/null +++ b/modules/challenges/token_challenge/06/test/SafeMathProxyTest.js @@ -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'); + }); +}); diff --git a/modules/challenges/token_challenge/06/test/SimpleCrowdfundTest.js b/modules/challenges/token_challenge/06/test/SimpleCrowdfundTest.js new file mode 100644 index 0000000..998badb --- /dev/null +++ b/modules/challenges/token_challenge/06/test/SimpleCrowdfundTest.js @@ -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}); + }); +}); diff --git a/modules/challenges/token_challenge/06/test/SimpleTokenTest.js b/modules/challenges/token_challenge/06/test/SimpleTokenTest.js new file mode 100644 index 0000000..f364118 --- /dev/null +++ b/modules/challenges/token_challenge/06/test/SimpleTokenTest.js @@ -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 { + 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'); + }); +});