Error: sets the total supply upon deployment

by johnho.91   Last Updated April 14, 2019 20:28 PM

Please help !

When i try to run test from truffle, i got this problem, here my test js code:

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

contract(DappToken, function(accounts) {
    it ('sets the total supply upon deployment', function() {
        return DappToken.deployed().then(function(instance) {
            tokenInstance = instance;
            return tokenInstance.totalSupply();}).then(function(totalSupply){
                assert.equal(totalSupply.toNumber(), 1000000, "sets the total supply to 1000000");
            });
        });
    })

and here my contract code:

pragma solidity ^0.5.0;

contract DappToken {
    uint256 public totalSupply;
    function DToken () public {
        totalSupply = 1000000;
    }   
}

and here the result of the test:

test contract truffle

PS: for more information, I follow the instruction video "Code Your Own Cryptocurrency on Ethereum (Full)" from Dapp University chanel on youtube , at 40:03

Tags : solidity truffle


Answers 1


Your error is here.

contract DappToken {
    uint256 public totalSupply;
    function DToken () public { <----
        totalSupply = 1000000;
    }   
}

I suppose you meant it to be the constructor. Since the version 0.4.22 of Solidity, you have to design the constructor with a special keyword constructor. So it becomes like that :

contract DappToken {
    uint256 public totalSupply;
     constructor() public {
        totalSupply = 1000000;
    }   
}
Eli Drion
Eli Drion
April 14, 2019 19:32 PM

Related Questions


Updated August 08, 2018 05:28 AM

Updated October 23, 2018 07:28 AM

Updated October 26, 2018 04:28 AM

Updated February 27, 2019 01:28 AM