|
| 1 | +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' |
| 2 | +import { expect } from 'chai' |
| 3 | +import hre from 'hardhat' |
| 4 | +import { chainIdIsL2 } from '../../../../cli/utils' |
| 5 | + |
| 6 | +describe('[L2] L2 bridge auth protection', () => { |
| 7 | + const { |
| 8 | + contracts: { L2GraphToken, L2GraphTokenGateway }, |
| 9 | + getTestAccounts, |
| 10 | + } = hre.graph() |
| 11 | + |
| 12 | + let unauthorized: SignerWithAddress |
| 13 | + |
| 14 | + before(async function () { |
| 15 | + const chainId = (await hre.ethers.provider.getNetwork()).chainId |
| 16 | + if (!chainIdIsL2(chainId)) this.skip() |
| 17 | + |
| 18 | + unauthorized = (await getTestAccounts())[0] |
| 19 | + }) |
| 20 | + |
| 21 | + describe('L2GraphToken calls with unauthorized user', () => { |
| 22 | + it('mint should revert', async function () { |
| 23 | + const tx = L2GraphToken.connect(unauthorized).mint( |
| 24 | + unauthorized.address, |
| 25 | + '1000000000000000000000', |
| 26 | + ) |
| 27 | + await expect(tx).revertedWith('Only minter can call') |
| 28 | + }) |
| 29 | + |
| 30 | + it('bridgeMint should revert', async function () { |
| 31 | + const tx = L2GraphToken.connect(unauthorized).bridgeMint( |
| 32 | + unauthorized.address, |
| 33 | + '1000000000000000000000', |
| 34 | + ) |
| 35 | + await expect(tx).revertedWith('NOT_GATEWAY') |
| 36 | + }) |
| 37 | + |
| 38 | + it('setGateway should revert', async function () { |
| 39 | + const tx = L2GraphToken.connect(unauthorized).setGateway(unauthorized.address) |
| 40 | + await expect(tx).revertedWith('Only Governor can call') |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + describe('L2GraphTokenGateway calls with unauthorized user', () => { |
| 45 | + it('initialize should revert', async function () { |
| 46 | + const tx = L2GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address) |
| 47 | + await expect(tx).revertedWith('Caller must be the implementation') |
| 48 | + }) |
| 49 | + |
| 50 | + it('setL2Router should revert', async function () { |
| 51 | + const tx = L2GraphTokenGateway.connect(unauthorized).setL2Router(unauthorized.address) |
| 52 | + await expect(tx).revertedWith('Caller must be Controller governor') |
| 53 | + }) |
| 54 | + |
| 55 | + it('setL1TokenAddress should revert', async function () { |
| 56 | + const tx = L2GraphTokenGateway.connect(unauthorized).setL1TokenAddress(unauthorized.address) |
| 57 | + await expect(tx).revertedWith('Caller must be Controller governor') |
| 58 | + }) |
| 59 | + |
| 60 | + it('setL1CounterpartAddress should revert', async function () { |
| 61 | + const tx = L2GraphTokenGateway.connect(unauthorized).setL1CounterpartAddress( |
| 62 | + unauthorized.address, |
| 63 | + ) |
| 64 | + await expect(tx).revertedWith('Caller must be Controller governor') |
| 65 | + }) |
| 66 | + |
| 67 | + it('outboundTransfer should revert', async function () { |
| 68 | + const tx = L2GraphTokenGateway.connect(unauthorized)[ |
| 69 | + 'outboundTransfer(address,address,uint256,uint256,uint256,bytes)' |
| 70 | + ](L2GraphToken.address, unauthorized.address, '1000000000000', 0, 0, '0x00') |
| 71 | + |
| 72 | + await expect(tx).revertedWith('TOKEN_NOT_GRT') |
| 73 | + }) |
| 74 | + |
| 75 | + it('finalizeInboundTransfer should revert', async function () { |
| 76 | + const tx = L2GraphTokenGateway.connect(unauthorized).finalizeInboundTransfer( |
| 77 | + unauthorized.address, |
| 78 | + unauthorized.address, |
| 79 | + unauthorized.address, |
| 80 | + '1000000000000', |
| 81 | + '0x00', |
| 82 | + ) |
| 83 | + |
| 84 | + await expect(tx).revertedWith('ONLY_COUNTERPART_GATEWAY') |
| 85 | + }) |
| 86 | + }) |
| 87 | +}) |
0 commit comments