Skip to content

Commit c57410f

Browse files
davin-coreParasSalonia
authored andcommitted
feat: added operator == and expand unit test for pendingAirdropld (hiero-ledger#1293)
Signed-off-by: Davin <[email protected]>
1 parent 46638d8 commit c57410f

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/sdk/main/include/PendingAirdropId.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ class PendingAirdropId
7272
*/
7373
void validateChecksum(const Client& client) const;
7474

75+
/**
76+
* Compare this PendingAirdropId to another PendingAirdropId and determine if they represent the same pending airdrop.
77+
*
78+
* @param other The other PendingAirdropId with which to compare this PendingAirdropId.
79+
* @return \c TRUE if this PendingAirdropId is the same as the input PendingAirdropId, otherwise \c FALSE.
80+
*/
81+
[[nodiscard]] bool operator==(const PendingAirdropId& other) const;
82+
7583
/**
7684
* Construct an PendingAirdropId protobuf object from this PendingAirdropId object.
7785
*

src/sdk/main/src/PendingAirdropId.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ void PendingAirdropId::validateChecksum(const Client& client) const
5757
mNft.value().mTokenId.validateChecksum(client);
5858
}
5959
}
60+
61+
//-----
62+
bool PendingAirdropId::operator==(const PendingAirdropId& other) const
63+
{
64+
return (mSender == other.mSender) && (mReceiver == other.mReceiver) && (mFt == other.mFt) && (mNft == other.mNft);
65+
}
6066
//-----
6167
std::unique_ptr<proto::PendingAirdropId> PendingAirdropId::toProtobuf() const
6268
{

src/sdk/tests/unit/PendingAirdropIdUnitTests.cc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,90 @@ TEST_F(PendingAirdropIdUnitTests, FromProtobuf)
8282
EXPECT_FALSE(pendingAirdrop.mNft.has_value());
8383
}
8484

85+
//-----
86+
TEST_F(PendingAirdropIdUnitTests, FromProtobufNft)
87+
{
88+
// Given
89+
proto::PendingAirdropId proto;
90+
proto.mutable_sender_id()->set_shardnum(1);
91+
proto.mutable_sender_id()->set_realmnum(2);
92+
proto.mutable_sender_id()->set_accountnum(3);
93+
94+
proto.mutable_receiver_id()->set_shardnum(4);
95+
proto.mutable_receiver_id()->set_realmnum(5);
96+
proto.mutable_receiver_id()->set_accountnum(6);
97+
98+
proto.mutable_non_fungible_token()->mutable_token_id()->set_shardnum(7);
99+
proto.mutable_non_fungible_token()->mutable_token_id()->set_realmnum(8);
100+
proto.mutable_non_fungible_token()->mutable_token_id()->set_tokennum(9);
101+
proto.mutable_non_fungible_token()->set_serial_number(10);
102+
103+
// When
104+
PendingAirdropId pendingAirdrop = PendingAirdropId::fromProtobuf(proto);
105+
106+
// Then
107+
EXPECT_EQ(pendingAirdrop.mSender, AccountId(1, 2, 3));
108+
EXPECT_EQ(pendingAirdrop.mReceiver, AccountId(4, 5, 6));
109+
EXPECT_FALSE(pendingAirdrop.mFt.has_value());
110+
EXPECT_TRUE(pendingAirdrop.mNft.has_value());
111+
EXPECT_EQ(pendingAirdrop.mNft.value(), NftId(TokenId(7, 8, 9), 10));
112+
}
113+
114+
//-----
115+
TEST_F(PendingAirdropIdUnitTests, OperatorEqualsFt)
116+
{
117+
// Given
118+
PendingAirdropId lhs(AccountId(1, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 9));
119+
PendingAirdropId rhs(AccountId(1, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 9));
120+
121+
// Then
122+
EXPECT_TRUE(lhs == rhs);
123+
}
124+
125+
//-----
126+
TEST_F(PendingAirdropIdUnitTests, OperatorEqualsNft)
127+
{
128+
// Given
129+
PendingAirdropId lhs(AccountId(1, 2, 3), AccountId(4, 5, 6), NftId(TokenId(7, 8, 9), 10));
130+
PendingAirdropId rhs(AccountId(1, 2, 3), AccountId(4, 5, 6), NftId(TokenId(7, 8, 9), 10));
131+
132+
// Then
133+
EXPECT_TRUE(lhs == rhs);
134+
}
135+
136+
//-----
137+
TEST_F(PendingAirdropIdUnitTests, OperatorNotEqualsDifferentSender)
138+
{
139+
// Given
140+
PendingAirdropId lhs(AccountId(1, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 9));
141+
PendingAirdropId rhs(AccountId(10, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 9));
142+
143+
// Then
144+
EXPECT_FALSE(lhs == rhs);
145+
}
146+
147+
//-----
148+
TEST_F(PendingAirdropIdUnitTests, OperatorNotEqualsDifferentReceiver)
149+
{
150+
// Given
151+
PendingAirdropId lhs(AccountId(1, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 9));
152+
PendingAirdropId rhs(AccountId(1, 2, 3), AccountId(4, 5, 10), TokenId(7, 8, 9));
153+
154+
// Then
155+
EXPECT_FALSE(lhs == rhs);
156+
}
157+
158+
//-----
159+
TEST_F(PendingAirdropIdUnitTests, OperatorNotEqualsDifferentToken)
160+
{
161+
// Given
162+
PendingAirdropId lhs(AccountId(1, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 9));
163+
PendingAirdropId rhs(AccountId(1, 2, 3), AccountId(4, 5, 6), TokenId(7, 8, 10));
164+
165+
// Then
166+
EXPECT_FALSE(lhs == rhs);
167+
}
168+
85169
//-----
86170
TEST_F(PendingAirdropIdUnitTests, ToProtobuf)
87171
{

0 commit comments

Comments
 (0)