diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index f3746de2..c011be55 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -554,7 +554,7 @@ contract AToken is ERC20 { bool fromIndexReset = false; //reset the user data if the remaining balance is 0 - if (fromBalance.sub(_value) == 0) { + if (fromBalance.sub(_value) == 0 && _from != _to) { fromIndexReset = resetDataOnZeroBalanceInternal(_from); } diff --git a/test/atoken-transfer.spec.ts b/test/atoken-transfer.spec.ts index 879ff09e..0ebc24ab 100644 --- a/test/atoken-transfer.spec.ts +++ b/test/atoken-transfer.spec.ts @@ -188,4 +188,19 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER ); }); + + it('User 1 transfers the whole amount to himself', async () => { + const {users, pool, aDai, dai} = testEnv; + + const user1BalanceBefore = await aDai.balanceOf(users[1].address); + + await aDai.connect(users[1].signer).transfer(users[1].address, user1BalanceBefore); + + const user1BalanceAfter = await aDai.balanceOf(users[1].address); + + expect(user1BalanceAfter.toString()).to.be.equal( + user1BalanceBefore, + INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER + ); + }); });