feat(base58): unfixed bug with double \0 and incorrect real str_size

This commit is contained in:
2024-09-19 01:50:32 +03:00
parent f2119850ee
commit 817f6c4fb1
8 changed files with 172 additions and 61 deletions

35
test/test-base58.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <utility>
#include <base/base58.hpp>
#include <base/hex.hpp>
#include <gtest/gtest.h>
using namespace base58;
std::pair<std::string, std::string> test = {
"003812e515df45235c6bcc2233ac9d0c4ebbd781de",
"167VUagc755PbQoB7cCTfTPjbQ5Nk6fEuD",
};
TEST(base58, encodeCheck)
{
EXPECT_EQ(encodeCheck(hex::decode(test.first)), test.second);
}
TEST(base58, decodeCheck)
{
EXPECT_EQ(test.first, hex::encode(decodeCheck(test.second)));
try
{
decodeCheck("incorrect");
}
catch (const std::exception &e)
{
EXPECT_STREQ(e.what(), "base58::decodeCheck: checksum incorrect");
}
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}