Ejemplo n.º 1
0
    def process_new_block(self, block):
        # Update the state and refresh the sockets so new nodes can join
        self.update_state(block)
        self.socket_authenticator.refresh_governance_sockets()

        # Store the block if it's a masternode
        if self.store:
            encoded_block = encode(block)
            encoded_block = json.loads(encoded_block)

            self.blocks.store_block(encoded_block)

            # create Event File
            self.event_writer.write_event(
                Event(topics=[NEW_BLOCK_EVENT], data=encoded_block))

        # Prepare for the next block by flushing out driver and notification state
        # self.new_block_processor.clean()

        # Finally, check and initiate an upgrade if one needs to be done
        self.driver.commit()

        self.driver.clear_pending_state()
        gc.collect()  # Force memory cleanup every block

        self.nonces.flush_pending()
Ejemplo n.º 2
0
    def test_tx_with_error_returns_exception(self):
        tx = build_transaction(wallet=Wallet(),
                               processor=self.ws.wallet.verifying_key,
                               stamps=123,
                               nonce=0,
                               contract='currency',
                               function='transfer',
                               kwargs={
                                   'amount': 123,
                                   'to': 'jeff'
                               })

        tx = decode(tx)
        tx['payload']['stamps_supplied'] = -123
        tx = encode(tx)

        _, response = self.ws.app.test_client.post('/', data=tx)

        self.assertDictEqual(
            response.json, {'error': 'Transaction is not formatted properly.'})