File tree Expand file tree Collapse file tree
main/java/com/hedera/hashgraph/sdk
test/java/com/hedera/hashgraph/sdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -495,7 +495,10 @@ public boolean equals(Object object) {
495495 var id = (TransactionId ) object ;
496496
497497 if (accountId != null && validStart != null && id .accountId != null && id .validStart != null ) {
498- return id .accountId .equals (accountId ) && id .validStart .equals (validStart ) && scheduled == id .scheduled ;
498+ return id .accountId .equals (accountId )
499+ && id .validStart .equals (validStart )
500+ && scheduled == id .scheduled
501+ && Objects .equals (nonce , id .nonce );
499502 } else {
500503 return false ;
501504 }
Original file line number Diff line number Diff line change 33
44import static org .assertj .core .api .Assertions .assertThat ;
55import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
6+ import static org .junit .jupiter .api .Assertions .assertFalse ;
67
78import com .google .protobuf .InvalidProtocolBufferException ;
89import io .github .jsonSnapshot .SnapshotMatcher ;
@@ -170,4 +171,19 @@ void shouldAddTrailingZeroesToNanoseconds() {
170171 var txId = TransactionId .fromString (txIdString );
171172 assertThat (txId ).hasToString (txIdString );
172173 }
174+
175+ @ Test
176+ void equalsHashCodeContractWithNonce () {
177+ AccountId accountId = new AccountId (0 , 0 , 1000 );
178+ Instant now = Instant .now ();
179+
180+ TransactionId txnId1 = TransactionId .withValidStart (accountId , now );
181+ TransactionId txnId2 = TransactionId .withValidStart (accountId , now );
182+
183+ txnId2 .setNonce (0 );
184+
185+ assertFalse (
186+ txnId1 .equals (txnId2 ) && txnId1 .hashCode () != txnId2 .hashCode (),
187+ "equals/hashCode contract violation: equal objects must have same hashCode" );
188+ }
173189}
You can’t perform that action at this time.
0 commit comments