Skip to content

Commit

Permalink
fix(derivation): Revert C++ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Aug 1, 2024
1 parent e6baf2a commit c8b4c2e
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 54 deletions.
2 changes: 0 additions & 2 deletions codegen/lib/templates/TWDerivation.h.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ enum TWDerivation {
TWDerivationCustom = 1, // custom, for any coin
<% enum_count += 1 -%>
<% coins.each do |coin| -%>
<% if coin['derivation'].count > 1 -%>
<% coin['derivation'].each_with_index do |deriv, index| -%>
<% if index > 0 or !deriv['name'].nil? -%>
<%= derivation_enum_name(deriv, coin) %> = <% enum_count += 1 -%><%= enum_count %>,
<% end -%>
<% end -%>
<% end -%>
<% end -%>
};

TW_EXTERN_C_END
7 changes: 4 additions & 3 deletions src/Bitcoin/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ std::string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW
case TWCoinTypeSyscoin:
case TWCoinTypeStratis:
switch (derivation) {
case TWDerivationLegacy:
case TWDerivationBitcoinLegacy:
case TWDerivationLitecoinLegacy:
return Address(publicKey, p2pkh).string();

case TWDerivationTestnet:
case TWDerivationBitcoinTestnet:
return SegwitAddress::createTestnetFromPublicKey(publicKey).string();

case TWDerivationSegwit:
case TWDerivationBitcoinSegwit:
case TWDerivationDefault:
default:
return SegwitAddress(publicKey, hrp).string();
Expand Down
2 changes: 1 addition & 1 deletion src/BitcoinDiamond/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TWDeriv
const char* hrp = getFromPrefixHrpOrDefault(addressPrefix, coin);

switch (derivation) {
case TWDerivationLegacy:
case TWDerivationBitcoinLegacy:
case TWDerivationDefault:
return Bitcoin::Address(publicKey, p2pkh).string();
default:
Expand Down
2 changes: 1 addition & 1 deletion src/Groestlcoin/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::string Entry::deriveAddress([[maybe_unused]] TWCoinType coin, const PublicK
auto p2pkh = getFromPrefixPkhOrDefault(addressPrefix, coin);

switch (derivation) {
case TWDerivationLegacy:
case TWDerivationBitcoinLegacy:
return Address(publicKey, p2pkh).string();
default:
return TW::Bitcoin::SegwitAddress(publicKey, hrp).string();
Expand Down
2 changes: 1 addition & 1 deletion src/Verge/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TWDeriv
const char* hrp = getFromPrefixHrpOrDefault(addressPrefix, coin);

switch (derivation) {
case TWDerivationLegacy:
case TWDerivationBitcoinLegacy:
case TWDerivationDefault:
return Bitcoin::Address(publicKey, p2pkh).string();
default:
Expand Down
6 changes: 3 additions & 3 deletions tests/chains/Bitcoin/SegwitAddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ TEST(SegwitAddress, SegwitDerivationHDWallet) {
// addresses with different derivations
EXPECT_EQ(wallet.deriveAddress(coin), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationDefault), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationSegwit), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationLegacy), "1GVb4mfQrvymPLz7zeZ3LnQ8sFv3NedZXe");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationTestnet), "tb1qq8p994ak933c39d2jaj8n4sg598tnkhnyk5sg5");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationBitcoinSegwit), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationBitcoinLegacy), "1GVb4mfQrvymPLz7zeZ3LnQ8sFv3NedZXe");
EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationBitcoinTestnet), "tb1qq8p994ak933c39d2jaj8n4sg598tnkhnyk5sg5");
}

} // namespace TW::Bitcoin::tests
4 changes: 2 additions & 2 deletions tests/chains/BitcoinDiamond/AddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(BitcoinDiamondAddress, FromPublicKey) {
auto addr = wallet.deriveAddress(TWCoinTypeBitcoinDiamond);
EXPECT_EQ(addr, "1KaRW9xPPtCTZ9FdaTHduCPck4YvSeEWNn");

addr = wallet.deriveAddress(TWCoinTypeBitcoinDiamond, TWDerivationSegwit);
addr = wallet.deriveAddress(TWCoinTypeBitcoinDiamond, TWDerivationBitcoinSegwit);
EXPECT_EQ(addr, "bcd1q7jh5qukuy9fc2pjm89xnyvx5dtfyvru9evw30x");
}

Expand All @@ -45,7 +45,7 @@ TEST(BitcoinDiamondAddress, FromString) {

TEST(BitcoinDiamondAddress, AddressData) {
const auto publicKey = PublicKey(parse_hex("02485a209514cc896f8ed736e205bc4c35bd5299ef3f9e84054475336b964c02a3"), TWPublicKeyTypeSECP256k1);
auto address = TW::deriveAddress(TWCoinTypeBitcoinDiamond, publicKey, TWDerivationSegwit);
auto address = TW::deriveAddress(TWCoinTypeBitcoinDiamond, publicKey, TWDerivationBitcoinSegwit);

auto data = TW::addressToData(TWCoinTypeBitcoinDiamond, "1G15VvshDxwFTnahZZECJfFwEkq9fP79o8");
ASSERT_EQ(hex(data), "a48da46386ce52cccad178de900c71f06130c310");
Expand Down
4 changes: 2 additions & 2 deletions tests/chains/BitcoinDiamond/SignerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST(BitcoinDiamondSigner, SignSegwit) {
auto utxoKey0 =
PrivateKey(parse_hex("d2b9f2846d3adcead910ee0124a3ba7ae29e8a4729787d27f9bea1f532928eee"));
auto utxoAddr0 =
TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationSegwit);
TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationBitcoinSegwit);
ASSERT_EQ(utxoAddr0, "bcd1q5jx6gcuxeefvejk30r0fqrr37psnpscslrrd0y");
auto script0 = Bitcoin::Script::lockScriptForAddress(utxoAddr0, TWCoinTypeBitcoinDiamond);
ASSERT_EQ(hex(script0.bytes), "0014a48da46386ce52cccad178de900c71f06130c310");
Expand Down Expand Up @@ -162,7 +162,7 @@ TEST(BitcoinDiamondSigner, SignAnyoneCanPay) {
auto utxoKey0 =
PrivateKey(parse_hex("d2b9f2846d3adcead910ee0124a3ba7ae29e8a4729787d27f9bea1f532928eee"));
auto utxoAddr0 =
TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationSegwit);
TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationBitcoinSegwit);
ASSERT_EQ(utxoAddr0, "bcd1q5jx6gcuxeefvejk30r0fqrr37psnpscslrrd0y");
auto script0 = Bitcoin::Script::lockScriptForAddress(utxoAddr0, TWCoinTypeBitcoinDiamond);
ASSERT_EQ(hex(script0.bytes), "0014a48da46386ce52cccad178de900c71f06130c310");
Expand Down
6 changes: 3 additions & 3 deletions tests/chains/Groestlcoin/AddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ TEST(GroestlcoinAddress, Derive) {
auto address = TW::deriveAddress(TWCoinTypeGroestlcoin, wallet.getKey(TWCoinTypeGroestlcoin, path));
ASSERT_EQ(address, "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne");

address = TW::deriveAddress(TWCoinTypeGroestlcoin, wallet.getKey(TWCoinTypeGroestlcoin, path), TWDerivationLegacy);
address = TW::deriveAddress(TWCoinTypeGroestlcoin, wallet.getKey(TWCoinTypeGroestlcoin, path), TWDerivationBitcoinLegacy);
ASSERT_EQ(address, "FfsAQrzfdECwEsApubn2rvxgamU8CcqsLT");
}

TEST(GroestlcoinAddress, AddressData) {
const auto publicKey = PublicKey(parse_hex("03b85cc59b67c35851eb5060cfc3a759a482254553c5857075c9e247d74d412c91"), TWPublicKeyTypeSECP256k1);
auto address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationLegacy);
auto address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationBitcoinLegacy);
ASSERT_EQ(address, "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM");

auto addressData = TW::addressToData(TWCoinTypeGroestlcoin, address);
ASSERT_EQ(hex(addressData), "98af0aaca388a7e1024f505c033626d908e3b54a");

address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationSegwit);
address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationBitcoinSegwit);
EXPECT_EQ(address, "grs1qnzhs4t9r3zn7zqj02pwqxd3xmyyw8d22q55nf8");

addressData = TW::addressToData(TWCoinTypeGroestlcoin, address);
Expand Down
4 changes: 2 additions & 2 deletions tests/chains/Litecoin/LitecoinAddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace TW::Bitcoin::tests {

TEST(LitecoinAddress, deriveAddress_legacy) {
const auto pubKey = PublicKey(parse_hex("03b49081a4d7ad24b20e209bc6fe10491aadb5607777baf0509a036cce96025db0"), TWPublicKeyTypeSECP256k1);
auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationLegacy);
auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationLitecoinLegacy);
EXPECT_EQ(addrStr, "LW6HjAU6GL9fK2LZWUA6VZCzomTdrpx3nr");

const auto address = Address(pubKey, TWCoinTypeP2pkhPrefix(TWCoinTypeLitecoin));
Expand All @@ -29,7 +29,7 @@ TEST(LitecoinAddress, deriveAddress_legacy) {

TEST(LitecoinAddress, deriveAddress_segwit) {
const auto pubKey = PublicKey(parse_hex("030fc2fdd1a0b5d43b31227a4b1cd57e7d35a6edc93fb12f9315e67762abeb8be0"), TWPublicKeyTypeSECP256k1);
auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationSegwit);
auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationBitcoinSegwit);
EXPECT_EQ(addrStr, "ltc1q3m3ujh350qrqdl33pv7pjw0d0m9qnm6qjcjpga");

const auto address = SegwitAddress(pubKey, stringForHRP(TWCoinTypeHRP(TWCoinTypeLitecoin)));
Expand Down
2 changes: 1 addition & 1 deletion tests/chains/Nebl/AddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(NeblAddress, FromPublicKey) {
auto address = Address(publicKey, TWCoinTypeP2pkhPrefix(TWCoinTypeNebl));
ASSERT_EQ(address.string(), "NboLGGKWtK5eXzaah5GVpXju9jCcoMi4cc");

auto addr = TW::deriveAddress(TWCoinTypeNebl, publicKey, TWDerivationLegacy);
auto addr = TW::deriveAddress(TWCoinTypeNebl, publicKey, TWDerivationBitcoinLegacy);
ASSERT_EQ(addr, "NboLGGKWtK5eXzaah5GVpXju9jCcoMi4cc");
}

Expand Down
4 changes: 2 additions & 2 deletions tests/chains/Verge/AddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(VergeAddress, FromPrivateKey) {
auto address = Address(publicKey, TWCoinTypeP2pkhPrefix(TWCoinTypeVerge));
ASSERT_EQ(address.string(), "DRyNFvJaybnF22UfMS6NR1Qav3mqxPj86E");

auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationSegwit);
auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationBitcoinSegwit);
ASSERT_EQ(addr, "vg1qujpe553lzgyg95g7k0w6zwscuy0ae022h4q4zg");
}

Expand All @@ -40,7 +40,7 @@ TEST(VergeAddress, FromPublicKey) {
auto address = Address(publicKey, TWCoinTypeP2pkhPrefix(TWCoinTypeVerge));
ASSERT_EQ(address.string(), "D8rBdwBfz5wvLhmHvRkXnNzeeihQgxkLmL");

auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationLegacy);
auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationBitcoinLegacy);
ASSERT_EQ(addr, "D8rBdwBfz5wvLhmHvRkXnNzeeihQgxkLmL");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/common/AnyAddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST(AnyAddress, createFromPubKeyDerivation) {
EXPECT_EQ(addr->address, ANY_ADDRESS_TEST_ADDRESS);
}
{
std::unique_ptr<AnyAddress> addr(AnyAddress::createAddress(publicKey, TWCoinTypeBitcoin, TWDerivationLegacy, std::monostate()));
std::unique_ptr<AnyAddress> addr(AnyAddress::createAddress(publicKey, TWCoinTypeBitcoin, TWDerivationBitcoinLegacy, std::monostate()));
EXPECT_EQ(addr->address, "1JvRfEQFv5q5qy9uTSAezH7kVQf4hqnHXx");
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/common/Keystore/DerivationPathTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ TEST(Derivation, derivationPath) {
TEST(Derivation, alternativeDerivation) {
EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin).string(), "m/84'/0'/0'/0/0");
EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationDefault).string(), "m/84'/0'/0'/0/0");
EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationSegwit).string(), "m/84'/0'/0'/0/0");
EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationSegwit)), "segwit");
EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationLegacy).string(), "m/44'/0'/0'/0/0");
EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationLegacy)), "legacy");
EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationBitcoinSegwit).string(), "m/84'/0'/0'/0/0");
EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationBitcoinSegwit)), "segwit");
EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationBitcoinLegacy).string(), "m/44'/0'/0'/0/0");
EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationBitcoinLegacy)), "legacy");

EXPECT_EQ(TW::derivationPath(TWCoinTypeLitecoin, TWDerivationDefault).string(), "m/84'/2'/0'/0/0");
EXPECT_EQ(TW::derivationPath(TWCoinTypeLitecoin, TWDerivationLegacy).string(), "m/44'/2'/0'/0/0");
EXPECT_EQ(TW::derivationPath(TWCoinTypeLitecoin, TWDerivationLitecoinLegacy).string(), "m/44'/2'/0'/0/0");

EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana).string(), "m/44'/501'/0'");
EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana, TWDerivationDefault).string(), "m/44'/501'/0'");
EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana, TWDerivationSolana).string(), "m/44'/501'/0'/0'");
EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeSolana, TWDerivationSolana)), "solana");
EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana, TWDerivationSolanaSolana).string(), "m/44'/501'/0'/0'");
EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeSolana, TWDerivationSolanaSolana)), "solana");
}

} // namespace TW
18 changes: 9 additions & 9 deletions tests/common/Keystore/StoredKeyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,17 @@ TEST(StoredKey, AddRemoveAccountDerivation) {
EXPECT_EQ(key.accounts.size(), 1ul);
}
{
key.addAccount("1NyRyFewhZcWMa9XCj3bBxSXPXyoSg8dKz", coinTypeBc, TWDerivationLegacy, derivationPath, "", "xpub6CR52eaUuVb4kXAVyHC2i5ZuqJ37oWNPZFtjXaazFPXZD45DwWBYEBLdrF7fmCR9pgBuCA9Q57zZfyJjDUBDNtWkhWuGHNYKLgDHpqrHsxV");
key.addAccount("1NyRyFewhZcWMa9XCj3bBxSXPXyoSg8dKz", coinTypeBc, TWDerivationBitcoinLegacy, derivationPath, "", "xpub6CR52eaUuVb4kXAVyHC2i5ZuqJ37oWNPZFtjXaazFPXZD45DwWBYEBLdrF7fmCR9pgBuCA9Q57zZfyJjDUBDNtWkhWuGHNYKLgDHpqrHsxV");
EXPECT_EQ(key.accounts.size(), 2ul);
}

key.removeAccount(coinTypeBc, TWDerivationDefault);
EXPECT_EQ(key.accounts.size(), 1ul);
key.removeAccount(coinTypeBc, TWDerivationDefault); // try 2nd time
EXPECT_EQ(key.accounts.size(), 1ul);
key.removeAccount(coinTypeBc, TWDerivationLegacy);
key.removeAccount(coinTypeBc, TWDerivationBitcoinLegacy);
EXPECT_EQ(key.accounts.size(), 0ul);
key.removeAccount(coinTypeBc, TWDerivationLegacy); // try 2nd time
key.removeAccount(coinTypeBc, TWDerivationBitcoinLegacy); // try 2nd time
EXPECT_EQ(key.accounts.size(), 0ul);
}

Expand Down Expand Up @@ -627,23 +627,23 @@ TEST(StoredKey, CreateMultiAccounts) { // Multiple accounts for the same coin
{ // Create alternative P2PK Bitcoin account (different address format)
const auto coin = TWCoinTypeBitcoin;

const auto btc2 = key.account(coin, TWDerivationLegacy, wallet);
const auto btc2 = key.account(coin, TWDerivationBitcoinLegacy, wallet);

EXPECT_EQ(btc2.address, expectedBtc2);
EXPECT_EQ(btc2.derivationPath.string(), "m/44'/0'/0'/0/0");
EXPECT_EQ(btc2.extendedPublicKey, "xpub6CR52eaUuVb4kXAVyHC2i5ZuqJ37oWNPZFtjXaazFPXZD45DwWBYEBLdrF7fmCR9pgBuCA9Q57zZfyJjDUBDNtWkhWuGHNYKLgDHpqrHsxV");
EXPECT_EQ(key.accounts.size(), ++expectedAccounts);
EXPECT_EQ(key.accounts[expectedAccounts - 1].address, expectedBtc2);
EXPECT_EQ(key.account(coin)->address, expectedBtc1);
EXPECT_EQ(key.account(coin, TWDerivationLegacy, wallet).address, expectedBtc2);
EXPECT_EQ(key.account(coin, TWDerivationBitcoinLegacy, wallet).address, expectedBtc2);
EXPECT_EQ(key.getAccounts(coin).size(), 2ul);
EXPECT_EQ(key.getAccounts(coin)[0].address, expectedBtc1);
EXPECT_EQ(key.getAccounts(coin)[1].address, expectedBtc2);
}
{ // Create alternative Solana account with non-default derivation path (different derivation path and address)
const auto coin = TWCoinTypeSolana;

const auto sol2 = key.account(coin, TWDerivationSolana, wallet);
const auto sol2 = key.account(coin, TWDerivationSolanaSolana, wallet);

const auto expectedSol2 = "CgWJeEWkiYqosy1ba7a3wn9HAQuHyK48xs3LM4SSDc1C";
EXPECT_EQ(sol2.address, expectedSol2);
Expand All @@ -652,7 +652,7 @@ TEST(StoredKey, CreateMultiAccounts) { // Multiple accounts for the same coin
EXPECT_EQ(key.accounts[expectedAccounts - 1].address, expectedSol2);
// Now we have 2 Solana addresses, 1st is returned here
EXPECT_EQ(key.account(coin)->address, expectedSol1);
EXPECT_EQ(key.account(coin, TWDerivationSolana, wallet).address, expectedSol2);
EXPECT_EQ(key.account(coin, TWDerivationSolanaSolana, wallet).address, expectedSol2);
EXPECT_EQ(key.getAccounts(coin).size(), 2ul);
EXPECT_EQ(key.getAccounts(coin)[0].address, expectedSol1);
EXPECT_EQ(key.getAccounts(coin)[1].address, expectedSol2);
Expand Down Expand Up @@ -697,13 +697,13 @@ TEST(StoredKey, CreateWithMnemonicAlternativeDerivation) {
ASSERT_EQ(key.accounts.size(), 1ul);

// alternative derivation, different keys
EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151");
EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolanaSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151");

ASSERT_EQ(key.accounts.size(), 2ul);
EXPECT_EQ(key.accounts[1].coin, coin);
EXPECT_EQ(key.accounts[1].address, "CgWJeEWkiYqosy1ba7a3wn9HAQuHyK48xs3LM4SSDc1C");
EXPECT_EQ(key.accounts[1].publicKey, "ad8f57924dce62f9040f93b4f6ce3c3d39afde7e29bcb4013dad59db7913c4c7");
EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151");
EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolanaSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151");
}

} // namespace TW::Keystore
4 changes: 2 additions & 2 deletions tests/interface/TWAnyAddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ TEST(TWAnyAddress, createFromPubKeyDerivation) {
assertStringsEqual(WRAPS(TWAnyAddressDescription(addr.get())), "bc1qcj2vfjec3c3luf9fx9vddnglhh9gawmncmgxhz");
}
{
const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationLegacy));
const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationBitcoinLegacy));
assertStringsEqual(WRAPS(TWAnyAddressDescription(addr.get())), "1JvRfEQFv5q5qy9uTSAezH7kVQf4hqnHXx");
}
{
const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationTestnet));
const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationBitcoinTestnet));
assertStringsEqual(WRAPS(TWAnyAddressDescription(addr.get())), "tb1qcj2vfjec3c3luf9fx9vddnglhh9gawmnjan4v3");
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/interface/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ TEST(TWCoinType, DeriveAddress) {
auto pkData = DATA("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798");
auto publicKey = WRAP(TWPublicKey, TWPublicKeyCreateWithData(pkData.get(), TWPublicKeyTypeSECP256k1));

auto address = WRAPS(TWCoinTypeDeriveAddressFromPublicKeyAndDerivation(TWCoinTypeBitcoin, publicKey.get(), TWDerivationSegwit));
auto address = WRAPS(TWCoinTypeDeriveAddressFromPublicKeyAndDerivation(TWCoinTypeBitcoin, publicKey.get(), TWDerivationBitcoinSegwit));
assertStringsEqual(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
}

Expand All @@ -162,14 +162,14 @@ TEST(TWCoinType, TWCoinTypeDerivationPath) {
}

TEST(TWCoinType, TWCoinTypeDerivationPathWithDerivation) {
auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeBitcoin, TWDerivationLegacy);
auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeBitcoin, TWDerivationBitcoinLegacy);
auto result = *reinterpret_cast<const std::string *>(res);
ASSERT_EQ(result, "m/44'/0'/0'/0/0");
TWStringDelete(res);
}

TEST(TWCoinType, TWCoinTypeDerivationPathWithDerivationSolana) {
auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeSolana, TWDerivationSolana);
auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeSolana, TWDerivationSolanaSolana);
auto result = *reinterpret_cast<const std::string *>(res);
ASSERT_EQ(result, "m/44'/501'/0'/0'");
TWStringDelete(res);
Expand Down
Loading

0 comments on commit c8b4c2e

Please sign in to comment.