web3 for dutch

This commit is contained in:
dennis00010011b 2018-06-01 18:27:35 -07:00
parent eac30ae7ba
commit d2cb8c26ef
23 changed files with 315 additions and 268 deletions

View File

@ -1,20 +0,0 @@
const Web3 = require('web3');
module.exports = deployContract
function deployContract(web3, abi, bin, from, gas = 1500000, gasPrice = '5000000000') {
const Contract = new web3.eth.Contract(abi, { from });
return Contract
.deploy( {
data: bin
})
.send({
from,
gas,
gasPrice
})
}

View File

@ -1,48 +0,0 @@
const Logger= require('../entity/Logger.js');
const logger=Logger.logger;
const Web3 = require('web3');
const fs = require('fs');
const deployContract = require('./DeployContract.js');
deployRegistry();
async function deployRegistry() {
//logger.info("Deploy Registry for address "+ address);
const web3 = await new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
const registryPath = './contracts/Registry_flat';
const registryAbi = await JSON.parse(fs.readFileSync(`${registryPath}.abi`).toString());
let registryBin = await fs.readFileSync(`${registryPath}.bin`).toString();
if (registryBin.slice(0, 2) !== '0x' && registryBin.slice(0, 2) !== '0X') {
registryBin = '0x' + registryBin;
}
var contract=await web3.eth.getAccounts()
.then((accounts) => {
return deployContract(web3, registryAbi, registryBin,accounts[0])
});
var networkID=await web3.eth.net.getId();
var registryAddress=contract._address;
if (await !fs.existsSync("./.env")) await fs.writeFileSync("./.env");
let envContent = `REACT_APP_REGISTRY_ADDRESS='{"${networkID}":"${registryAddress}"}'`;
await fs.writeFileSync("./.env", envContent);
logger.info("Registry deployed");
logger.info("Ganache Chain ID: "+networkID);
logger.info("Contract address: "+registryAddress);
logger.info("Data saved to file ./token-wizard-test-automation/.env");
}
module.exports = deployRegistry;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[{"constant":true,"inputs":[{"name":"deployer","type":"address"}],"name":"count","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"deployAddress","type":"address"}],"name":"add","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"deployedContracts","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":true,"name":"deployAddress","type":"address"}],"name":"Added","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]

View File

@ -1 +0,0 @@
60606040525b60008054600160a060020a03191633600160a060020a03161790555b5b61035e806100316000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166305d85eda81146100665780630a3b0a4f1461009457806345967555146100b25780638da5cb5b146100ed578063f2fde38b14610119575bfe5b341561006e57fe5b610082600160a060020a0360043516610137565b60408051918252519081900360200190f35b341561009c57fe5b6100b0600160a060020a0360043516610156565b005b34156100ba57fe5b6100d1600160a060020a03600435166024356101fe565b60408051600160a060020a039092168252519081900360200190f35b34156100f557fe5b6100d1610240565b60408051600160a060020a039092168252519081900360200190f35b341561012157fe5b6100b0600160a060020a036004351661024f565b005b600160a060020a0381166000908152600160205260409020545b919050565b600160a060020a033316600090815260016020819052604090912080549091810161018183826102e7565b916000526020600020900160005b83909190916101000a815481600160a060020a030219169083600160a060020a031602179055505080600160a060020a031633600160a060020a03167f938c63ac3d228b23f6bee7618fefc6790522e338ac202c958a2ea9eb9706c5d160405180905060405180910390a35b50565b60016020528160005260406000208181548110151561021957fe5b906000526020600020900160005b915091509054906101000a9004600160a060020a031681565b600054600160a060020a031681565b60005433600160a060020a0390811691161461026b5760006000fd5b600160a060020a03811615156102815760006000fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b5b50565b81548183558181151161030b5760008381526020902061030b918101908301610311565b5b505050565b61032f91905b8082111561032b5760008155600101610317565b5090565b905600a165627a7a72305820ac72cdc4f8c1fcae46741c7157b740ec9c476270ed104e1f689e90b2b4c180fd0029

View File

@ -1,66 +0,0 @@
// Created using Token Wizard https://github.com/poanetwork/token-wizard by POA Network
pragma solidity ^0.4.11;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* Registry of contracts deployed from Token Wizard.
*/
contract Registry is Ownable {
mapping (address => address[]) public deployedContracts;
event Added(address indexed sender, address indexed deployAddress);
function add(address deployAddress) public {
deployedContracts[msg.sender].push(deployAddress);
Added(msg.sender, deployAddress);
}
function count(address deployer) constant returns (uint) {
return deployedContracts[deployer].length;
}
}

View File

@ -19,6 +19,8 @@ class Crowdsale {
this.url;
this.tokenContractAbi;
this.executionID;
this.networkID;
this.sort;
}
async parser(fileName) {

View File

@ -8,12 +8,11 @@ const WizardStep4 = require('../pages/WizardStep4.js').WizardStep4;
const TierPage = require('../pages/TierPage.js').TierPage;
const ReservedTokensPage = require('../pages/ReservedTokensPage.js').ReservedTokensPage;
const CrowdsalePage = require('../pages/CrowdsalePage.js').CrowdsalePage;
const InvestPage = require('../pages/InvestPage.js').InvestPage;
const InvestPage = require('../pages/ContributionPage.js').InvestPage;
const ManagePage = require('../pages/ManagePage.js').ManagePage;
const Utils = require('../utils/Utils.js').Utils;
const Crowdsale = require('../entity/Crowdsale.js').Crowdsale;
const Page = require('../pages/Page.js').Page;
const fs = require('fs');
class User {
@ -38,13 +37,18 @@ class User {
}
async getTokenBalance(crowdsale) {
logger.info("GetTokenBalance: account=" + this.account);
logger.info("Token address=" + crowdsale.tokenAddress);
logger.info("getTokenBalance");
try {
let web3 = Utils.setNetwork(this.networkID);
let tokenContract = crowdsale.tokenContractAbi;
let MyContract = new web3.eth.Contract(tokenContract, crowdsale.tokenAddress);
return await MyContract.methods.balanceOf(this.account).call();
const web3 = await Utils.getWeb3Instance(crowdsale.networkID);
let contractAddress = await Utils.getContractAddressInitCrowdsale(crowdsale);
logger.info("contractAddress"+ contractAddress);
let addressRegistryStorage = await Utils.getEnvAddressRegistryStorage();
logger.info("addressRegistryStorage"+ addressRegistryStorage);
let abi = await Utils.getContractABIInitCrowdsale(crowdsale);
let myContract = new web3.eth.Contract(abi, contractAddress);
let balance = await myContract.methods.balanceOf(addressRegistryStorage, crowdsale.executionID, this.account).call();
logger.info("Balance = " + balance );
return balance;
}
catch (err) {
logger.info("Can not get balance. " + err);
@ -260,7 +264,7 @@ class User {
const investPage = new InvestPage(this.driver);
return !await investPage.waitUntilShowUpWarning(15)
&& await investPage.waitUntilLoaderGone()
&& await investPage.fillInvest(amount)
&& await investPage.fillContribute(amount)
&& await investPage.clickButtonContribute()
&& !await investPage.waitUntilShowUpErrorNotice(10)//3 sec
&& !await investPage.waitUntilShowUpWarning(10)//3 sec
@ -298,6 +302,7 @@ class User {
async createMintedCappedCrowdsale(crowdsale) {
logger.info(" createMintedCappedCrowdsale ");
const startURL = Utils.getStartURL();
const welcomePage = new WizardWelcome(this.driver, startURL);
const wizardStep1 = new WizardStep1(this.driver);
@ -366,13 +371,14 @@ class User {
crowdsale.executionID = await investPage.getExecutionID();
logger.info("Final invest page link: " + crowdsale.url);
logger.info("token address: " + crowdsale.executionID);
crowdsale.networkID = this.networkID;
return result && crowdsale.executionID !== "";
}
async createDutchAuctionCrowdsale(crowdsale) {
logger.info(" createDutchAuctionCrowdsale ");
const startURL = Utils.getStartURL();
const welcomePage = new WizardWelcome(this.driver, startURL);
const wizardStep1 = new WizardStep1(this.driver);
@ -443,6 +449,8 @@ class User {
crowdsale.executionID = await investPage.getExecutionID();
logger.info("Final invest page link: " + crowdsale.url);
logger.info("token address: " + crowdsale.executionID);
crowdsale.networkID = this.networkID;
logger.info("crowdsale.networkID " + crowdsale.networkID);
return result && crowdsale.executionID !== "";
}

View File

@ -63,7 +63,7 @@ async function srun(){
var abi=[{"constant":true,"inputs":[],"name":"isPricingStrategy","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"tier","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"value","type":"uint256"},{"name":"weiRaised","type":"uint256"},{"name":"tokensSold","type":"uint256"},{"name":"msgSender","type":"address"},{"name":"decimals","type":"uint256"}],"name":"calculatePrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_tier","type":"address"}],"name":"setTier","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOneTokenInWei","type":"uint256"}],"name":"updateRate","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"oneTokenInWei","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"crowdsale","type":"address"}],"name":"isSane","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"purchaser","type":"address"}],"name":"isPresalePurchase","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"_oneTokenInWei","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newOneTokenInWei","type":"uint256"}],"name":"RateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]
var web3 = Utils.setNetwork(this.networkID);
var web3 = Utils.getWeb3Instance(this.networkID);
var tokenContract=abi;
var MyContract = new web3.eth.Contract(tokenContract, tokenAddress);

5
package-lock.json generated
View File

@ -1393,6 +1393,11 @@
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz",
"integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg="
},
"dotenv": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz",
"integrity": "sha512-4As8uPrjfwb7VXC+WnLCbXK7y+Ueb2B3zgNCePYfhxS1PYeaO1YTeplffTEcbfLhvFNGLAz90VvJs9yomG7bow=="
},
"drbg.js": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz",

View File

@ -7,12 +7,13 @@
"e2e-deployRegistry": "node ./contracts/DeployRegistry.js",
"e2eMinted": "mocha -b ./test/e2eMinted.js",
"e2eDutch": "mocha -b ./test/e2eDutch.js",
"ra": "node ./test/testRA.js",
"margo": "node ./test/margo.js",
"e2eMintedRopsten": "mocha ./test/e2eMintedRopsten.js",
"e2eDutchRopsten": "mocha ./test/e2eDutchRopsten.js"
},
"dependencies": {
"chromedriver": "^2.35.0",
"dotenv": "^5.0.1",
"ethereumjs-wallet": "^0.6.0",
"fs-extra": "^5.0.0",
"mocha": "^5.0.1",

View File

@ -2,7 +2,7 @@ const logger = require('../entity/Logger.js').logger;
const Page = require('./Page.js').Page;
const By = require('selenium-webdriver/lib/by').By;
const buttonContribute = By.className("button button_fill");
const fieldInvest = By.className("invest-form-input");
const fieldContribute = By.id("contribute");
const buttonOk = By.className( "swal2-confirm swal2-styled");
const fieldBalance = By.className("balance-title");
const fields = By.className("hashes-title");
@ -13,7 +13,7 @@ const countdownTimerValue = By.className("timer-count");
const countdownTimerStatus = By.className("timer-interval");
const statusTimer = {start : "START", end : "END", finalized : "HAS BEEN"}
class InvestPage extends Page {
class ContributionPage extends Page {
constructor(driver) {
super(driver);
@ -45,7 +45,7 @@ class InvestPage extends Page {
}
async initTimerFields() {
logger.info(this.name + "initTimer ");
logger.info(this.name + "initTimerFields ");
try {
let array = await super.findWithWait(countdownTimerStatus);
this.timer = array[0];
@ -118,28 +118,28 @@ class InvestPage extends Page {
return await super.clickWithWait(buttonOk);
}
async fillInvest(amount) {
logger.info(this.name + "field Contribute :");
return await super.fillWithWait(fieldInvest, amount);
async fillContribute(amount) {
logger.info(this.name + "fillContribute");
return await super.fillWithWait(fieldContribute, amount);
}
async clickButtonContribute() {
logger.info(this.name + "button Contribute :");
logger.info(this.name + "clickButtonContribute");
return await super.clickWithWait(buttonContribute);
}
async getWarningText() {
logger.info(this.name + "Warning text :");
logger.info(this.name + "getWarningText");
return await super.getTextForElement(warningText);
}
async getErrorText() {
logger.info(this.name + "Error text :");
logger.info(this.name + "getErrorText");
return await super.getTextForElement(errorNotice);
}
async getExecutionID() {
logger.info(this.name + "field TokenAddress :");
logger.info(this.name + "getExecutionID");
return (await this.initFields() !== null) &&
await super.getTextForElement(this.fieldExecutionID);
}
@ -161,5 +161,5 @@ class InvestPage extends Page {
}
}
module.exports.InvestPage = InvestPage;
module.exports.InvestPage = ContributionPage;

View File

@ -93,7 +93,7 @@ class Page {
}
catch (err) {
logger.info("Error: " + err);
return false;
return null;
}
}
@ -190,6 +190,7 @@ class Page {
logger.info("click with wait: " + element);
try {
let field = await this.getElement(element, Twaiting);
await field.click();
return true;
}
@ -203,6 +204,7 @@ class Page {
logger.info("fill with wait : value = " + k);
try {
let field = await this.getElement(element, Twaiting);
if (field === null) return false;
await field.sendKeys(k);
return true;
}

View File

@ -99,7 +99,7 @@ class TierPage extends Page {
}
async fillMaxRate() {
logger.info(this.name + "fillMinRate ");
logger.info(this.name + "fillMaxRate ");
if (this.tier.maxRate === undefined) return true;
return await super.clearField(fieldMaxRate) &&
await super.fillWithWait(fieldMaxRate, this.tier.maxRate);

View File

@ -11,7 +11,7 @@
"tiers":[
{
"allowModify": true,
"isWhitelisted":false,
"isWhitelisted":true,
"startDate": "",
"startTime": "",
"endDate":"360000",
@ -27,8 +27,8 @@
},
{
"address": "0x9E963042D581D262AdE4E31541360e7FDAeE70C6",
"min": 50,
"max": 150
"min": 0,
"max": 1000
}
]
}]

View File

@ -6,12 +6,12 @@
"reservedTokens":[
{
"address" :"0xecDFec71AbCD5a612eAf9169B19E907eAA2717d9",
"dimension": "tokens",
"dimension": "percentage",
"value": 1000
},
{
"address" :"0x56B2e3C3cFf7f3921Dc2e0F8B8e20d1eEc29216b",
"dimension": "percentage",
"dimension": "tokens",
"value": 250
}
],

View File

@ -11,7 +11,7 @@ const WizardStep4 = require('../pages/WizardStep4.js').WizardStep4;
const TierPage = require('../pages/TierPage.js').TierPage;
const ReservedTokensPage = require('../pages/ReservedTokensPage.js').ReservedTokensPage;
const CrowdsalePage = require('../pages/CrowdsalePage.js').CrowdsalePage;
const InvestPage = require('../pages/InvestPage.js').InvestPage;
const InvestPage = require('../pages/ContributionPage.js').InvestPage;
const ManagePage = require('../pages/ManagePage.js').ManagePage;
const logger = require('../entity/Logger.js').logger;
const tempOutputPath = require('../entity/Logger.js').tempOutputPath;
@ -57,7 +57,8 @@ test.describe('POA token-wizard. Test DutchAuctionCrowdsale', async function ()
/////////////////////////////////////////////////////////////////////////
test.before(async function () {
logger.info("Version 2.5.0 - Wizard2.0 - DutchAuction");
logger.info("Version 2.6.1 - Wizard2.0 - DutchAuction");
await Utils.copyEnvFromWizard();
e2eMinCap = await Utils.getDutchCrowdsaleInstance(scenarioE2eMinCap);
e2eWhitelist = await Utils.getDutchCrowdsaleInstance(scenarioE2eWhitelist);
crowdsaleForUItests = await Utils.getDutchCrowdsaleInstance(scenarioForUItests);
@ -169,7 +170,13 @@ test.describe('POA token-wizard. Test DutchAuctionCrowdsale', async function ()
assert.equal(await owner.setMetaMaskAccount(), true, "Can not set Metamask account");
return assert.equal(await wizardStep2.isDisplayedFieldSupply(), true, "Persistant failed if account has changed");
});
test.it.skip('Wizard step#2:Check persistant if page refreshed ',
async function () {
let investor = Investor1;
let owner = Owner;
return assert.equal(false, true, "Persistant failed if account has changed");
});
test.it('Wizard step#2: user able to fill out Name field with valid data',
async function () {
await wizardStep2.fillName("name");
@ -511,6 +518,7 @@ test.describe('POA token-wizard. Test DutchAuctionCrowdsale', async function ()
assert.equal(await investor.openInvestPage(e2eWhitelist), true, 'Investor can not open Invest page');
assert.equal(await investPage.waitUntilLoaderGone(), true, 'Loader displayed too long time');
let contribution = e2eWhitelist.tiers[0].supply;
investor.tokenBalance = Investor1.maxCap;
let result = await investor.contribute(contribution);
return await assert.equal(result, true, "Test FAILED.Investor can buy more than assigned max");
});
@ -522,7 +530,7 @@ test.describe('POA token-wizard. Test DutchAuctionCrowdsale', async function ()
assert.equal(await investPage.waitUntilLoaderGone(), true, 'Loader displayed too long time');
let newBalance = await investor.getBalanceFromInvestPage(e2eWhitelist);
investor.tokenBalance = e2eWhitelist.tiers[0].whitelist[0].max;
let result = (Math.abs(parseFloat(newBalance) - parseFloat(investor.tokenBalance)) < 300);
let result = (Math.abs(parseFloat(newBalance) - parseFloat(investor.tokenBalance)) < 500);
return await assert.equal(result, true, "Test FAILED.Investor can buy more than assigned max");
});
@ -586,36 +594,47 @@ test.describe('POA token-wizard. Test DutchAuctionCrowdsale', async function ()
return await assert.equal(result, true, "Test FAILED.'Owner can NOT finalize ");
});
test.it.skip('Investor#1 has received correct quantity of tokens after finalization',
test.it('Investor#1 has received correct quantity of tokens after finalization',
async function () {
let investor = Investor1;
let newBalance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let balance = e2eWhitelist.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
await investor.openInvestPage(e2eWhitelist);
assert.equal(await investor.setMetaMaskAccount(), true, "Can not set Metamask account");
let shouldBe = parseFloat(await investor.getBalanceFromInvestPage(e2eWhitelist));
let balance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
let result = (Math.abs(shouldBe - balance) < 1e-6);
return await assert.equal(result, true, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
test.it.skip('Investor#2 has received correct quantity of tokens after finalization',
test.it('Investor#2 has received correct quantity of tokens after finalization',
async function () {
let investor = Investor2;
let newBalance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let balance = e2eWhitelist.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
assert.equal(await investor.setMetaMaskAccount(), true, "Can not set Metamask account");
await investor.openInvestPage(e2eWhitelist);
let shouldBe = parseFloat(await investor.getBalanceFromInvestPage(e2eWhitelist));
let balance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
let result = (Math.abs(shouldBe - balance) < 1e-6);
return await assert.equal(result, true, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
test.it.skip('Owner has received correct quantity of tokens after finalization',
test.it('Owner has received correct quantity of tokens after finalization',
async function () {
let investor = Investor1;
let newBalance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let balance = e2eWhitelist.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
let investor = Owner;
let balance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let shouldBe = e2eWhitelist.totalSupply - e2eWhitelist.tiers[0].supply;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
let result = (Math.abs(shouldBe - balance) < 1e-6);
return await assert.equal(result, true, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
//////////////////////// Test SUITE #2 /////////////////////////////
test.it('Owner can create DutchAuction crowdsale(scenario scenarioE2eDutchMincapLong.json), minCap,no whitelist',
async function () {
@ -748,23 +767,28 @@ test.describe('POA token-wizard. Test DutchAuctionCrowdsale', async function ()
async function () {
let investor = Investor1;
let newBalance = await investor.getTokenBalance(e2eMinCap) / 1e18;
let balance = e2eMinCap.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
assert.equal(await investor.setMetaMaskAccount(), true, "Can not set Metamask account");
await investor.openInvestPage(e2eWhitelist);
let shouldBe = parseFloat(await investor.getBalanceFromInvestPage(e2eMinCap));
let balance = await investor.getTokenBalance(e2eMinCap) / 1e18;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
let result = (Math.abs(shouldBe - balance) < 1e-6);
return await assert.equal(result, true, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
test.it.skip('Owner has received correct quantity of tokens after finalization',
async function () {
let investor = Investor1;
let newBalance = await investor.getTokenBalance(e2eMinCap) / 1e18;
let balance = e2eMinCap.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
let investor = Owner;
let balance = await investor.getTokenBalance(e2eMinCap) / 1e18;
let shouldBe = e2eMinCap.totalSupply - e2eMinCap.tiers[0].supply;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
let result = (Math.abs(shouldBe - balance) < 1e-6);
return await assert.equal(result, true, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
});

View File

@ -10,7 +10,7 @@ const WizardStep4 = require('../pages/WizardStep4.js').WizardStep4;
const TierPage = require('../pages/TierPage.js').TierPage;
const ReservedTokensPage = require('../pages/ReservedTokensPage.js').ReservedTokensPage;
const CrowdsalePage = require('../pages/CrowdsalePage.js').CrowdsalePage;
const InvestPage = require('../pages/InvestPage.js').InvestPage;
const InvestPage = require('../pages/ContributionPage.js').InvestPage;
const ManagePage = require('../pages/ManagePage.js').ManagePage;
const logger = require('../entity/Logger.js').logger;
const tempOutputPath = require('../entity/Logger.js').tempOutputPath;

View File

@ -10,7 +10,7 @@ const WizardStep4 = require('../pages/WizardStep4.js').WizardStep4;
const TierPage = require('../pages/TierPage.js').TierPage;
const ReservedTokensPage = require('../pages/ReservedTokensPage.js').ReservedTokensPage;
const CrowdsalePage = require('../pages/CrowdsalePage.js').CrowdsalePage;
const InvestPage = require('../pages/InvestPage.js').InvestPage;
const InvestPage = require('../pages/ContributionPage.js').InvestPage;
const ManagePage = require('../pages/ManagePage.js').ManagePage;
const logger = require('../entity/Logger.js').logger;
const tempOutputPath = require('../entity/Logger.js').tempOutputPath;
@ -65,17 +65,15 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
/////////////////////////////////////////////////////////////////////////
test.before(async function () {
logger.info("Version 2.6.0 - Wizard2.0 ");
logger.info("Version 2.6.1 - Wizard2.0 ");
await Utils.copyEnvFromWizard();
const scenarioE2eMintedMinCap = './scenarios/scenarioE2eMintedMinCap.json';
const scenarioE2eMintedWhitelist = './scenarios/scenarioE2eMintedWhitelist.json';
const scenarioForUItests = './scenarios/scenarioUItests.json';
//const scenarioE2eMintedMultitier = './scenarios/scenarioE2eMintedMultitier.json'
crowdsaleForUItests = await Utils.getCrowdsaleInstance(scenarioForUItests);
e2eMinCap = await Utils.getCrowdsaleInstance(scenarioE2eMintedMinCap);
e2eWhitelist = await Utils.getCrowdsaleInstance(scenarioE2eMintedWhitelist);
//e2eMultitier = await Utils.getCrowdsaleInstance(scenarioE2eMintedMultitier);
crowdsaleForUItests = await Utils.getMintedCrowdsaleInstance(scenarioForUItests);
e2eMinCap = await Utils.getMintedCrowdsaleInstance(scenarioE2eMintedMinCap);
e2eWhitelist = await Utils.getMintedCrowdsaleInstance(scenarioE2eMintedWhitelist);
startURL = await Utils.getStartURL();
driver = await Utils.startBrowserWithMetamask();
@ -478,6 +476,9 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
let owner = Owner;
assert.equal(await owner.setMetaMaskAccount(), true, "Can not set Metamask account");
let result = await owner.createMintedCappedCrowdsale(e2eWhitelist);
logger.info("e2eWhitelist.executionID " + e2eWhitelist.executionID);
logger.info("e2eWhitelist.networkID " + e2eWhitelist.networkID);
logger.info("e2eWhitelist.sort " + e2eWhitelist.sort);
balanceEthOwnerBefore = await Utils.getBalance(Owner);
Owner.tokenBalance = 0;
Investor1.tokenBalance = 0;
@ -580,11 +581,11 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
return await assert.equal(result, true, 'Test FAILED. End time doest match the given value');
});
test.it.skip('Manage page: end time of tier#2 changed accordingly after modifying ',
test.it.skip('Manage page: end time of tier#2 properly changed after modifying ',
async function () {
let owner = Owner;
await owner.openManagePage(e2eWhitelist);
let tierNumber = 1;
let tierNumber = 2;
let newTime = await owner.getEndTime(tierNumber);
let result = await Utils.compareDates(newTime, endDate, endTime);
return await assert.equal(result, true, 'Test FAILED. End time doest match the given value');
@ -645,7 +646,7 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
});
test.it('Whitelisted investor is NOT able to buy less than min in first transaction',
test.it('Whitelisted investor is not able to buy less than min in first transaction',
async function () {
let investor = Investor1;
assert.equal(await investor.setMetaMaskAccount(), true, "Can not set Metamask account");
@ -868,24 +869,57 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
return await assert.equal(await investor.contribute(contribution), false, 'Whitelisted investor is able to buy if crowdsale finalized');
});
test.it.skip('Reserved address has received correct quantity of tokens after distribution',
test.it.skip('Reserved address#1 has received correct percent of tokens after finalization',
async function () {
let newBalance = await ReservedAddress.getTokenBalance(e2eWhitelist) / 1e18;
let balance = e2eWhitelist.reservedTokens[0].value;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance);
let balance = await ReservedAddress.getTokenBalance(e2eWhitelist) / 1e18;
const totalSupply = e2eWhitelist.tiers[0].supply + e2eWhitelist.tiers[1].supply;
let shouldBe = e2eWhitelist.reservedTokens[0].value * totalSupply / 100
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe);
});
test.it.skip('Investor has received correct quantity of tokens after finalization',
test.it.skip('Reserved address#2 has received correct quantity of tokens after finalization',
async function () {
let balance = await Owner.getTokenBalance(e2eWhitelist) / 1e18;
let shouldBe = e2eWhitelist.reservedTokens[1].value;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe);
});
test.it.skip('Investor#1 has received correct quantity of tokens after finalization',
async function () {
let investor = Investor1;
let newBalance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let balance = e2eWhitelist.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
let balance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let shouldBe = investor.maxCap;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
test.it.skip('Investor#2 has received correct quantity of tokens after finalization',
async function () {
let investor = Investor2;
let balance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let shouldBe = e2eWhitelist.tiers[0].supply - Investor1.maxCap;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
test.it.skip('Investor#3 has received correct quantity of tokens after finalization',
async function () {
let investor = Investor3;
let balance = await investor.getTokenBalance(e2eWhitelist) / 1e18;
let shouldBe = e2eWhitelist.tiers[1].supply;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
throw("stop!!!");
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
//////////////////////// Test SUITE #2 /////////////////////////////
@ -963,7 +997,7 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
balanceEthOwnerBefore = await Utils.getBalance(Owner);
let investor = Investor1;
let contribution = e2eMinCap.minCap;
balance = contribution;
investor.tokenBalance += contribution
let result = await investor.openInvestPage(e2eMinCap)
&& await investor.contribute(contribution);
return await assert.equal(result, true, 'Test FAILED. Investor can not buy amount = min');
@ -977,12 +1011,12 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
return await assert.equal(result, true, "Owner's balance incorrect");
});
test.it('Invest page: Investors balance is changed accordingly after purchase ',
test.it('Invest page: Investors balance is properly changed after purchase ',
async function () {
let investor = Investor1;
await investor.openInvestPage(e2eMinCap);
let newBalance = await investor.getBalanceFromInvestPage(e2eMinCap);
let result = (newBalance.toString() === balance.toString());
let result = (newBalance.toString() === investor.tokenBalance.toString());
return await assert.equal(result, true, "Test FAILED. Investor can buy but balance did not changed");
});
@ -992,10 +1026,8 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
let investor = Investor1;
await investor.openInvestPage(e2eMinCap);
let contribution = smallAmount + 10;
balance = balance + contribution;
await investor.contribute(contribution);
let newBalance = await investor.getBalanceFromInvestPage(e2eMinCap);
let result = (newBalance.toString() === balance.toString());
investor.tokenBalance += contribution;
let result = await investor.contribute(contribution);
return await assert.equal(result, true, "Test FAILED. Investor can not buy less than mincap after first transaction");
});
@ -1054,25 +1086,32 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
return await assert.equal(result, false, "Test FAILED. Investor can buy if crowdsale is finalized");
});
test.it.skip('Reserved address has received correct quantity of tokens after distribution',
test.it('Reserved address#1 has received correct percent of tokens after finalization',
async function () {
let newBalance = await ReservedAddress.getTokenBalance(e2eMinCap) / 1e18;
let balance = e2eMinCap.reservedTokens[0].value;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance);
let balance = await ReservedAddress.getTokenBalance(e2eMinCap) / 1e18;
let shouldBe = e2eMinCap.reservedTokens[0].value * Investor1.tokenBalance / 100;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe);
});
test.it.skip('Investor has received correct quantity of tokens after finalization', async function () {
test.it('Reserved address#2 has received correct quantity of tokens after finalization',
async function () {
let balance = await Owner.getTokenBalance(e2eMinCap) / 1e18;
let shouldBe = e2eMinCap.reservedTokens[1].value;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
return await assert.equal(shouldBe, balance, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe);
});
test.it('Investor#1 has received correct quantity of tokens after finalization', async function () {
let investor = Investor1;
let newBalance = await investor.getTokenBalance(e2eMinCap) / 1e18;
let balance = e2eMinCap.minCap + smallAmount + 10;
logger.info("Investor should receive = " + balance);
logger.info("Investor has received balance = " + newBalance);
logger.info("Difference = " + (newBalance - balance));
return await assert.equal(balance, newBalance, "Test FAILED.'Investor has received " + newBalance + " tokens instead " + balance)
let balance = await investor.getTokenBalance(e2eMinCap) / 1e18;
let shouldBe = investor.tokenBalance;
logger.info("Investor should receive = " + shouldBe);
logger.info("Investor has received balance = " + balance);
logger.info("Difference = " + (balance - shouldBe));
return await assert.equal(balance, shouldBe, "Test FAILED.'Investor has received " + balance + " tokens instead " + shouldBe)
});
});

View File

@ -10,7 +10,7 @@ const WizardStep4 = require('../pages/WizardStep4.js').WizardStep4;
const TierPage = require('../pages/TierPage.js').TierPage;
const ReservedTokensPage = require('../pages/ReservedTokensPage.js').ReservedTokensPage;
const CrowdsalePage = require('../pages/CrowdsalePage.js').CrowdsalePage;
const InvestPage = require('../pages/InvestPage.js').InvestPage;
const InvestPage = require('../pages/ContributionPage.js').InvestPage;
const ManagePage = require('../pages/ManagePage.js').ManagePage;
const logger = require('../entity/Logger.js').logger;
const tempOutputPath = require('../entity/Logger.js').tempOutputPath;
@ -69,7 +69,7 @@ test.describe('POA token-wizard. Test MintedCappedCrowdsale', async function ()
const scenarioRopsten = './scenarios/scenarioMintedRopsten.json';
e2eRopsten = await Utils.getCrowdsaleInstance(scenarioRopsten);
e2eRopsten = await Utils.getMintedCrowdsaleInstance(scenarioRopsten);
startURL = await Utils.getStartURL();
driver = await Utils.startBrowserWithMetamask();

35
test/margo.js Normal file
View File

@ -0,0 +1,35 @@
require('dotenv').config()
let test = require('selenium-webdriver/testing');
let assert = require('assert');
const fs = require('fs-extra');
const Web3 = require('web3');
const Utils = require('../utils/Utils.js').Utils;
const addressRegistryStorage = '0xB1D914e7c55f16C2BAcAc11af6b3e011Aee38caF';
const addressMintedInitCrowdsale = '0x4FEEC2b6944E510EEf031D96330cB70F9051c440';
const Crowdsale = require('../entity/Crowdsale.js').Crowdsale;
const User = require("../entity/User.js").User;
//const execID = '0x39e0f8fc2049d5176112b8695b4f245ad4c5a2a8b8b4dfd04607cf4f95e74ebc';
run();
async function run()
{
fs.copySync('../../.env','./.env',{overwrite:true});
let crowdsale = new Crowdsale();
crowdsale.executionID = '0xf7cc57908a78e00776b804768aa3583eda0da18f06c691e9cb5927c4f68e8797';
crowdsale.sort = "dutch";
crowdsale.networkID=8545;
const account = '0xF16AB2EA0a7F7B28C267cbA3Ed211Ea5c6e27411';
const user8545_F16AFile = './users/user8545_F16A.json';//Investor2 - whitelisted before deployment
let user = new User(null, user8545_F16AFile);
console.log("user.account "+user.account )
let balance = await user.getTokenBalance(crowdsale)
console.log("Balance = " + balance );
}

View File

@ -1,15 +1,17 @@
const nodemailer = require('nodemailer');
require('dotenv').config();
const logger = require('../entity/Logger.js').logger;
const tempOutputPath = require('../entity/Logger.js').tempOutputPath;
const webdriver = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome');
const fs = require('fs');
const fs = require('fs-extra');
const Web3 = require('web3');
const {spawn} = require('child_process');
const Crowdsale = require('../entity/Crowdsale.js').Crowdsale;
const DutchAuction = require("../entity/DutchAuction.js").DutchAuction;
const configFile = 'config.json';
const _minted = 'minted';
const _dutch = 'dutch';
class Utils {
@ -70,7 +72,8 @@ class Utils {
}
}
static setNetwork(network) {
static getWeb3Instance(network) {
logger.info("Utils: getWeb3Instance")
let url;
switch (network) {
case 3: {
@ -97,13 +100,8 @@ class Utils {
return new Web3(new Web3.providers.HttpProvider(url));
}
static getTransactionCount(network, address) {
let web3 = Utils.setNetwork(network);
return web3.eth.getTransactionCount(address.toString());
}
static async getBalance(user) {
let web3 = Utils.setNetwork(user.networkID);
let web3 = Utils.getWeb3Instance(user.networkID);
return await web3.eth.getBalance(user.account.toString());
}
@ -282,10 +280,11 @@ class Utils {
}
static async getCrowdsaleInstance(fileName) {
static async getMintedCrowdsaleInstance(fileName) {
try {
let crowdsale = new Crowdsale();
await crowdsale.parser(fileName);
crowdsale.sort = _minted;
return crowdsale;
}
catch (err) {
@ -299,6 +298,7 @@ class Utils {
try {
let crowdsale = new DutchAuction();
await crowdsale.parser(fileName);
crowdsale.sort = _dutch;
return crowdsale;
}
catch (err) {
@ -313,16 +313,81 @@ class Utils {
}
static async compareBalance(balanceEthOwnerBefore, balanceEthOwnerAfter, contribution, rate, delta) {
let balanceShouldBe = balanceEthOwnerBefore/1e18 + (contribution / rate);
logger.info("contribution / rate= " + (contribution / rate) );
logger.info("rate= " + rate );
let balanceShouldBe = balanceEthOwnerBefore / 1e18 + (contribution / rate);
logger.info("contribution / rate= " + (contribution / rate));
logger.info("rate= " + rate);
logger.info("balanceEthOwnerBefore= " + balanceEthOwnerBefore / 1e18);
logger.info("contribution= " + contribution );
logger.info("balanceShouldBe= " + balanceShouldBe );
logger.info("contribution= " + contribution);
logger.info("balanceShouldBe= " + balanceShouldBe);
logger.info("balanceEthOwnerAfter= " + balanceEthOwnerAfter / 1e18);
if (delta === undefined) delta = 0.01;
logger.info("delta= " + delta);
return ( Math.abs(balanceShouldBe - balanceEthOwnerAfter/1e18) < delta );
return (Math.abs(balanceShouldBe - balanceEthOwnerAfter / 1e18) < delta);
}
static async getEnvAddressMintedInitCrowdsale() {
logger.info("Utils:getEnvAddressMintedInitCrowdsale");
return Object.values(JSON.parse(process.env.REACT_APP_MINTED_CAPPED_CROWDSALE_INIT_CROWDSALE_ADDRESS))[0];
}
static async getEnvAddressDutchInitCrowdsale() {
logger.info("Utils:getEnvAddressDutchInitCrowdsale");
return Object.values(JSON.parse(process.env.REACT_APP_DUTCH_CROWDSALE_INIT_CROWDSALE_ADDRESS))[0];
}
static async getEnvAddressRegistryStorage() {
logger.info("Utils:getEnvAddressRegistryStorage");
return Object.values(JSON.parse(process.env.REACT_APP_REGISTRY_STORAGE_ADDRESS))[0];
}
static async getEnvNetworkId() {
logger.info("Utils:getEnvNetworkId");
return Object.keys(JSON.parse(process.env.REACT_APP_REGISTRY_STORAGE_ADDRESS))[0];
}
static async getContractAddressInitCrowdsale(crowdsale) {
logger.info("Utils:getContractAddressInitCrowdsale");
switch (crowdsale.sort) {
case 'minted':
return Utils.getEnvAddressMintedInitCrowdsale();
break;
case 'dutch':
return Utils.getEnvAddressDutchInitCrowdsale();
break;
default:
return Utils.getEnvAddressMintedInitCrowdsale();
}
}
static async getContractABIInitCrowdsale(crowdsale) {
logger.info("Utils:getContractABIInitCrowdsale");
let path = './contracts/';
switch (crowdsale.sort) {
case 'minted':
path = path + 'MintedInitCrowdsale.abi';
break;
case 'dutch':
path = path + 'DutchInitCrowdsale.abi';
break;
default:
path = path + 'MintedInitCrowdsale.abi'
}
return await JSON.parse(fs.readFileSync(path).toString());
}
static async copyEnvFromWizard() {
try {
fs.copySync('../../.env', './.env', {overwrite: true});
return true;
}
catch(err){
logger.info("! Can't find .env file in wizard's directory !");
logger.info(err);
return false;
}
}
}