|
|
|
@ -16,15 +16,91 @@ import re
@@ -16,15 +16,91 @@ import re
|
|
|
|
|
class KevaTest(BitcoinTestFramework): |
|
|
|
|
def set_test_params(self): |
|
|
|
|
self.setup_clean_chain = True |
|
|
|
|
self.num_nodes = 3 |
|
|
|
|
self.num_nodes = 2 |
|
|
|
|
|
|
|
|
|
def setup_network(self): |
|
|
|
|
super().setup_network() |
|
|
|
|
connect_nodes(self.nodes[0], 2) |
|
|
|
|
connect_nodes_bi(self.nodes, 0, 1) |
|
|
|
|
self.sync_all() |
|
|
|
|
|
|
|
|
|
def run_unconfirmed_namespaces(self): |
|
|
|
|
self.sync_all() |
|
|
|
|
response = self.nodes[1].keva_namespace('second_namespace') |
|
|
|
|
namespaceId = response['namespaceId'] |
|
|
|
|
response = self.nodes[1].keva_list_namespaces() |
|
|
|
|
# Node 0's unconfirmed namespace should not be here |
|
|
|
|
assert(len(response) == 1) |
|
|
|
|
|
|
|
|
|
# Node 0's unconfirmed operations should not be here |
|
|
|
|
self.nodes[1].keva_put(namespaceId, 'second_key', 'second_value') |
|
|
|
|
response = self.nodes[1].keva_pending() |
|
|
|
|
# Pending namespace and put operation. |
|
|
|
|
assert(len(response) == 2) |
|
|
|
|
self.sync_all() |
|
|
|
|
|
|
|
|
|
def run_test_disconnect_block(self, namespaceId): |
|
|
|
|
key = 'This is the test key' |
|
|
|
|
value = 'This is the test value' |
|
|
|
|
self.nodes[0].keva_put(namespaceId, key, value) |
|
|
|
|
self.nodes[0].generate(1) |
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, key) |
|
|
|
|
assert(response['value'] == value) |
|
|
|
|
# Disconnect the block |
|
|
|
|
self.sync_all() |
|
|
|
|
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) |
|
|
|
|
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) |
|
|
|
|
self.sync_all() |
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, key) |
|
|
|
|
assert(response['value'] == '') |
|
|
|
|
|
|
|
|
|
self.log.info("Test undeleting after disconnecting blocks") |
|
|
|
|
keyToDelete = 'This is the test key to delete' |
|
|
|
|
valueToDelete = 'This is the test value of the key' |
|
|
|
|
self.nodes[0].keva_put(namespaceId, keyToDelete, valueToDelete) |
|
|
|
|
self.nodes[0].generate(1) |
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, keyToDelete) |
|
|
|
|
assert(response['value'] == valueToDelete) |
|
|
|
|
# Now delete the key |
|
|
|
|
self.nodes[0].keva_delete(namespaceId, keyToDelete) |
|
|
|
|
self.nodes[0].generate(1) |
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, keyToDelete) |
|
|
|
|
assert(response['value'] == '') |
|
|
|
|
# Disconnect the block |
|
|
|
|
self.sync_all() |
|
|
|
|
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) |
|
|
|
|
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) |
|
|
|
|
self.sync_all() |
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, keyToDelete) |
|
|
|
|
# The value should be undeleted. |
|
|
|
|
assert(response['value'] == valueToDelete) |
|
|
|
|
|
|
|
|
|
self.log.info("Test namespace after disconnecting blocks") |
|
|
|
|
displayName = 'A new namspace' |
|
|
|
|
response = self.nodes[0].keva_namespace(displayName) |
|
|
|
|
newNamespaceId = response['namespaceId'] |
|
|
|
|
self.nodes[0].generate(1) |
|
|
|
|
response = self.nodes[0].keva_list_namespaces() |
|
|
|
|
found = False |
|
|
|
|
print(response) |
|
|
|
|
for ns in response: |
|
|
|
|
if (ns['namespaceId'] == newNamespaceId): |
|
|
|
|
found = True |
|
|
|
|
assert(found) |
|
|
|
|
# Now disconnect the block and the namespace should be gone. |
|
|
|
|
self.sync_all() |
|
|
|
|
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) |
|
|
|
|
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) |
|
|
|
|
self.sync_all() |
|
|
|
|
found = False |
|
|
|
|
for ns in response: |
|
|
|
|
if (ns['namespaceId'] == newNamespaceId): |
|
|
|
|
found = True |
|
|
|
|
assert(not found) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_test(self): |
|
|
|
|
self.nodes[0].generate(161) #block 161 |
|
|
|
|
self.nodes[0].generate(105) |
|
|
|
|
self.nodes[1].generate(105) |
|
|
|
|
response = self.nodes[0].keva_namespace('first_namespace') |
|
|
|
|
namespaceId = response['namespaceId'] |
|
|
|
|
|
|
|
|
@ -38,6 +114,9 @@ class KevaTest(BitcoinTestFramework):
@@ -38,6 +114,9 @@ class KevaTest(BitcoinTestFramework):
|
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, key) |
|
|
|
|
assert(response['value'] == value) |
|
|
|
|
|
|
|
|
|
self.log.info("Test other wallet's unconfirmed namespaces do not show up in ours") |
|
|
|
|
self.run_unconfirmed_namespaces() |
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(1) |
|
|
|
|
response = self.nodes[0].keva_pending() |
|
|
|
|
assert(len(response) == 0) |
|
|
|
@ -99,5 +178,9 @@ class KevaTest(BitcoinTestFramework):
@@ -99,5 +178,9 @@ class KevaTest(BitcoinTestFramework):
|
|
|
|
|
response = self.nodes[0].keva_get(namespaceId, keyToDelete) |
|
|
|
|
assert(response['value'] == newValue) |
|
|
|
|
|
|
|
|
|
self.log.info("Test disconnecting blocks") |
|
|
|
|
self.run_test_disconnect_block(namespaceId) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
KevaTest().main() |
|
|
|
|