Skip to content

Commit

Permalink
[Codegen] Map coin test folder name to coin-id (trustwallet#2574)
Browse files Browse the repository at this point in the history
* [Codegen] Renamed test directories to match coin ID-s
Also, rename Ripple and (H)ECO, split Terra/TerraV2 and Evmos/NativeEvmos
* Fix compiler error after Ripple -> XRP directories renamed
* Remove exclusion list; add optional coin property testFolderName
  • Loading branch information
miloserdow authored Sep 21, 2022
1 parent e61fedd commit 5e2c207
Show file tree
Hide file tree
Showing 31 changed files with 712 additions and 657 deletions.
8 changes: 0 additions & 8 deletions codegen/bin/cointests
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ CurrentDir = File.dirname(__FILE__)
$LOAD_PATH.unshift(File.join(CurrentDir, '..', 'lib'))
require 'coin_test_gen'

# Transforms a coin name to a C++ name
def self.format_name(n)
formatted = n
#formatted = formatted.sub(/^([a-z]+)/, &:upcase)
formatted = formatted.sub(/\s/, '')
formatted
end

# Transforms number to hex
def self.to_hex(i)
hex = i.to_i().to_s(16)
Expand Down
14 changes: 11 additions & 3 deletions codegen/lib/coin_test_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def initialize()
# Transforms a coin name to a C++ name
def format_name(n)
formatted = n
#formatted = formatted.sub(/^([a-z]+)/, &:upcase)
formatted = formatted.sub(/\s/, '')

# Remove whitespaces
formatted.gsub!(/\s+/, '')

formatted
end

Expand Down Expand Up @@ -61,7 +63,13 @@ def generate_coin_test_file(coin, templateFile, overwriteExisting = true)
template = ERB.new(File.read(path), nil, '-')
result = template.result(binding)

folder = 'tests/' + format_name(coin['name'])
folder = 'tests/'
if coin.key?('testFolderName')
folder += format_name(coin['testFolderName'])
else
folder += format_name(coin['name'])
end

file = 'TWCoinTypeTests.cpp'
FileUtils.mkdir_p folder
path = File.join(folder, file)
Expand Down
21 changes: 14 additions & 7 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,8 @@
"rpc": "https://data-seed-prebsc-1-s1.binance.org:8545",
"documentation": "https://eth.wiki/json-rpc/API"
},
"deprecated": true
"deprecated": true,
"testFolderName" : "Binance"
},
{
"id": "smartchain",
Expand Down Expand Up @@ -1937,7 +1938,8 @@
"source": "https://github.com/binance-chain/bsc",
"rpc": "https://bsc-dataseed1.binance.org",
"documentation": "https://eth.wiki/json-rpc/API"
}
},
"testFolderName" : "Binance"
},
{
"id": "polygon",
Expand Down Expand Up @@ -2086,7 +2088,8 @@
"source": "https://github.com/HuobiGroup/huobi-eco-chain",
"rpc": "https://http-mainnet-node.huobichain.com",
"documentation": "https://eth.wiki/json-rpc/API"
}
},
"testFolderName" : "ECO"
},
{
"id": "avalanchec",
Expand Down Expand Up @@ -2116,7 +2119,8 @@
"client": "https://github.com/ava-labs/avalanchego",
"clientPublic": "https://api.avax.network/ext/bc/C/rpc",
"clientDocs": "https://docs.avax.network/"
}
},
"testFolderName" : "Avalanche"
},
{
"id": "xdai",
Expand Down Expand Up @@ -2363,7 +2367,8 @@
"client": "https://github.com/crypto-org-chain/cronos",
"clientPublic": "https://evm-cronos.crypto.org",
"clientDocs": "https://eth.wiki/json-rpc/API"
}
},
"testFolderName" : "Cronos"
},
{
"id": "kavaevm",
Expand Down Expand Up @@ -2421,7 +2426,8 @@
"source": "https://github.com/smartbch/smartbch",
"rpc": "https://smartbch.fountainhead.cash/mainnet",
"documentation": "https://github.com/smartbch/docs/blob/main/developers-guide/jsonrpc.md"
}
},
"testFolderName" : "Bitcoin"
},
{
"id": "kcc",
Expand Down Expand Up @@ -2451,7 +2457,8 @@
"source": "https://github.com/kcc-community/kcc",
"rpc": "https://rpc-mainnet.kcc.network",
"documentation": "https://docs.kcc.io/#/en-us/"
}
},
"testFolderName" : "KuCoinCommunityChain"
},
{
"id": "boba",
Expand Down
2 changes: 1 addition & 1 deletion src/Coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "Oasis/Entry.h"
#include "Ontology/Entry.h"
#include "Polkadot/Entry.h"
#include "Ripple/Entry.h"
#include "XRP/Entry.h"
#include "Ronin/Entry.h"
#include "Solana/Entry.h"
#include "Stellar/Entry.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/interface/TWRippleXAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

#include "../Ripple/XAddress.h"
#include "../XRP/XAddress.h"

#include <TrustWalletCore/TWHash.h>
#include <TrustWalletCore/TWPublicKey.h>
Expand Down
File renamed without changes.
25 changes: 3 additions & 22 deletions tests/Evmos/TWAnyAddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include <gtest/gtest.h>

namespace TW::Evmos::tests {

TEST(EvmosAnyAddress, EvmosValidate) {
auto string = STRING("0x30627903124Aa1e71384bc52e1cb96E4AB3252b6");

Expand All @@ -34,25 +36,4 @@ TEST(EvmosAnyAddress, EvmosCreate) {
assertHexEqual(keyHash, "8f348f300873fd5da36950b2ac75a26584584fee");
}

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::Evmos::tests
21 changes: 3 additions & 18 deletions tests/Evmos/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <TrustWalletCore/TWCoinTypeConfiguration.h>
#include <gtest/gtest.h>

namespace TW::Evmos::tests {

TEST(TWEvmosCoinType, TWCoinTypeEvmos) {
auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeEvmos));
auto txId = WRAPS(TWStringCreateWithUTF8Bytes("0x24af42cf4977a96d62e3a82c3cd9b519c3e7c53dd83398b88f0cb435d867b422"));
Expand All @@ -27,21 +29,4 @@ TEST(TWEvmosCoinType, TWCoinTypeEvmos) {
assertStringsEqual(name, "Evmos");
}

TEST(TWEvmosCoinType, TWCoinTypeNativeEvmos) {
auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeNativeEvmos));
auto txId = WRAPS(TWStringCreateWithUTF8Bytes("A16C211C83AD1E684DE46F694FAAC17D8465C864BD7385A81EC062CDE0638811"));
auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeNativeEvmos, txId.get()));
auto accId = WRAPS(TWStringCreateWithUTF8Bytes("evmos17xpfvakm2amg962yls6f84z3kell8c5ljcjw34"));
auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(TWCoinTypeNativeEvmos, accId.get()));
auto id = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeNativeEvmos));
auto name = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeNativeEvmos));

ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeNativeEvmos), 18);
ASSERT_EQ(TWBlockchainCosmos, TWCoinTypeBlockchain(TWCoinTypeNativeEvmos));

assertStringsEqual(symbol, "EVMOS");
assertStringsEqual(txUrl, "https://mintscan.io/evmos/txs/A16C211C83AD1E684DE46F694FAAC17D8465C864BD7385A81EC062CDE0638811");
assertStringsEqual(accUrl, "https://mintscan.io/evmos/account/evmos17xpfvakm2amg962yls6f84z3kell8c5ljcjw34");
assertStringsEqual(id, "nativeevmos");
assertStringsEqual(name, "Native Evmos");
}
} // namespace TW::Evmos::tests
39 changes: 39 additions & 0 deletions tests/NativeEvmos/TWAnyAddressTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © 2017-2022 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 "../interface/TWTestUtilities.h"

#include <TrustWalletCore/TWAnyAddress.h>
#include <TrustWalletCore/TWCoinType.h>

#include <gtest/gtest.h>

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
32 changes: 32 additions & 0 deletions tests/NativeEvmos/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright © 2017-2022 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 "../interface/TWTestUtilities.h"
#include <TrustWalletCore/TWCoinTypeConfiguration.h>
#include <gtest/gtest.h>

namespace TW::NativeEvmos::tests {

TEST(TWEvmosCoinType, TWCoinTypeNativeEvmos) {
auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeNativeEvmos));
auto txId = WRAPS(TWStringCreateWithUTF8Bytes("A16C211C83AD1E684DE46F694FAAC17D8465C864BD7385A81EC062CDE0638811"));
auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeNativeEvmos, txId.get()));
auto accId = WRAPS(TWStringCreateWithUTF8Bytes("evmos17xpfvakm2amg962yls6f84z3kell8c5ljcjw34"));
auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(TWCoinTypeNativeEvmos, accId.get()));
auto id = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeNativeEvmos));
auto name = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeNativeEvmos));

ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeNativeEvmos), 18);
ASSERT_EQ(TWBlockchainCosmos, TWCoinTypeBlockchain(TWCoinTypeNativeEvmos));

assertStringsEqual(symbol, "EVMOS");
assertStringsEqual(txUrl, "https://mintscan.io/evmos/txs/A16C211C83AD1E684DE46F694FAAC17D8465C864BD7385A81EC062CDE0638811");
assertStringsEqual(accUrl, "https://mintscan.io/evmos/account/evmos17xpfvakm2amg962yls6f84z3kell8c5ljcjw34");
assertStringsEqual(id, "nativeevmos");
assertStringsEqual(name, "Native Evmos");
}

} // namespace TW::NativeEvmos::tests
Loading

0 comments on commit 5e2c207

Please sign in to comment.