I can't figure out why this error occurs

Here my test js code:

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

contract('YarockToken', function(accounts) {
  var tokenInstance;

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

  it('allocates the initial supply upon deployment', function() {
    return YarockToken.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 account');

  it('transfers token ownership', function() {
    return YarockToken.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');

and here my contract code:

pragma solidity ^0.5.16;
contract YarockToken {
    string  public name = "Yarock Token";
    string  public symbol = "YAROCK";
    string  public standard = "Yarock 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;

    constructor(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;



and this is the error I am getting

      Contract: YarockToken
    ✓ initializes the contract with the correct values (238ms)
    ✓ allocates the initial supply upon deployment (123ms)
    1) transfers token ownership
    > No events were emitted

  2 passing (541ms)
  1 failing

  1) Contract: YarockToken
       transfers token ownership:
     AssertionError: error message must contain revert
      at /Users/Kantemirovs/token_sale/test/YarockToken.js:39:7
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

Can someone please enlighten me about this ??

  • Try in the last test tokenInstance.transfer(accounts[1], 99999999999999999999999) instead, ie remove .call.
    – Ismael
    Dec 29 '20 at 23:46

I had the same problem, I found the solution on Github. Basically, you need to delete indexOf() function after error.message so it should look like this

assert(error.message, 'error message must contain revert');

Here is your answer: https://github.com/dappuniversity/token_sale/issues/27

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Dec 30 '20 at 0:21
  • Do you have a better answer than the link?
    – Itsjonie
    Dec 30 '20 at 11:15

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.