mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-13 00:28:03 +00:00
Added block disconnecting test cases for keva.
This commit is contained in:
parent
1aa9fbd044
commit
1e187fea9d
@ -293,7 +293,7 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(tx.IsKevacoin ());
|
||||
assert(tx.IsKevacoin());
|
||||
if (nameOut == -1) {
|
||||
return state.Invalid (error ("%s: Kevacoin tx %s has no keva outputs", __func__, txid));
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
|
||||
"\nArguments:\n"
|
||||
"\nResult:\n"
|
||||
"[\n"
|
||||
" xxxxx: display_name (string) namespace id : (string) display name\n"
|
||||
" { namespaceId: <namespce Id>, displayName: <display name> }\n"
|
||||
" ...\n"
|
||||
"]\n"
|
||||
"\nExamples:\n"
|
||||
@ -133,28 +133,26 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
|
||||
|
||||
std::map<std::string, std::string> mapObjects;
|
||||
{
|
||||
LOCK2 (cs_main, pwallet->cs_wallet);
|
||||
for (const auto& item : pwallet->mapWallet)
|
||||
{
|
||||
LOCK2 (cs_main, pwallet->cs_wallet);
|
||||
for (const auto& item : pwallet->mapWallet) {
|
||||
const CWalletTx& tx = item.second;
|
||||
if (!tx.tx->IsKevacoin ())
|
||||
if (!tx.tx->IsKevacoin()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CKevaScript kevaOp;
|
||||
int nOut = -1;
|
||||
for (unsigned i = 0; i < tx.tx->vout.size(); ++i)
|
||||
{
|
||||
const CKevaScript cur(tx.tx->vout[i].scriptPubKey);
|
||||
if (cur.isKevaOp ())
|
||||
{
|
||||
if (nOut != -1) {
|
||||
LogPrintf ("ERROR: wallet contains tx with multiple name outputs");
|
||||
} else {
|
||||
kevaOp = cur;
|
||||
nOut = i;
|
||||
}
|
||||
}
|
||||
for (unsigned i = 0; i < tx.tx->vout.size(); ++i) {
|
||||
const CKevaScript cur(tx.tx->vout[i].scriptPubKey);
|
||||
if (cur.isKevaOp()) {
|
||||
if (nOut != -1) {
|
||||
LogPrintf ("ERROR: wallet contains tx with multiple name outputs");
|
||||
} else {
|
||||
kevaOp = cur;
|
||||
nOut = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nOut == -1) {
|
||||
continue;
|
||||
@ -172,7 +170,7 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
|
||||
continue;
|
||||
}
|
||||
|
||||
const bool mine = IsMine(*pwallet, kevaOp.getAddress ());
|
||||
const bool mine = IsMine(*pwallet, kevaOp.getAddress());
|
||||
CKevaData data;
|
||||
if (mine && pcoinsTip->GetNamespace(nameSpace, data)) {
|
||||
std::string displayName = ValtypeToString(data.getValue());
|
||||
|
@ -38,22 +38,42 @@ class KevaTest(BitcoinTestFramework):
|
||||
assert(len(response) == 2)
|
||||
self.sync_all()
|
||||
|
||||
def run_test_disconnect_block(self, namespaceId):
|
||||
def run_test_disconnect_block(self):
|
||||
displayName = 'namespace_to_test'
|
||||
response = self.nodes[0].keva_namespace(displayName)
|
||||
namespaceId = response['namespaceId']
|
||||
self.nodes[0].generate(1)
|
||||
|
||||
key = 'This is the test key'
|
||||
value = 'This is the test value'
|
||||
self.nodes[0].keva_put(namespaceId, key, value)
|
||||
value1 = 'This is the test value 1'
|
||||
value2 = 'This is the test value 1'
|
||||
self.nodes[0].keva_put(namespaceId, key, value1)
|
||||
self.nodes[0].generate(1)
|
||||
response = self.nodes[0].keva_get(namespaceId, key)
|
||||
assert(response['value'] == value)
|
||||
assert(response['value'] == value1)
|
||||
self.nodes[0].keva_put(namespaceId, key, value2)
|
||||
self.nodes[0].generate(1)
|
||||
response = self.nodes[0].keva_get(namespaceId, key)
|
||||
assert(response['value'] == value2)
|
||||
# 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'] == value1)
|
||||
# Disconnect the block again
|
||||
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'] == '')
|
||||
response = self.nodes[0].keva_get(namespaceId, '_KEVA_NS_')
|
||||
assert(response['value'] == displayName)
|
||||
|
||||
self.log.info("Test undeleting after disconnecting blocks")
|
||||
self.nodes[0].generate(1)
|
||||
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)
|
||||
@ -81,7 +101,6 @@ class KevaTest(BitcoinTestFramework):
|
||||
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
|
||||
@ -91,6 +110,11 @@ class KevaTest(BitcoinTestFramework):
|
||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
|
||||
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
|
||||
self.sync_all()
|
||||
# The namespace display name should not be set.
|
||||
response = self.nodes[0].keva_get(newNamespaceId, '_KEVA_NS_')
|
||||
assert(response['value'] == '')
|
||||
# The namespace should not appear in the result of keva_list_namespaces
|
||||
response = self.nodes[0].keva_list_namespaces()
|
||||
found = False
|
||||
for ns in response:
|
||||
if (ns['namespaceId'] == newNamespaceId):
|
||||
@ -179,7 +203,7 @@ class KevaTest(BitcoinTestFramework):
|
||||
assert(response['value'] == newValue)
|
||||
|
||||
self.log.info("Test disconnecting blocks")
|
||||
self.run_test_disconnect_block(namespaceId)
|
||||
self.run_test_disconnect_block()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user