Example #1
0
 def start(self) -> None:
     """Has to be called before any other method can be called."""
     assert not self._started
     self._started = True
     self._patches_rc_increment()
     first_timestamp = min(tx.timestamp for tx in _get_genesis_transactions_unsafe(None))
     dt = self.rng.randint(3600, 120 * 24 * 3600)
     self._clock.advance(first_timestamp + dt)
     self.log.debug('randomized step: clock advance start', dt=dt)
Example #2
0
 def setUp(self):
     super().setUp()
     from hathor.transaction.genesis import _get_genesis_transactions_unsafe
     self.block = next(x for x in _get_genesis_transactions_unsafe(None)
                       if x.is_block)
     self.transport = StringTransportWithDisconnection()
     self.protocol = StratumClient()
     self.protocol.makeConnection(self.transport)
     self.job_request_params = {
         'data': self.block.get_header_without_nonce().hex(),
         'job_id': 'a734d03fe4b64739be2894742f3de20f',
         'nonce_size': Block.SERIALIZATION_NONCE_SIZE,
         'weight': self.block.weight,
     }
    def setUp(self):
        super().setUp()

        # import sys
        # from twisted.python import log
        # log.startLogging(sys.stdout)

        # self.set_random_seed(0)

        from hathor.transaction.genesis import _get_genesis_transactions_unsafe
        first_timestamp = min(tx.timestamp for tx in _get_genesis_transactions_unsafe(None))
        self.clock.advance(first_timestamp + random.randint(3600, 120*24*3600))

        self.network = 'testnet'
    def test_genesis_ref(self):
        # Enable weakref to this test only.
        self.tx_storage._enable_weakref()

        genesis_set = set(self.tx_storage.get_all_genesis())
        for tx in genesis_set:
            tx2 = self.tx_storage.get_transaction(tx.hash)
            self.assertTrue(tx is tx2)

        from hathor.transaction.genesis import _get_genesis_transactions_unsafe
        genesis_from_settings = _get_genesis_transactions_unsafe(None)
        for tx in genesis_from_settings:
            tx2 = self.tx_storage.get_transaction(tx.hash)
            self.assertTrue(tx is not tx2)
            for tx3 in genesis_set:
                self.assertTrue(tx is not tx3)
                if tx2 == tx3:
                    self.assertTrue(tx2 is tx3)
Example #5
0
    def setUp(self):
        super().setUp()

        self.clock = HeapClock()
        self.set_random_seed(self.seed_config)

        print('-' * 30)
        print('Simulation seed config:', self.random_seed)
        print('-' * 30)

        def verify_pow(self: BaseTransaction) -> None:
            assert self.hash is not None

        self.old_verify_pow = BaseTransaction.verify_pow
        BaseTransaction.verify_pow = verify_pow

        self.network = 'testnet'

        first_timestamp = min(tx.timestamp
                              for tx in _get_genesis_transactions_unsafe(None))
        self.clock.advance(first_timestamp +
                           random.randint(3600, 120 * 24 * 3600))
 def _get_genesis_from_settings(self) -> List[BaseTransaction]:
     """Return all genesis from settings."""
     from hathor.transaction.genesis import _get_genesis_transactions_unsafe
     return _get_genesis_transactions_unsafe(self)