diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c07706c..7c2fe8b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,7 @@ set(TEST_SRC # WIF WIF/priv_encode.cpp WIF/priv_decode.cpp + WIF/pub_encode.cpp ) add_executable(doctest ${TEST_SRC}) diff --git a/tests/WIF/pub_encode.cpp b/tests/WIF/pub_encode.cpp new file mode 100644 index 0000000..cb6d627 --- /dev/null +++ b/tests/WIF/pub_encode.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + +TEST_CASE("WIF::wif_pub_encode") { + struct testcase { + std::string name; + libeosio::ec_pubkey_t key; + std::string expected; + }; + + std::vector tests { + { "one", { 0x03, 0x7a, 0x0e, 0x6b, 0xfd, 0xe4, 0xf1, 0xad, 0x36, 0x3f, 0x3a, 0xf9, 0xe0, 0x93, 0x63, 0x5a, 0xa9, 0x99, 0x21, 0x15, 0xbc, 0x23, 0x35, 0x75, 0x13, 0x69, 0x55, 0xee, 0x3f, 0xf8, 0xfd, 0x97, 0xec }, "EOS7kzJ5iFBmQWWT1LiWgAiocESD7TTNuuPCdYREUQysruq8VeFKy" }, + { "two", { 0x02, 0x5e, 0x94, 0xa5, 0xe7, 0x9f, 0x66, 0x37, 0x55, 0x7e, 0xc2, 0x28, 0x30, 0x40, 0x82, 0x9a, 0x38, 0x72, 0x10, 0x96, 0x6e, 0x15, 0xb7, 0xa5, 0x8a, 0x27, 0x9a, 0x71, 0x06, 0xa7, 0x64, 0x23, 0x30 }, "EOS5c9HkNCJLDebe2Wvapp8bpB38Pf1QWNpkrsFy3mshg7DZfPNeA" }, + { "three", { 0x03, 0xd4, 0xc6, 0x2a, 0xdc, 0x11, 0x1c, 0x65, 0x7a, 0x9f, 0x5b, 0xba, 0x96, 0x3f, 0xbb, 0x2a, 0x69, 0x2e, 0xc5, 0x4a, 0x48, 0x3b, 0xa3, 0x5f, 0x2a, 0x37, 0x6c, 0x59, 0x95, 0xb1, 0x95, 0x1c, 0xc9 }, "EOS8SwZMY8DChbbmRKS3wdHCAbv1VWgTRmQEDSaLyJk8pG4wm8BJF" } + }; + + for(auto it = tests.begin(); it != tests.end(); it++) { + + SUBCASE(it->name.c_str()) { + CHECK( libeosio::wif_pub_encode(it->key) == it->expected ); + } + } +} + + +TEST_CASE("WIF::wif_pub_encode [prefix]") { + + struct testcase { + std::string name; + libeosio::ec_pubkey_t key; + std::string expected; + }; + + std::vector tests { + { "one", { 0x03, 0xfc, 0xcc, 0xcb, 0x20, 0x5a, 0x04, 0xfe, 0x34, 0x25, 0x1f, 0x1e, 0x75, 0x82, 0x85, 0x13, 0xed, 0xda, 0x6f, 0x33, 0xba, 0xf4, 0xeb, 0xc7, 0x4d, 0xc4, 0xa6, 0xe8, 0x91, 0x4a, 0xf6, 0x81, 0x43 }, "ZYX8kZxzEW6Loj9Nc3SUcHdS1TMH1zfu4JFu239Af1W3dXrA6GfHG" }, + { "two", { 0x02, 0x8c, 0x58, 0xcb, 0xd4, 0xa4, 0xef, 0x23, 0xc3, 0xb8, 0x0e, 0x8f, 0xff, 0xe3, 0x4e, 0xe0, 0x1b, 0x64, 0x98, 0xe2, 0x12, 0xc9, 0xda, 0xbd, 0xee, 0x70, 0x7c, 0xf6, 0x6b, 0x2a, 0x15, 0x77, 0x06 }, "ZYX5xJKrJnDZQMzRZEzpm34g3MZxa93sANF5G1m9SnKH5gk7BCmAE" }, + { "three", { 0x03, 0xa2, 0xea, 0xad, 0x09, 0x3e, 0x34, 0x31, 0x04, 0xa3, 0x7a, 0xc0, 0x10, 0x29, 0x5d, 0xce, 0x41, 0xb3, 0x60, 0x3a, 0x2d, 0x21, 0xd9, 0x44, 0x0f, 0x7b, 0x4c, 0xad, 0xad, 0x7e, 0x4f, 0x73, 0x78 }, "ZYX84z22iUYZ4tUfNDh8WNvL9wtfMn1mDtYpdezp2v73qcpLTVesz" } + }; + + for(auto it = tests.begin(); it != tests.end(); it++) { + + SUBCASE(it->name.c_str()) { + CHECK( libeosio::wif_pub_encode(it->key, "ZYX") == it->expected ); + } + } +}