From bea6deb15e8267b2539fc0aba2d1d4a11ce266ba Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sun, 20 May 2018 20:52:26 -0300 Subject: [PATCH] improve tests --- test/minimetoken.js | 93 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 14 deletions(-) diff --git a/test/minimetoken.js b/test/minimetoken.js index 86eb957..d911652 100644 --- a/test/minimetoken.js +++ b/test/minimetoken.js @@ -4,8 +4,10 @@ const Controlled = require('./controlled'); describe("MiniMeToken", async function() { this.timeout(0); - var accountsArr; - + var accounts; + var miniMeTokenClone; + const b = []; + before(function(done) { var contractsConfig = { "MiniMeTokenFactory": { @@ -22,24 +24,82 @@ describe("MiniMeToken", async function() { ] } }; - EmbarkSpec.deployAll(contractsConfig, async function(accounts) { - accountsArr = accounts + EmbarkSpec.deployAll(contractsConfig, async function(accountsArr) { + accounts = accountsArr done() }); }); - it("should increase totalSupply in generateTokens", async function() { - let initialSupply = await MiniMeToken.methods.totalSupply().call(); - await MiniMeToken.methods.generateTokens(accountsArr[0], 100).send({from: accountsArr[0]}); - let result = await MiniMeToken.methods.totalSupply().call(); - assert.equal(result, +initialSupply+100); + + it('should generate tokens for address 1', async () => { + await MiniMeToken.methods.generateTokens(accounts[1], 10).send(); + assert.equal(await MiniMeToken.methods.totalSupply().call(), 10); + assert.equal(await MiniMeToken.methods.balanceOf(accounts[1]).call(), 10); + b[0] = await web3.eth.getBlockNumber(); }); - it("should increase accountBalance in generateTokens", async function() { - let initialBalance = await MiniMeToken.methods.balanceOf(accountsArr[1]).call(); - await MiniMeToken.methods.generateTokens(accountsArr[1], 100).send({from: accountsArr[0]}); - let result = await MiniMeToken.methods.balanceOf(accountsArr[1]).call(); - assert.equal(result, +initialBalance+100); + it('should transfer tokens from address 1 to address 3', async () => { + await MiniMeToken.methods.transfer(accounts[3], 1).send({from: accounts[1]}); + assert.equal(await MiniMeToken.methods.totalSupply().call(), 10); + assert.equal(await MiniMeToken.methods.balanceOf(accounts[1]).call(), 9); + assert.equal(await MiniMeToken.methods.balanceOf(accounts[3]).call(), 1); + b[1] = await web3.eth.getBlockNumber(); + }); + + it('should destroy 3 tokens from 1 and 1 from 2', async () => { + await MiniMeToken.methods.destroyTokens(accounts[1], 3).send({ from: accounts[0] }); + assert.equal(await MiniMeToken.methods.totalSupply().call(), 7); + assert.equal(await MiniMeToken.methods.balanceOf(accounts[1]).call(), 6); + b[2] = await web3.eth.getBlockNumber(); + }); + + + it('should create the clone token', async () => { + const miniMeTokenCloneTx = await MiniMeToken.methods.createCloneToken( + 'Clone Token 1', + 18, + 'MMTc', + 0, + true).send({ from: accounts[0]}); + let addr = miniMeTokenCloneTx.events.NewCloneToken.raw.topics[1]; + addr = `0x${addr.slice(26)}`; + addr = web3.utils.toChecksumAddress(addr); + miniMeTokenClone = new web3.eth.Contract(MiniMeToken._jsonInterface, addr); + + b[3] = await web3.eth.getBlockNumber(); + + assert.equal(await miniMeTokenClone.methods.parentToken().call(), MiniMeToken.address); + assert.equal(await miniMeTokenClone.methods.parentSnapShotBlock().call(), b[3]); + assert.equal(await miniMeTokenClone.methods.totalSupply().call(), 7); + assert.equal(await MiniMeToken.methods.balanceOf(accounts[1]).call(), 6); + + assert.equal(await miniMeTokenClone.methods.totalSupplyAt(b[2]).call(), 7); + assert.equal(await miniMeTokenClone.methods.balanceOfAt(accounts[3], b[2]).call(), 1); + }); + + it('should move tokens in the clone token from 2 to 3', async () => { + + await miniMeTokenClone.methods.transfer(accounts[2], 4).send({ from: accounts[1], gas: 1000000 }); + b[4] = await web3.eth.getBlockNumber(); + + assert.equal(await MiniMeToken.methods.balanceOfAt(accounts[1], b[3]).call(), 6); + assert.equal(await MiniMeToken.methods.balanceOfAt(accounts[2], b[3]).call(), 0); + assert.equal(await miniMeTokenClone.methods.totalSupply().call(), 7); + assert.equal(await miniMeTokenClone.methods.balanceOf(accounts[1]).call(), 2); + assert.equal(await miniMeTokenClone.methods.balanceOf(accounts[2]).call(), 4); + assert.equal(await miniMeTokenClone.methods.balanceOfAt(accounts[1], b[3]).call(), 6); + assert.equal(await miniMeTokenClone.methods.balanceOfAt(accounts[2], b[3]).call(), 0); + assert.equal(await miniMeTokenClone.methods.balanceOfAt(accounts[1], b[2]).call(), 6); + assert.equal(await miniMeTokenClone.methods.balanceOfAt(accounts[2], b[2]).call(), 0); + assert.equal(await miniMeTokenClone.methods.totalSupplyAt(b[3]).call(), 7); + assert.equal(await miniMeTokenClone.methods.totalSupplyAt(b[2]).call(), 7); + }); + + it('should create tokens in the child token', async () => { + await miniMeTokenClone.methods.generateTokens(accounts[1], 10).send({ from: accounts[0], gas: 1000000}); + assert.equal(await miniMeTokenClone.methods.totalSupply().call(), 17); + assert.equal(await miniMeTokenClone.methods.balanceOf(accounts[1]).call(), 12); + assert.equal(await miniMeTokenClone.methods.balanceOf(accounts[2]).call(), 4); }); var erc20tokenConfig = { @@ -67,4 +127,9 @@ describe("MiniMeToken", async function() { Controlled.Test(erc20tokenConfig, async function (accounts, MiniMeToken) { }); + + + }); + +