3

I write tests using completium-cli and jest. All the tests I wrote work correctly, except one. It requires waiting for X blocks (X=3 in current example) and calling entrypoint with the valid parameters. Tried to use setMockupNow(now+3000), but the contract throws an error "GAME_NOT_ENDED", even that 3000s == 100 blocks, so setMockupNow doesn't work as expected.

test.js - endpoint and init setMockupNow details:

  setEndpoint('mockup')
  jest.setTimeout(30000);

  // Mockup Time
  const now = Math.floor(Date.now() / 1000)
  
  setMockupNow(now) 

test.js - failed test

test('Game ended', async () => {
  var after = now + 3000;
  console.log("Now: ", now);
  console.log("After: ", after);
  setMockupNow(after);

  var op = await room.end_game({
    arg:{
      room_idb: "NYC",
      serverid: "NYC",
      packed_outcome: PACKED_OUTCOME,
      signed_outcome: SIGNED_OUTCOME
    }, as: bob.pkh
  })
  })

console output

console.log
    Now:  1670511829

      at Object.log (__tests__/test_room.js:199:11)

  console.log
    After:  1670514829

      at Object.log (__tests__/test_room.js:200:11)

 FAIL  __tests__/test_room.js (15.027 s)
  ✓ Contract deployed (2265 ms)
  ✓ Server created (1092 ms)
  ✓ Room filled (3697 ms)
  ✓ Refund after game started (1098 ms)
  ✓ Game still active (1141 ms)
  ✓ Player not inside room (1105 ms)
  ✓ Room not exist on this server (1093 ms)
  ✓ Wrong server (1070 ms)
  ✕ Game ended (1457 ms)

  ● Game ended

    thrown: Object {
      "value": "\"GAME_STILL_ACTIVE\"",
    }

contract.arl - require entrypoint part

entry end_game (room_idb : string, serverid : string, packed_outcome : bytes, signed_outcome : signature) {
    require {
        r7: server.contains(serverid) otherwise "WRONG_SERVER";
        r8: server[serverid].players.contains(caller) otherwise "NOT_PARTICIPATED";
        r9: server[serverid].rooms.contains(room_idb) otherwise "NO_ROOM_ON_THIS_SERVER";
        r10: level > room[room_idb].finish_block otherwise "GAME_STILL_ACTIVE";
    }

2 Answers 2

2

actually in mockup mode, the way setMockupNow works does not increase block level. Fortunately a way to increase the block level is by manually calling the baking process. We have added the call mockup_bake() that will invoke the underlying bake process and increase block level by 1. It is available in version 0.4.52 of completium-cli.

Hence in your code, in order to move 100 blocks forwards you will need something like:

for(let i=0; i < 100; i++) {
  await mockup_bake()
} 

The drawback is that it will take a bit less that a one minute ...

1

I don’t have enough stack exchange reputation to comment on your post so I'll just leave this as an answer (even though it isn't much of an answer).

There was a bug fix on setmockupnow just a few days ago so its probably worth just confirming that you have updated to the latest version of everything - just in case that fixes your problem (best delete package-lock.json as well as node modules before you run npm i as there have been some recent bug fixes associated with dependencies also)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.