diff --git a/LevelDB.cpp b/LevelDB.cpp index a3bdf1cb755288ec5a9b8a7c8468ca6ea76dc6ff..1468f93a8c82dc242f2109e46967c644d5d97cc0 100644 --- a/LevelDB.cpp +++ b/LevelDB.cpp @@ -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; } diff --git a/SGXWalletServer.cpp b/SGXWalletServer.cpp index b8748653490c20d75c1843d91db12d62d1323dc4..baf70925ffe5619a5febe6ad7e505b3799c4b175 100644 --- a/SGXWalletServer.cpp +++ b/SGXWalletServer.cpp @@ -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; diff --git a/TestUtils.cpp b/TestUtils.cpp index facbb29a41d27042c24f3a5b57eaa223de93d538..5569c5a760e32120c55285e14fbff719d4732852 100644 --- a/TestUtils.cpp +++ b/TestUtils.cpp @@ -424,4 +424,4 @@ void TestUtils::doDKG(StubClient &c, int n, int t, cerr << i << endl; -} \ No newline at end of file +} diff --git a/testw.cpp b/testw.cpp index 92d62eae01c80f8be60fc80678349127934593bc..b8254fe52748ceddf9bf6c0552b055d1c9af7ab7 100644 --- a/testw.cpp +++ b/testw.cpp @@ -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]") { diff --git a/testw.py b/testw.py index 6aeaa532ba731c5b767b65b909f62e5e607abf6c..1d52376849913fdb35e3a4287fa79c4bfe5e36c0 100755 --- a/testw.py +++ b/testw.py @@ -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]",