Skip to content

Commit

Permalink
update tests for HD wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Oct 7, 2024
1 parent e1947ea commit eb1cd6f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -4791,7 +4791,7 @@
"blockchain": "Pactus",
"derivation": [
{
"path": "m/44'/21888'/2'/0"
"path": "m/44'/21888'/3'/0'"
}
],
"curve": "ed25519",
Expand Down
2 changes: 1 addition & 1 deletion rust/tw_tests/tests/coin_address_derivation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
37 changes: 37 additions & 0 deletions tests/chains/Pactus/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
// Copyright © 2017 Trust Wallet.

#include "TestUtilities.h"
#include "Pactus/Entry.h"
#include "PrivateKey.h"
#include "PublicKey.h"
#include <TrustWalletCore/TWCoinTypeConfiguration.h>
#include <TrustWalletCore/TWAnyAddress.h>
#include <TrustWalletCore/TWHDWallet.h>
#include <gtest/gtest.h>

namespace TW::Pactus::tests {

TEST(TWPactusCoinType, TWCoinType) {
const auto coin = TWCoinTypePactus;
const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin));
Expand All @@ -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);
}

}
2 changes: 1 addition & 1 deletion tests/common/CoinAddressDerivationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb1cd6f

Please sign in to comment.