def test_from_dict(self): value = { "chain": "BNB", "from_address": "USER", "to_address": "VAULT", "coins": [ {"asset": "BNB.BNB", "amount": 1000}, {"asset": RUNE, "amount": "1000"}, ], "memo": "STAKE:BNB.BNB", } txn = Transaction.from_dict(value) self.assertEqual(txn.chain, "BNB") self.assertEqual(txn.from_address, "USER") self.assertEqual(txn.to_address, "VAULT") self.assertEqual(txn.memo, "STAKE:BNB.BNB") self.assertEqual(txn.coins[0].asset, "BNB.BNB") self.assertEqual(txn.coins[0].amount, 1000) self.assertEqual(txn.coins[1].asset, RUNE) self.assertEqual(txn.coins[1].amount, 1000) self.assertEqual(txn.gas, None) value["coins"] = None value["gas"] = [{"asset": "BNB.BNB", "amount": "37500"}] txn = Transaction.from_dict(value) self.assertEqual(txn.chain, "BNB") self.assertEqual(txn.from_address, "USER") self.assertEqual(txn.to_address, "VAULT") self.assertEqual(txn.memo, "STAKE:BNB.BNB") self.assertEqual(txn.coins, None) self.assertEqual(txn.gas[0].asset, "BNB.BNB") self.assertEqual(txn.gas[0].amount, 37500)
def run(self): for i, txn in enumerate(self.txns): txn = Transaction.from_dict(txn) if self.bitcoin_reorg: # get block hash from bitcoin we are going to invalidate later if i == 14 or i == 24: current_height = self.mock_bitcoin.get_block_height() block_hash = self.mock_bitcoin.get_block_hash( current_height) logging.info( f"Block to invalidate {current_height} {block_hash}") # now we processed some btc txs and we invalidate an older block # to make those txs not valid anymore and test thornode reaction if i == 18 or i == 28: self.mock_bitcoin.invalidate_block(block_hash) logging.info("Reorg triggered") if self.ethereum_reorg: # get block hash from ethereum we are going to invalidate later if i == 14 or i == 24: current_height = self.mock_ethereum.get_block_height() block_hash = self.mock_ethereum.get_block_hash( current_height) logging.info( f"Block to invalidate {current_height} {block_hash}") # now we processed some eth txs and we invalidate an older block # to make those txs not valid anymore and test thornode reaction if i == 18 or i == 28: self.mock_ethereum.set_block(current_height) logging.info("Reorg triggered") logging.info(f"{i:2} {txn}") self.broadcast_chain(txn) self.broadcast_simulator(txn) if txn.memo == "SEED": continue self.sim_catch_up(txn) # check if we are verifying the results if self.no_verify: continue self.check_events() self.check_pools() self.check_binance() self.check_chain(self.bitcoin, self.mock_bitcoin, self.bitcoin_reorg) self.check_chain(self.ethereum, self.mock_ethereum, self.ethereum_reorg) if RUNE.get_chain() == "THOR": self.check_chain(self.thorchain, self.mock_thorchain, None) self.check_vaults()