diff --git a/tests/chains/Agoric/AddressTests.cpp b/tests/chains/Agoric/AddressTests.cpp deleted file mode 100644 index 636faa3ab65..00000000000 --- a/tests/chains/Agoric/AddressTests.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "HexCoding.h" -#include "Cosmos/Address.h" -#include "PublicKey.h" -#include "PrivateKey.h" -#include -#include - -namespace TW::Cosmos::tests { - -TEST(AgoricAddress, Valid) { - ASSERT_TRUE(Address::isValid(TWCoinTypeSecret, "secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf")); - ASSERT_TRUE(Address::isValid(TWCoinTypeSecret, "secret15rgv8teecnt53h0gdvngzt3am3yuz3rxh4fnle")); -} - -TEST(AgoricAddress, Invalid) { - ASSERT_FALSE(Address::isValid(TWCoinTypeAgoric, "agoric1cqvwa8jr6pmt45jndanc8lqmdsxjkhw0yert212")); - ASSERT_FALSE(Address::isValid(TWCoinTypeAgoric, "osmo1nvt7lu3e0l8wqahlya6m98zmma6qc9r40evp0v")); -} - -TEST(AgoricAddress, FromPrivateKey) { - auto privateKey = PrivateKey(parse_hex("037048190544fa57651452f477c096de4f3073e7835cf3845b04602563a73f73")); - auto address = Address(TWCoinTypeAgoric, privateKey.getPublicKey(TWPublicKeyTypeSECP256k1)); - ASSERT_EQ(address.string(), "agoric18zvvgk6j3eq5wd7mqxccgt20gz2w94cy88aek5"); -} - -TEST(AgoricAddress, FromPublicKey) { - auto publicKey = PublicKey(parse_hex("03df9a5e4089f89d45913fb2b856de984c7e8bf1344cc6444cc9705899a48c939d"), TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeAgoric, publicKey); - ASSERT_EQ(address.string(), "agoric18zvvgk6j3eq5wd7mqxccgt20gz2w94cy88aek5"); -} - -TEST(AgoricAddress, FromString) { - Address address; - EXPECT_TRUE(Address::decode("agoric18zvvgk6j3eq5wd7mqxccgt20gz2w94cy88aek5", address)); - EXPECT_EQ(address.string(), "agoric18zvvgk6j3eq5wd7mqxccgt20gz2w94cy88aek5"); -} -} diff --git a/tests/chains/Axelar/TWAnyAddressTests.cpp b/tests/chains/Axelar/TWAnyAddressTests.cpp deleted file mode 100644 index b02f46e99dc..00000000000 --- a/tests/chains/Axelar/TWAnyAddressTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include -#include "PublicKey.h" -#include "Bech32Address.h" -#include "HexCoding.h" -#include "Hash.h" -#include "PublicKey.h" -#include "Bech32Address.h" - -#include "TestUtilities.h" -#include - -namespace TW::Cosmos::tests { - -TEST(TWAxelarAnyAddress, IsValid) { - EXPECT_TRUE(TWAnyAddressIsValidBech32(STRING("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5").get(), TWCoinTypeCosmos, STRING("axelar").get())); - EXPECT_TRUE(TWAnyAddressIsValid(STRING("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5").get(), TWCoinTypeAxelar)); - EXPECT_FALSE(TWAnyAddressIsValidBech32(STRING("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5").get(), TWCoinTypeBitcoin, STRING("axelar").get())); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5").get(), TWCoinTypeCosmos)); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5").get(), TWCoinTypeBitcoin)); -} - -TEST(TWAxelarAnyAddress, createFromPubKeyAxelar) { - const auto hrp = STRING("axelar"); - const auto data = DATA("02cbfdb5e472893322294e60cf0883d43df431e1089d29ecb447a9e6d55045aae5"); - const auto pubkey = TWPublicKeyCreateWithData(data.get(), TWPublicKeyTypeSECP256k1); - const auto twAddress = TWAnyAddressCreateBech32WithPublicKey(pubkey, TWCoinTypeCosmos, hrp.get()); - auto twData = TWAnyAddressData(twAddress); - auto hexData = hex(*reinterpret_cast(twData)); - ASSERT_EQ(hexData, "d8c95f06c8ed16d8397fe11fb3af30f87bfb340f"); - ASSERT_EQ(hex(Bech32Address("axelar", TW::Hash::HasherSha256ripemd, pubkey->impl).getKeyHash()), hexData); - auto address = TWAnyAddressDescription(twAddress); - EXPECT_EQ("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5", *reinterpret_cast(address)); - TWStringDelete(address); - TWAnyAddressDelete(twAddress); - TWDataDelete(twData); - TWPublicKeyDelete(pubkey); -} - -TEST(TWAxelarAnyAddress, createFromStringAxelar) { - const auto AxelarAddress = STRING("axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5"); - const auto hrp = STRING("axelar"); - const auto anyAddr = TWAnyAddressCreateBech32(AxelarAddress.get(), TWCoinTypeCosmos, hrp.get()); - const auto addrDescription = TWAnyAddressDescription(anyAddr); - ASSERT_TRUE(TWAnyAddressIsValidBech32(addrDescription, TWCoinTypeCosmos, hrp.get())); - TWStringDelete(addrDescription); - TWAnyAddressDelete(anyAddr); -} - -} diff --git a/tests/chains/Cosmos/Agoric/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Agoric/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..5c536171324 --- /dev/null +++ b/tests/chains/Cosmos/Agoric/TWAnyAddressTests.cpp @@ -0,0 +1,23 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gAgoricAddr = "agoric1wu32wujsvz290sasq308fswznx77nk9k0cxqwg"; +static const std::string gAgoricHrp = "agoric"; + +TEST(TWAgoricAnyAddress, AllAgoricAddressTests) { + CosmosAddressParameters parameters{.hrp = gAgoricHrp, + .coinType = TWCoinTypeAgoric, + .address = gAgoricAddr, + .privKey = "9457d0a4b7bdfe23528af07603af0f7d0ac0c510526da7721abefdc3948461f6", + .publicKey = "03602731bc2f787eec358c1ba8ddb8e7c7720f56a0406b8d16e20c93b822953960"}; + TestCosmosAddressParameters(parameters); +} + +} // namespace TW::Cosmos::tests diff --git a/tests/chains/Agoric/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Agoric/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Agoric/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Agoric/TWCoinTypeTests.cpp diff --git a/tests/chains/Cosmos/Axelar/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Axelar/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..0dd526419d0 --- /dev/null +++ b/tests/chains/Cosmos/Axelar/TWAnyAddressTests.cpp @@ -0,0 +1,19 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gAxelarAddr = "axelar1mry47pkga5tdswtluy0m8teslpalkdq060xxh5"; +static const std::string gAxelarHrp = "axelar"; + +TEST(TWAxelarAnyAddress, AllAxelarAddressTests) { + CosmosAddressParameters parameters{.hrp = gAxelarHrp, .coinType = TWCoinTypeAxelar, .address = gAxelarAddr}; + TestCosmosAddressParameters(parameters); +} + +} diff --git a/tests/chains/Axelar/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Axelar/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Axelar/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Axelar/TWCoinTypeTests.cpp diff --git a/tests/chains/BandChain/TWCoinTypeTests.cpp b/tests/chains/Cosmos/BandChain/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/BandChain/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/BandChain/TWCoinTypeTests.cpp diff --git a/tests/chains/Bluzelle/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Bluzelle/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Bluzelle/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Bluzelle/TWCoinTypeTests.cpp diff --git a/tests/chains/Cosmos/CosmosTestHelpers.h b/tests/chains/Cosmos/CosmosTestHelpers.h new file mode 100644 index 00000000000..d15a2ea34b9 --- /dev/null +++ b/tests/chains/Cosmos/CosmosTestHelpers.h @@ -0,0 +1,109 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#pragma once + +#include +#include +#include +#include "HexCoding.h" +#include "Hash.h" +#include "PublicKey.h" +#include "Bech32Address.h" +#include "Cosmos/Address.h" + +#include "TestUtilities.h" +#include + +namespace TW::Cosmos::tests { + +struct CosmosAddressParameters { + const std::string hrp{}; + TWCoinType coinType; + const std::string address; + bool standaloneChain{true}; + TWPublicKeyType publicKeyType{TWPublicKeyTypeSECP256k1}; + const std::string privKey{"a498a9ee41af9bab5ef2a8be63d5c970135c3c109e70efc8c56c534e6636b433"}; + const std::string publicKey{"02cbfdb5e472893322294e60cf0883d43df431e1089d29ecb447a9e6d55045aae5"}; +}; + +} + +namespace TW::Cosmos::tests::internal { + static inline void isValidAddress(const CosmosAddressParameters& addressParameters) { + auto address_utf8 = STRING(addressParameters.address.c_str()); + auto hrp_utf8 = STRING(addressParameters.hrp.c_str()); + EXPECT_TRUE(TWAnyAddressIsValidBech32(address_utf8.get(), TWCoinTypeCosmos, hrp_utf8.get())); + EXPECT_TRUE(TWAnyAddressIsValid(address_utf8.get(), addressParameters.coinType)); + EXPECT_FALSE(TWAnyAddressIsValidBech32(address_utf8.get(), TWCoinTypeBitcoin, hrp_utf8.get())); + if (addressParameters.coinType != TWCoinTypeCosmos) { + EXPECT_FALSE(TWAnyAddressIsValid(address_utf8.get(), TWCoinTypeCosmos)); + } + EXPECT_FALSE(TWAnyAddressIsValid(address_utf8.get(), TWCoinTypeBitcoin)); + } + + static inline void testCreateFromPubKeyWrapper(const CosmosAddressParameters& addressParameters) { + if (addressParameters.standaloneChain) { + const auto hrp_utf8 = STRING(addressParameters.hrp.c_str()); + const auto data = DATA(addressParameters.publicKey.c_str()); + const auto pubkey = TWPublicKeyCreateWithData(data.get(), TWPublicKeyTypeSECP256k1); + const auto twAddress = TWAnyAddressCreateBech32WithPublicKey(pubkey, TWCoinTypeCosmos, hrp_utf8.get()); + auto twData = TWAnyAddressData(twAddress); + auto hexData = hex(*reinterpret_cast(twData)); + ASSERT_EQ(hex(Bech32Address(addressParameters.hrp, TW::Hash::HasherSha256ripemd, pubkey->impl).getKeyHash()), hexData); + auto address = TWAnyAddressDescription(twAddress); + EXPECT_EQ(addressParameters.address, *reinterpret_cast(address)); + TWStringDelete(address); + TWAnyAddressDelete(twAddress); + TWDataDelete(twData); + TWPublicKeyDelete(pubkey); + } + + // With coin type + { + auto publicKey = PublicKey(parse_hex(addressParameters.publicKey), addressParameters.publicKeyType); + auto address = Address(addressParameters.coinType, publicKey); + } + } + + static inline void testCreateFromPrivKey(const CosmosAddressParameters& addressParameters) { + auto privateKey = PrivateKey(parse_hex(addressParameters.privKey)); + auto address = Address(addressParameters.coinType, privateKey.getPublicKey(addressParameters.publicKeyType)); + ASSERT_EQ(address.string(), addressParameters.address); + } + + static inline void testCreateFromString(const CosmosAddressParameters& addressParameters) { + // BECH32 + if (addressParameters.standaloneChain) { + const auto address = STRING(addressParameters.address.c_str()); + const auto hrp = STRING(addressParameters.hrp.c_str()); + const auto anyAddr = TWAnyAddressCreateBech32(address.get(), TWCoinTypeCosmos, hrp.get()); + const auto addrDescription = TWAnyAddressDescription(anyAddr); + ASSERT_TRUE(TWAnyAddressIsValidBech32(addrDescription, TWCoinTypeCosmos, hrp.get())); + TWStringDelete(addrDescription); + TWAnyAddressDelete(anyAddr); + } + + // With Coin Type + { + const auto address = STRING(addressParameters.address.c_str()); + const auto anyAddr = TWAnyAddressCreateWithString(address.get(), addressParameters.coinType); + const auto addrDescription = TWAnyAddressDescription(anyAddr); + ASSERT_TRUE(TWAnyAddressIsValid(addrDescription, addressParameters.coinType)); + TWStringDelete(addrDescription); + TWAnyAddressDelete(anyAddr); + } + } +} + +namespace TW::Cosmos::tests { + static inline void TestCosmosAddressParameters(const CosmosAddressParameters& addressParameters) { + internal::isValidAddress(addressParameters); + internal::testCreateFromPubKeyWrapper(addressParameters); + internal::testCreateFromPrivKey(addressParameters); + internal::testCreateFromString(addressParameters); + } +} diff --git a/tests/chains/CryptoOrg/SignerTests.cpp b/tests/chains/Cosmos/CryptoOrg/SignerTests.cpp similarity index 100% rename from tests/chains/CryptoOrg/SignerTests.cpp rename to tests/chains/Cosmos/CryptoOrg/SignerTests.cpp diff --git a/tests/chains/Cosmos/CryptoOrg/TWAnyAddressTests.cpp b/tests/chains/Cosmos/CryptoOrg/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..5946ec84956 --- /dev/null +++ b/tests/chains/Cosmos/CryptoOrg/TWAnyAddressTests.cpp @@ -0,0 +1,23 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gCryptoorgAddr = "cro1tcfsr7m7d6jk6fpyety373m8c39ea2f8dmp830"; +static const std::string gCryptoorgHrp = "cro"; + +TEST(TWCryptoorgAnyAddress, AllCryptoorgAddressTests) { + CosmosAddressParameters parameters{.hrp = gCryptoorgHrp, + .coinType = TWCoinTypeCryptoOrg, + .address = gCryptoorgAddr, + .privKey = "5469c1a88e67d6d490e647ac8d82d54c4a17b8f00d272b3b30fac2253339aa28", + .publicKey = "025824f188c340235910b15e5e35aea11cfc28eabfa7756da5585c08f74db437ef"}; + TestCosmosAddressParameters(parameters); +} + +} // namespace TW::Cosmos::tests diff --git a/tests/chains/CryptoOrg/TWAnySignerTests.cpp b/tests/chains/Cosmos/CryptoOrg/TWAnySignerTests.cpp similarity index 100% rename from tests/chains/CryptoOrg/TWAnySignerTests.cpp rename to tests/chains/Cosmos/CryptoOrg/TWAnySignerTests.cpp diff --git a/tests/chains/CryptoOrg/TWCoinTypeTests.cpp b/tests/chains/Cosmos/CryptoOrg/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/CryptoOrg/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/CryptoOrg/TWCoinTypeTests.cpp diff --git a/tests/chains/Cosmos/Juno/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Juno/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..6796ff98934 --- /dev/null +++ b/tests/chains/Cosmos/Juno/TWAnyAddressTests.cpp @@ -0,0 +1,19 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gJunoAddr = "juno1mry47pkga5tdswtluy0m8teslpalkdq0gnn4mf"; +static const std::string gJunoHrp = "juno"; + +TEST(TWJunoAnyAddress, AllJunoAddressTests) { + CosmosAddressParameters parameters{.hrp = gJunoHrp, .coinType = TWCoinTypeJuno, .address = gJunoAddr}; + TestCosmosAddressParameters(parameters); +} + +} diff --git a/tests/chains/Juno/TWAnySignerTests.cpp b/tests/chains/Cosmos/Juno/TWAnySignerTests.cpp similarity index 100% rename from tests/chains/Juno/TWAnySignerTests.cpp rename to tests/chains/Cosmos/Juno/TWAnySignerTests.cpp diff --git a/tests/chains/Juno/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Juno/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Juno/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Juno/TWCoinTypeTests.cpp diff --git a/tests/chains/Kava/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Kava/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Kava/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Kava/TWCoinTypeTests.cpp diff --git a/tests/chains/Cosmos/NativeEvmos/TWAnyAddressTests.cpp b/tests/chains/Cosmos/NativeEvmos/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..7331a3109e6 --- /dev/null +++ b/tests/chains/Cosmos/NativeEvmos/TWAnyAddressTests.cpp @@ -0,0 +1,26 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gNativeEvmosAddr = "evmos14py36sx57ud82t9yrks9z6hdsrpn5x6k0r05np"; +static const std::string gNativeEvmosHrp = "evmos"; + +TEST(TWNativeEvmosAnyAddress, AllNativeEvmosAddressTests) { + CosmosAddressParameters parameters{.hrp = gNativeEvmosHrp, + .coinType = TWCoinTypeNativeEvmos, + .address = gNativeEvmosAddr, + .standaloneChain = false, + .publicKeyType = TWPublicKeyTypeSECP256k1Extended, + .privKey = "8d2a3bd62d300a148c89dc8635f87b7a24a951bd1c4e78675fe40e1a640d46ed", + .publicKey = "04868e7e1634417db2adfd9fe38205bfa0fea01898a7fd30565d13f7056a37c065211845f6e553524c2c1611af9712ac02b7a3b439c9f0cfcadfd81a2c86cc0ab8", + }; + TestCosmosAddressParameters(parameters); +} + +} // namespace TW::Cosmos::tests diff --git a/tests/chains/NativeEvmos/TWCoinTypeTests.cpp b/tests/chains/Cosmos/NativeEvmos/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/NativeEvmos/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/NativeEvmos/TWCoinTypeTests.cpp diff --git a/tests/chains/NativeInjective/SignerTests.cpp b/tests/chains/Cosmos/NativeInjective/SignerTests.cpp similarity index 100% rename from tests/chains/NativeInjective/SignerTests.cpp rename to tests/chains/Cosmos/NativeInjective/SignerTests.cpp diff --git a/tests/chains/Cosmos/NativeInjective/TWAnyAddressTests.cpp b/tests/chains/Cosmos/NativeInjective/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..f8425d00967 --- /dev/null +++ b/tests/chains/Cosmos/NativeInjective/TWAnyAddressTests.cpp @@ -0,0 +1,26 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gNativeInjectiveAddr = "inj14py36sx57ud82t9yrks9z6hdsrpn5x6k8tf7m3"; +static const std::string gNativeInjectiveHrp = "inj"; + +TEST(TWNativeInjectiveAnyAddress, AllNativeInjectiveAddressTests) { + CosmosAddressParameters parameters{.hrp = gNativeInjectiveHrp, + .coinType = TWCoinTypeNativeInjective, + .address = gNativeInjectiveAddr, + .standaloneChain = false, + .publicKeyType = TWPublicKeyTypeSECP256k1Extended, + .privKey = "8d2a3bd62d300a148c89dc8635f87b7a24a951bd1c4e78675fe40e1a640d46ed", + .publicKey = "04868e7e1634417db2adfd9fe38205bfa0fea01898a7fd30565d13f7056a37c065211845f6e553524c2c1611af9712ac02b7a3b439c9f0cfcadfd81a2c86cc0ab8", + }; + TestCosmosAddressParameters(parameters); +} + +} // namespace TW::Cosmos::tests diff --git a/tests/chains/NativeInjective/TWCoinTypeTests.cpp b/tests/chains/Cosmos/NativeInjective/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/NativeInjective/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/NativeInjective/TWCoinTypeTests.cpp diff --git a/tests/chains/Osmosis/SignerTests.cpp b/tests/chains/Cosmos/Osmosis/SignerTests.cpp similarity index 100% rename from tests/chains/Osmosis/SignerTests.cpp rename to tests/chains/Cosmos/Osmosis/SignerTests.cpp diff --git a/tests/chains/Cosmos/Osmosis/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Osmosis/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..69eee155454 --- /dev/null +++ b/tests/chains/Cosmos/Osmosis/TWAnyAddressTests.cpp @@ -0,0 +1,19 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gOsmosisAddr = "osmo1mry47pkga5tdswtluy0m8teslpalkdq0k6r728"; +static const std::string gOsmosisHrp = "osmo"; + +TEST(TWOsmosisAnyAddress, AllOsmosisAddressTests) { + CosmosAddressParameters parameters{.hrp = gOsmosisHrp, .coinType = TWCoinTypeOsmosis, .address = gOsmosisAddr}; + TestCosmosAddressParameters(parameters); +} + +} diff --git a/tests/chains/Osmosis/TWAnySignerTests.cpp b/tests/chains/Cosmos/Osmosis/TWAnySignerTests.cpp similarity index 100% rename from tests/chains/Osmosis/TWAnySignerTests.cpp rename to tests/chains/Cosmos/Osmosis/TWAnySignerTests.cpp diff --git a/tests/chains/Osmosis/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Osmosis/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Osmosis/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Osmosis/TWCoinTypeTests.cpp diff --git a/tests/chains/Secret/SignerTests.cpp b/tests/chains/Cosmos/Secret/SignerTests.cpp similarity index 100% rename from tests/chains/Secret/SignerTests.cpp rename to tests/chains/Cosmos/Secret/SignerTests.cpp diff --git a/tests/chains/Cosmos/Secret/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Secret/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..e3f9452e1f3 --- /dev/null +++ b/tests/chains/Cosmos/Secret/TWAnyAddressTests.cpp @@ -0,0 +1,23 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gSecretAddr = "secret1l0cjpuwu09hwu4wdds7pljn83346x2c90d8h0l"; +static const std::string gSecretHrp = "secret"; + +TEST(TWSecretAnyAddress, AllSecretAddressTests) { + CosmosAddressParameters parameters{.hrp = gSecretHrp, + .coinType = TWCoinTypeSecret, + .address = gSecretAddr, + .privKey = "a054c9a67d81ada560ab6fda3310ebf5971e163ff2291ee736ca64b6a5af1ada", + .publicKey = "03967d2c6263c2d74d9c2fac3a024e2892a94497b64edb294ffab4042851f00b90"}; + TestCosmosAddressParameters(parameters); +} + +} // namespace TW::Cosmos::tests diff --git a/tests/chains/Secret/TWAnySignerTests.cpp b/tests/chains/Cosmos/Secret/TWAnySignerTests.cpp similarity index 100% rename from tests/chains/Secret/TWAnySignerTests.cpp rename to tests/chains/Cosmos/Secret/TWAnySignerTests.cpp diff --git a/tests/chains/Secret/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Secret/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Secret/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Secret/TWCoinTypeTests.cpp diff --git a/tests/chains/Cosmos/Stargaze/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Stargaze/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..e07e1eb6ecb --- /dev/null +++ b/tests/chains/Cosmos/Stargaze/TWAnyAddressTests.cpp @@ -0,0 +1,22 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include +#include "TestUtilities.h" +#include +#include "../CosmosTestHelpers.h" + +namespace TW::Cosmos::tests { + +static const std::string gStarsAddr = "stars1mry47pkga5tdswtluy0m8teslpalkdq02a8nhy"; +static const std::string gStarsHrp = "stars"; + +TEST(TWStargazeAnyAddress, AllStargazeAddressTests) { + CosmosAddressParameters parameters{.hrp = gStarsHrp, .coinType = TWCoinTypeStargaze, .address = gStarsAddr}; + TestCosmosAddressParameters(parameters); +} + +} diff --git a/tests/chains/Stargaze/TWAnySignerTests.cpp b/tests/chains/Cosmos/Stargaze/TWAnySignerTests.cpp similarity index 100% rename from tests/chains/Stargaze/TWAnySignerTests.cpp rename to tests/chains/Cosmos/Stargaze/TWAnySignerTests.cpp diff --git a/tests/chains/Cosmos/Stride/TWAnyAddressTests.cpp b/tests/chains/Cosmos/Stride/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..26b6e7a129b --- /dev/null +++ b/tests/chains/Cosmos/Stride/TWAnyAddressTests.cpp @@ -0,0 +1,21 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "../CosmosTestHelpers.h" +#include "TestUtilities.h" +#include + +namespace TW::Cosmos::tests { + +static const std::string gStrideAddr = "stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge"; +static const std::string gStrideHrp = "stride"; + +TEST(TWStrideAnyAddress, AllStrideAddressTests) { + CosmosAddressParameters parameters{.hrp = gStrideHrp, .coinType = TWCoinTypeStride, .address = gStrideAddr}; + TestCosmosAddressParameters(parameters); +} + +} diff --git a/tests/chains/Stride/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Stride/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Stride/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Stride/TWCoinTypeTests.cpp diff --git a/tests/chains/THORChain/SignerTests.cpp b/tests/chains/Cosmos/THORChain/SignerTests.cpp similarity index 100% rename from tests/chains/THORChain/SignerTests.cpp rename to tests/chains/Cosmos/THORChain/SignerTests.cpp diff --git a/tests/chains/THORChain/SwapTests.cpp b/tests/chains/Cosmos/THORChain/SwapTests.cpp similarity index 100% rename from tests/chains/THORChain/SwapTests.cpp rename to tests/chains/Cosmos/THORChain/SwapTests.cpp diff --git a/tests/chains/THORChain/TWAnyAddressTests.cpp b/tests/chains/Cosmos/THORChain/TWAnyAddressTests.cpp similarity index 100% rename from tests/chains/THORChain/TWAnyAddressTests.cpp rename to tests/chains/Cosmos/THORChain/TWAnyAddressTests.cpp diff --git a/tests/chains/THORChain/TWAnySignerTests.cpp b/tests/chains/Cosmos/THORChain/TWAnySignerTests.cpp similarity index 100% rename from tests/chains/THORChain/TWAnySignerTests.cpp rename to tests/chains/Cosmos/THORChain/TWAnySignerTests.cpp diff --git a/tests/chains/THORChain/TWCoinTypeTests.cpp b/tests/chains/Cosmos/THORChain/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/THORChain/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/THORChain/TWCoinTypeTests.cpp diff --git a/tests/chains/THORChain/TWSwapTests.cpp b/tests/chains/Cosmos/THORChain/TWSwapTests.cpp similarity index 100% rename from tests/chains/THORChain/TWSwapTests.cpp rename to tests/chains/Cosmos/THORChain/TWSwapTests.cpp diff --git a/tests/chains/Cosmos/TWAnyAddressTests.cpp b/tests/chains/Cosmos/TWAnyAddressTests.cpp index d05919a62cf..b6387f7bd57 100644 --- a/tests/chains/Cosmos/TWAnyAddressTests.cpp +++ b/tests/chains/Cosmos/TWAnyAddressTests.cpp @@ -4,18 +4,16 @@ // terms governing use, modification, and redistribution, is contained in the // file LICENSE at the root of the source code distribution tree. -#include "TestUtilities.h" +#include "CosmosTestHelpers.h" -#include -#include +namespace TW::Cosmos::tests { -#include +static const std::string gAtomAddr = "cosmos1mry47pkga5tdswtluy0m8teslpalkdq07pswu4"; +static const std::string gAtomHrp = "cosmos"; + +TEST(TWAtomAnyAddress, AllAtomAddressTests) { + CosmosAddressParameters parameters{.hrp = gAtomHrp, .coinType = TWCoinTypeCosmos, .address = gAtomAddr}; + TestCosmosAddressParameters(parameters); +} -TEST(CosmosAnyAddress, Cosmos) { - auto string = STRING("cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02"); - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithString(string.get(), TWCoinTypeCosmos)); - auto string2 = WRAPS(TWAnyAddressDescription(addr.get())); - EXPECT_TRUE(TWStringEqual(string.get(), string2.get())); - auto keyHash = WRAPD(TWAnyAddressData(addr.get())); - assertHexEqual(keyHash, "bc2da90c84049370d1b7c528bc164bc588833f21"); } diff --git a/tests/chains/Terra/SignerTests.cpp b/tests/chains/Cosmos/Terra/SignerTests.cpp similarity index 100% rename from tests/chains/Terra/SignerTests.cpp rename to tests/chains/Cosmos/Terra/SignerTests.cpp diff --git a/tests/chains/Terra/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Terra/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/Terra/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/Terra/TWCoinTypeTests.cpp diff --git a/tests/chains/TerraV2/SignerTests.cpp b/tests/chains/Cosmos/TerraV2/SignerTests.cpp similarity index 100% rename from tests/chains/TerraV2/SignerTests.cpp rename to tests/chains/Cosmos/TerraV2/SignerTests.cpp diff --git a/tests/chains/TerraV2/TWCoinTypeTests.cpp b/tests/chains/Cosmos/TerraV2/TWCoinTypeTests.cpp similarity index 100% rename from tests/chains/TerraV2/TWCoinTypeTests.cpp rename to tests/chains/Cosmos/TerraV2/TWCoinTypeTests.cpp diff --git a/tests/chains/CryptoOrg/AddressTests.cpp b/tests/chains/CryptoOrg/AddressTests.cpp deleted file mode 100644 index 5db7dbe8d39..00000000000 --- a/tests/chains/CryptoOrg/AddressTests.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "HexCoding.h" -#include "Cosmos/Address.h" -#include "PublicKey.h" -#include "PrivateKey.h" -#include - -#include -#include - -namespace TW::Cosmos::tests { - -TEST(CryptoorgAddress, Valid) { - ASSERT_TRUE(Address::isValid(TWCoinTypeCryptoOrg, "cro1ctwtcwpgksky988dhth6jslxveumgu0d45zgf0")); - ASSERT_TRUE(Address::isValid(TWCoinTypeCryptoOrg, "cro1xpahy6c7wldxacv6ld99h435mhvfnsup24vcus")); - ASSERT_TRUE(Address::isValid(TWCoinTypeCryptoOrg, "cro1z53wwe7md6cewz9sqwqzn0aavpaun0gw39h3rd")); - ASSERT_TRUE(Address::isValid(TWCoinTypeCryptoOrg, "cro1y8ua5laceufhqtwzyhahq0qk7rm87hhugtsfey")); -} - -TEST(CryptoorgAddress, Invalid) { - EXPECT_FALSE(Address::isValid(TWCoinTypeCryptoOrg, "cro1ctwtcwpgksky988dhth6jslxveumgu0d45zgf1")); - EXPECT_FALSE(Address::isValid(TWCoinTypeCryptoOrg, "cro1z53wwe7md6cewz9sqwqzn0aavpaun0gw39h3re")); - EXPECT_FALSE(Address::isValid(TWCoinTypeCryptoOrg, "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02")); // valid cosmos -} - -TEST(CryptoorgAddress, FromPrivateKey) { - auto privateKey = PrivateKey(parse_hex("7105512f0c020a1dd759e14b865ec0125f59ac31e34d7a2807a228ed50cb343e")); - auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeCryptoOrg, publicKey); - EXPECT_EQ(address.string(), "cro1z53wwe7md6cewz9sqwqzn0aavpaun0gw39h3rd"); - EXPECT_EQ(hex(address.getKeyHash()), "1522e767db6eb19708b0038029bfbd607bc9bd0e"); -} - -TEST(CryptoorgAddress, FromPublicKey) { - auto publicKey = PublicKey(parse_hex("03ed997e396cf4292f5fce5a42bba41599ccd5d96e313154a7c9ea7049de317c77"), TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeCryptoOrg, publicKey); - EXPECT_EQ(address.string(), "cro1z53wwe7md6cewz9sqwqzn0aavpaun0gw39h3rd"); - EXPECT_EQ(hex(address.getKeyHash()), "1522e767db6eb19708b0038029bfbd607bc9bd0e"); -} - -TEST(CryptoorgAddress, FromString) { - Address address; - EXPECT_TRUE(Address::decode("cro1ctwtcwpgksky988dhth6jslxveumgu0d45zgf0", address)); - EXPECT_EQ(address.string(), "cro1ctwtcwpgksky988dhth6jslxveumgu0d45zgf0"); - EXPECT_EQ(hex(address.getKeyHash()), "c2dcbc3828b42c429cedbaefa943e66679b471ed"); -} - -} // namespace TW::Cosmos::tests \ No newline at end of file diff --git a/tests/chains/CryptoOrg/TWAnyAddressTests.cpp b/tests/chains/CryptoOrg/TWAnyAddressTests.cpp deleted file mode 100644 index b4213ac7e77..00000000000 --- a/tests/chains/CryptoOrg/TWAnyAddressTests.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include "HexCoding.h" - -#include "TestUtilities.h" -#include - -using namespace TW; - -TEST(CryptoorgAnyAddress, IsValid) { - EXPECT_TRUE(TWAnyAddressIsValid(STRING("cro1ctwtcwpgksky988dhth6jslxveumgu0d45zgf0").get(), TWCoinTypeCryptoOrg)); - EXPECT_TRUE(TWAnyAddressIsValid(STRING("cro1xpahy6c7wldxacv6ld99h435mhvfnsup24vcus").get(), TWCoinTypeCryptoOrg)); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02").get(), TWCoinTypeCryptoOrg)); -} - -TEST(CryptoorgAnyAddress, Create) { - auto string = STRING("cro1ctwtcwpgksky988dhth6jslxveumgu0d45zgf0"); - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithString(string.get(), TWCoinTypeCryptoOrg)); - auto string2 = WRAPS(TWAnyAddressDescription(addr.get())); - EXPECT_TRUE(TWStringEqual(string.get(), string2.get())); - auto keyHash = WRAPD(TWAnyAddressData(addr.get())); - assertHexEqual(keyHash, "c2dcbc3828b42c429cedbaefa943e66679b471ed"); -} diff --git a/tests/chains/Juno/TWAnyAddressTests.cpp b/tests/chains/Juno/TWAnyAddressTests.cpp deleted file mode 100644 index 951502b5f7e..00000000000 --- a/tests/chains/Juno/TWAnyAddressTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include -#include "PublicKey.h" -#include "Bech32Address.h" -#include "HexCoding.h" -#include "Hash.h" -#include "PublicKey.h" -#include "Bech32Address.h" - -#include "TestUtilities.h" -#include - -namespace TW::Cosmos::tests { - -TEST(TWJunoAnyAddress, IsValid) { - EXPECT_TRUE(TWAnyAddressIsValidBech32(STRING("juno1gckvjxau7k56f8wg8c8xj80khyp83y8x8eqc94").get(), TWCoinTypeCosmos, STRING("juno").get())); - EXPECT_TRUE(TWAnyAddressIsValid(STRING("juno1gckvjxau7k56f8wg8c8xj80khyp83y8x8eqc94").get(), TWCoinTypeJuno)); - EXPECT_FALSE(TWAnyAddressIsValidBech32(STRING("juno1gckvjxau7k56f8wg8c8xj80khyp83y8x8eqc94").get(), TWCoinTypeBitcoin, STRING("juno").get())); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("juno1gckvjxau7k56f8wg8c8xj80khyp83y8x8eqc94").get(), TWCoinTypeCosmos)); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("juno1gckvjxau7k56f8wg8c8xj80khyp83y8x8eqc94").get(), TWCoinTypeBitcoin)); -} - -TEST(TWJunoAnyAddress, createFromPubKeyJuno) { - const auto hrp = STRING("juno"); - const auto data = DATA("02753f5c275e1847ba4d2fd3df36ad00af2e165650b35fe3991e9c9c46f68b12bc"); - const auto pubkey = TWPublicKeyCreateWithData(data.get(), TWPublicKeyTypeSECP256k1); - const auto twAddress = TWAnyAddressCreateBech32WithPublicKey(pubkey, TWCoinTypeCosmos, hrp.get()); - auto twData = TWAnyAddressData(twAddress); - auto hexData = hex(*reinterpret_cast(twData)); - ASSERT_EQ(hexData, "c494c4cb388e23fe24a93158d6cd1fbdca8ebb73"); - ASSERT_EQ(hex(Bech32Address("juno", TW::Hash::HasherSha256ripemd, pubkey->impl).getKeyHash()), hexData); - auto address = TWAnyAddressDescription(twAddress); - EXPECT_EQ("juno1cj2vfjec3c3luf9fx9vddnglhh9gawmncn4k5n", *reinterpret_cast(address)); - TWStringDelete(address); - TWAnyAddressDelete(twAddress); - TWDataDelete(twData); - TWPublicKeyDelete(pubkey); -} - -TEST(TWJunoAnyAddress, createFromStringJuno) { - const auto junoAddress = STRING("juno1cj2vfjec3c3luf9fx9vddnglhh9gawmncn4k5n"); - const auto hrp = STRING("juno"); - const auto anyAddr = TWAnyAddressCreateBech32(junoAddress.get(), TWCoinTypeCosmos, hrp.get()); - const auto addrDescription = TWAnyAddressDescription(anyAddr); - ASSERT_TRUE(TWAnyAddressIsValidBech32(addrDescription, TWCoinTypeCosmos, hrp.get())); - TWStringDelete(addrDescription); - TWAnyAddressDelete(anyAddr); -} - -} diff --git a/tests/chains/NativeEvmos/TWAnyAddressTests.cpp b/tests/chains/NativeEvmos/TWAnyAddressTests.cpp deleted file mode 100644 index ceb6da6ce0f..00000000000 --- a/tests/chains/NativeEvmos/TWAnyAddressTests.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "TestUtilities.h" - -#include -#include -#include - -#include - -namespace TW::NativeEvmos::tests { - -TEST(EvmosAnyAddress, NativeEvmosValidate) { - auto string = STRING("evmos1mwspdc5y6lj0glm90j9sg7vmr5ksmqcnzhg0h9"); - - EXPECT_TRUE(TWAnyAddressIsValid(string.get(), TWCoinTypeNativeEvmos)); - - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithString(string.get(), TWCoinTypeNativeEvmos)); - - auto keyHash = WRAPD(TWAnyAddressData(addr.get())); - assertHexEqual(keyHash, "dba016e284d7e4f47f657c8b04799b1d2d0d8313"); -} - -TEST(EvmosAnyAddress, NativeEvmosCreate) { - auto publicKeyHex = "035a0c6b83b8bd9827e507270cadb499b7e3a9095246f6a2213281f783d877c98b"; // shoot island position ... - const auto publicKey = WRAP(TWPublicKey, TWPublicKeyCreateWithData(DATA(publicKeyHex).get(), TWPublicKeyTypeSECP256k1)); - - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKey(publicKey.get(), TWCoinTypeNativeEvmos)); - - EXPECT_EQ(std::string(TWStringUTF8Bytes(WRAPS(TWAnyAddressDescription(addr.get())).get())), std::string("evmos1mwspdc5y6lj0glm90j9sg7vmr5ksmqcnzhg0h9")); - - auto keyHash = WRAPD(TWAnyAddressData(addr.get())); - assertHexEqual(keyHash, "dba016e284d7e4f47f657c8b04799b1d2d0d8313"); -} - -} // namespace TW::NativeEvmos::tests diff --git a/tests/chains/NativeInjective/TWAnyAddressTests.cpp b/tests/chains/NativeInjective/TWAnyAddressTests.cpp deleted file mode 100644 index b3a88aa17ea..00000000000 --- a/tests/chains/NativeInjective/TWAnyAddressTests.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include "HexCoding.h" - -#include "TestUtilities.h" -#include - -using namespace TW; - -TEST(TWNativeInjective, Address) { - auto string = STRING("inj1xmpkmxr4as00em23tc2zgmuyy2gr4h3wgcl6vd"); - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithString(string.get(), TWCoinTypeNativeInjective)); - auto string2 = WRAPS(TWAnyAddressDescription(addr.get())); - EXPECT_TRUE(TWStringEqual(string.get(), string2.get())); -} diff --git a/tests/chains/Osmosis/AddressTests.cpp b/tests/chains/Osmosis/AddressTests.cpp deleted file mode 100644 index 3f0224aafa1..00000000000 --- a/tests/chains/Osmosis/AddressTests.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "Cosmos/Address.h" -#include "HexCoding.h" -#include "PrivateKey.h" -#include "PublicKey.h" -#include -#include - -namespace TW::Cosmos::tests { - -TEST(OsmosisAddress, Valid) { - EXPECT_TRUE(Address::isValid(TWCoinTypeOsmosis, "osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5")); - EXPECT_TRUE(Address::isValid(TWCoinTypeOsmosis, "osmo18s0hdnsllgcclweu9aymw4ngktr2k0rkvn7jmn")); -} - -TEST(OsmosisAddress, Invalid) { - EXPECT_FALSE(Address::isValid(TWCoinTypeOsmosis, "osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f6")); - EXPECT_FALSE(Address::isValid(TWCoinTypeOsmosis, "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02")); // valid cosmos -} - -TEST(OsmosisAddress, FromPrivateKey) { - auto privateKey = PrivateKey(parse_hex("8bbec3772ddb4df68f3186440380c301af116d1422001c1877d6f5e4dba8c8af")); - auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeOsmosis, publicKey); - ASSERT_EQ(address.string(), "osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5"); -} - -TEST(OsmosisAddress, FromPublicKey) { - auto publicKey = PublicKey(parse_hex("02ecef5ce437a302c67f95468de4b31f36e911f467d7e6a52b41c1e13e1d563649"), TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeOsmosis, publicKey); - ASSERT_EQ(address.string(), "osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5"); -} - -TEST(OsmosisAddress, FromString) { - Address address; - EXPECT_TRUE(Address::decode("osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5", address)); - EXPECT_EQ(address.string(), "osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5"); - EXPECT_EQ(hex(address.getKeyHash()), "dd89a2e267cd96e23cf5a33382f030686f65996f"); -} - -} // namespace TW::Cosmos::tests diff --git a/tests/chains/Osmosis/TWAnyAddressTests.cpp b/tests/chains/Osmosis/TWAnyAddressTests.cpp deleted file mode 100644 index 4474ba4e424..00000000000 --- a/tests/chains/Osmosis/TWAnyAddressTests.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include "HexCoding.h" - -#include "TestUtilities.h" -#include - -using namespace TW; - -TEST(TWOsmosisAnyAddress, IsValid) { - EXPECT_TRUE(TWAnyAddressIsValid(STRING("osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5").get(), TWCoinTypeOsmosis)); - EXPECT_TRUE(TWAnyAddressIsValid(STRING("osmo18s0hdnsllgcclweu9aymw4ngktr2k0rkvn7jmn").get(), TWCoinTypeOsmosis)); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02").get(), TWCoinTypeOsmosis)); -} - -TEST(TWOsmosisAnyAddress, Create) { - auto string = STRING("osmo1mky69cn8ektwy0845vec9upsdphktxt0en97f5"); - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithString(string.get(), TWCoinTypeOsmosis)); - auto string2 = WRAPS(TWAnyAddressDescription(addr.get())); - EXPECT_TRUE(TWStringEqual(string.get(), string2.get())); - auto keyHash = WRAPD(TWAnyAddressData(addr.get())); - assertHexEqual(keyHash, "dd89a2e267cd96e23cf5a33382f030686f65996f"); -} diff --git a/tests/chains/Secret/AddressTests.cpp b/tests/chains/Secret/AddressTests.cpp deleted file mode 100644 index b1387110bb4..00000000000 --- a/tests/chains/Secret/AddressTests.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "HexCoding.h" -#include "Cosmos/Address.h" -#include "PublicKey.h" -#include "PrivateKey.h" -#include -#include - -namespace TW::Cosmos::tests { - -TEST(SecretAddress, Valid) { - ASSERT_TRUE(Address::isValid(TWCoinTypeSecret, "secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf")); - ASSERT_TRUE(Address::isValid(TWCoinTypeSecret, "secret15rgv8teecnt53h0gdvngzt3am3yuz3rxh4fnle")); - ASSERT_TRUE(Address::isValid(TWCoinTypeSecret, "secret1pjp5dpvrjumn653dycszk3g264zgqusz2xhdq7")); -} - -TEST(SecretAddress, Invalid) { - ASSERT_FALSE(Address::isValid(TWCoinTypeSecret, "secret15rgv8teecnt53h0gdvngzt3am3yuz3rxh4fnla")); - ASSERT_FALSE(Address::isValid(TWCoinTypeSecret, "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02")); // valid cosmos -} - -TEST(SecretAddress, FromPrivateKey) { - auto privateKey = PrivateKey(parse_hex("92ded9fb8b4646b66d0c127fa38523133ce11bdc5dadee2d5fc1c0ccd9fec664")); - auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeSecret, publicKey); - ASSERT_EQ(address.string(), "secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf"); -} - -TEST(SecretAddress, FromPublicKey) { - auto publicKey = PublicKey(parse_hex("0250bba49f3d5a574b38de891387420877de10fd44de609567d5e6e0c97bfa4bb2"), TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeSecret, publicKey); - ASSERT_EQ(address.string(), "secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf"); -} - -TEST(SecretAddress, FromString) { - Address address; - EXPECT_TRUE(Address::decode("secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf", address)); - EXPECT_EQ(address.string(), "secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf"); - EXPECT_EQ(hex(address.getKeyHash()), "d31d1487c68d162dbbf66d88219d888626f165cb"); -} - -} // namespace TW::Cosmos::tests diff --git a/tests/chains/Secret/TWAnyAddressTests.cpp b/tests/chains/Secret/TWAnyAddressTests.cpp deleted file mode 100644 index c7e298b7005..00000000000 --- a/tests/chains/Secret/TWAnyAddressTests.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include "HexCoding.h" - -#include "TestUtilities.h" -#include - -using namespace TW; - -TEST(TWSecretAnyAddress, IsValid) { - EXPECT_TRUE(TWAnyAddressIsValid(STRING("secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf").get(), TWCoinTypeSecret)); - EXPECT_TRUE(TWAnyAddressIsValid(STRING("secret15rgv8teecnt53h0gdvngzt3am3yuz3rxh4fnle").get(), TWCoinTypeSecret)); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02").get(), TWCoinTypeSecret)); -} - -TEST(TWSecretAnyAddress, Create) { - auto string = STRING("secret16vw3fp7x35tzmwlkdkyzr8vgscn0zewtduyjuf"); - auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithString(string.get(), TWCoinTypeSecret)); - auto string2 = WRAPS(TWAnyAddressDescription(addr.get())); - EXPECT_TRUE(TWStringEqual(string.get(), string2.get())); - auto keyHash = WRAPD(TWAnyAddressData(addr.get())); - assertHexEqual(keyHash, "d31d1487c68d162dbbf66d88219d888626f165cb"); -} diff --git a/tests/chains/Stargaze/AddressTests.cpp b/tests/chains/Stargaze/AddressTests.cpp deleted file mode 100644 index d951de5708f..00000000000 --- a/tests/chains/Stargaze/AddressTests.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "HexCoding.h" -#include "Cosmos/Address.h" -#include "PublicKey.h" -#include "PrivateKey.h" -#include -#include - -namespace TW::Cosmos::tests { - -TEST(StargazeAddress, IsValid) { - ASSERT_TRUE(Address::isValid(TWCoinTypeStargaze, "stars1mry47pkga5tdswtluy0m8teslpalkdq02a8nhy")); - ASSERT_FALSE(Address::isValid(TWCoinTypeStargaze, "cosmos1kd5q7qejlqz94kpmd9pvr4v2gzgnca3lchdmcs")); -} - -TEST(StargazeAddress, FromPrivateKey) { - auto privateKey = PrivateKey(parse_hex("a498a9ee41af9bab5ef2a8be63d5c970135c3c109e70efc8c56c534e6636b433")); - auto address = Address(TWCoinTypeStargaze, privateKey.getPublicKey(TWPublicKeyTypeSECP256k1)); - ASSERT_EQ(address.string(), "stars1mry47pkga5tdswtluy0m8teslpalkdq02a8nhy"); -} - -TEST(StargazeAddress, FromPublicKey) { - auto publicKey = PublicKey(parse_hex("02cbfdb5e472893322294e60cf0883d43df431e1089d29ecb447a9e6d55045aae5"), TWPublicKeyTypeSECP256k1); - auto address = Address(TWCoinTypeStargaze, publicKey); - ASSERT_EQ(address.string(), "stars1mry47pkga5tdswtluy0m8teslpalkdq02a8nhy"); -} - -} // namespace TW::Stargaze::tests diff --git a/tests/chains/Stride/TWAnyAddressTests.cpp b/tests/chains/Stride/TWAnyAddressTests.cpp deleted file mode 100644 index 53da3dc1114..00000000000 --- a/tests/chains/Stride/TWAnyAddressTests.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright © 2017-2023 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include -#include -#include "PublicKey.h" -#include "Bech32Address.h" -#include "HexCoding.h" -#include "Hash.h" -#include "PublicKey.h" -#include "Bech32Address.h" - -#include "TestUtilities.h" -#include - -namespace TW::Cosmos::tests { - -TEST(TWStrideAnyAddress, IsValid) { - EXPECT_TRUE(TWAnyAddressIsValidBech32(STRING("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge").get(), TWCoinTypeCosmos, STRING("stride").get())); - EXPECT_TRUE(TWAnyAddressIsValid(STRING("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge").get(), TWCoinTypeStride)); - EXPECT_FALSE(TWAnyAddressIsValidBech32(STRING("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge").get(), TWCoinTypeBitcoin, STRING("stride").get())); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge").get(), TWCoinTypeCosmos)); - EXPECT_FALSE(TWAnyAddressIsValid(STRING("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge").get(), TWCoinTypeBitcoin)); -} - -TEST(TWStrideAnyAddress, createFromPubKeyStride) { - const auto hrp = STRING("stride"); - const auto data = DATA("02cbfdb5e472893322294e60cf0883d43df431e1089d29ecb447a9e6d55045aae5"); - const auto pubkey = TWPublicKeyCreateWithData(data.get(), TWPublicKeyTypeSECP256k1); - const auto twAddress = TWAnyAddressCreateBech32WithPublicKey(pubkey, TWCoinTypeCosmos, hrp.get()); - auto twData = TWAnyAddressData(twAddress); - auto hexData = hex(*reinterpret_cast(twData)); - ASSERT_EQ(hexData, "d8c95f06c8ed16d8397fe11fb3af30f87bfb340f"); - ASSERT_EQ(hex(Bech32Address("stride", TW::Hash::HasherSha256ripemd, pubkey->impl).getKeyHash()), hexData); - auto address = TWAnyAddressDescription(twAddress); - EXPECT_EQ("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge", *reinterpret_cast(address)); - TWStringDelete(address); - TWAnyAddressDelete(twAddress); - TWDataDelete(twData); - TWPublicKeyDelete(pubkey); -} - -TEST(TWStrideAnyAddress, createFromStringStride) { - const auto StrideAddress = STRING("stride1mry47pkga5tdswtluy0m8teslpalkdq0a2sjge"); - const auto hrp = STRING("stride"); - const auto anyAddr = TWAnyAddressCreateBech32(StrideAddress.get(), TWCoinTypeCosmos, hrp.get()); - const auto addrDescription = TWAnyAddressDescription(anyAddr); - ASSERT_TRUE(TWAnyAddressIsValidBech32(addrDescription, TWCoinTypeCosmos, hrp.get())); - TWStringDelete(addrDescription); - TWAnyAddressDelete(anyAddr); -} - -}