From ece1817d2347057ee5de1d596e76520dd999aa66 Mon Sep 17 00:00:00 2001 From: RuslanProgrammer Date: Tue, 23 Jan 2024 12:25:05 +0100 Subject: [PATCH] Changed minting of reward tokens in L2MessageReceiver --- contracts/L2MessageReceiver.sol | 16 +--------------- test/L2MessageReceiver.test.ts | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/contracts/L2MessageReceiver.sol b/contracts/L2MessageReceiver.sol index 9cbafeb..ce5c070 100644 --- a/contracts/L2MessageReceiver.sol +++ b/contracts/L2MessageReceiver.sol @@ -105,24 +105,10 @@ contract L2MessageReceiver is ILayerZeroReceiver, IL2MessageReceiver, OwnableUpg (address user_, uint256 amount_) = abi.decode(payload_, (address, uint256)); - _mintRewardTokens(user_, amount_); + IMOR(rewardToken).mint(user_, amount_); isNonceUsed[senderChainId_][nonce_] = true; } - function _mintRewardTokens(address user_, uint256 amount_) private { - uint256 maxAmount_ = IMOR(rewardToken).cap() - IMOR(rewardToken).totalSupply(); - - if (amount_ == 0 || maxAmount_ == 0) { - return; - } - - if (amount_ > maxAmount_) { - amount_ = maxAmount_; - } - - IMOR(rewardToken).mint(user_, amount_); - } - function _authorizeUpgrade(address) internal view override onlyOwner {} } diff --git a/test/L2MessageReceiver.test.ts b/test/L2MessageReceiver.test.ts index 08832dc..b4f87e0 100644 --- a/test/L2MessageReceiver.test.ts +++ b/test/L2MessageReceiver.test.ts @@ -126,16 +126,6 @@ describe('L2MessageReceiver', () => { expect(await l2MessageReceiver.isNonceUsed(2, 5)).to.be.equal(true); payload = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [await SECOND.getAddress(), wei(2)]); tx = await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 6, payload); - await expect(tx).to.changeTokenBalance(mor, SECOND, wei(1)); - expect(await l2MessageReceiver.isNonceUsed(2, 6)).to.be.equal(true); - payload = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [await SECOND.getAddress(), wei(2)]); - tx = await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 7, payload); - await expect(tx).to.changeTokenBalance(mor, SECOND, wei(0)); - expect(await l2MessageReceiver.isNonceUsed(2, 7)).to.be.equal(true); - payload = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [await SECOND.getAddress(), wei(0)]); - tx = await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 8, payload); - await expect(tx).to.changeTokenBalance(mor, SECOND, wei(0)); - expect(await l2MessageReceiver.isNonceUsed(2, 8)).to.be.equal(true); }); it('should revert if provided wrong lzEndpoint', async () => { await expect(l2MessageReceiver.lzReceive(0, '0x', 1, '0x')).to.be.revertedWith('L2MR: invalid gateway'); @@ -155,6 +145,26 @@ describe('L2MessageReceiver', () => { await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload); expect(await l2MessageReceiver.failedMessages(2, address, 5)).to.eq(ethers.keccak256(payload)); }); + it('should fail if provided wrong mint amount', async () => { + const address = ethers.solidityPacked( + ['address', 'address'], + [await OWNER.getAddress(), await l2MessageReceiver.getAddress()], + ); + const payload = ethers.AbiCoder.defaultAbiCoder().encode( + ['address', 'uint256'], + [await SECOND.getAddress(), wei(100)], + ); + + await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload); + + expect(await l2MessageReceiver.failedMessages(2, address, 5)).to.eq(ZERO_BYTES32); + await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload); + expect(await l2MessageReceiver.failedMessages(2, address, 5)).to.eq(ethers.keccak256(payload)); + + await mor.connect(SECOND).burn(wei(100)); + + await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload); + }); }); describe('#nonblockingLzReceive', () => {