Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/10274-fix-erc-721-c…
Browse files Browse the repository at this point in the history
…ontract-interactions-suite' into 10274-fix-erc-721-contract-interactions-suite
  • Loading branch information
dikel committed Dec 8, 2023
2 parents 35e9488 + a75c46b commit 6729343
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6729343

Please sign in to comment.