class TestReputationBase(AbstractServer): """ This class contains various utility methods to add transactions to the TradeChain. """ def setUp(self, annotate=True): super(TestReputationBase, self).setUp(annotate=annotate) os.mkdir(os.path.join(self.session_base_dir, 'sqlite')) self.market_db = MarketDB(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) }, "type": "tx_done" } block = TradeChainBlock.create(transaction, self.market_db, pubkey1, link=None, link_pk=pubkey2) link_block = TradeChainBlock.create(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
class TestReputationBase(AbstractServer): """ This class contains various utility methods to add transactions to the TradeChain. """ def setUp(self, annotate=True): super(TestReputationBase, self).setUp(annotate=annotate) os.mkdir(os.path.join(self.session_base_dir, 'sqlite')) self.market_db = MarketDB(self.session_base_dir, 'market') def insert_transaction(self, pubkey1, pubkey2, asset1_type, asset1_amount, asset2_type, asset2_amount): latest_block = self.market_db.get_latest(pubkey1) block = TradeChainBlock() block.public_key = pubkey1 if latest_block: block.sequence_number = latest_block.sequence_number + 1 block.link_public_key = pubkey2 transaction = { "asset1_type": asset1_type, "asset1_amount": asset1_amount, "asset2_type": asset2_type, "asset2_amount": asset2_amount } block.transaction = transaction self.market_db.add_block(block)