From d465c78e8c25c8fd54d2bba0f73209f5b1209038 Mon Sep 17 00:00:00 2001 From: Satoshi Otomakan Date: Tue, 10 Sep 2024 09:50:57 +0200 Subject: [PATCH] feat(ton): Fix C++ build --- tests/common/Keystore/StoredKeyTonTests.cpp | 66 ++++++++++----------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/common/Keystore/StoredKeyTonTests.cpp b/tests/common/Keystore/StoredKeyTonTests.cpp index ef37738f31c..c41f25376c8 100644 --- a/tests/common/Keystore/StoredKeyTonTests.cpp +++ b/tests/common/Keystore/StoredKeyTonTests.cpp @@ -20,61 +20,61 @@ namespace TW::Keystore::tests { using namespace std; -static const auto gName = "name"; -static const auto gPasswordString = "password"; -static const auto gPassword = TW::data(string(gPasswordString)); -static const auto gTonMnemonic = "protect drill sugar gallery note admit input wrist chicken swarm scheme hedgehog orbit ritual glove ski buddy slogan fragile sun delay toy lucky require"; +const auto gTONName = "name"; +const auto gTONPasswordString = "password"; +const auto gTONPassword = TW::data(string(gTONPasswordString)); +const auto gTONMnemonic = "protect drill sugar gallery note admit input wrist chicken swarm scheme hedgehog orbit ritual glove ski buddy slogan fragile sun delay toy lucky require"; // The following TON mnemonic requires a passphrase to be used that we don't support right now. -static const auto gInvalidMnemonic = "mimic close sibling chair shuffle goat fashion chunk increase tennis scene ceiling divert cross treat happy soccer sample umbrella oyster advance quality perfect call"; -static const auto gPrivateKey = "cdcea50b87d3f1ca859e7b2bdf9a5339b7b6804b5c70ac85198829f9607dc43b"; -static const auto gPublicKey = "9016f03f9cfa4e183707761f25407e0e1975194a33a56b3e8d2c26f2438fa3d1"; -static const auto gBounceableAddress = "EQBlm676c6vy6Q9Js732pvf3ivfmIkVc0MVDQy-F6NAFJYPh"; -static const auto gNonBounceableAddress = "UQBlm676c6vy6Q9Js732pvf3ivfmIkVc0MVDQy-F6NAFJd4k"; +const auto gTONInvalidMnemonic = "mimic close sibling chair shuffle goat fashion chunk increase tennis scene ceiling divert cross treat happy soccer sample umbrella oyster advance quality perfect call"; +const auto gTONPrivateKey = "cdcea50b87d3f1ca859e7b2bdf9a5339b7b6804b5c70ac85198829f9607dc43b"; +const auto gTONPublicKey = "9016f03f9cfa4e183707761f25407e0e1975194a33a56b3e8d2c26f2438fa3d1"; +const auto gBounceableAddress = "EQBlm676c6vy6Q9Js732pvf3ivfmIkVc0MVDQy-F6NAFJYPh"; +const auto gNonBounceableAddress = "UQBlm676c6vy6Q9Js732pvf3ivfmIkVc0MVDQy-F6NAFJd4k"; static std::string testDataPath(const char* subpath) { return TESTS_ROOT + "/common/Keystore/Data/" + subpath; } TEST(StoredKeyTon, CreateWithTonMnemonicAddDefault) { - auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeTON, gTonMnemonic); + auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeTON, gTONMnemonic); EXPECT_EQ(key.type, StoredKeyType::tonMnemonicPhrase); - const Data& mnemo2Data = key.payload.decrypt(gPassword); - EXPECT_EQ(string(mnemo2Data.begin(), mnemo2Data.end()), string(gTonMnemonic)); + const Data& mnemo2Data = key.payload.decrypt(gTONPassword); + EXPECT_EQ(string(mnemo2Data.begin(), mnemo2Data.end()), string(gTONMnemonic)); EXPECT_EQ(key.accounts.size(), 1ul); EXPECT_EQ(key.accounts[0].coin, TWCoinTypeTON); EXPECT_EQ(key.accounts[0].address, "UQBlm676c6vy6Q9Js732pvf3ivfmIkVc0MVDQy-F6NAFJd4k"); - EXPECT_EQ(key.accounts[0].publicKey, gPublicKey); + EXPECT_EQ(key.accounts[0].publicKey, gTONPublicKey); EXPECT_EQ(key.accounts[0].extendedPublicKey, ""); EXPECT_EQ(key.accounts[0].derivationPath.string(), ""); EXPECT_EQ(key.accounts[0].derivation, TWDerivationDefault); - EXPECT_EQ(hex(key.privateKey(TWCoinTypeTON, gPassword).bytes), gPrivateKey); + EXPECT_EQ(hex(key.privateKey(TWCoinTypeTON, gTONPassword).bytes), gTONPrivateKey); EXPECT_EQ(key.payload.params.cipher(), "aes-128-ctr"); const auto json = key.json(); - EXPECT_EQ(json["name"], gName); + EXPECT_EQ(json["name"], gTONName); EXPECT_EQ(json["type"], "ton-mnemonic"); EXPECT_EQ(json["version"], 3); } TEST(StoredKeyTon, CreateWithTonMnemonicInvalid) { EXPECT_THROW( - StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeTON, gInvalidMnemonic), + StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeTON, gTONInvalidMnemonic), std::invalid_argument ); } TEST(StoredKeyTon, CreateWithTonMnemonicInvalidCoinType) { EXPECT_THROW( - StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeBitcoin, gTonMnemonic), + StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeBitcoin, gTONMnemonic), std::invalid_argument ); } TEST(StoredKeyTon, CreateWithMnemonicAddDefaultAddressAes256) { - auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeTON, gTonMnemonic, TWStoredKeyEncryptionAes256Ctr); + auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeTON, gTONMnemonic, TWStoredKeyEncryptionAes256Ctr); EXPECT_EQ(key.type, StoredKeyType::tonMnemonicPhrase); - const Data& mnemo2Data = key.payload.decrypt(gPassword); - EXPECT_EQ(string(mnemo2Data.begin(), mnemo2Data.end()), string(gTonMnemonic)); + const Data& mnemo2Data = key.payload.decrypt(gTONPassword); + EXPECT_EQ(string(mnemo2Data.begin(), mnemo2Data.end()), string(gTONMnemonic)); EXPECT_EQ(key.accounts.size(), 1ul); EXPECT_EQ(key.accounts[0].coin, TWCoinTypeTON); EXPECT_EQ(key.accounts[0].address, "UQBlm676c6vy6Q9Js732pvf3ivfmIkVc0MVDQy-F6NAFJd4k"); @@ -82,12 +82,12 @@ TEST(StoredKeyTon, CreateWithMnemonicAddDefaultAddressAes256) { } TEST(StoredKeyTon, HDWalletNotSupported) { - auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeTON, gTonMnemonic); - EXPECT_THROW(key.wallet(gPassword), std::invalid_argument); + auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeTON, gTONMnemonic); + EXPECT_THROW(key.wallet(gTONPassword), std::invalid_argument); } TEST(StoredKeyTon, AddRemoveAccount) { - auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeTON, gTonMnemonic); + auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeTON, gTONMnemonic); EXPECT_EQ(key.accounts.size(), 1ul); // Add another dummy (doesn't belong to the mnemonic) TON account. @@ -105,28 +105,28 @@ TEST(StoredKeyTon, AddRemoveAccount) { TEST(StoredKeyTon, FixAddressHasNoEffect) { // `StoredKey::createWithTonMnemonicAddDefaultAddress` derives the correct address. - auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gName, gPassword, TWCoinTypeTON, gTonMnemonic); + auto key = StoredKey::createWithTonMnemonicAddDefaultAddress(gTONName, gTONPassword, TWCoinTypeTON, gTONMnemonic); EXPECT_EQ(key.accounts.size(), 1ul); - key.fixAddresses(gPassword); + key.fixAddresses(gTONPassword); EXPECT_EQ(key.accounts[0].address, gNonBounceableAddress); } TEST(StoredKeyTon, FixAddress) { - auto key = StoredKey::createWithTonMnemonic(gName, gPassword, gTonMnemonic); + auto key = StoredKey::createWithTonMnemonic(gTONName, gTONPassword, gTONMnemonic); EXPECT_EQ(key.accounts.size(), 0ul); // Add an account with an invalid address manually. { const DerivationPath derivationPath {}; - const auto publicKey = gPublicKey; + const auto publicKey = gTONPublicKey; const auto extendedPublicKey = ""; const auto invalidAddress = "INVALID_ADDRESS"; key.addAccount(invalidAddress, TWCoinTypeTON, TWDerivationDefault, derivationPath, publicKey, extendedPublicKey); EXPECT_EQ(key.accounts.size(), 1ul); } - key.fixAddresses(gPassword); + key.fixAddresses(gTONPassword); EXPECT_EQ(key.accounts.size(), 1ul); EXPECT_EQ(key.accounts[0].coin, TWCoinTypeTON); // Address should be fixed to a valid non-bounceable address. @@ -134,13 +134,13 @@ TEST(StoredKeyTon, FixAddress) { } TEST(StoredKeyTon, UpdateAddress) { - auto key = StoredKey::createWithTonMnemonic(gName, gPassword, gTonMnemonic); + auto key = StoredKey::createWithTonMnemonic(gTONName, gTONPassword, gTONMnemonic); EXPECT_EQ(key.accounts.size(), 0ul); // Add an account with a bounceable (EQ) address. { const DerivationPath derivationPath {}; - const auto publicKey = gPublicKey; + const auto publicKey = gTONPublicKey; const auto extendedPublicKey = ""; const auto invalidAddress = gBounceableAddress; key.addAccount(invalidAddress, TWCoinTypeTON, TWDerivationDefault, derivationPath, publicKey, extendedPublicKey); @@ -164,14 +164,14 @@ TEST(StoredKeyTon, LoadTonMnemonic) { EXPECT_EQ(key.id, "f7a2172e-fb7a-427a-8526-99779fc47c0a"); EXPECT_EQ(key.name, "Test TON Account"); - const auto data = key.payload.decrypt(gPassword); + const auto data = key.payload.decrypt(gTONPassword); const auto mnemonic = string(reinterpret_cast(data.data())); - EXPECT_EQ(mnemonic, gTonMnemonic); + EXPECT_EQ(mnemonic, gTONMnemonic); EXPECT_EQ(key.accounts[0].coin, TWCoinTypeTON); EXPECT_EQ(key.accounts[0].derivationPath.string(), ""); EXPECT_EQ(key.accounts[0].address, gNonBounceableAddress); - EXPECT_EQ(key.accounts[0].publicKey, gPublicKey); + EXPECT_EQ(key.accounts[0].publicKey, gTONPublicKey); } TEST(StoredKeyTon, InvalidPassword) {