1import smartpy as sp
2
3
4@sp.module
5def main():
6 class C(sp.Contract):
7 def __init__(self):
8 self.data.out = False
9 self.data.next = sp.timestamp(0)
10 self.data.before = sp.timestamp(-1)
11
12 @sp.entrypoint
13 def ep(self):
14 self.data.out = sp.now > sp.add_seconds(sp.now, 1)
15 assert sp.add_seconds(sp.now, 12) - sp.now == 12
16 assert sp.now - sp.add_seconds(sp.now, 12) == -12
17 assert sp.now - sp.add_seconds(sp.now, 12) == -12
18 assert sp.add(sp.now, sp.int(500)) == sp.timestamp(1500)
19 assert sp.add(sp.int(500), sp.now) == sp.timestamp(1500)
20 self.data.next = sp.add_seconds(sp.now, 24 * 3600)
21 assert sp.timestamp_from_utc(1, 1, 1, 0, 0, 0) == sp.timestamp(-62135596800)
22 assert sp.timestamp_from_utc(1970, 1, 1, 0, 0, 0) == sp.timestamp(0)
23 assert sp.timestamp_from_utc(2019, 9, 26, 10, 59, 51) == sp.timestamp(
24 1569495591
25 )
26
27
28@sp.add_test()
29def test():
30 scenario = sp.test_scenario("Timestamp", main)
31 scenario.h1("Timestamps")
32 c = main.C()
33 scenario += c
34 c.ep(_now=sp.timestamp(1000))