From eb1cd6fe5789fab604be6c581f1b4b084f56eaae Mon Sep 17 00:00:00 2001 From: Mostafa Date: Wed, 28 Aug 2024 23:56:20 +0800 Subject: [PATCH] update tests for HD wallet --- registry.json | 2 +- .../tests/coin_address_derivation_test.rs | 2 +- tests/chains/Pactus/TWCoinTypeTests.cpp | 37 +++++++++++++++++++ tests/common/CoinAddressDerivationTests.cpp | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/registry.json b/registry.json index 0e5cdc65a66..17ee4bdd977 100644 --- a/registry.json +++ b/registry.json @@ -4791,7 +4791,7 @@ "blockchain": "Pactus", "derivation": [ { - "path": "m/44'/21888'/2'/0" + "path": "m/44'/21888'/3'/0'" } ], "curve": "ed25519", diff --git a/rust/tw_tests/tests/coin_address_derivation_test.rs b/rust/tw_tests/tests/coin_address_derivation_test.rs index 1c7ffc295a3..17d758e40c6 100644 --- a/rust/tw_tests/tests/coin_address_derivation_test.rs +++ b/rust/tw_tests/tests/coin_address_derivation_test.rs @@ -155,7 +155,7 @@ fn test_coin_address_derivation() { CoinType::Solana => "5sn9QYhDaq61jLXJ8Li5BKqGL4DDMJQvU1rdN8XgVuwC", CoinType::Sui => "0x01a5c6c1b74cec4fbd12b3e17252b83448136065afcdf24954dc3a9c26df4905", CoinType::TON => "UQCj3jAU_Ec2kXdAqweKt4rYjiwTNwiCfaUnIDHGh7wTwx_G", - CoinType::Pactus => todo!(), + CoinType::Pactus => "pc1rk2qaaeu9pj3zwtvm49d3d4yqxzpp4te87cx0am", // end_of_coin_address_derivation_tests_marker_do_not_modify _ => panic!("{:?} must be covered", coin), }; diff --git a/tests/chains/Pactus/TWCoinTypeTests.cpp b/tests/chains/Pactus/TWCoinTypeTests.cpp index 2435428a1b8..2a6636f44d6 100644 --- a/tests/chains/Pactus/TWCoinTypeTests.cpp +++ b/tests/chains/Pactus/TWCoinTypeTests.cpp @@ -3,9 +3,16 @@ // Copyright © 2017 Trust Wallet. #include "TestUtilities.h" +#include "Pactus/Entry.h" +#include "PrivateKey.h" +#include "PublicKey.h" #include +#include +#include #include +namespace TW::Pactus::tests { + TEST(TWPactusCoinType, TWCoinType) { const auto coin = TWCoinTypePactus; const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin)); @@ -27,3 +34,33 @@ TEST(TWPactusCoinType, TWCoinType) { assertStringsEqual(txUrl, "https://pacviewer.com/transaction/"); assertStringsEqual(accUrl, "https://pacviewer.com/address/"); } + +TEST(TWPactusCoinType, DerivationPath) { + auto derivationPath = TWCoinTypeDerivationPath(TWCoinTypePactus); + assertStringsEqual(WRAPS(derivationPath), "m/44'/21888'/3'/0'"); +} + +TEST(TWPactusCoinType, HDWallet) { + auto mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon cactus"; + auto passphrase = ""; + auto wallet = WRAP(TWHDWallet, TWHDWalletCreateWithMnemonic(STRING(mnemonic).get(), STRING(passphrase).get())); + + auto derivationPath1 = TWStringCreateWithUTF8Bytes("m/44'/21888'/3'/0'"); + auto privateKey1 = WRAP(TWPrivateKey, TWHDWalletGetKey(wallet.get(), TWCoinTypePactus, derivationPath1)); + auto publicKey1 = WRAP(TWPublicKey, TWPrivateKeyGetPublicKeyEd25519(privateKey1.get())); + auto address1 = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKey(publicKey1.get(), TWCoinTypePactus)); + auto addressStr1 = WRAPS(TWAnyAddressDescription(address1.get())); + + auto derivationPath2 = TWStringCreateWithUTF8Bytes("m/44'/21888'/3'/1'"); + auto privateKey2 = WRAP(TWPrivateKey, TWHDWalletGetKey(wallet.get(), TWCoinTypePactus, derivationPath2)); + auto publicKey2 = WRAP(TWPublicKey, TWPrivateKeyGetPublicKeyEd25519(privateKey2.get())); + auto address2 = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKey(publicKey2.get(), TWCoinTypePactus)); + auto addressStr2 = WRAPS(TWAnyAddressDescription(address2.get())); + + assertStringsEqual(addressStr1, "pc1rcx9x55nfme5juwdgxd2ksjdcmhvmvkrygmxpa3"); + assertStringsEqual(addressStr2, "pc1r7aynw9urvh66ktr3fte2gskjjnxzruflkgde94"); + TWStringDelete(derivationPath1); + TWStringDelete(derivationPath2); +} + +} \ No newline at end of file diff --git a/tests/common/CoinAddressDerivationTests.cpp b/tests/common/CoinAddressDerivationTests.cpp index a0300abecb9..6df5336c5c0 100644 --- a/tests/common/CoinAddressDerivationTests.cpp +++ b/tests/common/CoinAddressDerivationTests.cpp @@ -397,7 +397,7 @@ TEST(Coin, DeriveAddress) { EXPECT_EQ(address, "dydx1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z0sz38vk"); break; case TWCoinTypePactus: - EXPECT_EQ(address, "__TODO__"); + EXPECT_EQ(address, "pc1rehvlc6tfn79z0zjqqaj8zas5j5h9c2fe59a4ff"); break; // end_of_coin_address_derivation_tests_marker_do_not_modify // no default branch here, intentionally, to better notice any missing coins