-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
339 additions
and
545 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <TrustWalletCore/TWAnyAddress.h> | ||
#include <TrustWalletCore/TWPublicKey.h> | ||
#include <TrustWalletCore/TWPrivateKey.h> | ||
#include "HexCoding.h" | ||
#include "Hash.h" | ||
#include "PublicKey.h" | ||
#include "Bech32Address.h" | ||
#include "Cosmos/Address.h" | ||
|
||
#include "TestUtilities.h" | ||
#include <gtest/gtest.h> | ||
|
||
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<const Data*>(twData)); | ||
ASSERT_EQ(hex(Bech32Address(addressParameters.hrp, TW::Hash::HasherSha256ripemd, pubkey->impl).getKeyHash()), hexData); | ||
auto address = TWAnyAddressDescription(twAddress); | ||
EXPECT_EQ(addressParameters.address, *reinterpret_cast<const std::string*>(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); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.