Ejemplo n.º 1
0
class TestReputationBase(AbstractServer):
    """
    This class contains various utility methods to add transactions to the TrustChain.
    """
    def setUp(self, annotate=True):
        super(TestReputationBase, self).setUp(annotate=annotate)

        os.mkdir(os.path.join(self.session_base_dir, 'sqlite'))
        self.market_db = TrustChainDB(self.session_base_dir, 'market')

    def insert_transaction(self, pubkey1, pubkey2, quantity, price):
        transaction = {
            "tx": {
                "quantity_type": quantity.wallet_id,
                "quantity": float(quantity),
                "price_type": price.wallet_id,
                "price": float(price)
            },
        }
        block = TrustChainBlock.create('tx_done',
                                       transaction,
                                       self.market_db,
                                       pubkey1,
                                       link=None,
                                       link_pk=pubkey2)
        link_block = TrustChainBlock.create('tx_done',
                                            transaction,
                                            self.market_db,
                                            pubkey2,
                                            link=block,
                                            link_pk=pubkey1)

        self.market_db.add_block(block)
        self.market_db.add_block(link_block)

    def compute_reputations(self):
        blocks = self.market_db.get_all_blocks()
        rep_manager = TemporalPagerankReputationManager(blocks)
        rep = rep_manager.compute(own_public_key='a')
        self.assertIsInstance(rep, dict)
        return rep
Ejemplo n.º 2
0
class TestReputationBase(AbstractServer):
    """
    This class contains various utility methods to add transactions to the TrustChain.
    """
    def setUp(self):
        super(TestReputationBase, self).setUp()

        os.mkdir(os.path.join(self.session_base_dir, 'sqlite'))
        self.market_db = TrustChainDB(self.session_base_dir, 'market')

    def insert_transaction(self, pubkey1, pubkey2, assets_traded):
        transaction = {
            "tx": {
                "assets": assets_traded.to_dictionary(),
                "transferred": assets_traded.to_dictionary()
            },
        }
        block = TrustChainBlock.create('tx_done',
                                       transaction,
                                       self.market_db,
                                       pubkey1,
                                       link=None,
                                       link_pk=pubkey2)
        link_block = TrustChainBlock.create('tx_done',
                                            transaction,
                                            self.market_db,
                                            pubkey2,
                                            link=block,
                                            link_pk=pubkey1)

        self.market_db.add_block(block)
        self.market_db.add_block(link_block)

    def compute_reputations(self):
        blocks = self.market_db.get_all_blocks()
        rep_manager = TemporalPagerankReputationManager(blocks)
        rep = rep_manager.compute(own_public_key='a')
        self.assertIsInstance(rep, dict)
        return rep
Ejemplo n.º 3
0
    def setUp(self, annotate=True):
        super(TestReputationBase, self).setUp(annotate=annotate)

        os.mkdir(os.path.join(self.session_base_dir, 'sqlite'))
        self.market_db = TrustChainDB(self.session_base_dir, 'market')