From ad7f33c8a9bac0a60a7df33ce3c423522e0a97bb Mon Sep 17 00:00:00 2001 From: Alain Olivier Date: Thu, 14 Mar 2024 12:31:16 +0100 Subject: [PATCH] test(fork): add integration test for depositing rewards --- test/fork/dao.test.js | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/fork/dao.test.js b/test/fork/dao.test.js index bb9ed50..59f4644 100644 --- a/test/fork/dao.test.js +++ b/test/fork/dao.test.js @@ -41,6 +41,7 @@ const { PNETWORK, ASSOCIATION, FINANCE_VAULT: FINANCE_VAULT_V1, + FORWARDER_ETHPNT: FORWARDER_ON_MAINNET_ETHPNT, PBTC: PBTC_ON_ETHEREUM, PBTC_MINTER, CROSS_EXECUTOR, @@ -78,6 +79,9 @@ const WITHDRAW_INFLATION_FROM_GNOSIS_USER_DATA = const WITHDRAW_INFLATION_FROM_GNOSIS_USER_DATA_3 = // secretlint-disable-next-line '0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000cf759bccfef5f322af58adae2d28885658b5e0200000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000f4ea6b892853413bd9d9f1a5d3a620a0ba39c5b2000000000000000000000000f4ea6b892853413bd9d9f1a5d3a620a0ba39c5b2000000000000000000000000e396757ec7e6ac7c8e5abe7285dde47b98f22db80000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000443352d49b0000000000000000000000006a4bd6de0de7b80f24a307f31b40856da975b5a70000000000000000000000000000000000000000000000056bc75e2d63100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000e396757ec7e6ac7c8e5abe7285dde47b98f22db80000000000000000000000000000000000000000000000056bc75e2d63100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124c322525d0000000000000000000000000000000000000000000000056bc75e2d63100000000000000000000000000000f4ea6b892853413bd9d9f1a5d3a620a0ba39c5b200000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000f1918e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30786631663635363861373635353964383563463638453635393766413538373534343138346444343600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' +const DEPOSIT_REWARDS_USER_DATA = + // secretlint-disable-next-line + '0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000002211bfd97b1c02ae8ac305d206e9780ba7d8bff40000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000008805aa0c1a8e59b03fa95740f691e28942cf44f60000000000000000000000002ec44f9f31a55b52b3c1ff98647e38d63f829fb70000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000002ec44f9f31a55b52b3c1ff98647e38d63f829fb70000000000000000000000000000000000000000000000000000000000000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044dc5e3ccd0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006300000000000000000000000000000000000000000000000000000000' const getBytes = (_hexString) => Buffer.from(_hexString.slice(2), 'hex') @@ -825,6 +829,21 @@ describe('Integration tests on Gnosis deployment', () => { ) }) + it('[dapp] should deposit rewards from forwarder call (1)', async () => { + const depositedAmount = await rewardsManager.depositedAmountByEpoch(4) + const metadata = encodeMetadata(ethers, { + userData: DEPOSIT_REWARDS_USER_DATA, + sourceNetworkId: PNETWORK_NETWORK_IDS.MAINNET, + senderAddress: FORWARDER_ON_MAINNET_ETHPNT, + destinationNetworkId: PNETWORK_NETWORK_IDS.GNOSIS, + receiverAddress: forwarder.target + }) + await expect(mintPToken(pntOnGnosis, pntMinter, forwarder.target, 99n, metadata)) + .to.emit(pntOnGnosis, 'Transfer') + .withArgs(FORWARDER_ON_GNOSIS, REWARDS_MANAGER, 99) + expect(await rewardsManager.depositedAmountByEpoch(4)).to.be.eq(99n + depositedAmount) + }) + it('[dapp] should delegateVote from forwarder call', async () => { const stakedAmount = ethers.parseUnits('10') await mintPntOnGnosis(user.address, stakedAmount) @@ -1186,6 +1205,42 @@ describe('Integration tests on Ethereum deployment', () => { ) }) + it('[dapp] should open a vote for depositing rewards', async () => { + expect(await ethPnt.inflationOwner()).to.be.eq(crossExecutor.target) + const INFLATION_OWNER_SLOT = '0x131' // 305 (found brute forcing eth_getStorageAt()) + await ethers.provider.send('hardhat_setStorageAt', [ + ethPnt.target, + INFLATION_OWNER_SLOT, + ethers.zeroPadValue(daoVotingV1.target, 32) + ]) + expect(await ethPnt.inflationOwner()).to.be.eq(daoVotingV1.target) + await daoVotingV1.connect(association).newVote( + // secretlint-disable-next-line + '0x00000001f4ea6b892853413bd9d9f1a5d3a620a0ba39c5b2000000443352d49b000000000000000000000000dd92eb1478d3189707ab7f4a5ace3a615cdd04760000000000000000000000000000000000000000000000056bc75e2d63100000dd92eb1478d3189707ab7f4a5ace3a615cdd047600000064beabacc8000000000000000000000000f4ea6b892853413bd9d9f1a5d3a620a0ba39c5b20000000000000000000000002211bfd97b1c02ae8ac305d206e9780ba7d8bff40000000000000000000000000000000000000000000000056bc75e2d63100000f4ea6b892853413bd9d9f1a5d3a620a0ba39c5b200000044095ea7b3000000000000000000000000d60792770ca2b54b9231041c8af641f48818da8d0000000000000000000000000000000000000000000000056bc75e2d63100000d60792770ca2b54b9231041c8af641f48818da8d000002a4996adf5500000000000000000000000000000000000000000000000000000000000000640000000000000000000000002422eb5b6a20c7b8e3567c12ed6f5ed9d1cf1f79000000000000000000000000000000000000000000000000000000000000008000f1918e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000008805aa0c1a8e59b03fa95740f691e28942cf44f60000000000000000000000002ec44f9f31a55b52b3c1ff98647e38d63f829fb70000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000002ec44f9f31a55b52b3c1ff98647e38d63f829fb70000000000000000000000000000000000000000000000000000000000000063000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044dc5e3ccd0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006300000000000000000000000000000000000000000000000000000000', + 'shall we deposit rewards?', + false + ) + const voteId = await daoVotingV1.votesLength() + await Promise.all(tokenHolders.map((_holder) => daoVotingV1.connect(_holder).vote(voteId, true))) + const vote = await daoVotingV1.getVote(voteId) + await mineUpTo(vote[3] + 1n) + await expect(daoVotingV1.connect(association).executeVote(voteId)) + .to.emit(daoVotingV1, 'ExecuteVote') + .withArgs(voteId) + .and.to.emit(ethPnt, 'Transfer') + .withArgs(FORWARDER_ON_MAINNET_ETHPNT, vault.target, 100) + .and.to.emit(vault, 'PegIn') + .withArgs( + PNT_ON_ETH, + FORWARDER_ON_MAINNET_ETHPNT, + 100, + FORWARDER_ON_GNOSIS.slice(2).toLowerCase(), + DEPOSIT_REWARDS_USER_DATA, + PNETWORK_NETWORK_IDS.MAINNET, + PNETWORK_NETWORK_IDS.GNOSIS + ) + }) + // pBTC is not native! so the execution script should not peg-in it.skip('[dapp] should open a vote for migrating pBTC treasury funds (4)', async () => { const amount = ethers.parseEther('100')