diff options
Diffstat (limited to 'tde2e')
| -rw-r--r-- | tde2e/td/e2e/Call.cpp | 9 | ||||
| -rw-r--r-- | tde2e/td/e2e/e2e_errors.h | 5 | ||||
| -rw-r--r-- | tde2e/test/e2e.cpp | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/tde2e/td/e2e/Call.cpp b/tde2e/td/e2e/Call.cpp index c467329c8..dca0e3459 100644 --- a/tde2e/td/e2e/Call.cpp +++ b/tde2e/td/e2e/Call.cpp @@ -571,6 +571,15 @@ td::Result<std::string> Call::create_self_add_block(const PrivateKey &private_ke } td::Result<Call> Call::create(td::int64 user_id, PrivateKey private_key, td::Slice last_block_server) { + { + // Forbid creating multiple calls with the same key + static std::mutex mutex; + static td::FlatHashSet<td::UInt256, UInt256Hash> public_keys; + std::lock_guard<std::mutex> lock(mutex); + if (!public_keys.insert(private_key.to_public_key().to_u256()).second) { + return Error(E::CallKeyAlreadyUsed); + } + } TRY_RESULT(last_block, Blockchain::from_server_to_local(last_block_server.str())); TRY_RESULT(blockchain, ClientBlockchain::create_from_block(last_block, private_key.to_public_key())); auto call = Call(user_id, std::move(private_key), std::move(blockchain)); diff --git a/tde2e/td/e2e/e2e_errors.h b/tde2e/td/e2e/e2e_errors.h index 686311418..d1168ef18 100644 --- a/tde2e/td/e2e/e2e_errors.h +++ b/tde2e/td/e2e/e2e_errors.h @@ -37,7 +37,8 @@ enum class ErrorCode : int { InvalidBroadcast_InvalidReveal = 505, InvalidBroadcast_InvalidBlockHash = 506, InvalidCallChannelId = 600, - CallFailed = 601 + CallFailed = 601, + CallKeyAlreadyUsed = 602 }; inline std::string_view error_string(ErrorCode error_code) { switch (error_code) { @@ -93,6 +94,8 @@ inline std::string_view error_string(ErrorCode error_code) { return "INVALID_BROADCAST__INVALID_BLOCK_HASH"; case ErrorCode::CallFailed: return "CALL_FAILED"; + case ErrorCode::CallKeyAlreadyUsed: + return "CALL_KEY_ALREADY_USED"; case ErrorCode::InvalidCallChannelId: return "INVALID_CALL_CHANNEL_ID"; } diff --git a/tde2e/test/e2e.cpp b/tde2e/test/e2e.cpp index 6ad625d06..808a776f7 100644 --- a/tde2e/test/e2e.cpp +++ b/tde2e/test/e2e.cpp @@ -736,6 +736,7 @@ TEST(Call, Basic_API) { auto zero_block = F(call_create_zero_block(key0, CallState{0, {CallParticipant{-1, pkey0, 3}}})).value(); auto call1 = call_create(-1, key0, zero_block).value(); + ASSERT_TRUE(!call_create(-1, key0, zero_block).is_ok()); auto block0 = F(call_create_self_add_block(key1, zero_block, CallParticipant{1, pkey1, 3})).value(); call1 = call_create(1, key1, block0).value(); |
