0

I can't seem to understand where this error comes from. Maybe someone can help

My token solidity file :

pragma solidity >=0.4.2 <0.6.0;

    contract LairToken {
    //Name
    string public name = "Lair Token";
    //Symbol
    string public symbol = "LAIR";
    string public standard = "Lair Token v1.0";
    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    constructor (uint256 _initialSupply) public {
        balanceOf[msg.sender] = _initialSupply;

        totalSupply = _initialSupply;
        // allocate the initial supply
    }

        // Transfer tokens

      function transfer(address _to, uint256 _value) public returns (bool sucess) {
        // Exception if the account doesnt have enough

        require(balanceOf[msg.sender] >= _value);
        // Return a boolean
        // Transfer Event
        // Transfer


      }

}

My test file js:

var LairToken = artifacts.require("./LairToken.sol");

contract ('LairToken', function(accounts) {

var tokenInstance;

it('initializes the contract with the correct values', function() {
return LairToken.deployed().then(function(instance) {
    tokenInstance = instance;
    return tokenInstance.name();
}).then(function(name) {
assert.equal(name, 'Lair Token' , 'has the correct name');
return tokenInstance.symbol();
}).then(function(symbol) {
 assert.equal(symbol, 'LAIR', 'hast the correct symbol ');
 return tokenInstance.standard();
}).then(function(standard) {
assert.equal(standard, 'Lair Token v1.0', 'has the correct standard' );
});
})


it('allocates the initial supply upon deployment', function(){
 return LairToken.deployed().then(function(instance) {
    tokenInstance = instance ;
    return tokenInstance.totalSupply();
}).then(function(totalSupply) {
    assert.equal(totalSupply.toNumber(), 1000000, 'sets the total supply 
to 1,000,000');
    return tokenInstance.balanceOf(accounts[0]);
}).then(function(adminBalance) {
    assert.equal(adminBalance.toNumber(), 1000000 , 'it allocates the 
initial supply to the admin'); 

    });

 });
});


it('transfers token ownership', function() {
return LairToken.deployed().then(function(instance) {
  tokenInstance = instance;
  // Test `require` statement first by transferring something larger than 
the sender's balance
  return tokenInstance.transfer.call(accounts[1], 
 99999999999999999999999);
}).then(assert.fail).catch(function(error) {
  assert(error.message.indexOf('revert') >= 0, 'error message must 
contain revert');

});

});

Error that shows upon testing

error that comes up

0

This is because ganache has implemented a workaround to forward the reason of a failed require but other clients will fail with a regular exception.

This is good for ganache because truffle is able to show the exact cause of a require failure. But the feature is not portable because other clients didn't implement a similar feature.

| improve this answer | |
0

Replace this code with your test : )

  it("transfers token ownership", function () {
        return ValleyToken.deployed()
          .then(function (instance) {
            tokenInstance = instance;
            return tokenInstance.transfer.call(accounts[1], 9999999999999999);
          })
          .then(assert.fail)
          .catch(function (error) {
            assert(error.message, "error message must contain revert");
            return tokenInstance.transfer.call(accounts[1], 250000, {
              from: accounts[0],
            });
          })
          .then(function (success) {
            assert(success, true, "it returns true");
            return tokenInstance.transfer(accounts[1], 250000, {
              from: accounts[0],
            });
          })
          .then(function (receipt) {
            assert.equal(receipt.logs.length, 1, "triggers one event");
            assert.equal(
              receipt.logs[0].event,
              "Transfer",
              'should be the "Transfer" event'
            );
            assert.equal(
              receipt.logs[0].args._from,
              accounts[0],
              "logs the account the tokens are transferred from"
            );
            assert.equal(
              receipt.logs[0].args._to,
              accounts[1],
              "logs the account the tokens are transferred to"
            );
            assert.equal(
              receipt.logs[0].args._value,
              250000,
              "logs the transfer amount"
            );
            return tokenInstance.balanceOf(accounts[1]);
          })
          .then(function (reciept) {
            return tokenInstance.balanceOf(accounts[1]);
          })
          .then(function (balance) {
            assert.equal(
              balance.toNumber(),
              250000,
              "adds the amount to the recieving amount"
            );
            return tokenInstance.balanceOf(accounts[0]);
          })
          .then(function (balance) {
            assert.equal(
              balance.toNumber(),
              750000,
              "deducts the amount from the sending account"
            );
          });
      });
| improve this answer | |

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.