SKALE-2844 add test for deleting bls key

parent 53b3e091
......@@ -53,14 +53,15 @@ std::shared_ptr<string> LevelDB::readString(const string &_key) {
throw SGXException(NULL_DATABASE, "Null db");
}
auto status = db->Get(readOptions, _key, &*result);
spdlog::info("key to read from db: {}",_key );
spdlog::debug("key to read from db: {}",_key );
auto status = db->Get(readOptions, _key, &*result);
throwExceptionOnError(status);
if (status.IsNotFound())
if (status.IsNotFound()) {
return nullptr;
}
return result;
}
......
......@@ -667,14 +667,18 @@ Json::Value SGXWalletServer::deleteBlsKeyImpl(const std::string& name) {
result["deleted"] = false;
try {
if (!checkName(name, "BLS_KEY")) {
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name");
throw SGXException(INVALID_BLS_NAME, "Invalid BLSKey name format");
}
std::shared_ptr <std::string> bls_ptr = LevelDB::getLevelDb()->readString(name);
std::string key = "BLSKEYSHARE:" + name;
std::shared_ptr <std::string> bls_ptr = LevelDB::getLevelDb()->readString(key);
if (bls_ptr != nullptr) {
result["deleted"] = true;
return result;
}
} else {
std::string error_msg = "BLS key with such name not found: " + name;
throw SGXException(INVALID_BLS_NAME, error_msg.c_str());
}
LevelDB::getLevelDb()->deleteKey(name);
} HANDLE_SGX_EXCEPTION(result)
return result;
......
......@@ -424,4 +424,4 @@ void TestUtils::doDKG(StubClient &c, int n, int t,
cerr << i << endl;
}
\ No newline at end of file
}
......@@ -573,11 +573,17 @@ TEST_CASE_METHOD(TestFixture, "DKG_BLS test", "[dkg-bls]") {
dkgID = TestUtils::randGen();
TestUtils::doDKG(c, 16, 5, ecdsaKeyNames, blsKeyNames, schainID, dkgID);
}
for (const auto& name : blsKeyNames) {
REQUIRE(c.deleteBlsKey(name)["deleted"] == true);
}
TEST_CASE_METHOD(TestFixture, "Delete Bls Key", "[delete-bls-key]") {
HttpClient client(RPC_ENDPOINT);
StubClient c(client, JSONRPC_CLIENT_V2);
std::string name = "BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0";
libff::alt_bn128_Fr key = libff::alt_bn128_Fr("6507625568967977077291849236396320012317305261598035438182864059942098934847");
std::string key_str = TestUtils::stringFromFr(key);
c.importBLSKeyShare(key_str, name, 1, 2, 1);
REQUIRE(c.deleteBlsKey(name)["deleted"] == true);
}
TEST_CASE_METHOD(TestFixture, "Backup Key", "[backup-key]") {
......
......@@ -33,6 +33,7 @@ testList = [ "[cert-sign]",
"[get-server-status]",
"[get-server-version]",
"[backup-key]",
"[delete-bls-key]",
"[ecdsa-key-gen]",
"[ecdsa-aes-key-gen]",
"[ecdsa-key-sig-gen]",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment