Skip to content

Commit

Permalink
Fix test_bilateral_transaction_timestamps depending on real time (#7703)
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Nov 21, 2023
1 parent 1adfe20 commit 6b301c6
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest.mock

from ipv8.keyvault.crypto import default_eccrypto
from ipv8.peer import Peer

Expand Down Expand Up @@ -66,10 +68,17 @@ async def test_bilateral_transaction(self):

async def test_bilateral_transaction_timestamps(self):
"""
Test creating subsequent transactions and check whether the timestamps are different.
Test whether the timestamps are different for transactions created at different times.
We do not depend on chance and ensure that `time.time()` is different between calls.
"""
tx1 = await self.overlay(ID1).do_payout(self.peer(ID2), 500)
tx2 = await self.overlay(ID1).do_payout(self.peer(ID2), 500)
with unittest.mock.patch('time.time') as fake_time:
fake_time.return_value = 10.0
tx1 = await self.overlay(ID1).do_payout(self.peer(ID2), 500)

with unittest.mock.patch('time.time') as fake_time:
fake_time.return_value = 11.0
tx2 = await self.overlay(ID1).do_payout(self.peer(ID2), 500)

assert tx1.timestamp != tx2.timestamp

Expand Down

0 comments on commit 6b301c6

Please sign in to comment.