First, we're going to take a closer look at the code behind createRandomZombie():

function createRandomZombie(string _name) public {
  require(ownerZombieCount[msg.sender] == 0);
  uint randDna = _generateRandomDna(_name);
  randDna = randDna - randDna % 100;
  _createZombie(_name, randDna);
}

So far so good. Moving forward, let's dig into _createZombie():

function _createZombie(string _name, uint _dna) internal {
  uint id = zombies.push(Zombie(_name, _dna, 1, uint32(now + cooldownTime), 0, 0)) - 1;
  zombieToOwner[id] = msg.sender;
  ownerZombieCount[msg.sender] = ownerZombieCount[msg.sender].add(1);
  emit NewZombie(id, _name, _dna);
}

Ohh, you see the issue?

Our test failed because we've added a cooldown period to our game, and made it so zombies have to wait 1 day after attacking (or feeding) to attack again.

Without this, the zombie could attack and multiply countless times per day, which would make the game way too easy.

Now, what should we do now... wait for a day?

Time Travelling

Fortunately, we don't have to wait that much. In fact, there's no need to wait at all. That's because Ganache provides a way to move forward in time through two helper functions:

You don't even need a Tardis or a DeLorean for this kind of time travel.

Let me explain how these functions work:

Putting it together, we can fix our test by traveling through time as follows:

await web3.currentProvider.sendAsync({
  jsonrpc: "2.0",
  method: "evm_increaseTime",
  params: [86400],// there are 86400 seconds in a dayid: new Date().getTime()
}, () => { });

web3.currentProvider.send({
    jsonrpc: '2.0',
    method: 'evm_mine',
    params: [],
    id: new Date().getTime()
});