diff --git a/test/integration/dual/deposit.integration.js b/test/integration/dual/deposit.integration.js index bc5a6600f5..caa4326997 100644 --- a/test/integration/dual/deposit.integration.js +++ b/test/integration/dual/deposit.integration.js @@ -11,21 +11,23 @@ describe('deposit() integration tests (L1, L2)', () => { const amountToDeposit = ethers.utils.parseEther('10'); let owner; - let Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow; + let Synthetix, SynthetixL2, SynthetixBridgeToOptimism, SynthetixBridgeEscrow; - let ownerBalance, escrowBalance; + let ownerBalance, ownerL2Balance, escrowBalance; let depositReceipt; describe('when the owner deposits SNX', () => { before('target contracts and users', () => { ({ Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow } = ctx.l1.contracts); + ({ Synthetix: SynthetixL2 } = ctx.l2.contracts); owner = ctx.l1.users.owner; }); before('record balances', async () => { ownerBalance = await Synthetix.balanceOf(owner.address); + ownerL2Balance = await SynthetixL2.balanceOf(owner.address); escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address); }); @@ -59,21 +61,18 @@ describe('deposit() integration tests (L1, L2)', () => { describe('when the deposit gets picked up in L2', () => { before('target contracts and users', () => { - ({ Synthetix } = ctx.l2.contracts); - owner = ctx.l2.users.owner; }); - before('record balances', async () => { - ownerBalance = await Synthetix.balanceOf(owner.address); - }); - before('wait for deposit finalization', async () => { await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash }); }); it('increases the owner balance', async () => { - assert.bnEqual(await Synthetix.balanceOf(owner.address), ownerBalance.add(amountToDeposit)); + assert.bnEqual( + await SynthetixL2.balanceOf(owner.address), + ownerL2Balance.add(amountToDeposit) + ); }); }); }); diff --git a/test/integration/dual/depositReward.integration.js b/test/integration/dual/depositReward.integration.js index 250d65acaf..94f313e044 100644 --- a/test/integration/dual/depositReward.integration.js +++ b/test/integration/dual/depositReward.integration.js @@ -11,13 +11,24 @@ describe('depositReward() integration tests (L1, L2)', () => { const rewardsToDeposit = ethers.utils.parseEther('10'); let owner; - let FeePool, Synthetix, SynthetixBridgeEscrow, SynthetixBridgeToOptimism, RewardEscrowV2; + let FeePoolL2, + Synthetix, + SynthetixL2, + SynthetixBridgeEscrow, + SynthetixBridgeToOptimism, + RewardEscrowV2L2; let depositReceipt, escrowBalance; + let currentFeePeriodRewards, rewardEscrowBalanceL2; describe('when the owner deposits SNX for rewards', () => { before('target contracts and users', () => { ({ Synthetix, SynthetixBridgeEscrow, SynthetixBridgeToOptimism } = ctx.l1.contracts); + ({ + FeePool: FeePoolL2, + RewardEscrowV2: RewardEscrowV2L2, + Synthetix: SynthetixL2, + } = ctx.l2.contracts); owner = ctx.l1.users.owner; }); @@ -33,6 +44,9 @@ describe('depositReward() integration tests (L1, L2)', () => { before('record values', async () => { escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address); + + rewardEscrowBalanceL2 = await SynthetixL2.balanceOf(RewardEscrowV2L2.address); + currentFeePeriodRewards = (await FeePoolL2.recentFeePeriods(0)).rewardsToDistribute; }); before('deposit rewards', async () => { @@ -49,31 +63,20 @@ describe('depositReward() integration tests (L1, L2)', () => { }); describe('when the deposit gets picked up in L2', () => { - let currentFeePeriodRewards, rewardEscrowBalanceL2; - - before('target contracts', () => { - ({ FeePool, RewardEscrowV2, Synthetix } = ctx.l2.contracts); - }); - - before('record current fee period rewards', async () => { - rewardEscrowBalanceL2 = await Synthetix.balanceOf(RewardEscrowV2.address); - currentFeePeriodRewards = (await FeePool.recentFeePeriods(0)).rewardsToDistribute; - }); - before('wait for deposit finalization', async () => { await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash }); }); it('increases the RewardEscrowV2 balance on L2', async () => { assert.bnEqual( - await Synthetix.balanceOf(RewardEscrowV2.address), + await SynthetixL2.balanceOf(RewardEscrowV2L2.address), rewardEscrowBalanceL2.add(rewardsToDeposit) ); }); it('increases the current fee periods rewards to distribute', async () => { assert.bnEqual( - (await FeePool.recentFeePeriods(0)).rewardsToDistribute, + (await FeePoolL2.recentFeePeriods(0)).rewardsToDistribute, currentFeePeriodRewards.add(rewardsToDeposit) ); }); diff --git a/test/integration/dual/depositTo.integration.test.js b/test/integration/dual/depositTo.integration.js similarity index 90% rename from test/integration/dual/depositTo.integration.test.js rename to test/integration/dual/depositTo.integration.js index c51b2c1088..7e08f1c422 100644 --- a/test/integration/dual/depositTo.integration.test.js +++ b/test/integration/dual/depositTo.integration.js @@ -11,7 +11,7 @@ describe('depositTo() integration tests (L1, L2)', () => { const amountToDeposit = ethers.utils.parseEther('10'); let owner, user; - let Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow; + let Synthetix, SynthetixL2, SynthetixBridgeToOptimism, SynthetixBridgeEscrow; let ownerBalance, beneficiaryBalance, escrowBalance; @@ -20,6 +20,7 @@ describe('depositTo() integration tests (L1, L2)', () => { describe('when the owner deposits SNX for a user', () => { before('target contracts and users', () => { ({ Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow } = ctx.l1.contracts); + ({ Synthetix: SynthetixL2 } = ctx.l2.contracts); owner = ctx.l1.users.owner; user = ctx.l1.users.someUser; @@ -28,6 +29,7 @@ describe('depositTo() integration tests (L1, L2)', () => { before('record balances', async () => { ownerBalance = await Synthetix.balanceOf(owner.address); escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address); + beneficiaryBalance = await SynthetixL2.balanceOf(user.address); }); before('approve if needed', async () => { @@ -65,17 +67,13 @@ describe('depositTo() integration tests (L1, L2)', () => { owner = ctx.l2.users.owner; }); - before('record balances', async () => { - beneficiaryBalance = await Synthetix.balanceOf(user.address); - }); - before('wait for deposit finalization', async () => { await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash }); }); it('increases the beneficiary balance', async () => { assert.bnEqual( - await Synthetix.balanceOf(user.address), + await SynthetixL2.balanceOf(user.address), beneficiaryBalance.add(amountToDeposit) ); }); diff --git a/test/integration/dual/inflationDiversion.integration.js b/test/integration/dual/inflationDiversion.integration.js index e163689082..973a143d8c 100644 --- a/test/integration/dual/inflationDiversion.integration.js +++ b/test/integration/dual/inflationDiversion.integration.js @@ -12,28 +12,38 @@ describe('inflationDiversion() integration tests (L1, L2)', () => { let ownerL1, ownerL2; - let FeePool, + let FeePoolL2, RewardsDistributionL1, RewardsDistributionL2, - RewardEscrowV2, + RewardEscrowV2L2, Synthetix, + SynthetixL2, SynthetixBridgeToOptimism, SynthetixBridgeEscrow, TradingRewards; let depositReceipt; + let currentFeePeriodRewards; + let rewardEscrowBalanceL2, tradingRewardsBalanceL2; + const rewardsToDistribute = rewardsToDeposit.sub(tradingRewards); + describe('when the owner diverts part of the inflation to L2', () => { before('target contracts and users', () => { ({ - FeePool, RewardsDistribution: RewardsDistributionL1, Synthetix, SynthetixBridgeEscrow, SynthetixBridgeToOptimism, } = ctx.l1.contracts); - ({ RewardsDistribution: RewardsDistributionL2, TradingRewards } = ctx.l2.contracts); + ({ + RewardsDistribution: RewardsDistributionL2, + TradingRewards, + FeePool: FeePoolL2, + RewardEscrowV2: RewardEscrowV2L2, + Synthetix: SynthetixL2, + } = ctx.l2.contracts); ownerL1 = ctx.l1.users.owner; ownerL2 = ctx.l2.users.owner; @@ -44,6 +54,10 @@ describe('inflationDiversion() integration tests (L1, L2)', () => { before('record values', async () => { escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address); + + rewardEscrowBalanceL2 = await SynthetixL2.balanceOf(RewardEscrowV2L2.address); + tradingRewardsBalanceL2 = await SynthetixL2.balanceOf(TradingRewards.address); + currentFeePeriodRewards = (await FeePoolL2.recentFeePeriods(0)).rewardsToDistribute; }); before('add new distributions', async () => { @@ -89,41 +103,27 @@ describe('inflationDiversion() integration tests (L1, L2)', () => { }); describe('when the rewards deposit gets picked up in L2', () => { - let currentFeePeriodRewards; - let rewardEscrowBalanceL2, tradingRewardsBalanceL2; - const rewardsToDistribute = rewardsToDeposit.sub(tradingRewards); - - before('target contracts', () => { - ({ FeePool, RewardEscrowV2, Synthetix } = ctx.l2.contracts); - }); - - before('record current values', async () => { - rewardEscrowBalanceL2 = await Synthetix.balanceOf(RewardEscrowV2.address); - tradingRewardsBalanceL2 = await Synthetix.balanceOf(TradingRewards.address); - currentFeePeriodRewards = (await FeePool.recentFeePeriods(0)).rewardsToDistribute; - }); - before('wait for deposit finalization', async () => { await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash }); }); it('increases the current fee periods rewards to distribute', async () => { assert.bnEqual( - (await FeePool.recentFeePeriods(0)).rewardsToDistribute, + (await FeePoolL2.recentFeePeriods(0)).rewardsToDistribute, currentFeePeriodRewards.add(rewardsToDistribute) ); }); it('increases the TradingRewards balance on L2', async () => { assert.bnEqual( - await Synthetix.balanceOf(TradingRewards.address), + await SynthetixL2.balanceOf(TradingRewards.address), tradingRewardsBalanceL2.add(tradingRewards) ); }); it('increases the RewardEscrowV2 balance on L2', async () => { assert.bnEqual( - await Synthetix.balanceOf(RewardEscrowV2.address), + await SynthetixL2.balanceOf(RewardEscrowV2L2.address), rewardEscrowBalanceL2.add(rewardsToDistribute) ); }); diff --git a/test/integration/dual/withdraw.integration.js b/test/integration/dual/withdraw.integration.js index c1962e64f8..b8b05eeb42 100644 --- a/test/integration/dual/withdraw.integration.js +++ b/test/integration/dual/withdraw.integration.js @@ -12,21 +12,23 @@ describe('withdraw() integration tests (L1, L2)', () => { const amountToWithdraw = ethers.utils.parseEther('10'); let owner; - let Synthetix, SynthetixBridgeToBase; + let Synthetix, SynthetixL1, SynthetixBridgeToBase; - let ownerBalance; + let ownerBalance, ownerL1Balance; let withdrawalReceipt; describe('when the owner withdraws SNX', () => { before('target contracts and users', () => { ({ Synthetix, SynthetixBridgeToBase } = ctx.l2.contracts); + ({ Synthetix: SynthetixL1 } = ctx.l1.contracts); owner = ctx.l2.users.owner; }); before('record balances', async () => { ownerBalance = await Synthetix.balanceOf(owner.address); + ownerL1Balance = await SynthetixL1.balanceOf(owner.address); }); before('make the withdrawal', async () => { @@ -55,24 +57,14 @@ describe('withdraw() integration tests (L1, L2)', () => { } }); - before('target contracts and users', () => { - ({ Synthetix } = ctx.l1.contracts); - - owner = ctx.l1.users.owner; - }); - - before('record balances', async () => { - ownerBalance = await Synthetix.balanceOf(owner.address); - }); - before('wait for withdrawal finalization', async () => { await finalizationOnL1({ ctx, transactionHash: withdrawalReceipt.transactionHash }); }); it('increases the owner balance', async () => { assert.bnEqual( - await Synthetix.balanceOf(owner.address), - ownerBalance.add(amountToWithdraw) + await SynthetixL1.balanceOf(owner.address), + ownerL1Balance.add(amountToWithdraw) ); }); }); diff --git a/test/integration/dual/withdrawTo.integration.js b/test/integration/dual/withdrawTo.integration.js index afa257c8df..e9497399cb 100644 --- a/test/integration/dual/withdrawTo.integration.js +++ b/test/integration/dual/withdrawTo.integration.js @@ -12,7 +12,7 @@ describe('withdrawTo() integration tests (L1, L2)', () => { const amountToWithdraw = ethers.utils.parseEther('10'); let owner, user; - let Synthetix, SynthetixBridgeToBase; + let Synthetix, SynthetixL1, SynthetixBridgeToBase; let ownerBalance, beneficiaryBalance; @@ -21,6 +21,7 @@ describe('withdrawTo() integration tests (L1, L2)', () => { describe('when the owner withdraws SNX for a user', () => { before('target contracts and users', () => { ({ Synthetix, SynthetixBridgeToBase } = ctx.l2.contracts); + ({ Synthetix: SynthetixL1 } = ctx.l1.contracts); owner = ctx.l2.users.owner; user = ctx.l2.users.someUser; @@ -28,6 +29,7 @@ describe('withdrawTo() integration tests (L1, L2)', () => { before('record balances', async () => { ownerBalance = await Synthetix.balanceOf(owner.address); + beneficiaryBalance = await SynthetixL1.balanceOf(user.address); }); before('make the withdrawal', async () => { @@ -56,23 +58,17 @@ describe('withdrawTo() integration tests (L1, L2)', () => { }); before('target contracts and users', () => { - ({ Synthetix } = ctx.l1.contracts); - owner = ctx.l1.users.owner; user = ctx.l1.users.someUser; }); - before('record balances', async () => { - beneficiaryBalance = await Synthetix.balanceOf(user.address); - }); - before('wait for withdrawal finalization', async () => { await finalizationOnL1({ ctx, transactionHash: withdrawalReceipt.transactionHash }); }); it('increases the user balance', async () => { assert.bnEqual( - await Synthetix.balanceOf(user.address), + await SynthetixL1.balanceOf(user.address), beneficiaryBalance.add(amountToWithdraw) ); }); diff --git a/test/integration/utils/optimism-temp.js b/test/integration/utils/optimism-temp.js index 40a9be2183..2615e4995f 100644 --- a/test/integration/utils/optimism-temp.js +++ b/test/integration/utils/optimism-temp.js @@ -111,13 +111,31 @@ class Watcher { const msgHashes = []; for (const log of receipt.logs) { if ( - log.topics[0] === '0x4b388aecf9fa6cc92253704e5975a6129a4f735bdbd99567df4ed0094ee4ceb5' // TransactionEnqueued event + log.address === layer.messengerAddress && + log.topics[0] === '0xcb0f7ffd78f9aee47a248fae8db181db6eee833039123e026dcbff529522e52a' // SentMessage event ) { - const [, message] = ethers.utils.defaultAbiCoder.decode( - ['uint', 'bytes', 'uint'], + const [sender, message, messageNonce] = ethers.utils.defaultAbiCoder.decode( + ['address', 'bytes', 'uint256', 'uint256'], log.data ); - msgHashes.push(ethers.utils.solidityKeccak256(['bytes'], [message])); + + const msgWithoutMethod = ethers.utils.defaultAbiCoder.encode( + ['address', 'address', 'bytes', 'uint256'], + [ + ethers.utils.defaultAbiCoder.decode(['address'], log.topics[1])[0], + sender, + message, + messageNonce, + ] + ); + + const fullMsg = '0xcbd4ece9' + msgWithoutMethod.slice(2); + + if (hre.config.debugOptimism) { + console.log(chalk.yellow(`encoded msg for hash: ${fullMsg}`)); + } + + msgHashes.push(ethers.utils.keccak256(fullMsg)); } } return msgHashes;