0

Im newbie and doing an exercise Im having this errors at truffle testing:

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



  Contract: MasterICO
    1) Deploys all contracts
    > No events were emitted
    2) Does the first buy
    > No events were emitted



  0 passing (1s)
  2 failing

  1) Contract: MasterICO
       Deploys all contracts:
     TypeError: Cannot read property 'new' of undefined
      at Context.<anonymous> (test/testMasterICO.js:12:37)
      at web3.eth.getBlockNumber.then.result (/home/pm/.node_modules_global/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/testing/testrunner.js:15
2:1)
      at processTicksAndRejections (internal/process/next_tick.js:81:5)

  2) Contract: MasterICO
       Does the first buy:
     ReferenceError: masterToken is not defined
      at Context.<anonymous> (test/testMasterICO.js:19:24)
      at web3.eth.getBlockNumber.then.result (/home/pm/.node_modules_global/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/testing/testrunner.js:15
2:1)
      at processTicksAndRejections (internal/process/next_tick.js:81:5)

The testMasterICO.js is:

const MasterICO = artifacts.require("MasterICO");
const MasterToken = artifacts.require("MasterToken");

contract("MasterICO", function(accounts) {
  const addressTokenHolder1 = accounts[0];
  const addressEther = accounts[3];

  let MasterToken;
  let MasterICO;

  it("Deploys all contracts", async function() {
    MasterToken = await MasterToken.new();
    MasterICO = await MasterICO.new();

    await masterToken.changeController(masterICO.address);
    await masterICO.initialize(masterToken.address, addressEther);
  });
  it("Does the first buy", async function() {
    const preBalance = await masterToken.balanceOf(addressTokenHolder1);
    const preTotalEth = await web3.eth.getBalance(addressEther);
    await masterToken.sendTransaction({
      value: web3.toWei(1),
      gas: 300000,
      gasPrice: "20000000000",
      from: addressTokenHolder1
    });
    const postBalance = await masterToken.balanceOf(addressTokenHolder1);
    const postTotalEth = await web3.eth.getBalance(addressEther);
    const currentBalance = postBalance - preBalance;
    const currentTotalEth = postTotalEth - preTotalEth;
    assert.equal(web3.fromWei(currentBalance), 1);
    assert.equal(web3.fromWei(currentTotalEth), 1);
  });
});

thanks

  • 1
    Cannot read property 'new' of undefined - Step 1: search for new in your code. Step 2: find out why the variable which precedes .new() is undefined. I did that myself, and my conclusion is that one of your contracts is not located where it should be (Truffle expects to find all contracts under a folder named contracts), or it has a different name than what you've used. Please note that by "different name", I refer to the name of the contract, not to the name of the file. – goodvibration Mar 10 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.