-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_get_insert_remove.py
More file actions
111 lines (92 loc) · 5.01 KB
/
test_get_insert_remove.py
File metadata and controls
111 lines (92 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
from pytest import fixture, mark
from src.blockchain_api import BlockchainApi
from tests.governed_map.conftest import string_to_hex_bytes, hex_bytes_to_string
pytestmark = [mark.xdist_group(name="governance_action"), mark.staging]
@mark.staging
class TestGet:
@mark.test_key("ETCM-10357")
def test_insert_returncode(self, insert_data):
assert 0 == insert_data.returncode
@mark.usefixtures("insert_data")
@mark.test_key("ETCM-10358")
def test_get_returncode(self, api: BlockchainApi, genesis_utxo, random_key):
result = api.partner_chains_node.smart_contracts.governed_map.get(genesis_utxo, random_key)
assert 0 == result.returncode
@mark.usefixtures("insert_data")
@mark.test_key("ETCM-10359")
def test_get_value(self, api: BlockchainApi, genesis_utxo, random_key, random_value):
result = api.partner_chains_node.smart_contracts.governed_map.get(genesis_utxo, random_key)
value = hex_bytes_to_string(result.json)
assert random_value == value, "Data mismatch in governed map retrieval"
@mark.test_key("ETCM-10360")
def test_get_non_existent_key(self, api: BlockchainApi, genesis_utxo):
result = api.partner_chains_node.smart_contracts.governed_map.get(genesis_utxo, "non_existent_key")
assert {} == result.json
assert 0 == result.returncode
@mark.usefixtures("insert_data")
@mark.test_key("ETCM-10361")
def test_list_whole_map(self, api: BlockchainApi, genesis_utxo, random_key, random_value):
result = api.partner_chains_node.smart_contracts.governed_map.list(genesis_utxo)
expected_value = string_to_hex_bytes(random_value)
assert 0 == result.returncode
assert random_key in result.json
assert expected_value == result.json[random_key], f"Value mismatch for key {random_key} in governed map list"
@mark.staging
class TestInsertTwice:
@fixture(scope="class")
def insert_twice_with_the_same_value(self, api: BlockchainApi, insert_data, genesis_utxo, random_key, random_value, payment_key):
hex_data = string_to_hex_bytes(random_value)
result = api.partner_chains_node.smart_contracts.governed_map.insert(genesis_utxo, random_key, hex_data, payment_key)
return result
@fixture(scope="class")
def insert_twice_with_different_value(
self, api: BlockchainApi, insert_data, genesis_utxo, random_key, new_value_hex_bytes, payment_key
):
hex_data = string_to_hex_bytes(new_value_hex_bytes)
result = api.partner_chains_node.smart_contracts.governed_map.insert(genesis_utxo, random_key, hex_data, payment_key)
return result
@mark.test_key("ETCM-10362")
def test_insert_with_the_same_value(self, insert_twice_with_the_same_value):
result = insert_twice_with_the_same_value
assert 0 == result.returncode
assert {} == result.json
@mark.test_key("ETCM-10363")
def test_value_remains_the_same(
self, api: BlockchainApi, insert_twice_with_the_same_value, genesis_utxo, random_key, random_value
):
get_result = api.partner_chains_node.smart_contracts.governed_map.get(genesis_utxo, random_key)
value = hex_bytes_to_string(get_result.json)
assert random_value == value
@mark.test_key("ETCM-10364")
def test_insert_with_different_value(self, insert_twice_with_different_value):
result = insert_twice_with_different_value
assert 1 == result.returncode
assert "There is already a value stored for key" in result.stderr
@mark.test_key("ETCM-10365")
def test_value_was_not_updated(
self, api: BlockchainApi, insert_twice_with_different_value, genesis_utxo, random_key, random_value
):
get_result = api.partner_chains_node.smart_contracts.governed_map.get(genesis_utxo, random_key)
value = hex_bytes_to_string(get_result.json)
assert 0 == get_result.returncode
assert random_value == value
@mark.staging
class TestRemove:
@fixture(scope="class")
def remove_data(self, api: BlockchainApi, insert_data, genesis_utxo, random_key, payment_key):
result = api.partner_chains_node.smart_contracts.governed_map.remove(genesis_utxo, random_key, payment_key)
return result
@mark.test_key("ETCM-10366")
def test_remove_returncode(self, remove_data):
assert 0 == remove_data.returncode
@mark.test_key("ETCM-10367")
def test_get_after_remove(self, api: BlockchainApi, remove_data, genesis_utxo, random_key):
result = api.partner_chains_node.smart_contracts.governed_map.get(genesis_utxo, random_key)
assert {} == result.json
assert 0 == result.returncode
@mark.test_key("ETCM-10368")
def test_remove_non_existent_key(self, api: BlockchainApi, genesis_utxo, payment_key):
result = api.partner_chains_node.smart_contracts.governed_map.remove(genesis_utxo, "non_existent_key", payment_key)
assert 0 == result.returncode
assert {} == result.json
assert "There is no value stored for key 'non_existent_key'. Skipping remove." in result.stderr