1

After running truffle test i get the following unexpected error:

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

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/RiskxToken.sol...
Compiling ./contracts/RiskxTokenSale.sol...

Compilation warnings encountered:

/Users/zanemassey/Desktop/riskxtoken/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/riskxtoken/contracts/RiskxToken.sol:24:5: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
    function RiskxToken (uint256 _initialSupply) public {
    ^ (Relevant source part starts here and spans across multiple lines).
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxTokenSale.sol:9:2: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
    function RiskxTokenSale(RiskxToken _tokenContract) public {
 ^ (Relevant source part starts here and spans across multiple lines).
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxToken.sol:35:9: Warning: Invoking events without "emit" prefix is deprecated.
        Transfer(msg.sender, _to, _value);
        ^-------------------------------^
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxToken.sol:43:9: Warning: Invoking events without "emit" prefix is deprecated.
        Approval(msg.sender, _spender, _value);
        ^------------------------------------^
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxToken.sol:57:9: Warning: Invoking events without "emit" prefix is deprecated.
        Transfer(_from, _to, _value);
        ^--------------------------^

Error: RiskxTokenSale contract constructor expected 1 arguments, received 0
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:390:1
    at new Promise (<anonymous>)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:374:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Zanes-iMac:riskxtoken zanemassey$ truffle test
Using network 'development'.

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/RiskxToken.sol...
Compiling ./contracts/RiskxTokenSale.sol...

Compilation warnings encountered:

/Users/zanemassey/Desktop/riskxtoken/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/riskxtoken/contracts/RiskxToken.sol:24:5: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
    function RiskxToken (uint256 _initialSupply) public {
    ^ (Relevant source part starts here and spans across multiple lines).
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxTokenSale.sol:9:2: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
    function RiskxTokenSale(RiskxToken _tokenContract) public {
 ^ (Relevant source part starts here and spans across multiple lines).
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxToken.sol:35:9: Warning: Invoking events without "emit" prefix is deprecated.
        Transfer(msg.sender, _to, _value);
        ^-------------------------------^
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxToken.sol:43:9: Warning: Invoking events without "emit" prefix is deprecated.
        Approval(msg.sender, _spender, _value);
        ^------------------------------------^
,/Users/zanemassey/Desktop/riskxtoken/contracts/RiskxToken.sol:57:9: Warning: Invoking events without "emit" prefix is deprecated.
        Transfer(_from, _to, _value);
        ^--------------------------^

Error: RiskxTokenSale contract constructor expected 1 arguments, received 0
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:390:1
    at new Promise (<anonymous>)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:374:1
    at process._tickCallback (internal/process/next_tick.js:68:7)

I was expecting to get 5 passing 1 failing and for the contract to initialise with the correct values + an assertion error for the crowdsale contract:

pragma solidity ^0.4.23;

import "./RiskxToken.sol";

contract RiskxTokenSale {
    address admin;
    RiskxToken public tokenContract;

    function RiskxTokenSale(RiskxToken _tokenContract) public {
        admin = msg.sender;
        tokenContract = _tokenContract; 
        // Token contract
        // Token Price
    }
}

this is my token contract:

pragma solidity ^0.4.23;

contract RiskxToken {
    string  public name = "Riskx Token";
    string  public symbol = "RIX";
    string  public standard = "Riskx Token v1.0";
    uint256 public totalSupply;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

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

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        Transfer(msg.sender, _to, _value);

        return true;
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowance[msg.sender][_spender] = _value;

        Approval(msg.sender, _spender, _value);

        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_value <= balanceOf[_from]);
        require(_value <= allowance[_from][msg.sender]);

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;

        allowance[_from][msg.sender] -= _value;

        Transfer(_from, _to, _value);

        return true;
    }
}

Im not trying to emit anything at this stage, i'm just trying to get the test to fail. Does anyone know why this is happening?

  • Your crowdsale deployment fails, so the rest of the tests don't run. The rest of the output is just warnings (which you should probably still fix). Try updating your test code to intialize the crowdsale correctly. – Raghav Sood Jul 28 '18 at 9:26
1

Figured out the issue. I had to add the following code to my migrations file:

module.exports = function(deployer) {
    deployer.deploy(RiskxToken, 600000000).then(function() {
        return deployer.deploy(RiskxTokenSale, RiskxToken.address); 
    });
};

In case anyone else runs into this problem.

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.