-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Codegen]: Generate TWCoinTypeTests.cppp file
- Loading branch information
1 parent
1cca1b1
commit c177cd0
Showing
10 changed files
with
153 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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,31 @@ | ||
// Copyright © 2017-{YEAR} 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 <TrustWalletCore/TWCoinTypeConfiguration.h> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(TW{COIN_TYPE}CoinType, TWCoinType) { | ||
const auto coin = TWCoinType{COIN_TYPE}; | ||
const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin)); | ||
const auto id = WRAPS(TWCoinTypeConfigurationGetID(coin)); | ||
const auto name = WRAPS(TWCoinTypeConfigurationGetName(coin)); | ||
const auto txId = WRAPS(TWStringCreateWithUTF8Bytes("{EXPLORER_SAMPLE_TX}")); | ||
const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); | ||
const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("{EXPLORER_SAMPLE_ACCOUNT}")); | ||
const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); | ||
|
||
assertStringsEqual(id, "{COIN_ID}"); | ||
assertStringsEqual(name, "{COIN_TYPE}"); | ||
assertStringsEqual(symbol, "{SYMBOL}"); | ||
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), {DECIMALS}); | ||
ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchain{BLOCKCHAIN}); | ||
ASSERT_EQ(TWCoinTypeP2pkhPrefix(coin), {P2PKH_PREFIX}); | ||
ASSERT_EQ(TWCoinTypeP2shPrefix(coin), {P2SH_PREFIX}); | ||
ASSERT_EQ(TWCoinTypeStaticPrefix(coin), {STATIC_PREFIX}); | ||
assertStringsEqual(txUrl, "{EXPLORER_URL}{EXPLORER_TX_PATH}{EXPLORER_SAMPLE_TX}"); | ||
assertStringsEqual(accUrl, "{EXPLORER_URL}{EXPLORER_ACCOUNT_PATH}{EXPLORER_SAMPLE_ACCOUNT}"); | ||
} |
48 changes: 48 additions & 0 deletions
48
codegen-v2/src/codegen/cpp/tw_coin_type_tests_generator.rs
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,48 @@ | ||
// 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. | ||
|
||
use crate::codegen::cpp::coin_integration_tests_directory; | ||
use crate::codegen::template_generator::TemplateGenerator; | ||
use crate::registry::CoinItem; | ||
use crate::Result; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
const TW_COIN_TYPE_TESTS_TEMPLATE: &str = include_str!("templates/TWCoinTypeTests.cpp"); | ||
|
||
pub fn tw_coin_type_tests_path(coin: &CoinItem) -> PathBuf { | ||
coin_integration_tests_directory(coin).join("TWCoinTypeTests.cpp") | ||
} | ||
|
||
pub struct TWCoinTypeTestsGenerator { | ||
coin: CoinItem, | ||
} | ||
|
||
impl TWCoinTypeTestsGenerator { | ||
pub fn new(coin: CoinItem) -> TWCoinTypeTestsGenerator { | ||
TWCoinTypeTestsGenerator { coin } | ||
} | ||
|
||
pub fn generate(self) -> Result<()> { | ||
let coin_tests_dir = coin_integration_tests_directory(&self.coin); | ||
let tw_coin_type_tests_path = coin_tests_dir.join("TWCoinTypeTests.cpp"); | ||
|
||
if !coin_tests_dir.exists() { | ||
fs::create_dir(coin_tests_dir)?; | ||
} | ||
|
||
if tw_coin_type_tests_path.exists() { | ||
return Ok(()); | ||
} | ||
|
||
TemplateGenerator::new(TW_COIN_TYPE_TESTS_TEMPLATE) | ||
.write_to(tw_coin_type_tests_path) | ||
.with_default_patterns(&self.coin) | ||
.write()?; | ||
|
||
Ok(()) | ||
} | ||
} |
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
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
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
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
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