1
+ import json
2
+
1
3
import pytest
4
+ from django .db import connection
2
5
3
6
from node .blockchain .facade import BlockchainFacade
4
7
from node .blockchain .inner_models .block_confirmation import BlockConfirmation
@@ -25,3 +28,30 @@ def test_send_confirmation_to_cv(confirmation_validator_key_pair_2, api_client):
25
28
assert confirmation_orm
26
29
assert confirmation_orm .signer == confirmation_validator_key_pair_2 .public
27
30
assert confirmation_orm .body == payload
31
+
32
+
33
+ @pytest .mark .usefixtures ('rich_blockchain' , 'as_confirmation_validator' )
34
+ def test_confirmation_with_invalid_signature_is_not_accepted (confirmation_validator_key_pair_2 , api_client ):
35
+ assert not ORMBlockConfirmation .objects .exists ()
36
+
37
+ facade = BlockchainFacade .get_instance ()
38
+ assert facade .get_next_block_number () >= 4
39
+ block = facade .get_block_by_number (4 )
40
+
41
+ hash_ = block .make_hash ()
42
+ block_confirmation = BlockConfirmation .create (
43
+ block .get_block_number (), hash_ , confirmation_validator_key_pair_2 .private
44
+ )
45
+ payload_dict = block_confirmation .dict ()
46
+ payload_dict ['signature' ] = '0' * 128
47
+ payload = json .dumps (payload_dict )
48
+ response = api_client .post ('/api/block-confirmations/' , payload , content_type = 'application/json' )
49
+
50
+ assert response .status_code == 400
51
+ assert response .json () == {'non_field_errors' : [{'code' : 'invalid' , 'message' : 'Invalid signature' }]}
52
+
53
+ # This is because we have queried the database and nested transactions (save points) are not supported
54
+ assert connection .needs_rollback
55
+ connection .set_rollback (False )
56
+
57
+ assert not ORMBlockConfirmation .objects .exists ()
0 commit comments