test script for testtoken and erc20token

This commit is contained in:
Ricardo Guilherme Schmidt 2018-05-12 21:16:18 -03:00
parent a597410b66
commit 0a1cbb5fff
7 changed files with 119 additions and 16 deletions

View File

@ -9,12 +9,12 @@
"maxpeers": 0,
"rpcHost": "localhost",
"rpcPort": 8545,
"rpcCorsDomain": "http://localhost:8000",
"rpcCorsDomain": "auto",
"account": {
"password": "config/development/password"
},
"targetGasLimit": 8000000,
"wsOrigins": "http://localhost:8000",
"wsOrigins": "auto",
"wsRPC": true,
"wsHost": "localhost",
"wsPort": 8546,

View File

@ -1,6 +1,8 @@
{
"config": {
"homesteadBlock": 1
"homesteadBlock": 1,
"byzantiumBlock": 1,
"daoForkSupport": true
},
"nonce": "0x0000000000000042",
"difficulty": "0x0",

View File

@ -66,7 +66,7 @@ contract StandardToken is ERC20Token {
function totalSupply()
external
view
returns(uint256 supply)
returns(uint256 totalSupply)
{
return supply;
}

View File

@ -1,10 +1,17 @@
{
"contracts": ["contracts/**"],
"app": {
"js/dapp.js": ["app/dapp.js"],
"index.html": "app/index.html",
"images/": ["app/images/**"]
},
"buildDir": "dist/",
"config": "config/",
"plugins": {
},
"versions": {
"solc": "0.4.23"
"web3": "1.0.0-beta",
"solc": "0.4.23",
"ipfs-api": "17.2.4"
},
"plugins": {
}
}

View File

@ -1,6 +1,7 @@
{
"name": "status-contracts",
"version": "1.0.0",
"version": "0.0.1",
"description": "",
"scripts": {
"solidity-coverage": "./node_modules/.bin/solidity-coverage",
"test": "embark test"
@ -15,13 +16,6 @@
"url": "https://github.com/status-im/contracts/issues"
},
"homepage": "https://github.com/status-im/contracts#readme",
"devDependencies": {
"solidity-coverage": "^0.5.0",
"elliptic": "^6.4.0"
},
"dependencies": {
"embark": "^2.7.0",
"elliptic-curve": "^0.1.0",
"ethereumjs-util": "^5.1.5"
"dependencies": {
}
}

66
test/erc20token.js Normal file
View File

@ -0,0 +1,66 @@
describe("ERC20Token", async function() {
this.timeout(0);
var ERC20Token;
var accountsArr;
before(function(done) {
this.timeout(0);
var contractsConfig = {
"TestToken": {
}
};
EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
ERC20Token = TestToken;
accountsArr = accounts;
for(i=0;i<accountsArr.length;i++){
await ERC20Token.methods.mint(100).send({from: accountsArr[i]})
}
done()
});
});
it("should transfer 1 token", async function() {
let initialBalance0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
let initialBalance1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
await ERC20Token.methods.transfer(accountsArr[1],1).send({from: accountsArr[0]});
let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
assert.equal(result0, +initialBalance0-1);
assert.equal(result1, +initialBalance1+1);
});
it("should set approved amount", async function() {
await ERC20Token.methods.approve(accountsArr[2],10000000).send({from: accountsArr[0]});
let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
assert.equal(result, 10000000);
});
it("should consume allowance amount", async function() {
let initialAllowance = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
await ERC20Token.methods.transferFrom(accountsArr[0], accountsArr[0],1).send({from: accountsArr[2]});
let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
assert.equal(result, +initialAllowance-1);
});
it("should transfer approved amount", async function() {
let initialBalance0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
let initialBalance1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
await ERC20Token.methods.transferFrom(accountsArr[0], accountsArr[1],1).send({from: accountsArr[2]});
let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
assert.equal(result0, +initialBalance0-1);
assert.equal(result1, +initialBalance1+1);
});
it("should unset approved amount", async function() {
await ERC20Token.methods.approve(accountsArr[2],0).send({from: accountsArr[0]});
let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
assert.equal(result, 0);
});
//TODO: include checks for expected events fired
});

34
test/testtoken.js Normal file
View File

@ -0,0 +1,34 @@
describe("TestToken", function() {
this.timeout(0);
var accountsArr;
before(function(done) {
this.timeout(0);
var contractsConfig = {
"TestToken": {
}
};
EmbarkSpec.deployAll(contractsConfig, (accounts) => { accountsArr = accounts; done() });
});
it("should start totalSupply 0", async function() {
let result = await TestToken.methods.totalSupply().call();
assert.equal(result, 0);
});
it("should increase totalSupply in mint", async function() {
let initialSupply = await TestToken.methods.balanceOf(accountsArr[0]).call();
await TestToken.methods.mint(100).send({from: accountsArr[0]});
let result = await TestToken.methods.totalSupply().call();
assert.equal(result, 100);
});
it("should increase accountBalance in mint", async function() {
let initialBalance = await TestToken.methods.balanceOf(accountsArr[0]).call();
await TestToken.methods.mint(100).send({from: accountsArr[0]});
let result = await TestToken.methods.totalSupply().call();
assert.equal(result, +initialBalance+100);
});
});