github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/test/crypto/gtest_hash.cpp (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  #include "crypto/hash.h"
    21  #include <gtest/gtest.h>
    22  
    23  TEST(test_sha3_hash, simple) {
    24    std::unordered_map<std::string, neb::crypto::sha3_256_hash_t> test_hashs;
    25    test_hashs.insert(std::make_pair(
    26        "", neb::crypto::sha3_256_hash_t(
    27                {167, 255, 198, 248, 191, 30,  215, 102, 81, 193, 71,
    28                 86,  160, 97,  214, 98,  245, 128, 255, 77, 228, 59,
    29                 73,  250, 130, 216, 10,  75,  128, 248, 67, 74})));
    30    test_hashs.insert(std::make_pair(
    31        "Hello, world", neb::crypto::sha3_256_hash_t(
    32                            {53,  80, 171, 169, 116, 146, 222, 56,  175, 48,  102,
    33                             240, 21, 127, 197, 50,  219, 103, 145, 179, 125, 83,
    34                             38,  44, 231, 104, 141, 204, 93,  70,  24,  86})));
    35    test_hashs.insert(
    36        std::make_pair("https://nebulas.io",
    37                       neb::crypto::sha3_256_hash_t(
    38                           {94,  159, 238, 157, 152, 227, 18, 248, 53,  8,  13,
    39                            247, 231, 21,  17,  14,  172, 34, 192, 157, 24, 175,
    40                            119, 254, 126, 208, 174, 17,  14, 77,  1,   55})));
    41  
    42    for (auto it : test_hashs) {
    43      auto r = neb::crypto::sha3_256_hash(it.first);
    44      EXPECT_TRUE(r == it.second);
    45    }
    46  }