diff --git a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/api/TokenServiceApiImpl.java b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/api/TokenServiceApiImpl.java index 9a6685fef1b0..cfd5af2d234e 100644 --- a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/api/TokenServiceApiImpl.java +++ b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/api/TokenServiceApiImpl.java @@ -274,11 +274,14 @@ public void transferFromTo(@NonNull AccountID fromId, @NonNull AccountID toId, l throw new IllegalArgumentException( "Overflow on transfer of " + amount + " tinybars from " + fromId + " to " + toId); } - accountStore.put(from.copyBuilder() - .tinybarBalance(from.tinybarBalance() - amount) - .build()); - accountStore.put( - to.copyBuilder().tinybarBalance(to.tinybarBalance() + amount).build()); + if (!from.accountIdOrThrow().equals(to.accountIdOrThrow())) { + accountStore.put(from.copyBuilder() + .tinybarBalance(from.tinybarBalance() - amount) + .build()); + accountStore.put(to.copyBuilder() + .tinybarBalance(to.tinybarBalance() + amount) + .build()); + } } @Override diff --git a/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/api/TokenServiceApiImplTest.java b/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/api/TokenServiceApiImplTest.java index 32578353f97f..19f025a06ef0 100644 --- a/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/api/TokenServiceApiImplTest.java +++ b/hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/api/TokenServiceApiImplTest.java @@ -322,6 +322,20 @@ void transfersRequestedValue() { assertEquals(23L, postTransferReceiver.tinybarBalance()); } + @Test + void identicalFromToIsNoop() { + accountStore.put(Account.newBuilder() + .accountId(CONTRACT_ACCOUNT_ID) + .tinybarBalance(123L) + .smartContract(true) + .build()); + + subject.transferFromTo(CONTRACT_ACCOUNT_ID, CONTRACT_ACCOUNT_ID, 23L); + + final var postTransfer = requireNonNull(accountState.get(CONTRACT_ACCOUNT_ID)); + assertEquals(123L, postTransfer.tinybarBalance()); + } + @Test void refusesToTransferNegativeAmount() { assertThrows(