0

After running truffle test i get the following error:

Zanes-iMac:xyztoken zanemassey$ truffle test
Using network 'development'.

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/xyzToken.sol...

Compilation warnings encountered:

/Users/zanemassey/Desktop/xyztoken/contracts/Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
  function Migrations() public {
  ^ (Relevant source part starts here and spans across multiple lines).
,/Users/zanemassey/Desktop/xyztoken/contracts/xyzToken.sol:8:2: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
    function xyzToken (uint256 _initialSupply) public {
 ^ (Relevant source part starts here and spans across multiple lines).



  Contract: xyzToken
    1) sets the total supply upon deployment
    > No events were emitted


  0 passing (36ms)
  1 failing

  1) Contract: xyzToken
       sets the total supply upon deployment:
     ReferenceError: xyzToken is not defined
      at Context.<anonymous> (test/xyzToken.js:7:3)
      at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/testing/testrunner.js:135:1
      at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/property.js:119:1
      at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:89:1
      at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:134:1
      at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
      at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
      at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
      at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
      at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
      at endReadableNT (_stream_readable.js:1081:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)

If no events were emitted then what exactly is it failing?

this is my js:

var DappToken = artifacts.require("./xyzToken.sol");

contract('xyzToken', function(accounts) {
    var tokenInstance;

    it('sets the total supply upon deployment', function() {
        return xyzToken.deployed().then(function(instance) {
          tokenInstance = instance;
          return tokenInstance.totalSupply();
        }).then(function(totalSupply) {
          assert.equal(totalSupply.toNumber(), 600000000, 'sets the total supply to 600,000,000');
          return tokenInstance.balanceOf(accounts[0]);
        }).then(function(adminBalance) {
          assert.equal(adminBalance.toNumber(), 600000000, 'it allocates the inital supply to the admin account');
        });
    });
});

and solidity:

pragma solidity ^0.4.23;

contract xyzToken {
    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    function xyzToken (uint256 _initialSupply) public {
        balanceOf[msg.sender] = _initialSupply;
        totalSupply = _initialSupply;
    }
}

I have asserted total supply for number and admin balance and i have configured ganache accounts with an associative array. What exactly isn't defined about my token?

any help would be appreciated

1

The top line of your javascript is wrong. You've called the artifact DappToken but tried to instantiate it with xyzToken, which isn't defined, and hence the error you're getting.

Also, consider switching to async/await like the following - it makes the tests much easier on the eyes:

const DappToken = artifacts.require("./xyzToken.sol");

contract('xyzToken', accounts => {

  it('sets the total supply upon deployment', async () => {
    const tokenInstance = await DappToken.deployed()
        , initSupply    = 600000000
        , totalSupply   = await tokenInstance.totalSupply()
        , adminBalance  = await tokenInstance.balanceOf(accounts[0])
    assert.equal(totalSupply.toNumber(), initSupply, `Total supply should be ${initSupply}!`)
    assert.equal(adminBalance.toNumber(), initSupply, 'Initial supply should be allocated to admin account!')
  })
})

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.