/* * This file is part of the Monero P2Pool * Copyright (c) 2021-2024 SChernykh * Copyright (c) 2026 jpk68 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "common.h" #include "i2p.h" #include "gtest/gtest.h" namespace p2pool { TEST(i2p, decode_encode) { const hash expected{ 0xad, 0xcc, 0x78, 0x7e, 0x8e, 0x46, 0xd9, 0xd4, 0xd2, 0xa5, 0x56, 0x9d, 0x36, 0x5d, 0x67, 0xe4, 0x0f, 0x60, 0xf3, 0x57, 0x18, 0x71, 0x32, 0x1e, 0x60, 0x3c, 0x08, 0xa9, 0x38, 0x4b, 0x11, 0x27 }; const std::string addr1 = "vxghq7uoi3m5juvfk2otmxlh4qhwb42xdbytehtahqeksoclcetq.b32.i2p"; const hash result1 = from_i2p_b32(addr1); EXPECT_EQ(result1, expected); EXPECT_EQ(to_i2p_b32(result1), addr1); // Uppercase const std::string addr2 = "VXGHQ7uoi3m5juvfk2otmxlh4qhwb42xdbytehtahqeksoclcetq.b32.i2p"; EXPECT_EQ(from_i2p_b32(addr2), expected); // Invalid character const std::string addr3 = "1xghq7uoi3m5juvfk2otmxlh4qhwb42xdbytehtahqeksoclcetq.b32.i2p"; EXPECT_EQ(from_i2p_b32(addr3), hash()); // Too short EXPECT_EQ(from_i2p_b32(""), hash()); // No suffix EXPECT_EQ(from_i2p_b32("vxghq7uoi3m5juvfk2otmxlh4qhwb42xdbytehtahqeksoclcetq"), hash()); // Too long EXPECT_EQ(from_i2p_b32("vxghq7uoi3m5juvfk2otmxlh4qhwb42xdbytehtahqeksoclcetq2.b32.i2p"), hash()); } } // namespace p2pool