¿Por qué no recibo '5 aprobados, 1 reprobado' después de realizar la prueba de trufa?

Después de ejecutar truffle test, aparece el siguiente error inesperado:

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)

Esperaba obtener 5 pasando 1 fallando y que el contrato se inicializara con los valores correctos + un error de afirmación para el contrato de venta colectiva:

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
    }
}

este es mi contrato token:

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;
    }
}

No estoy tratando de emitir nada en esta etapa, solo estoy tratando de que la prueba falle. ¿Alguien sabe por qué ocurre esto?

Su implementación de crowdsale falla, por lo que el resto de las pruebas no se ejecutan. El resto de la salida son solo advertencias (que probablemente aún debería corregir). Intente actualizar su código de prueba para iniciar el crowdsale correctamente.

Respuestas (1)

Resolví el problema. Tuve que agregar el siguiente código a mi archivo de migraciones:

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

En caso de que alguien más se encuentre con este problema.