Skip to content

Commit

Permalink
test(timestamp): finalize e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-cristino committed Mar 1, 2024
1 parent 7b29b7f commit 0ea8018
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/timestamp/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import { timestamp } from '@slangroom/timestamp';
test('fetch timestamp in seconds', async (t) => {
const contract = `Rule unknown ignore
Given I fetch the local timestamp in seconds and output into 'output'
Given I have a 'string' named 'output'
Given I have a 'time' named 'output'
Then print data
`
const sl = new Slangroom(timestamp);
const res = await sl.execute(contract);
const ts = new Date().getTime() / 1000;
t.true(Math.abs(Number(res) - ts) < 100);
t.truthy(res.result['output']);
t.true(Math.abs(Number(res.result['output']) - ts) < 100);
});

test('fetch timestamp in milliseconds', async (t) => {
const contract = `Rule unknown ignore
Given I fetch the local timestamp in seconds and output into 'output'
Given I fetch the local timestamp in milliseconds and output into 'output'
Given I have a 'string' named 'output'
Then print data
`
const sl = new Slangroom(timestamp);
const res = await sl.execute(contract);
const ts = new Date().getTime();
t.true(Math.abs(Number(res) - ts) < 100);
t.truthy(res.result['output']);
t.true(Math.abs(Number(res.result['output']) - ts) < 100000);
});

0 comments on commit 0ea8018

Please sign in to comment.