Add docstrings
This commit is contained in:
19
tests/test_block.py
Normal file
19
tests/test_block.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
|
||||
# local imports
|
||||
from chainlib.eth.jsonrpc import to_blockheight_param
|
||||
|
||||
|
||||
class TestBlock(unittest.TestCase):
|
||||
|
||||
def test_blockheight_param(self):
|
||||
self.assertEqual(to_blockheight_param('latest'), 'latest')
|
||||
self.assertEqual(to_blockheight_param(0), 'latest')
|
||||
self.assertEqual(to_blockheight_param('pending'), 'pending')
|
||||
self.assertEqual(to_blockheight_param(-1), 'pending')
|
||||
self.assertEqual(to_blockheight_param(1), '0x0000000000000001')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -28,6 +28,7 @@ from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
)
|
||||
from chainlib.eth.block import Block
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -35,6 +36,7 @@ logg = logging.getLogger()
|
||||
|
||||
class TxTestCase(EthTesterCase):
|
||||
|
||||
|
||||
def test_tx_reciprocal(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
gas_oracle = RPCGasOracle(self.rpc)
|
||||
@@ -75,5 +77,70 @@ class TxTestCase(EthTesterCase):
|
||||
logg.debug('r {}'.format(tx_signed_raw_bytes_recovered.hex()))
|
||||
self.assertEqual(tx_signed_raw_bytes, tx_signed_raw_bytes_recovered)
|
||||
|
||||
|
||||
def test_apply_block(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
gas_oracle = RPCGasOracle(self.rpc)
|
||||
c = Gas(signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_spec=self.chain_spec)
|
||||
(tx_hash_hex, o) = c.create(self.accounts[0], self.accounts[1], 1024, tx_format=TxFormat.RLP_SIGNED)
|
||||
tx_data = unpack(bytes.fromhex(strip_0x(o)), self.chain_spec)
|
||||
|
||||
block_hash = os.urandom(32).hex()
|
||||
block = Block({
|
||||
'hash': block_hash,
|
||||
'number': 42,
|
||||
'timestamp': 13241324,
|
||||
'transactions': [],
|
||||
})
|
||||
with self.assertRaises(AttributeError):
|
||||
tx = Tx(tx_data, block=block)
|
||||
|
||||
tx_unknown_hash = os.urandom(32).hex()
|
||||
block.txs = [add_0x(tx_unknown_hash)]
|
||||
block.txs.append(add_0x(tx_data['hash']))
|
||||
tx = Tx(tx_data, block=block)
|
||||
|
||||
block.txs = [add_0x(tx_unknown_hash)]
|
||||
block.txs.append(tx_data)
|
||||
tx = Tx(tx_data, block=block)
|
||||
|
||||
|
||||
def test_apply_receipt(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
gas_oracle = RPCGasOracle(self.rpc)
|
||||
c = Gas(signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_spec=self.chain_spec)
|
||||
(tx_hash_hex, o) = c.create(self.accounts[0], self.accounts[1], 1024, tx_format=TxFormat.RLP_SIGNED)
|
||||
tx_data = unpack(bytes.fromhex(strip_0x(o)), self.chain_spec)
|
||||
|
||||
rcpt = {
|
||||
'transaction_hash': os.urandom(32).hex(),
|
||||
'block_hash': os.urandom(32).hex(),
|
||||
'status': 1,
|
||||
'block_number': 42,
|
||||
'transaction_index': 1,
|
||||
'logs': [],
|
||||
'gas_used': 21000,
|
||||
}
|
||||
with self.assertRaises(ValueError):
|
||||
tx = Tx(tx_data, rcpt=rcpt)
|
||||
|
||||
rcpt['transaction_hash'] = tx_data['hash']
|
||||
tx = Tx(tx_data, rcpt=rcpt)
|
||||
|
||||
block_hash = os.urandom(32).hex()
|
||||
block = Block({
|
||||
'hash': block_hash,
|
||||
'number': 42,
|
||||
'timestamp': 13241324,
|
||||
'transactions': [],
|
||||
})
|
||||
block.txs = [add_0x(tx_data['hash'])]
|
||||
with self.assertRaises(ValueError):
|
||||
tx = Tx(tx_data, rcpt=rcpt, block=block)
|
||||
|
||||
rcpt['block_hash'] = block.hash
|
||||
tx = Tx(tx_data, rcpt=rcpt, block=block)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user