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";
}