|
| 1 | +const ethers = require('ethers'); |
| 2 | +const { assert } = require('../../contracts/common'); |
| 3 | +const { bootstrapDual } = require('../utils/bootstrap'); |
| 4 | +const { finalizationOnL2 } = require('../utils/watchers'); |
| 5 | +const { approveIfNeeded } = require('../utils/approve'); |
| 6 | + |
| 7 | +describe('depositTo() integration tests (L1, L2)', () => { |
| 8 | + const ctx = this; |
| 9 | + bootstrapDual({ ctx }); |
| 10 | + |
| 11 | + const amountToDeposit = ethers.utils.parseEther('10'); |
| 12 | + |
| 13 | + let owner, user; |
| 14 | + let Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow; |
| 15 | + |
| 16 | + let ownerBalance, beneficiaryBalance, escrowBalance; |
| 17 | + |
| 18 | + let depositReceipt; |
| 19 | + |
| 20 | + describe('when the owner deposits SNX for a user', () => { |
| 21 | + before('target contracts and users', () => { |
| 22 | + ({ Synthetix, SynthetixBridgeToOptimism, SynthetixBridgeEscrow } = ctx.l1.contracts); |
| 23 | + |
| 24 | + owner = ctx.l1.owner; |
| 25 | + user = ctx.l1.user; |
| 26 | + }); |
| 27 | + |
| 28 | + before('record balances', async () => { |
| 29 | + ownerBalance = await Synthetix.balanceOf(owner.address); |
| 30 | + escrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address); |
| 31 | + }); |
| 32 | + |
| 33 | + before('approve if needed', async () => { |
| 34 | + await approveIfNeeded({ |
| 35 | + token: Synthetix, |
| 36 | + owner, |
| 37 | + beneficiary: SynthetixBridgeToOptimism, |
| 38 | + amount: amountToDeposit, |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + before('make the deposit', async () => { |
| 43 | + SynthetixBridgeToOptimism = SynthetixBridgeToOptimism.connect(owner); |
| 44 | + |
| 45 | + const tx = await SynthetixBridgeToOptimism.depositTo(user.address, amountToDeposit); |
| 46 | + depositReceipt = await tx.wait(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('decreases the owner balance', async () => { |
| 50 | + const newOwnerBalance = await Synthetix.balanceOf(owner.address); |
| 51 | + |
| 52 | + assert.bnEqual(newOwnerBalance, ownerBalance.sub(amountToDeposit)); |
| 53 | + }); |
| 54 | + |
| 55 | + it('increases the escrow balance', async () => { |
| 56 | + const newEscrowBalance = await Synthetix.balanceOf(SynthetixBridgeEscrow.address); |
| 57 | + |
| 58 | + assert.bnEqual(newEscrowBalance, escrowBalance.add(amountToDeposit)); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('when the deposit gets picked up in L2', () => { |
| 62 | + before('target contracts and users', () => { |
| 63 | + ({ Synthetix } = ctx.l2.contracts); |
| 64 | + |
| 65 | + owner = ctx.l2.owner; |
| 66 | + }); |
| 67 | + |
| 68 | + before('record balances', async () => { |
| 69 | + beneficiaryBalance = await Synthetix.balanceOf(user.address); |
| 70 | + }); |
| 71 | + |
| 72 | + before('wait for deposit finalization', async () => { |
| 73 | + await finalizationOnL2({ ctx, transactionHash: depositReceipt.transactionHash }); |
| 74 | + }); |
| 75 | + |
| 76 | + it('increases the beneficiary balance', async () => { |
| 77 | + assert.bnEqual( |
| 78 | + await Synthetix.balanceOf(user.address), |
| 79 | + beneficiaryBalance.add(amountToDeposit) |
| 80 | + ); |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments