Last active
April 11, 2018 16:48
-
-
Save kirillsurkov/04554aa6e7558ecefdbbdc194a2d9d08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web3.utils = web3._extend.utils; | |
| const BigNumber = require("bignumber.js"); | |
| const TheAbyssDAICO = artifacts.require("TheAbyssDAICO"); | |
| const AbyssToken = artifacts.require("AbyssToken"); | |
| const incTime = seconds => new Promise(next => | |
| web3.currentProvider.sendAsync({jsonrpc: "2.0", method: "evm_increaseTime", params: [seconds], id: 0}, () => | |
| web3.currentProvider.sendAsync({jsonrpc: "2.0", method: "evm_mine", id: 0}, next) | |
| ) | |
| ); | |
| const getTime = () => new Promise(next => web3.eth.getBlock("latest", (err, block) => next(block.timestamp))); | |
| const getBalance = address => new Promise(next => web3.eth.getBalance(address, (err, balance) => next(balance))); | |
| contract("TheAbyssDAICO", accounts => { | |
| const tokenPriceNum = 100; | |
| const tokenPriceDenom = 1; | |
| it("test min / max contribution", async () => { | |
| const contract = await TheAbyssDAICO.deployed(); | |
| await contract.setTokenPrice(tokenPriceNum, tokenPriceDenom); | |
| await contract.setSoftCap(web3.utils.toWei("1.337", "ether")); | |
| await contract.setHardCap(web3.utils.toWei("100", "ether")); | |
| await contract.addToWhiteList(accounts[12]); | |
| let minContribFail = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("0.19", "ether"), from: accounts[12]}); | |
| } catch(e) { | |
| minContribFail = true; | |
| } | |
| assert.equal(minContribFail, true); | |
| let minContribPass = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("0.2", "ether"), from: accounts[12]}); | |
| minContribPass = true; | |
| } catch(e) { | |
| } | |
| assert.equal(minContribPass, true); | |
| let maxContribFail = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("20", "ether"), from: accounts[12]}); | |
| } catch(e) { | |
| maxContribFail = true; | |
| } | |
| assert.equal(maxContribFail, true); | |
| let maxContribPass = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("19.8", "ether"), from: accounts[12]}); | |
| maxContribPass = true; | |
| } catch(e) { | |
| } | |
| assert.equal(maxContribPass, true); | |
| await incTime(86400); | |
| let maxContribPassAfter1Day = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("25", "ether"), from: accounts[12]}); | |
| maxContribPassAfter1Day = true; | |
| } catch(e) { | |
| } | |
| assert.equal(maxContribPassAfter1Day, true); | |
| }); | |
| it("test pause / unpause", async () => { | |
| const contract = await TheAbyssDAICO.deployed(); | |
| await contract.pause(); | |
| let contribFail = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("1", "ether"), from: accounts[12]}); | |
| } catch(e) { | |
| contribFail = true; | |
| } | |
| assert.equal(contribFail, true); | |
| await contract.unpause(); | |
| let contribPass = false; | |
| try { | |
| await contract.sendTransaction({value: web3.utils.toWei("1", "ether"), from: accounts[12]}); | |
| contribPass = true; | |
| } catch(e) { | |
| } | |
| assert.equal(contribPass, true); | |
| }); | |
| it("test bonuses", async () => { | |
| const contract = await TheAbyssDAICO.deployed(); | |
| const token = await AbyssToken.deployed(); | |
| const toPay = 1; | |
| const tokens = new BigNumber(toPay * tokenPriceNum / tokenPriceDenom); | |
| tokens.mul = tokens.multipliedBy; | |
| let checkBonus = async (seconds, rate) => { | |
| await incTime(seconds); | |
| let balance = (await token.balanceOf(accounts[12])).div(10**18); | |
| await contract.sendTransaction({value: web3.utils.toWei(toPay.toString(), "ether"), from: accounts[12]}); | |
| let newBalance = (await token.balanceOf(accounts[12])).div(10**18); | |
| assert.equal(newBalance.sub(balance).toString(), tokens.mul(rate).toString()); | |
| balance = newBalance; | |
| }; | |
| await checkBonus(0, 1.25); | |
| await checkBonus(86400, 1.15); | |
| await checkBonus(86400 * 5, 1.10); | |
| await checkBonus(86400 * 7, 1.05); | |
| await checkBonus(86400 * 7, 1.00); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment