From 2ec2fef2e1b738126dcc7b4f13253bd6f8ddc67f Mon Sep 17 00:00:00 2001 From: Rob Walworth Date: Wed, 12 Jul 2023 11:15:26 -0500 Subject: [PATCH] Update TokenNftAllowance | Remove TokenNftRemoveAllowance as it is not required Signed-off-by: Rob Walworth --- sdk/main/CMakeLists.txt | 1 - .../AccountAllowanceDeleteTransaction.h | 6 +- sdk/main/include/TokenNftAllowance.h | 123 +++--------- sdk/main/include/TokenNftRemoveAllowance.h | 135 ------------- .../src/AccountAllowanceApproveTransaction.cc | 12 +- .../src/AccountAllowanceDeleteTransaction.cc | 38 +++- sdk/main/src/TokenNftAllowance.cc | 96 +++++----- sdk/main/src/TokenNftRemoveAllowance.cc | 95 ---------- .../AccountAllowanceApproveTransactionTest.cc | 63 +++--- .../AccountAllowanceDeleteTransactionTest.cc | 36 ++-- sdk/tests/unit/CMakeLists.txt | 1 - sdk/tests/unit/TokenNftAllowanceTest.cc | 179 +++--------------- sdk/tests/unit/TokenNftRemoveAllowanceTest.cc | 156 --------------- 13 files changed, 190 insertions(+), 751 deletions(-) delete mode 100644 sdk/main/include/TokenNftRemoveAllowance.h delete mode 100644 sdk/main/src/TokenNftRemoveAllowance.cc delete mode 100644 sdk/tests/unit/TokenNftRemoveAllowanceTest.cc diff --git a/sdk/main/CMakeLists.txt b/sdk/main/CMakeLists.txt index e799434f..8ee9b2a5 100644 --- a/sdk/main/CMakeLists.txt +++ b/sdk/main/CMakeLists.txt @@ -82,7 +82,6 @@ add_library(${PROJECT_NAME} STATIC src/TokenInfoQuery.cc src/TokenMintTransaction.cc src/TokenNftAllowance.cc - src/TokenNftRemoveAllowance.cc src/TokenNftTransfer.cc src/TokenSupplyType.cc src/TokenTransfer.cc diff --git a/sdk/main/include/AccountAllowanceDeleteTransaction.h b/sdk/main/include/AccountAllowanceDeleteTransaction.h index 0e64a96e..84e7dc7f 100644 --- a/sdk/main/include/AccountAllowanceDeleteTransaction.h +++ b/sdk/main/include/AccountAllowanceDeleteTransaction.h @@ -20,7 +20,7 @@ #ifndef HEDERA_SDK_CPP_ACCOUNT_ALLOWANCE_DELETE_TRANSACTION_H_ #define HEDERA_SDK_CPP_ACCOUNT_ALLOWANCE_DELETE_TRANSACTION_H_ -#include "TokenNftRemoveAllowance.h" +#include "TokenNftAllowance.h" #include "Transaction.h" namespace proto @@ -70,7 +70,7 @@ class AccountAllowanceDeleteTransaction : public Transaction getTokenNftAllowanceDeletions() const + [[nodiscard]] inline std::vector getTokenNftAllowanceDeletions() const { return mNftAllowanceDeletions; } @@ -115,7 +115,7 @@ class AccountAllowanceDeleteTransaction : public Transaction mNftAllowanceDeletions; + std::vector mNftAllowanceDeletions; }; } // namespace Hedera diff --git a/sdk/main/include/TokenNftAllowance.h b/sdk/main/include/TokenNftAllowance.h index 94484744..cb575bb6 100644 --- a/sdk/main/include/TokenNftAllowance.h +++ b/sdk/main/include/TokenNftAllowance.h @@ -23,6 +23,7 @@ #include "AccountId.h" #include "TokenId.h" +#include #include #include #include @@ -31,6 +32,7 @@ namespace proto { class NftAllowance; +class NftRemoveAllowance; } namespace Hedera @@ -56,12 +58,12 @@ class TokenNftAllowance * @param delegatingSpender The ID of the account who has an 'approveForAll' allowance and is granting approval to * spend an NFT to the spender. */ - TokenNftAllowance(const TokenId& tokenId, - AccountId owner, - AccountId spender, - std::vector serialNumbers, - std::optional allowAll = std::optional(), - std::optional delegatingSpender = std::optional()); + TokenNftAllowance(const std::optional& tokenId, + const std::optional& owner, + const std::optional& spender, + const std::vector& serialNumbers, + const std::optional& allowAll = std::optional(), + const std::optional& delegatingSpender = std::optional()); /** * Construct a TokenNftAllowance object from a NftAllowance protobuf object. @@ -72,124 +74,49 @@ class TokenNftAllowance [[nodiscard]] static TokenNftAllowance fromProtobuf(const proto::NftAllowance& proto); /** - * Construct a NftAllowance protobuf object from this TokenNftAllowance object. + * Construct a TokenNftAllowance object from a byte array. * - * @return A pointer to a constructed NftAllowance protobuf object filled with this TokenNftAllowance object's data. - */ - [[nodiscard]] std::unique_ptr toProtobuf() const; - - /** - * Set the ID of the token NFT type that is being approved to be spent. - * - * @param tokenId The ID of the token NFT type that is being approved to be spent. - * @return A reference to this TokenNftAllowance object with the newly-set token ID. - */ - TokenNftAllowance& setTokenId(const TokenId& tokenId); - - /** - * Set the ID of the account approving an allowance of its NFTs. - * - * @param accountId The ID of the account approving an allowance of its NFTs. - * @return A reference to this TokenNftAllowance object with the newly-set owner account ID. - */ - TokenNftAllowance& setOwnerAccountId(const AccountId& accountId); - - /** - * Set the ID of the account being allowed to spend the NFTs. - * - * @param accountId The ID of the account being allowed to spend the NFTs. - * @return A reference to this TokenNftAllowance object with the newly-set spender account ID. - */ - TokenNftAllowance& setSpenderAccountId(const AccountId& accountId); - - /** - * Add a serial number of one of the NFTs the spender is being allowed to spend. - * - * @param serialNumber The serial number of the NFT that is being allowed to be spent. - * @return A reference to this TokenNftAllowance object with the added NFT serial number. - */ - TokenNftAllowance& addSerialNumber(const uint64_t& serialNumber); - - /** - * Allow the spender access to all of the owner's NFTs of the designated token ID (currently owned and any in the - * future). - * - * @param allowAll \c TRUE to allow the spender access to all of the owner's NFTs of the designated token ID, - * \c FALSE to revoke the spender's access to all of the owner's NFTs of the designated token ID. - * @return A reference to this TokenNftAllowance object with the newly-set NFT allowance policy. - */ - TokenNftAllowance& approveForAll(bool allowAll); - - /** - * Set the ID of the account that is delegating the allowance to spend the NFT. This account should have an - * 'approveForAll' allowance. - * - * @param accountId The ID of the account that is delegating a spending allowance to the spender account. - * @return A reference to this TokenNftAllowance object with the newly-set delegate spender account ID. - */ - TokenNftAllowance& setDelegatingSpenderAccountId(const AccountId& accountId); - - /** - * Get the ID of the token NFT type that is being approved to be spent. - * - * @return The ID of the token NFT type that is being approved to be spent. - */ - [[nodiscard]] inline TokenId getTokenId() const { return mTokenId; } - - /** - * Set the ID of the account approving an allowance of its tokens. - * - * @return The ID of the account approving an allowance of its tokens. - */ - [[nodiscard]] inline AccountId getOwnerAccountId() const { return mOwnerAccountId; } - - /** - * Get the ID of the account being allowed to spend the tokens. - * - * @return The ID of the account being allowed to spend the tokens. + * @param bytes The byte array from which to construct an TokenNftAllowance object. + * @return The constructed TokenNftAllowance object. */ - [[nodiscard]] inline AccountId getSpenderAccountId() const { return mSpenderAccountId; } + [[nodiscard]] static TokenNftAllowance fromBytes(const std::vector& bytes); /** - * Get the list of NFT serial numbers that are being allowed to be spent. + * Construct an NftAllowance protobuf object from this TokenNftAllowance object. * - * @return The list of NFT serial numbers that are being allowed to be spent. + * @return A pointer to a constructed NftAllowance protobuf object filled with this TokenNftAllowance object's data. */ - [[nodiscard]] inline std::vector getSerialNumbers() const { return mSerialNumbers; } + [[nodiscard]] std::unique_ptr toProtobuf() const; /** - * Determine if this allowance allows the spender access to all of the owner's NFTs (currently owned and in the - * future). + * Construct an NftRemoveAllowance protobuf object from this TokenNftAllowance object. * - * @return \c TRUE if this TokenNftAllowance allows the spender access to all of the owner's NFTs (currently owned and - * in the future). Uninitialized if behavior has not been set. + * @return A pointer to a constructed NftRemoveAllowance protobuf object filled with this TokenNftAllowance object's + * data. */ - [[nodiscard]] inline std::optional getApprovedForAll() const { return mApprovedForAll; } + [[nodiscard]] std::unique_ptr toRemoveProtobuf() const; /** - * Get the ID of the spender account who is granted approved-for-all access and is granting approval of an NFT serial - * number to another spender. + * Construct a representative byte array from this TokenNftAllowance object. * - * @return The ID of the spender account who is granted approved-for-all access and is granting approval of an NFT - * serial number to another spender. Uninitialized if no delegating spender exists for this allowance. + * @return A representative byte array of this TokenNftAllowance object. */ - [[nodiscard]] inline std::optional getDelegateSpender() const { return mDelegatingSpenderAccountId; } + [[nodiscard]] std::vector toBytes() const; -private: /** * The ID of the token that is being approved to be spent. */ - TokenId mTokenId; + std::optional mTokenId; /** * The ID of the account approving an allowance of its tokens. */ - AccountId mOwnerAccountId; + std::optional mOwnerAccountId; /** * The ID of the account being allowed to spend the tokens. */ - AccountId mSpenderAccountId; + std::optional mSpenderAccountId; /** * The list of serial numbers that are being allowed to be spent. diff --git a/sdk/main/include/TokenNftRemoveAllowance.h b/sdk/main/include/TokenNftRemoveAllowance.h deleted file mode 100644 index ff242407..00000000 --- a/sdk/main/include/TokenNftRemoveAllowance.h +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * - * Hedera C++ SDK - * - * Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License") - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef HEDERA_SDK_CPP_TOKEN_NFT_REMOVE_ALLOWANCE_H_ -#define HEDERA_SDK_CPP_TOKEN_NFT_REMOVE_ALLOWANCE_H_ - -#include "AccountId.h" -#include "TokenId.h" - -#include -#include -#include -#include - -namespace proto -{ -class NftRemoveAllowance; -} - -namespace Hedera -{ -/** - * An NFT transfer allowance to remove. - */ -class TokenNftRemoveAllowance -{ -public: - TokenNftRemoveAllowance() = default; - - /** - * Construct with a token ID, owner, and list of serial numbers. - * - * @param tokenId The ID of the token NFT type that is being approved to be spent. - * @param owner The ID of the account approving an allowance of its NFTs. - * @param serialNumbers A list serial numbers of the NFT that is being allowed to be spent. - */ - TokenNftRemoveAllowance(const TokenId& tokenId, AccountId owner, std::vector serialNumbers); - - /** - * Construct a TokenNftRemoveAllowance object from a NftRemoveAllowance protobuf object. - * - * @param proto The NftRemoveAllowance protobuf object from which to construct an TokenNftRemoveAllowance object. - * @return The constructed TokenNftRemoveAllowance object. - */ - [[nodiscard]] static TokenNftRemoveAllowance fromProtobuf(const proto::NftRemoveAllowance& proto); - - /** - * Construct a NftRemoveAllowance protobuf object from this TokenNftRemoveAllowance object. - * - * @return A pointer to a constructed NftRemoveAllowance protobuf object filled with this TokenNftRemoveAllowance - * object's data. - */ - [[nodiscard]] std::unique_ptr toProtobuf() const; - - /** - * Set the ID of the token NFT type who's allowance is being revoked. - * - * @param tokenId The ID of the token NFT type who's allowance is being revoked. - * @return A reference to this TokenNftRemoveAllowance object with the newly-set token ID. - */ - TokenNftRemoveAllowance& setTokenId(const TokenId& tokenId); - - /** - * Set the ID of the account who's revoking an NFT allowances. - * - * @param accountId The ID of the account who's revoking an NFT allowances. - * @return A reference to this TokenNftRemoveAllowance object with the newly-set owner account ID. - */ - TokenNftRemoveAllowance& setOwnerAccountId(const AccountId& accountId); - - /** - * Add a serial number of one of the NFTs who's being removed from an allowance. - * - * @param serialNumber The serial number of the NFT that is being no longer being allowed to be spent. - * @return A reference to this TokenNftRemoveAllowance object with the added NFT serial number. - */ - TokenNftRemoveAllowance& addSerialNumber(const uint64_t& serialNumber); - - /** - * Get the ID of the token NFT type whose allowance is being revoked. - * - * @return The ID of the token NFT type whose allowance is being revoked. - */ - [[nodiscard]] inline TokenId getTokenId() const { return mTokenId; } - - /** - * Set the ID of the account whose revoking an NFT allowances. - * - * @return The ID of the account whose revoking an NFT allowances. - */ - [[nodiscard]] inline AccountId getOwnerAccountId() const { return mOwnerAccountId; } - - /** - * Get the list of NFT serial numbers whose allowance is being revoked. - * - * @return The list of NFT serial numbers whose allowance is being revoked. - */ - [[nodiscard]] inline std::vector getSerialNumbers() const { return mSerialNumbers; } - -private: - /** - * The ID of the token NFT type whose allowance is being revoked. - */ - TokenId mTokenId; - - /** - * The ID of the account whose revoking an NFT allowances. - */ - AccountId mOwnerAccountId; - - /** - * The list of NFT serial numbers whose allowance is being revoked. - */ - std::vector mSerialNumbers; -}; - -} // namespace Hedera - -#endif // HEDERA_SDK_CPP_TOKEN_NFT_REMOVE_ALLOWANCE_H_ diff --git a/sdk/main/src/AccountAllowanceApproveTransaction.cc b/sdk/main/src/AccountAllowanceApproveTransaction.cc index e892bb72..a55a6204 100644 --- a/sdk/main/src/AccountAllowanceApproveTransaction.cc +++ b/sdk/main/src/AccountAllowanceApproveTransaction.cc @@ -97,10 +97,10 @@ AccountAllowanceApproveTransaction& AccountAllowanceApproveTransaction::approveT // Add the serial number to the token allowance if there's already an allowance for this token ID, owner, and spender. for (TokenNftAllowance& allowance : mNftAllowances) { - if (allowance.getTokenId() == nftId.getTokenId() && allowance.getOwnerAccountId() == ownerAccountId && - allowance.getSpenderAccountId() == spenderAccountId) + if (allowance.mTokenId == nftId.getTokenId() && allowance.mOwnerAccountId == ownerAccountId && + allowance.mSpenderAccountId == spenderAccountId) { - allowance.addSerialNumber(nftId.getSerialNum()); + allowance.mSerialNumbers.push_back(nftId.getSerialNum()); return *this; } } @@ -124,10 +124,10 @@ AccountAllowanceApproveTransaction& AccountAllowanceApproveTransaction::approveN for (TokenNftAllowance& allowance : mNftAllowances) { - if (allowance.getTokenId() == tokenId && allowance.getOwnerAccountId() == ownerAccountId && - allowance.getSpenderAccountId() == spenderAccountId) + if (allowance.mTokenId == tokenId && allowance.mOwnerAccountId == ownerAccountId && + allowance.mSpenderAccountId == spenderAccountId) { - allowance.approveForAll(true); + allowance.mApprovedForAll = true; return *this; } } diff --git a/sdk/main/src/AccountAllowanceDeleteTransaction.cc b/sdk/main/src/AccountAllowanceDeleteTransaction.cc index 6149c4f6..776dcd67 100644 --- a/sdk/main/src/AccountAllowanceDeleteTransaction.cc +++ b/sdk/main/src/AccountAllowanceDeleteTransaction.cc @@ -42,7 +42,18 @@ AccountAllowanceDeleteTransaction::AccountAllowanceDeleteTransaction(const proto for (int i = 0; i < body.nftallowances_size(); ++i) { - mNftAllowanceDeletions.push_back(TokenNftRemoveAllowance::fromProtobuf(body.nftallowances(i))); + std::vector serialNumbers; + serialNumbers.reserve(body.nftallowances(i).serial_numbers_size()); + + for (int j = 0; j < body.nftallowances(i).serial_numbers_size(); ++j) + { + serialNumbers.push_back(static_cast(body.nftallowances(i).serial_numbers(j))); + } + + mNftAllowanceDeletions.emplace_back(TokenId::fromProtobuf(body.nftallowances(i).token_id()), + AccountId::fromProtobuf(body.nftallowances(i).owner()), + std::optional(), + serialNumbers); } } @@ -54,16 +65,17 @@ AccountAllowanceDeleteTransaction& AccountAllowanceDeleteTransaction::deleteAllT requireNotFrozen(); // Add the serial number to the token allowance if there's already an allowance for this token ID, owner, and spender. - for (TokenNftRemoveAllowance& allowance : mNftAllowanceDeletions) + for (TokenNftAllowance& allowance : mNftAllowanceDeletions) { - if (allowance.getTokenId() == nftId.getTokenId() && allowance.getOwnerAccountId() == owner) + if (allowance.mTokenId == nftId.getTokenId() && allowance.mOwnerAccountId == owner) { - allowance.addSerialNumber(nftId.getSerialNum()); + allowance.mSerialNumbers.push_back(nftId.getSerialNum()); return *this; } } - mNftAllowanceDeletions.emplace_back(nftId.getTokenId(), owner, std::vector{ nftId.getSerialNum() }); + mNftAllowanceDeletions.emplace_back( + nftId.getTokenId(), owner, std::optional(), std::vector{ nftId.getSerialNum() }); return *this; } @@ -91,13 +103,21 @@ proto::CryptoDeleteAllowanceTransactionBody* AccountAllowanceDeleteTransaction:: { auto body = std::make_unique(); - for (const TokenNftRemoveAllowance& allowance : mNftAllowanceDeletions) + for (const TokenNftAllowance& allowance : mNftAllowanceDeletions) { proto::NftRemoveAllowance* nftRemoveAllowance = body->add_nftallowances(); - nftRemoveAllowance->set_allocated_token_id(allowance.getTokenId().toProtobuf().release()); - nftRemoveAllowance->set_allocated_owner(allowance.getOwnerAccountId().toProtobuf().release()); - for (const uint64_t& num : allowance.getSerialNumbers()) + if (allowance.mTokenId.has_value()) + { + nftRemoveAllowance->set_allocated_token_id(allowance.mTokenId->toProtobuf().release()); + } + + if (allowance.mOwnerAccountId.has_value()) + { + nftRemoveAllowance->set_allocated_owner(allowance.mOwnerAccountId->toProtobuf().release()); + } + + for (const uint64_t& num : allowance.mSerialNumbers) { nftRemoveAllowance->add_serial_numbers(static_cast(num)); } diff --git a/sdk/main/src/TokenNftAllowance.cc b/sdk/main/src/TokenNftAllowance.cc index 8adb3e2a..f92b232c 100644 --- a/sdk/main/src/TokenNftAllowance.cc +++ b/sdk/main/src/TokenNftAllowance.cc @@ -18,24 +18,26 @@ * */ #include "TokenNftAllowance.h" +#include "impl/Utilities.h" #include +#include namespace Hedera { //----- -TokenNftAllowance::TokenNftAllowance(const TokenId& tokenId, - AccountId owner, - AccountId spender, - std::vector serialNumbers, - std::optional allowAll, - std::optional delegatingSpender) +TokenNftAllowance::TokenNftAllowance(const std::optional& tokenId, + const std::optional& owner, + const std::optional& spender, + const std::vector& serialNumbers, + const std::optional& allowAll, + const std::optional& delegatingSpender) : mTokenId(tokenId) - , mOwnerAccountId(std::move(owner)) - , mSpenderAccountId(std::move(spender)) - , mSerialNumbers(std::move(serialNumbers)) + , mOwnerAccountId(owner) + , mSpenderAccountId(spender) + , mSerialNumbers(serialNumbers) , mApprovedForAll(allowAll) - , mDelegatingSpenderAccountId(std::move(delegatingSpender)) + , mDelegatingSpenderAccountId(delegatingSpender) { } @@ -77,13 +79,33 @@ TokenNftAllowance TokenNftAllowance::fromProtobuf(const proto::NftAllowance& pro return allowance; } +//----- +TokenNftAllowance TokenNftAllowance::fromBytes(const std::vector& bytes) +{ + proto::NftAllowance nftAllowance; + nftAllowance.ParseFromArray(bytes.data(), static_cast(bytes.size())); + return fromProtobuf(nftAllowance); +} + //----- std::unique_ptr TokenNftAllowance::toProtobuf() const { auto proto = std::make_unique(); - proto->set_allocated_tokenid(mTokenId.toProtobuf().release()); - proto->set_allocated_owner(mOwnerAccountId.toProtobuf().release()); - proto->set_allocated_spender(mSpenderAccountId.toProtobuf().release()); + + if (mTokenId.has_value()) + { + proto->set_allocated_tokenid(mTokenId->toProtobuf().release()); + } + + if (mOwnerAccountId.has_value()) + { + proto->set_allocated_owner(mOwnerAccountId->toProtobuf().release()); + } + + if (mSpenderAccountId.has_value()) + { + proto->set_allocated_spender(mSpenderAccountId->toProtobuf().release()); + } for (const uint64_t& serialNumber : mSerialNumbers) { @@ -106,50 +128,32 @@ std::unique_ptr TokenNftAllowance::toProtobuf() const } //----- -TokenNftAllowance& TokenNftAllowance::setTokenId(const TokenId& tokenId) +std::unique_ptr TokenNftAllowance::toRemoveProtobuf() const { - mTokenId = tokenId; - return *this; -} + auto proto = std::make_unique(); -//----- -TokenNftAllowance& TokenNftAllowance::setOwnerAccountId(const AccountId& accountId) -{ - mOwnerAccountId = accountId; - return *this; -} - -//----- -TokenNftAllowance& TokenNftAllowance::setSpenderAccountId(const AccountId& accountId) -{ - mSpenderAccountId = accountId; - return *this; -} + if (mTokenId.has_value()) + { + proto->set_allocated_token_id(mTokenId->toProtobuf().release()); + } -//----- -TokenNftAllowance& TokenNftAllowance::addSerialNumber(const uint64_t& serialNumber) -{ - mSerialNumbers.push_back(static_cast(serialNumber)); - return *this; -} + if (mOwnerAccountId.has_value()) + { + proto->set_allocated_owner(mOwnerAccountId->toProtobuf().release()); + } -//----- -TokenNftAllowance& TokenNftAllowance::approveForAll(bool allowAll) -{ - mApprovedForAll = allowAll; - if (allowAll) + for (const uint64_t& serialNumber : mSerialNumbers) { - mSerialNumbers.clear(); + proto->add_serial_numbers(static_cast(serialNumber)); } - return *this; + return proto; } //----- -TokenNftAllowance& TokenNftAllowance::setDelegatingSpenderAccountId(const AccountId& accountId) +std::vector TokenNftAllowance::toBytes() const { - mDelegatingSpenderAccountId = accountId; - return *this; + return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); } } // namespace Hedera diff --git a/sdk/main/src/TokenNftRemoveAllowance.cc b/sdk/main/src/TokenNftRemoveAllowance.cc deleted file mode 100644 index 4bcd5309..00000000 --- a/sdk/main/src/TokenNftRemoveAllowance.cc +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * - * Hedera C++ SDK - * - * Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License") - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "TokenNftRemoveAllowance.h" - -#include - -namespace Hedera -{ -//----- -TokenNftRemoveAllowance::TokenNftRemoveAllowance(const TokenId& tokenId, - AccountId owner, - std::vector serialNumbers) - : mTokenId(tokenId) - , mOwnerAccountId(std::move(owner)) - , mSerialNumbers(std::move(serialNumbers)) -{ -} - -//----- -TokenNftRemoveAllowance TokenNftRemoveAllowance::fromProtobuf(const proto::NftRemoveAllowance& proto) -{ - TokenNftRemoveAllowance allowance; - - if (proto.has_token_id()) - { - allowance.mTokenId = TokenId::fromProtobuf(proto.token_id()); - } - - if (proto.has_owner()) - { - allowance.mOwnerAccountId = AccountId::fromProtobuf(proto.owner()); - } - - for (int i = 0; i < proto.serial_numbers_size(); ++i) - { - allowance.mSerialNumbers.push_back(static_cast(proto.serial_numbers(i))); - } - - return allowance; -} - -//----- -std::unique_ptr TokenNftRemoveAllowance::toProtobuf() const -{ - auto proto = std::make_unique(); - proto->set_allocated_token_id(mTokenId.toProtobuf().release()); - proto->set_allocated_owner(mOwnerAccountId.toProtobuf().release()); - - for (const uint64_t& serialNumber : mSerialNumbers) - { - proto->add_serial_numbers(static_cast(serialNumber)); - } - - return proto; -} - -//----- -TokenNftRemoveAllowance& TokenNftRemoveAllowance::setTokenId(const TokenId& tokenId) -{ - mTokenId = tokenId; - return *this; -} - -//----- -TokenNftRemoveAllowance& TokenNftRemoveAllowance::setOwnerAccountId(const AccountId& accountId) -{ - mOwnerAccountId = accountId; - return *this; -} - -//----- -TokenNftRemoveAllowance& TokenNftRemoveAllowance::addSerialNumber(const uint64_t& serialNumber) -{ - mSerialNumbers.push_back(static_cast(serialNumber)); - return *this; -} - -} // namespace Hedera diff --git a/sdk/tests/unit/AccountAllowanceApproveTransactionTest.cc b/sdk/tests/unit/AccountAllowanceApproveTransactionTest.cc index 75cc6df4..04e4dad7 100644 --- a/sdk/tests/unit/AccountAllowanceApproveTransactionTest.cc +++ b/sdk/tests/unit/AccountAllowanceApproveTransactionTest.cc @@ -123,14 +123,13 @@ TEST_F(AccountAllowanceApproveTransactionTest, ConstructAccountAllowanceApproveT EXPECT_EQ(accountAllowanceApproveTransaction.getTokenApprovals().at(0).getAmount(), getTestAmountHbar().toTinybars()); ASSERT_EQ(accountAllowanceApproveTransaction.getNftApprovals().size(), 1); - EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).getTokenId(), getTestTokenId()); - EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).getSpenderAccountId(), - getTestSpenderAccountId()); - EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).getSerialNumbers(), getTestSerialNumbers()); - ASSERT_TRUE(accountAllowanceApproveTransaction.getNftApprovals().at(0).getApprovedForAll().has_value()); - EXPECT_EQ(*accountAllowanceApproveTransaction.getNftApprovals().at(0).getApprovedForAll(), getTestApprovalForAll()); - EXPECT_EQ(*accountAllowanceApproveTransaction.getNftApprovals().at(0).getDelegateSpender(), + EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).mTokenId, getTestTokenId()); + EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).mSpenderAccountId, getTestSpenderAccountId()); + EXPECT_EQ(accountAllowanceApproveTransaction.getNftApprovals().at(0).mSerialNumbers, getTestSerialNumbers()); + ASSERT_TRUE(accountAllowanceApproveTransaction.getNftApprovals().at(0).mApprovedForAll.has_value()); + EXPECT_EQ(*accountAllowanceApproveTransaction.getNftApprovals().at(0).mApprovedForAll, getTestApprovalForAll()); + EXPECT_EQ(*accountAllowanceApproveTransaction.getNftApprovals().at(0).mDelegatingSpenderAccountId, getTestDelegatingSpenderAccountId()); } @@ -229,20 +228,20 @@ TEST_F(AccountAllowanceApproveTransactionTest, ApproveNftAllowance) // Then ASSERT_EQ(transaction.getNftApprovals().size(), 2); - EXPECT_EQ(transaction.getNftApprovals().at(0).getTokenId(), getTestTokenId()); - EXPECT_EQ(transaction.getNftApprovals().at(0).getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(transaction.getNftApprovals().at(0).getSpenderAccountId(), getTestSpenderAccountId()); - ASSERT_EQ(transaction.getNftApprovals().at(0).getSerialNumbers().size(), getTestSerialNumbers().size()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mTokenId, getTestTokenId()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mSpenderAccountId, getTestSpenderAccountId()); + ASSERT_EQ(transaction.getNftApprovals().at(0).mSerialNumbers.size(), getTestSerialNumbers().size()); for (int i = 0; i < getTestSerialNumbers().size(); ++i) { - EXPECT_EQ(transaction.getNftApprovals().at(0).getSerialNumbers().at(i), getTestSerialNumbers().at(i)); + EXPECT_EQ(transaction.getNftApprovals().at(0).mSerialNumbers.at(i), getTestSerialNumbers().at(i)); } - EXPECT_EQ(transaction.getNftApprovals().at(1).getTokenId(), tokenId); - EXPECT_EQ(transaction.getNftApprovals().at(1).getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(transaction.getNftApprovals().at(1).getSpenderAccountId(), getTestSpenderAccountId()); - ASSERT_EQ(transaction.getNftApprovals().at(1).getSerialNumbers().size(), 1); - EXPECT_EQ(transaction.getNftApprovals().at(1).getSerialNumbers().at(0), serialNum); + EXPECT_EQ(transaction.getNftApprovals().at(1).mTokenId, tokenId); + EXPECT_EQ(transaction.getNftApprovals().at(1).mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(transaction.getNftApprovals().at(1).mSpenderAccountId, getTestSpenderAccountId()); + ASSERT_EQ(transaction.getNftApprovals().at(1).mSerialNumbers.size(), 1); + EXPECT_EQ(transaction.getNftApprovals().at(1).mSerialNumbers.at(0), serialNum); } //----- @@ -270,13 +269,13 @@ TEST_F(AccountAllowanceApproveTransactionTest, ApproveNftAllowanceAllSerials) // Then ASSERT_EQ(transaction.getNftApprovals().size(), 1); - EXPECT_EQ(transaction.getNftApprovals().at(0).getTokenId(), getTestTokenId()); - EXPECT_EQ(transaction.getNftApprovals().at(0).getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(transaction.getNftApprovals().at(0).getSpenderAccountId(), getTestSpenderAccountId()); - ASSERT_TRUE(transaction.getNftApprovals().at(0).getSerialNumbers().empty()); - ASSERT_TRUE(transaction.getNftApprovals().at(0).getApprovedForAll().has_value()); - EXPECT_TRUE(*transaction.getNftApprovals().at(0).getApprovedForAll()); - EXPECT_FALSE(transaction.getNftApprovals().at(0).getDelegateSpender()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mTokenId, getTestTokenId()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mSpenderAccountId, getTestSpenderAccountId()); + ASSERT_TRUE(transaction.getNftApprovals().at(0).mSerialNumbers.empty()); + ASSERT_TRUE(transaction.getNftApprovals().at(0).mApprovedForAll.has_value()); + EXPECT_TRUE(*transaction.getNftApprovals().at(0).mApprovedForAll); + EXPECT_FALSE(transaction.getNftApprovals().at(0).mDelegatingSpenderAccountId); } //----- @@ -304,13 +303,13 @@ TEST_F(AccountAllowanceApproveTransactionTest, DeleteNftAllowanceAllSerials) // Then ASSERT_EQ(transaction.getNftApprovals().size(), 1); - EXPECT_EQ(transaction.getNftApprovals().at(0).getTokenId(), getTestTokenId()); - EXPECT_EQ(transaction.getNftApprovals().at(0).getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(transaction.getNftApprovals().at(0).getSpenderAccountId(), getTestSpenderAccountId()); - ASSERT_TRUE(transaction.getNftApprovals().at(0).getSerialNumbers().empty()); - ASSERT_TRUE(transaction.getNftApprovals().at(0).getApprovedForAll().has_value()); - EXPECT_FALSE(*transaction.getNftApprovals().at(0).getApprovedForAll()); - EXPECT_FALSE(transaction.getNftApprovals().at(0).getDelegateSpender()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mTokenId, getTestTokenId()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(transaction.getNftApprovals().at(0).mSpenderAccountId, getTestSpenderAccountId()); + ASSERT_TRUE(transaction.getNftApprovals().at(0).mSerialNumbers.empty()); + ASSERT_TRUE(transaction.getNftApprovals().at(0).mApprovedForAll.has_value()); + EXPECT_FALSE(*transaction.getNftApprovals().at(0).mApprovedForAll); + EXPECT_FALSE(transaction.getNftApprovals().at(0).mDelegatingSpenderAccountId); } //----- diff --git a/sdk/tests/unit/AccountAllowanceDeleteTransactionTest.cc b/sdk/tests/unit/AccountAllowanceDeleteTransactionTest.cc index 78aef98a..c194dea7 100644 --- a/sdk/tests/unit/AccountAllowanceDeleteTransactionTest.cc +++ b/sdk/tests/unit/AccountAllowanceDeleteTransactionTest.cc @@ -81,10 +81,10 @@ TEST_F(AccountAllowanceDeleteTransactionTest, ConstructAccountAllowanceDeleteTra // Then ASSERT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().size(), 1); - EXPECT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().at(0).getTokenId(), getTestTokenId()); - EXPECT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().at(0).getOwnerAccountId(), + EXPECT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().at(0).mTokenId, getTestTokenId()); + EXPECT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().at(0).mOwnerAccountId, getTestOwnerAccountId()); - EXPECT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().at(0).getSerialNumbers(), + EXPECT_EQ(accountAllowanceDeleteTransaction.getTokenNftAllowanceDeletions().at(0).mSerialNumbers, getTestSerialNumbers()); } @@ -102,9 +102,9 @@ TEST_F(AccountAllowanceDeleteTransactionTest, DeleteNftAllowances) // Then ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().size(), 1); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getTokenId(), getTestTokenId()); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getSerialNumbers(), getTestSerialNumbers()); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mTokenId, getTestTokenId()); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mSerialNumbers, getTestSerialNumbers()); } //----- @@ -125,20 +125,20 @@ TEST_F(AccountAllowanceDeleteTransactionTest, DeleteNftAllowancesDifferentTokenI // Then ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().size(), 3); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getTokenId(), tokenIds.at(0)); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getOwnerAccountId(), getTestOwnerAccountId()); - ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getSerialNumbers().size(), 1); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).getSerialNumbers().at(0), getTestSerialNumbers().at(0)); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mTokenId, tokenIds.at(0)); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mOwnerAccountId, getTestOwnerAccountId()); + ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mSerialNumbers.size(), 1); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(0).mSerialNumbers.at(0), getTestSerialNumbers().at(0)); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).getTokenId(), tokenIds.at(1)); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).getOwnerAccountId(), getTestOwnerAccountId()); - ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).getSerialNumbers().size(), 1); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).getSerialNumbers().at(0), getTestSerialNumbers().at(1)); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).mTokenId, tokenIds.at(1)); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).mOwnerAccountId, getTestOwnerAccountId()); + ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).mSerialNumbers.size(), 1); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(1).mSerialNumbers.at(0), getTestSerialNumbers().at(1)); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).getTokenId(), tokenIds.at(2)); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).getOwnerAccountId(), getTestOwnerAccountId()); - ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).getSerialNumbers().size(), 1); - EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).getSerialNumbers().at(0), getTestSerialNumbers().at(2)); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).mTokenId, tokenIds.at(2)); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).mOwnerAccountId, getTestOwnerAccountId()); + ASSERT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).mSerialNumbers.size(), 1); + EXPECT_EQ(transaction.getTokenNftAllowanceDeletions().at(2).mSerialNumbers.at(0), getTestSerialNumbers().at(2)); } //----- diff --git a/sdk/tests/unit/CMakeLists.txt b/sdk/tests/unit/CMakeLists.txt index 466c0311..059140af 100644 --- a/sdk/tests/unit/CMakeLists.txt +++ b/sdk/tests/unit/CMakeLists.txt @@ -73,7 +73,6 @@ add_executable(${TEST_PROJECT_NAME} TokenInfoUnitTests.cc TokenMintTransactionUnitTests.cc TokenNftAllowanceTest.cc - TokenNftRemoveAllowanceTest.cc TokenNftTransferTest.cc TokenSupplyTypeTest.cc TokenTransferTest.cc diff --git a/sdk/tests/unit/TokenNftAllowanceTest.cc b/sdk/tests/unit/TokenNftAllowanceTest.cc index 3e7f5520..4e26b670 100644 --- a/sdk/tests/unit/TokenNftAllowanceTest.cc +++ b/sdk/tests/unit/TokenNftAllowanceTest.cc @@ -54,133 +54,12 @@ TEST_F(TokenNftAllowanceTest, ConstructWithTokenIdOwnerSpenderSerialNumbersAppro getTestTokenId(), getTestOwnerAccountId(), getTestSpenderAccountId(), getTestSerialNumbers()); // Then - EXPECT_EQ(tokenNftAllowance.getTokenId(), getTestTokenId()); - EXPECT_EQ(tokenNftAllowance.getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(tokenNftAllowance.getSpenderAccountId(), getTestSpenderAccountId()); - EXPECT_EQ(tokenNftAllowance.getSerialNumbers(), getTestSerialNumbers()); - EXPECT_FALSE(tokenNftAllowance.getApprovedForAll().has_value()); - EXPECT_FALSE(tokenNftAllowance.getDelegateSpender().has_value()); -} - -//----- -TEST_F(TokenNftAllowanceTest, GetSetTokenId) -{ - // Given - TokenNftAllowance tokenNftAllowance; - - // When - tokenNftAllowance.setTokenId(getTestTokenId()); - - // Then - EXPECT_EQ(tokenNftAllowance.getTokenId(), getTestTokenId()); -} - -//----- -TEST_F(TokenNftAllowanceTest, GetSetOwnerAccountId) -{ - // Given - TokenNftAllowance tokenNftAllowance; - - // When - tokenNftAllowance.setOwnerAccountId(getTestOwnerAccountId()); - - // Then - EXPECT_EQ(tokenNftAllowance.getOwnerAccountId(), getTestOwnerAccountId()); -} - -//----- -TEST_F(TokenNftAllowanceTest, GetSetSpenderAccountId) -{ - // Given - TokenNftAllowance tokenNftAllowance; - - // When - tokenNftAllowance.setSpenderAccountId(getTestSpenderAccountId()); - - // Then - EXPECT_EQ(tokenNftAllowance.getSpenderAccountId(), getTestSpenderAccountId()); -} - -//----- -TEST_F(TokenNftAllowanceTest, GetSetSerialNumbers) -{ - // Given - TokenNftAllowance tokenNftAllowance; - - // When - for (const uint64_t& num : getTestSerialNumbers()) - { - tokenNftAllowance.addSerialNumber(num); - } - - // Then - ASSERT_EQ(tokenNftAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); - for (int i = 0; i < getTestSerialNumbers().size(); ++i) - { - EXPECT_EQ(tokenNftAllowance.getSerialNumbers().at(i), getTestSerialNumbers().at(i)); - } -} - -//----- -TEST_F(TokenNftAllowanceTest, GetSetApproveForAll) -{ - // Given - TokenNftAllowance tokenNftAllowance; - - // When - tokenNftAllowance.approveForAll(false); - - // Then - ASSERT_TRUE(tokenNftAllowance.getApprovedForAll().has_value()); - EXPECT_FALSE(*tokenNftAllowance.getApprovedForAll()); -} - -//----- -TEST_F(TokenNftAllowanceTest, GetSetDelegatingSpenderAccountId) -{ - // Given - TokenNftAllowance tokenNftAllowance; - - // When - tokenNftAllowance.setDelegatingSpenderAccountId(getTestDelegatingSpenderAccountId()); - - // Then - ASSERT_TRUE(tokenNftAllowance.getDelegateSpender().has_value()); - EXPECT_EQ(tokenNftAllowance.getDelegateSpender(), getTestDelegatingSpenderAccountId()); -} - -//----- -TEST_F(TokenNftAllowanceTest, ClearSerialNumbersIfApprovingAll) -{ - // Given - TokenNftAllowance tokenNftAllowance; - for (const uint64_t& num : getTestSerialNumbers()) - { - tokenNftAllowance.addSerialNumber(num); - } - - // When - tokenNftAllowance.approveForAll(true); - - // Then - EXPECT_TRUE(tokenNftAllowance.getSerialNumbers().empty()); -} - -//----- -TEST_F(TokenNftAllowanceTest, DoNotClearSerialNumbersIfRevokingAll) -{ - // Given - TokenNftAllowance tokenNftAllowance; - for (const uint64_t& num : getTestSerialNumbers()) - { - tokenNftAllowance.addSerialNumber(num); - } - - // When - tokenNftAllowance.approveForAll(false); - - // Then - EXPECT_EQ(tokenNftAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); + EXPECT_EQ(tokenNftAllowance.mTokenId, getTestTokenId()); + EXPECT_EQ(tokenNftAllowance.mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(tokenNftAllowance.mSpenderAccountId, getTestSpenderAccountId()); + EXPECT_EQ(tokenNftAllowance.mSerialNumbers, getTestSerialNumbers()); + EXPECT_FALSE(tokenNftAllowance.mApprovedForAll.has_value()); + EXPECT_FALSE(tokenNftAllowance.mDelegatingSpenderAccountId.has_value()); } //----- @@ -206,37 +85,32 @@ TEST_F(TokenNftAllowanceTest, FromProtobuf) const TokenNftAllowance tokenNftAllowance = TokenNftAllowance::fromProtobuf(protoNftAllowance); // Then - EXPECT_EQ(tokenNftAllowance.getTokenId(), getTestTokenId()); - EXPECT_EQ(tokenNftAllowance.getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(tokenNftAllowance.getSpenderAccountId(), getTestSpenderAccountId()); - ASSERT_TRUE(tokenNftAllowance.getApprovedForAll().has_value()); - EXPECT_FALSE(*tokenNftAllowance.getApprovedForAll()); + EXPECT_EQ(tokenNftAllowance.mTokenId, getTestTokenId()); + EXPECT_EQ(tokenNftAllowance.mOwnerAccountId, getTestOwnerAccountId()); + EXPECT_EQ(tokenNftAllowance.mSpenderAccountId, getTestSpenderAccountId()); + ASSERT_TRUE(tokenNftAllowance.mApprovedForAll.has_value()); + EXPECT_FALSE(*tokenNftAllowance.mApprovedForAll); - ASSERT_EQ(tokenNftAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); + ASSERT_EQ(tokenNftAllowance.mSerialNumbers.size(), getTestSerialNumbers().size()); for (int i = 0; i < getTestSerialNumbers().size(); ++i) { - EXPECT_EQ(tokenNftAllowance.getSerialNumbers().at(i), getTestSerialNumbers().at(i)); + EXPECT_EQ(tokenNftAllowance.mSerialNumbers.at(i), getTestSerialNumbers().at(i)); } - ASSERT_TRUE(tokenNftAllowance.getDelegateSpender().has_value()); - EXPECT_EQ(*tokenNftAllowance.getDelegateSpender(), getTestDelegatingSpenderAccountId()); + ASSERT_TRUE(tokenNftAllowance.mDelegatingSpenderAccountId.has_value()); + EXPECT_EQ(*tokenNftAllowance.mDelegatingSpenderAccountId, getTestDelegatingSpenderAccountId()); } //----- TEST_F(TokenNftAllowanceTest, ToProtobuf) { // Given - TokenNftAllowance tokenNftAllowance; - tokenNftAllowance.setTokenId(getTestTokenId()); - tokenNftAllowance.setOwnerAccountId(getTestOwnerAccountId()); - tokenNftAllowance.setSpenderAccountId(getTestSpenderAccountId()); - - for (const uint64_t& num : getTestSerialNumbers()) - { - tokenNftAllowance.addSerialNumber(num); - } - - tokenNftAllowance.approveForAll(false); + const TokenNftAllowance tokenNftAllowance(getTestTokenId(), + getTestOwnerAccountId(), + getTestSpenderAccountId(), + getTestSerialNumbers(), + false, + getTestDelegatingSpenderAccountId()); // When const std::unique_ptr protoNftAllowance = tokenNftAllowance.toProtobuf(); @@ -249,12 +123,15 @@ TEST_F(TokenNftAllowanceTest, ToProtobuf) ASSERT_TRUE(protoNftAllowance->has_spender()); EXPECT_EQ(AccountId::fromProtobuf(protoNftAllowance->spender()), getTestSpenderAccountId()); - ASSERT_EQ(tokenNftAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); + ASSERT_EQ(tokenNftAllowance.mSerialNumbers.size(), getTestSerialNumbers().size()); for (int i = 0; i < getTestSerialNumbers().size(); ++i) { - EXPECT_EQ(tokenNftAllowance.getSerialNumbers().at(i), getTestSerialNumbers().at(i)); + EXPECT_EQ(tokenNftAllowance.mSerialNumbers.at(i), getTestSerialNumbers().at(i)); } - ASSERT_TRUE(tokenNftAllowance.getApprovedForAll().has_value()); - EXPECT_FALSE(*tokenNftAllowance.getApprovedForAll()); + ASSERT_TRUE(tokenNftAllowance.mApprovedForAll.has_value()); + EXPECT_FALSE(*tokenNftAllowance.mApprovedForAll); + + ASSERT_TRUE(tokenNftAllowance.mDelegatingSpenderAccountId.has_value()); + EXPECT_EQ(tokenNftAllowance.mDelegatingSpenderAccountId.value(), getTestDelegatingSpenderAccountId()); } diff --git a/sdk/tests/unit/TokenNftRemoveAllowanceTest.cc b/sdk/tests/unit/TokenNftRemoveAllowanceTest.cc deleted file mode 100644 index a844b840..00000000 --- a/sdk/tests/unit/TokenNftRemoveAllowanceTest.cc +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * - * Hedera C++ SDK - * - * Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License") - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "TokenNftRemoveAllowance.h" -#include "AccountId.h" -#include "TokenId.h" - -#include -#include - -using namespace Hedera; - -class TokenNftRemoveAllowanceTest : public ::testing::Test -{ -protected: - [[nodiscard]] inline const TokenId& getTestTokenId() const { return mTokenId; } - [[nodiscard]] inline const AccountId& getTestOwnerAccountId() const { return mOwnerAccountId; } - [[nodiscard]] inline const std::vector& getTestSerialNumbers() const { return mSerialNumbers; } - -private: - const TokenId mTokenId = TokenId(1ULL); - const AccountId mOwnerAccountId = AccountId(2ULL); - const std::vector mSerialNumbers = { 3ULL, 4ULL }; -}; - -//----- -TEST_F(TokenNftRemoveAllowanceTest, ConstructWithTokenIdOwnerSerialNumbers) -{ - // Given / When - const TokenNftRemoveAllowance tokenNftRemoveAllowance( - getTestTokenId(), getTestOwnerAccountId(), getTestSerialNumbers()); - - // Then - EXPECT_EQ(tokenNftRemoveAllowance.getTokenId(), getTestTokenId()); - EXPECT_EQ(tokenNftRemoveAllowance.getOwnerAccountId(), getTestOwnerAccountId()); - EXPECT_EQ(tokenNftRemoveAllowance.getSerialNumbers(), getTestSerialNumbers()); -} - -//----- -TEST_F(TokenNftRemoveAllowanceTest, GetSetTokenId) -{ - // Given - TokenNftRemoveAllowance tokenNftRemoveAllowance; - - // When - tokenNftRemoveAllowance.setTokenId(getTestTokenId()); - - // Then - EXPECT_EQ(tokenNftRemoveAllowance.getTokenId(), getTestTokenId()); -} - -//----- -TEST_F(TokenNftRemoveAllowanceTest, GetSetOwnerAccountId) -{ - // Given - TokenNftRemoveAllowance tokenNftRemoveAllowance; - - // When - tokenNftRemoveAllowance.setOwnerAccountId(getTestOwnerAccountId()); - - // Then - EXPECT_EQ(tokenNftRemoveAllowance.getOwnerAccountId(), getTestOwnerAccountId()); -} - -//----- -TEST_F(TokenNftRemoveAllowanceTest, GetSetSerialNumbers) -{ - // Given - TokenNftRemoveAllowance tokenNftRemoveAllowance; - - // When - for (const uint64_t& num : getTestSerialNumbers()) - { - tokenNftRemoveAllowance.addSerialNumber(num); - } - - // Then - ASSERT_EQ(tokenNftRemoveAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); - for (int i = 0; i < getTestSerialNumbers().size(); ++i) - { - EXPECT_EQ(tokenNftRemoveAllowance.getSerialNumbers().at(i), getTestSerialNumbers().at(i)); - } -} - -//----- -TEST_F(TokenNftRemoveAllowanceTest, FromProtobuf) -{ - // Given - proto::NftRemoveAllowance protoNftRemoveAllowance; - protoNftRemoveAllowance.set_allocated_token_id(getTestTokenId().toProtobuf().release()); - protoNftRemoveAllowance.set_allocated_owner(getTestOwnerAccountId().toProtobuf().release()); - - for (const uint64_t& num : getTestSerialNumbers()) - { - protoNftRemoveAllowance.add_serial_numbers(static_cast(num)); - } - - // When - const TokenNftRemoveAllowance tokenNftRemoveAllowance = - TokenNftRemoveAllowance::fromProtobuf(protoNftRemoveAllowance); - - // Then - EXPECT_EQ(tokenNftRemoveAllowance.getTokenId(), getTestTokenId()); - EXPECT_EQ(tokenNftRemoveAllowance.getOwnerAccountId(), getTestOwnerAccountId()); - - ASSERT_EQ(tokenNftRemoveAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); - for (int i = 0; i < getTestSerialNumbers().size(); ++i) - { - EXPECT_EQ(tokenNftRemoveAllowance.getSerialNumbers().at(i), getTestSerialNumbers().at(i)); - } -} - -//----- -TEST_F(TokenNftRemoveAllowanceTest, ToProtobuf) -{ - // Given - TokenNftRemoveAllowance tokenNftRemoveAllowance; - tokenNftRemoveAllowance.setTokenId(getTestTokenId()); - tokenNftRemoveAllowance.setOwnerAccountId(getTestOwnerAccountId()); - - for (const uint64_t& num : getTestSerialNumbers()) - { - tokenNftRemoveAllowance.addSerialNumber(num); - } - - // When - const std::unique_ptr protoNftRemoveAllowance = tokenNftRemoveAllowance.toProtobuf(); - - // Then - ASSERT_TRUE(protoNftRemoveAllowance->has_token_id()); - EXPECT_EQ(TokenId::fromProtobuf(protoNftRemoveAllowance->token_id()), getTestTokenId()); - ASSERT_TRUE(protoNftRemoveAllowance->has_owner()); - EXPECT_EQ(AccountId::fromProtobuf(protoNftRemoveAllowance->owner()), getTestOwnerAccountId()); - - ASSERT_EQ(tokenNftRemoveAllowance.getSerialNumbers().size(), getTestSerialNumbers().size()); - for (int i = 0; i < getTestSerialNumbers().size(); ++i) - { - EXPECT_EQ(tokenNftRemoveAllowance.getSerialNumbers().at(i), getTestSerialNumbers().at(i)); - } -}