10
10
get_consensus_block_hash_with_confirmations , get_next_block_confirmations , is_valid_consensus ,
11
11
process_block_confirmations_task , process_next_block
12
12
)
13
+ from node .blockchain .tests .base import make_node_as_role
13
14
from node .blockchain .types import NodeRole
14
15
15
16
@@ -117,8 +118,11 @@ def test_process_block_confirmations_task():
117
118
118
119
@pytest .mark .usefixtures ('rich_blockchain' , 'as_confirmation_validator' )
119
120
def test_process_block_confirmations_integration (
120
- next_block , self_node_key_pair , confirmation_validator_key_pair , confirmation_validator_key_pair_2 , api_client
121
+ next_block , self_node_key_pair , confirmation_validator_key_pair , confirmation_validator_key_pair_2 ,
122
+ confirmation_validator_key_pair_3 , api_client
121
123
):
124
+ make_node_as_role (confirmation_validator_key_pair_3 .public , NodeRole .CONFIRMATION_VALIDATOR )
125
+
122
126
facade = BlockchainFacade .get_instance ()
123
127
block_number = facade .get_next_block_number ()
124
128
@@ -137,17 +141,34 @@ def test_process_block_confirmations_integration(
137
141
assert pending_block
138
142
assert pending_block .body == payload
139
143
144
+ assert not BlockConfirmation .objects .all ().exists ()
140
145
# TODO(dmu) CRITICAL: Remove artificial own confirmation
141
146
# https://thenewboston.atlassian.net/browse/BC-263
142
147
confirmation = PydanticBlockConfirmation .create_from_block (block , self_node_key_pair .private )
143
148
BlockConfirmation .objects .create_from_block_confirmation (confirmation )
149
+ assert BlockConfirmation .objects .all ().exists ()
144
150
145
151
# Create confirmations from other CVs
146
- for private_key in (confirmation_validator_key_pair .private , confirmation_validator_key_pair_2 .private ):
152
+ counter = 1
153
+ cv_keys = (
154
+ confirmation_validator_key_pair .private , confirmation_validator_key_pair_2 .private ,
155
+ confirmation_validator_key_pair_3 .private
156
+ )
157
+ for private_key in cv_keys :
147
158
confirmation = PydanticBlockConfirmation .create_from_block (block , private_key )
148
159
payload = confirmation .json ()
149
160
response = api_client .post ('/api/block-confirmations/' , payload , content_type = 'application/json' )
150
- assert response .status_code == 201
161
+
162
+ counter += 1
163
+ if counter < 3 :
164
+ assert response .status_code == 201
165
+ assert BlockConfirmation .objects .all ().exists ()
166
+ elif counter == 3 :
167
+ assert response .status_code == 201
168
+ assert not BlockConfirmation .objects .all ().exists () # because of always eager
169
+ else :
170
+ assert response .status_code == 204
171
+ assert not BlockConfirmation .objects .all ().exists ()
151
172
152
173
# Assert that block was added to the blockchain
153
174
assert facade .get_next_block_number () == block_number + 1
0 commit comments