32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 | @pytest.mark.parametrize(
"count,last_shape",
[
pytest.param(
17,
[(0, "branch", 3), (1, "leaf", 1)],
id="txs_17",
),
pytest.param(
129,
[(0, "branch", 9), (1, "branch", 2), (2, "leaf", 2)],
id="txs_129",
),
pytest.param(
130,
[
(0, "branch", 9),
(1, "branch", 2),
(2, "ext", 1),
(3, "branch", 2),
(4, "leaf", 0),
],
id="txs_130",
),
pytest.param(
145,
[
(0, "branch", 9),
(1, "branch", 2),
(2, "branch", 2),
(3, "leaf", 1),
],
id="txs_145",
),
pytest.param(
257,
[(0, "branch", 9), (1, "branch", 3), (2, "leaf", 4)],
id="txs_257",
),
pytest.param(
258,
[
(0, "branch", 9),
(1, "branch", 3),
(2, "ext", 3),
(5, "branch", 2),
(6, "leaf", 0),
],
id="txs_258",
),
pytest.param(
273,
[
(0, "branch", 9),
(1, "branch", 3),
(2, "ext", 2),
(4, "branch", 2),
(5, "leaf", 1),
],
id="txs_273",
),
],
)
def test_index_trie_shapes(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
count: int,
last_shape: Shape,
) -> None:
"""
One block of `count` transfers.
post: along the last key, for each count:
17: branch@0 -> {.., 1: leaf(1)}
129: branch@0 -> {8: branch@1 -> {leaf(0), leaf(2)}}
130: .. -> branch@1 -> {.., 1: ext(1) -> branch@3}
145: .. -> branch@1 -> {.., 1: branch@2}
257: branch@0 -> {8: branch@1 -> {.., 2: leaf(4)}}
258: .. -> branch@1 -> {.., 2: ext(3) -> branch@5}
273: .. -> branch@1 -> {.., 2: ext(2) -> branch@4}
The receipts trie of the block has the same keys.
"""
assert index_shape(count, count - 1) == last_shape
sender = pre.fund_eoa()
recipient = pre.fund_eoa(amount=0)
blockchain_test(
pre=pre,
post={recipient: Account(balance=count)},
blocks=[
Block(
txs=[
Transaction(sender=sender, to=recipient, value=1)
for _ in range(count)
]
)
],
)
|