def test_berlin_block_from_bytes(self): block: Block = rlp.decode(eth_fixtures.BERLIN_BLOCK, Block) self.assertEqual( Sha256Hash.from_string( "0ad3836807aa90218884be62c8dd912fe5228aafa6fc2a7c21028e8c09bc91ef" ), block.header.hash_object(), ) self.assertEqual(2, len(block.transactions)) legacy_tx = block.transactions[0] self.assertIsInstance(legacy_tx, LegacyTransaction) self.assertEqual( Sha256Hash.from_string( "77b19baa4de67e45a7b26e4a220bccdbb6731885aa9927064e239ca232023215" ), legacy_tx.hash(), ) acl_tx = block.transactions[1] self.assertIsInstance(acl_tx, AccessListTransaction) self.assertEqual( Sha256Hash.from_string( "554af720acf477830f996f1bc5d11e54c38aa40042aeac6f66cb66f9084a959d" ), acl_tx.hash(), ) re_encoded = rlp.encode(block) self.assertEqual(block, rlp.decode(re_encoded, Block))
def test_parse_tranasction(self): RAW_TX_HASH = "f86b01847735940082520894a2f6090c0483d6e6ac90a9c23d42e461fee2ac5188016147191f13b0008025a0784537f9801331b707ceedd5388d318d86b0bb43c6f5b32b30c9df960f596b05a042fe22aa47f2ae80cbb2c9272df2f8975c96a8a99020d8ac19d4d4b0e0b58219" transaction = transaction_validation_utils.parse_transaction( bytearray.fromhex(RAW_TX_HASH)) self.assertIsNotNone(transaction) self.assertEqual( transaction.hash(), Sha256Hash.from_string( "ffd59870844e5411f9e4043e654146b054bdcabe726a4bc4bd716049bfa54a69" ))
def test_legacy_transaction_from_bytes(self): transaction = rlp.decode(eth_fixtures.LEGACY_TRANSACTION, Transaction) re_encoded = rlp.encode(transaction) self.assertEqual(transaction, rlp.decode(re_encoded, Transaction)) self.assertEqual(EthTransactionType.LEGACY, transaction.transaction_type) self.assertIsInstance(transaction, LegacyTransaction) self.assertEqual( Sha256Hash.from_string(eth_fixtures.LEGACY_TRANSACTION_HASH), transaction.hash(), ) self.assertEqual("0xc296825bf94ca41b881390955c2731c1d3eaa059", transaction.from_address()) self.assertEqual(37, transaction.v)
def test_access_list_transaction_from_bytes(self): transaction: Transaction = rlp.decode(eth_fixtures.ACL_TRANSACTION, Transaction) re_encoded = rlp.encode(transaction) self.assertEqual(transaction, rlp.decode(re_encoded, Transaction)) self.assertEqual(EthTransactionType.ACCESS_LIST, transaction.transaction_type) self.assertIsInstance(transaction, AccessListTransaction) self.assertEqual( Sha256Hash.from_string(eth_fixtures.ACL_TRANSACTION_HASH), transaction.hash(), ) self.assertEqual(1, transaction.chain_id()) self.assertEqual(0, transaction.v) self.assertEqual("0x0087c5900b9bbc051b5f6299f5bce92383273b28", transaction.from_address()) self.assertEqual(3, len(transaction.access_list))
def validate_params(self) -> None: params = self.params if not isinstance(params, dict): raise RpcInvalidParams( self.request_id, "Params request field is either missing or not a dictionary type." ) if TRANSACTION_HASH_KEY not in params: raise RpcInvalidParams( self.request_id, "Transaction hash was missing from RPC params.") transaction_hash_str = params[TRANSACTION_HASH_KEY] try: transaction_hash = Sha256Hash.from_string(transaction_hash_str) except Exception as _e: raise RpcInvalidParams( self.request_id, f"Invalid transaction hash: {transaction_hash_str}") else: self.transaction_hash = transaction_hash