Warum erhalte ich nach dem Trüffeltest nicht „5 bestanden, 1 nicht bestanden“?

Nach dem Ausführen truffle testerhalte ich den folgenden unerwarteten Fehler:

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)

Ich hatte erwartet, dass 5 bestanden 1 fehlschlägt und der Vertrag mit den richtigen Werten + einem Assertionsfehler für den Crowdsale-Vertrag initialisiert wird:

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

Dies ist mein Token-Vertrag:

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

Ich versuche in diesem Stadium nichts zu emittieren, ich versuche nur, den Test zum Scheitern zu bringen. Weiß jemand, warum dies geschieht?

Ihre Crowdsale-Bereitstellung schlägt fehl, sodass die restlichen Tests nicht ausgeführt werden. Der Rest der Ausgabe sind nur Warnungen (die Sie wahrscheinlich noch beheben sollten). Versuchen Sie, Ihren Testcode zu aktualisieren, um den Crowdsale korrekt zu initialisieren.

Antworten (1)

Habe das Problem herausgefunden. Ich musste meiner Migrationsdatei den folgenden Code hinzufügen:

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

Falls noch jemand auf dieses Problem stößt.