error de prueba de trufa variables globales no escritas

Contrato:

contract owned {
    function owned() public { owner = msg.sender; }
    address owner;

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }
}

contract TestcontractCrowdSale is owned {
    uint public tokens_total = 0;

    struct holder {
        uint tokens_bonus_balance;
        uint tokens_all_balance;
        bool tokens_bonus_canspent;
        uint ethers_crowdfunded;
        uint list_pointer;
    }

    mapping (address => holder) public holders;
    address[] public holdersList;

    mapping (address => mapping (address => uint256)) public allowed;

    function checkIsHolder(address holderAddress) public constant returns (bool isIndeed) {
        if(holdersList.length == 0) return false;
        return (holdersList[holders[holderAddress].list_pointer] == holderAddress);
    }

    function getHoldersCount() public constant returns(uint count) {
        return holdersList.length;
    }

    function newHolder(address holderAddress) public returns(bool success) {
        if (!checkIsHolder(holderAddress)) {
            /*holders[holderAddress] = holder({
                tokens_bonus_balance: 0, 
                tokens_all_balance: 0,
                tokens_bonus_canspent : false,
                ethers_crowdfunded : 0,
                list_pointer : holdersList.push(holderAddress) - 1 
            });*/
            holders[holderAddress].list_pointer = holdersList.push(holderAddress) - 1;
        }
        return true;
    }

    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return holders[tokenOwner].tokens_all_balance;
    }

    function preprint(address _for, uint tokens) onlyOwner public returns (bool printed, address __for, uint bonus_all_tokens) {
        newHolder(_for);
        holders[_for].tokens_all_balance += tokens;
        holders[_for].tokens_bonus_balance += tokens;
        holders[_for].tokens_bonus_canspent = false;
        tokens_total += tokens;
        return (true, _for, holders[_for].tokens_bonus_balance );
    }
}

truffle.cmd develop

truffle(develop)> compile
truffle(develop)> migrate

truffle(develop)> TestcontractCrowdSale.deployed().then((instance) => {contract = instance});

truffle(develop)> contract.preprint.call("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
[ true,
  '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
  BigNumber { s: 1, e: 5, c: [ 123456 ] } ]
truffle(develop)> contract.preprint.call("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
[ true,
  '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
  BigNumber { s: 1, e: 5, c: [ 123456 ] } ]
truffle(develop)> contract.balanceOf("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef")
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.tokens_total()
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.tokens_total.call()
BigNumber { s: 1, e: 0, c: [ 0 ] }

Pero en remix todo funciona bien, la función de preimpresión funciona bien y no puedo entender, ¿por qué? ¡El contrato es el mismo!

ingrese la descripción de la imagen aquí

Eso es un gran problema para mí.

Respuestas (1)

Está utilizando el método web3.js .call , en contract.preprint.call().

Ejecuta una transacción de llamada de mensaje, que se ejecuta directamente en la máquina virtual del nodo, pero nunca se extrae en la cadena de bloques.

- documentos web3

Cambiar el comando a truffle(develop)> contract.preprint("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})debería solucionarlo.