SKALE-3951 fix getStatus, add tests

parent 6dfd5e58
...@@ -523,6 +523,24 @@ TEST_CASE_METHOD(TestFixture, "Delete Bls Key", "[delete-bls-key]") { ...@@ -523,6 +523,24 @@ TEST_CASE_METHOD(TestFixture, "Delete Bls Key", "[delete-bls-key]") {
REQUIRE(c.deleteBlsKey(name)["deleted"] == true); REQUIRE(c.deleteBlsKey(name)["deleted"] == true);
} }
TEST_CASE_METHOD(TestFixture, "Delete Bls Key Zmq", "[delete-bls-key-zmq]") {
auto client = make_shared<ZMQClient>(ZMQ_IP, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
"./sgx_data/cert_data/rootCA.key");
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);
REQUIRE(!client->importBLSKeyShare(key_str, name));
key_str = "0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f";
REQUIRE(client->importBLSKeyShare(key_str, name));
REQUIRE_NOTHROW(client->blsSignMessageHash(name, SAMPLE_HASH, 1, 1));
REQUIRE(client->deleteBLSKey(name));
}
TEST_CASE_METHOD(TestFixture, "Import ECDSA Key", "[import-ecdsa-key]") { TEST_CASE_METHOD(TestFixture, "Import ECDSA Key", "[import-ecdsa-key]") {
HttpClient client(RPC_ENDPOINT); HttpClient client(RPC_ENDPOINT);
StubClient c(client, JSONRPC_CLIENT_V2); StubClient c(client, JSONRPC_CLIENT_V2);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
Json::Value ECDSASignReqMessage::process() { Json::Value ECDSASignReqMessage::process() {
auto base = getUint64Rapid("base"); auto base = getInt64Rapid("base");
auto keyName = getStringRapid("keyName"); auto keyName = getStringRapid("keyName");
auto hash = getStringRapid("messageHash"); auto hash = getStringRapid("messageHash");
auto result = SGXWalletServer::ecdsaSignMessageHashImpl(base, keyName, hash); auto result = SGXWalletServer::ecdsaSignMessageHashImpl(base, keyName, hash);
...@@ -39,8 +39,8 @@ Json::Value ECDSASignReqMessage::process() { ...@@ -39,8 +39,8 @@ Json::Value ECDSASignReqMessage::process() {
Json::Value BLSSignReqMessage::process() { Json::Value BLSSignReqMessage::process() {
auto keyName = getStringRapid("keyShareName"); auto keyName = getStringRapid("keyShareName");
auto hash = getStringRapid("messageHash"); auto hash = getStringRapid("messageHash");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto result = SGXWalletServer::blsSignMessageHashImpl(keyName, hash, t, n); auto result = SGXWalletServer::blsSignMessageHashImpl(keyName, hash, t, n);
result["type"] = ZMQMessage::BLS_SIGN_RSP; result["type"] = ZMQMessage::BLS_SIGN_RSP;
return result; return result;
...@@ -77,7 +77,7 @@ Json::Value getPublicECDSAReqMessage::process() { ...@@ -77,7 +77,7 @@ Json::Value getPublicECDSAReqMessage::process() {
Json::Value generateDKGPolyReqMessage::process() { Json::Value generateDKGPolyReqMessage::process() {
auto polyName = getStringRapid("polyName"); auto polyName = getStringRapid("polyName");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto result = SGXWalletServer::generateDKGPolyImpl(polyName, t); auto result = SGXWalletServer::generateDKGPolyImpl(polyName, t);
result["type"] = ZMQMessage::GENERATE_DKG_POLY_RSP; result["type"] = ZMQMessage::GENERATE_DKG_POLY_RSP;
return result; return result;
...@@ -85,8 +85,8 @@ Json::Value generateDKGPolyReqMessage::process() { ...@@ -85,8 +85,8 @@ Json::Value generateDKGPolyReqMessage::process() {
Json::Value getVerificationVectorReqMessage::process() { Json::Value getVerificationVectorReqMessage::process() {
auto polyName = getStringRapid("polyName"); auto polyName = getStringRapid("polyName");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto result = SGXWalletServer::getVerificationVectorImpl(polyName, t, n); auto result = SGXWalletServer::getVerificationVectorImpl(polyName, t, n);
result["type"] = ZMQMessage::GET_VV_RSP; result["type"] = ZMQMessage::GET_VV_RSP;
return result; return result;
...@@ -94,8 +94,8 @@ Json::Value getVerificationVectorReqMessage::process() { ...@@ -94,8 +94,8 @@ Json::Value getVerificationVectorReqMessage::process() {
Json::Value getSecretShareReqMessage::process() { Json::Value getSecretShareReqMessage::process() {
auto polyName = getStringRapid("polyName"); auto polyName = getStringRapid("polyName");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto pubKeys = getJsonValueRapid("publicKeys"); auto pubKeys = getJsonValueRapid("publicKeys");
auto result = SGXWalletServer::getSecretShareV2Impl(polyName, pubKeys, t, n); auto result = SGXWalletServer::getSecretShareV2Impl(polyName, pubKeys, t, n);
result["type"] = ZMQMessage::GET_SECRET_SHARE_RSP; result["type"] = ZMQMessage::GET_SECRET_SHARE_RSP;
...@@ -104,9 +104,9 @@ Json::Value getSecretShareReqMessage::process() { ...@@ -104,9 +104,9 @@ Json::Value getSecretShareReqMessage::process() {
Json::Value dkgVerificationReqMessage::process() { Json::Value dkgVerificationReqMessage::process() {
auto ethKeyName = getStringRapid("ethKeyName"); auto ethKeyName = getStringRapid("ethKeyName");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto idx = getUint64Rapid("index"); auto idx = getInt64Rapid("index");
auto pubShares = getStringRapid("publicShares"); auto pubShares = getStringRapid("publicShares");
auto secretShare = getStringRapid("secretShare"); auto secretShare = getStringRapid("secretShare");
auto result = SGXWalletServer::dkgVerificationV2Impl(pubShares, ethKeyName, secretShare, t, n, idx); auto result = SGXWalletServer::dkgVerificationV2Impl(pubShares, ethKeyName, secretShare, t, n, idx);
...@@ -119,8 +119,8 @@ Json::Value createBLSPrivateKeyReqMessage::process() { ...@@ -119,8 +119,8 @@ Json::Value createBLSPrivateKeyReqMessage::process() {
auto ethKeyName = getStringRapid("ethKeyName"); auto ethKeyName = getStringRapid("ethKeyName");
auto polyName = getStringRapid("polyName"); auto polyName = getStringRapid("polyName");
auto secretShare = getStringRapid("secretShare"); auto secretShare = getStringRapid("secretShare");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto result = SGXWalletServer::createBLSPrivateKeyV2Impl(blsKeyName, ethKeyName, polyName, secretShare, t, n); auto result = SGXWalletServer::createBLSPrivateKeyV2Impl(blsKeyName, ethKeyName, polyName, secretShare, t, n);
result["type"] = ZMQMessage::CREATE_BLS_PRIVATE_RSP; result["type"] = ZMQMessage::CREATE_BLS_PRIVATE_RSP;
return result; return result;
...@@ -134,8 +134,8 @@ Json::Value getBLSPublicReqMessage::process() { ...@@ -134,8 +134,8 @@ Json::Value getBLSPublicReqMessage::process() {
} }
Json::Value getAllBLSPublicKeysReqMessage::process() { Json::Value getAllBLSPublicKeysReqMessage::process() {
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto pubShares = getJsonValueRapid("publicShares"); auto pubShares = getJsonValueRapid("publicShares");
auto result = SGXWalletServer::calculateAllBLSPublicKeysImpl(pubShares, t, n); auto result = SGXWalletServer::calculateAllBLSPublicKeysImpl(pubShares, t, n);
result["type"] = ZMQMessage::GET_ALL_BLS_PUBLIC_RSP; result["type"] = ZMQMessage::GET_ALL_BLS_PUBLIC_RSP;
...@@ -144,9 +144,9 @@ Json::Value getAllBLSPublicKeysReqMessage::process() { ...@@ -144,9 +144,9 @@ Json::Value getAllBLSPublicKeysReqMessage::process() {
Json::Value complaintResponseReqMessage::process() { Json::Value complaintResponseReqMessage::process() {
auto polyName = getStringRapid("polyName"); auto polyName = getStringRapid("polyName");
auto t = getUint64Rapid("t"); auto t = getInt64Rapid("t");
auto n = getUint64Rapid("n"); auto n = getInt64Rapid("n");
auto idx = getUint64Rapid("ind"); auto idx = getInt64Rapid("ind");
auto result = SGXWalletServer::complaintResponseImpl(polyName, t, n, idx); auto result = SGXWalletServer::complaintResponseImpl(polyName, t, n, idx);
result["type"] = ZMQMessage::COMPLAINT_RESPONSE_RSP; result["type"] = ZMQMessage::COMPLAINT_RESPONSE_RSP;
return result; return result;
......
...@@ -313,14 +313,14 @@ string ZMQClient::ecdsaSignMessageHash(int base, const std::string &keyName, con ...@@ -313,14 +313,14 @@ string ZMQClient::ecdsaSignMessageHash(int base, const std::string &keyName, con
return result->getSignature(); return result->getSignature();
} }
void ZMQClient::importBLSKeyShare(const std::string& keyShare, const std::string& keyName) { bool ZMQClient::importBLSKeyShare(const std::string& keyShare, const std::string& keyName) {
Json::Value p; Json::Value p;
p["type"] = ZMQMessage::IMPORT_BLS_REQ; p["type"] = ZMQMessage::IMPORT_BLS_REQ;
p["keyName"] = keyName; p["keyShareName"] = keyName;
p["keyShare"] = keyShare; p["keyShare"] = keyShare;
auto result = dynamic_pointer_cast<importBLSRspMessage>(doRequestReply(p)); auto result = dynamic_pointer_cast<importBLSRspMessage>(doRequestReply(p));
CHECK_STATE(result); CHECK_STATE(result);
CHECK_STATE(result->getStatus() == 0); return result->getStatus() == 0;
} }
string ZMQClient::importECDSAKey(const std::string& keyShare, const std::string& keyName) { string ZMQClient::importECDSAKey(const std::string& keyShare, const std::string& keyName) {
......
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
string ecdsaSignMessageHash(int base, const std::string &keyName, const std::string &messageHash); string ecdsaSignMessageHash(int base, const std::string &keyName, const std::string &messageHash);
void importBLSKeyShare(const std::string& keyShare, const std::string& keyName); bool importBLSKeyShare(const std::string& keyShare, const std::string& keyName);
string importECDSAKey(const std::string& keyShare, const std::string& keyName); string importECDSAKey(const std::string& keyShare, const std::string& keyName);
......
...@@ -34,12 +34,12 @@ ...@@ -34,12 +34,12 @@
#include "ZMQMessage.h" #include "ZMQMessage.h"
uint64_t ZMQMessage::getUint64Rapid(const char *_name) { uint64_t ZMQMessage::getInt64Rapid(const char *_name) {
CHECK_STATE(_name); CHECK_STATE(_name);
CHECK_STATE(d->HasMember(_name)); CHECK_STATE(d->HasMember(_name));
const rapidjson::Value &a = (*d)[_name]; const rapidjson::Value &a = (*d)[_name];
CHECK_STATE(a.IsUint64()); CHECK_STATE(a.IsInt64());
return a.GetUint64(); return a.GetInt64();
}; };
Json::Value ZMQMessage::getJsonValueRapid(const char *_name) { Json::Value ZMQMessage::getJsonValueRapid(const char *_name) {
......
...@@ -108,14 +108,22 @@ public: ...@@ -108,14 +108,22 @@ public:
string getStringRapid(const char *_name); string getStringRapid(const char *_name);
uint64_t getUint64Rapid(const char *_name); uint64_t getInt64Rapid(const char *_name);
Json::Value getJsonValueRapid(const char *_name); Json::Value getJsonValueRapid(const char *_name);
bool getBoolRapid(const char *_name); bool getBoolRapid(const char *_name);
uint64_t getStatus() { uint64_t getStatus() {
return getUint64Rapid("status"); return getInt64Rapid("status");
}
std::string rapidToString() {
rapidjson::StringBuffer buffer;
rapidjson::Writer< rapidjson::StringBuffer > writer( buffer );
d->Accept( writer );
std::string strRequest = buffer.GetString();
return strRequest;
} }
static shared_ptr <ZMQMessage> parse(const char* _msg, size_t _size, bool _isRequest, static shared_ptr <ZMQMessage> parse(const char* _msg, size_t _size, bool _isRequest,
......
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