improve abstract erc20token test

This commit is contained in:
Ricardo Guilherme Schmidt 2018-05-19 22:37:58 -03:00
parent e63ae2af6e
commit 1582881629
2 changed files with 9 additions and 13 deletions

View File

@ -1,18 +1,15 @@
exports.Test = (tokenContract, afterDeploy) => { exports.Test = (contractsConfig, afterDeploy) => {
describe("ERC20Token", async function() { describe("ERC20Token", async function() {
this.timeout(0); this.timeout(0);
var ERC20Token; var ERC20Token;
var accountsArr; var accountsArr;
before(function(done) { before(function(done) {
var contractsConfig = { contractsConfig["ERC20Receiver"] = {};
"Token": tokenContract,
"ERC20Receiver": { }
};
EmbarkSpec.deployAll(contractsConfig, async function(accounts) { EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
ERC20Token = Token; ERC20Token = Token;
accountsArr = accounts; accountsArr = accounts;
afterDeploy(accounts, Token); await afterDeploy(accounts, Token);
done() done()
}); });
}); });
@ -24,8 +21,8 @@ exports.Test = (tokenContract, afterDeploy) => {
let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call(); let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call(); let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
assert.equal(result0, +initialBalance0-1); assert.equal(result0, +initialBalance0-1, "account 0 balance unexpected");
assert.equal(result1, +initialBalance1+1); assert.equal(result1, +initialBalance1+1, "account 1 balance unexpected");
}); });
it("should set approved amount", async function() { it("should set approved amount", async function() {

View File

@ -11,9 +11,6 @@ describe("TestToken", async function() {
}; };
EmbarkSpec.deployAll(contractsConfig, async function(accounts) { EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
accountsArr = accounts accountsArr = accounts
for(i=0;i<accountsArr.length;i++) {
await TestToken.methods.mint(7 * 10 ^ 18).send({from: accountsArr[i]})
}
done() done()
}); });
}); });
@ -31,8 +28,10 @@ describe("TestToken", async function() {
let result = await TestToken.methods.balanceOf(accountsArr[0]).call(); let result = await TestToken.methods.balanceOf(accountsArr[0]).call();
assert.equal(result, +initialBalance+100); assert.equal(result, +initialBalance+100);
}); });
var erc20tokenConfig = {
ERC20Token.Test({ "instanceOf" : "TestToken" }, async function (accounts, TestToken) { "Token": { "instanceOf" : "TestToken" }
}
ERC20Token.Test(erc20tokenConfig, async function (accounts, TestToken) {
for(i=0;i<accounts.length;i++){ for(i=0;i<accounts.length;i++){
await TestToken.methods.mint(7 * 10 ^ 18).send({from: accounts[i]}) await TestToken.methods.mint(7 * 10 ^ 18).send({from: accounts[i]})
} }