improve tests
This commit is contained in:
parent
c76a499b31
commit
bea6deb15e
|
@ -4,7 +4,9 @@ const Controlled = require('./controlled');
|
||||||
|
|
||||||
describe("MiniMeToken", async function() {
|
describe("MiniMeToken", async function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
var accountsArr;
|
var accounts;
|
||||||
|
var miniMeTokenClone;
|
||||||
|
const b = [];
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
var contractsConfig = {
|
var contractsConfig = {
|
||||||
|
@ -22,24 +24,82 @@ describe("MiniMeToken", async function() {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
|
EmbarkSpec.deployAll(contractsConfig, async function(accountsArr) {
|
||||||
accountsArr = accounts
|
accounts = accountsArr
|
||||||
done()
|
done()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should increase totalSupply in generateTokens", async function() {
|
|
||||||
let initialSupply = await MiniMeToken.methods.totalSupply().call();
|
it('should generate tokens for address 1', async () => {
|
||||||
await MiniMeToken.methods.generateTokens(accountsArr[0], 100).send({from: accountsArr[0]});
|
await MiniMeToken.methods.generateTokens(accounts[1], 10).send();
|
||||||
let result = await MiniMeToken.methods.totalSupply().call();
|
assert.equal(await MiniMeToken.methods.totalSupply().call(), 10);
|
||||||
assert.equal(result, +initialSupply+100);
|
assert.equal(await MiniMeToken.methods.balanceOf(accounts[1]).call(), 10);
|
||||||
|
b[0] = await web3.eth.getBlockNumber();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should increase accountBalance in generateTokens", async function() {
|
it('should transfer tokens from address 1 to address 3', async () => {
|
||||||
let initialBalance = await MiniMeToken.methods.balanceOf(accountsArr[1]).call();
|
await MiniMeToken.methods.transfer(accounts[3], 1).send({from: accounts[1]});
|
||||||
await MiniMeToken.methods.generateTokens(accountsArr[1], 100).send({from: accountsArr[0]});
|
assert.equal(await MiniMeToken.methods.totalSupply().call(), 10);
|
||||||
let result = await MiniMeToken.methods.balanceOf(accountsArr[1]).call();
|
assert.equal(await MiniMeToken.methods.balanceOf(accounts[1]).call(), 9);
|
||||||
assert.equal(result, +initialBalance+100);
|
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 = {
|
var erc20tokenConfig = {
|
||||||
|
@ -67,4 +127,9 @@ describe("MiniMeToken", async function() {
|
||||||
Controlled.Test(erc20tokenConfig, async function (accounts, MiniMeToken) {
|
Controlled.Test(erc20tokenConfig, async function (accounts, MiniMeToken) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue