Skip to content

Commit 6b430d1

Browse files
authored
Merge pull request #49 from skalenetwork/bug-on-update
Fix bug in transfer to self
2 parents ef0bc43 + 690d6d6 commit 6b430d1

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

contracts/ConfidentialToken.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ contract ConfidentialToken is EIP3009, ERC20Permit, AccessManaged, IConfidential
322322
)
323323
internal
324324
{
325+
if (from == to) {
326+
_setBalance(from, fromBalance);
327+
_onUpdate(from, to, value);
328+
return;
329+
}
330+
325331
uint256 updatedFromBalance = fromBalance;
326332
uint256 updatedToBalance = toBalance;
327333

test/ConfidentialToken.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// cspell:words ECIES
22

33
import { ethers } from "hardhat";
4-
import { cleanMintableDeployment } from "./tools/fixtures";
4+
import { cleanMintableDeployment, withMintedTokens } from "./tools/fixtures";
55
import "chai/register-should";
66
import { getPublicKey } from "./tools/cryptography";
77
import { balanceOf } from "./tools/helpers";
@@ -226,4 +226,23 @@ describe("ConfidentialToken", () => {
226226
// Real balance should stay the same
227227
expect(realBalanceBefore).to.equal(realBalanceAfter);
228228
});
229+
230+
it("transfer to self should not change balance", async () => {
231+
const amount = ethers.parseEther("1.0");
232+
const [owner] = await ethers.getSigners();
233+
const { token, bite } = await withMintedTokens();
234+
235+
await token.connect(owner).setViewerPublicKey(
236+
await getPublicKey(owner)
237+
);
238+
await bite.sendCallback();
239+
240+
const balanceBefore = await balanceOf(token, bite, owner);
241+
242+
await token.connect(owner).transfer(owner, amount);
243+
await bite.sendCallback();
244+
245+
const balanceAfter = await balanceOf(token, bite, owner);
246+
balanceAfter.should.be.equal(balanceBefore);
247+
});
229248
});

0 commit comments

Comments
 (0)