diff --git a/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapReadableKVState.java b/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapReadableKVState.java index c8b8acb455..3d37e99211 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapReadableKVState.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapReadableKVState.java @@ -78,9 +78,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(getStateKey(), backingStore); } - - @Override - public String toString() { - return "MapReadableKVState{" + "backingStore=" + backingStore + '}'; - } } diff --git a/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableKVState.java b/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableKVState.java index bd0c365703..f331def8f1 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableKVState.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableKVState.java @@ -70,11 +70,6 @@ public long sizeOfDataSource() { return backingStore.size(); } - @Override - public String toString() { - return "MapWritableKVState{" + "backingStore=" + backingStore + '}'; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableStates.java b/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableStates.java index df5397a375..d9567f7cac 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableStates.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/state/utils/MapWritableStates.java @@ -122,9 +122,4 @@ public void commit() { onCommit.run(); } } - - @Override - public String toString() { - return "MapWritableStates{" + "states=" + states + '}'; - } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java index 00a624d4f8..722b270be8 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableKVStateTest.java @@ -67,11 +67,11 @@ void testReadFromDataSourceReturnsCorrectValue() { @Test void testIterateFromDataSourceReturnsEmptyIterator() { - final var backingStore = new HashMap(); - final var mapWritableKVState = new MapWritableKVState<>("ACCOUNTS", backingStore); - mapWritableKVState.putIntoDataSource(accountID, account); - assertThat(mapWritableKVState.iterateFromDataSource().next()) - .isEqualTo(backingStore.keySet().iterator().next()); + final var map = new HashMap(); + final var kvState = new MapWritableKVState<>("ACCOUNTS", map); + kvState.putIntoDataSource(accountID, account); + assertThat(kvState.iterateFromDataSource().next()) + .isEqualTo(map.keySet().iterator().next()); } @Test @@ -116,4 +116,23 @@ void testEqualsDifferentType() { void testEqualsWithNull() { assertThat(mapWritableKVState).isNotEqualTo(null); } + + @Test + void testEqualsDifferentKeys() { + MapWritableKVState other = new MapWritableKVState<>("ALIASES", backingStore); + assertThat(mapWritableKVState).isNotEqualTo(other); + } + + @Test + void testEqualsDifferentValues() { + final var accountMapOther = Map.of(AccountID.newBuilder().accountNum(3L).build(), account); + MapWritableKVState other = new MapWritableKVState<>("ACCOUNTS", accountMapOther); + assertThat(mapWritableKVState).isNotEqualTo(other); + } + + @Test + void testHashCode() { + MapWritableKVState other = new MapWritableKVState<>("ACCOUNTS", backingStore); + assertThat(mapWritableKVState).hasSameHashCodeAs(other); + } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java index 931c0d67bd..0f2b6fb7a8 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/state/utils/MapWritableStatesTest.java @@ -18,10 +18,12 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; -import com.swirlds.state.spi.WritableKVState; -import com.swirlds.state.spi.WritableQueueState; -import com.swirlds.state.spi.WritableSingletonState; +import com.swirlds.state.spi.WritableKVStateBase; +import com.swirlds.state.spi.WritableQueueStateBase; +import com.swirlds.state.spi.WritableSingletonStateBase; import java.util.Map; import java.util.Set; import org.junit.jupiter.api.BeforeEach; @@ -36,13 +38,13 @@ class MapWritableStatesTest { private MapWritableStates states; @Mock - private WritableKVState kvStateMock; + private WritableKVStateBase kvStateMock; @Mock - private WritableSingletonState singletonStateMock; + private WritableSingletonStateBase singletonStateMock; @Mock - private WritableQueueState queueStateMock; + private WritableQueueStateBase queueStateMock; private static final String KV_STATE_KEY = "kvState"; private static final String SINGLETON_KEY = "singleton"; @@ -139,4 +141,22 @@ void testHashCode() { Map.of(KV_STATE_KEY, kvStateMock, SINGLETON_KEY, singletonStateMock, QUEUE_KEY, queueStateMock)); assertThat(states).hasSameHashCodeAs(other); } + + @Test + void testCommit() { + final Runnable onCommit = () -> {}; + final var state = new MapWritableStates( + Map.of(KV_STATE_KEY, kvStateMock, SINGLETON_KEY, singletonStateMock, QUEUE_KEY, queueStateMock), + onCommit); + state.commit(); + verify(kvStateMock, times(1)).commit(); + verify(singletonStateMock, times(1)).commit(); + verify(queueStateMock, times(1)).commit(); + } + + @Test + void testCommitUnknownValue() { + final var state = new MapWritableStates(Map.of("other", new Object())); + assertThatThrownBy(state::commit).isInstanceOf(IllegalStateException.class); + } }