Skip to content

Commit 6d48061

Browse files
committed
Add test for tx validation in tx pool
1 parent 75be226 commit 6d48061

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import pytest
2+
3+
from eth.chains.base import (
4+
MiningChain,
5+
)
6+
from eth.tools.builder.chain import api
7+
from eth.vm.forks.frontier.transactions import (
8+
FrontierTransaction,
9+
)
10+
from eth.vm.forks.homestead.transactions import (
11+
HomesteadTransaction,
12+
)
13+
from eth.vm.forks.spurious_dragon.transactions import (
14+
SpuriousDragonTransaction,
15+
)
16+
17+
from trinity.plugins.builtin.tx_pool.validators import (
18+
DefaultTransactionValidator,
19+
)
20+
21+
22+
@pytest.mark.parametrize(
23+
(
24+
'initial_block_number',
25+
'expected_initial_tx_class',
26+
'expected_outdated_tx_class',
27+
'expected_future_tx_class',
28+
),
29+
[
30+
(1, FrontierTransaction, None, SpuriousDragonTransaction,),
31+
(5, HomesteadTransaction, FrontierTransaction, SpuriousDragonTransaction,),
32+
(6, HomesteadTransaction, FrontierTransaction, SpuriousDragonTransaction,),
33+
# If no initial block number is specified, the latest VM is assumed to be active
34+
(None, SpuriousDragonTransaction, HomesteadTransaction, SpuriousDragonTransaction,),
35+
],
36+
)
37+
def test_tx_class_resolution(initial_block_number,
38+
expected_initial_tx_class,
39+
expected_outdated_tx_class,
40+
expected_future_tx_class):
41+
chain = api.build(
42+
MiningChain,
43+
api.frontier_at(0),
44+
api.homestead_at(5),
45+
api.spurious_dragon_at(10),
46+
api.disable_pow_check,
47+
api.genesis
48+
)
49+
validator = DefaultTransactionValidator(chain, initial_block_number)
50+
assert validator.get_appropriate_tx_class() == expected_initial_tx_class
51+
52+
if expected_outdated_tx_class is not None:
53+
assert validator.is_outdated_tx_class(expected_outdated_tx_class)
54+
55+
# The `get_appropriate_tx_class` method has a cache decorator applied
56+
# To test it properly, we need to clear the cache
57+
validator.get_appropriate_tx_class.cache_clear()
58+
59+
# Check that the validator uses the correct tx class when we have reached the tip of the chain
60+
for n in range(10):
61+
chain.mine_block()
62+
63+
assert validator.get_appropriate_tx_class() == expected_future_tx_class

0 commit comments

Comments
 (0)