[Ethereum] Assertion error running truffle test

errorsoliditytokenstruffle-test

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

Best Answer

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.

Related Topic