From 92f2f2a9b39364318e500340cc1441d838bcf274 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 14 Jul 2020 14:43:43 +0200 Subject: [PATCH] Fixes aToken bug --- contracts/tokenization/AToken.sol | 2 +- test/atoken-transfer.spec.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 + ); + }); });