11import { TokenRolesEnum , ZERO_ADDRESS } from "@uma/common" ;
22import { mockTreeRoot , amountToReturn , amountHeldByPool } from "../constants" ;
3- import { ethers , expect , Contract , SignerWithAddress , getContractFactory , seedContract , toWei } from "../utils" ;
3+ import {
4+ ethers ,
5+ expect ,
6+ Contract ,
7+ SignerWithAddress ,
8+ getContractFactory ,
9+ seedContract ,
10+ toWei ,
11+ randomBigNumber ,
12+ seedWallet ,
13+ } from "../utils" ;
414import { hubPoolFixture } from "../fixtures/HubPool.Fixture" ;
515import { constructSingleRelayerRefundTree } from "../MerkleLib.utils" ;
616
@@ -13,9 +23,13 @@ describe("Polygon Spoke Pool", function () {
1323 [ owner , relayer , fxChild , rando ] = await ethers . getSigners ( ) ;
1424 ( { weth, hubPool, timer, l2Dai } = await hubPoolFixture ( ) ) ;
1525
26+ // The spoke pool exists on l2, so add a random chainId for L1 to ensure that the L2's block.chainid will not match.
27+ const l1ChainId = randomBigNumber ( ) ;
28+ const l2ChainId = await owner . getChainId ( ) ;
29+
1630 const polygonTokenBridger = await (
1731 await getContractFactory ( "PolygonTokenBridger" , owner )
18- ) . deploy ( hubPool . address , weth . address ) ;
32+ ) . deploy ( hubPool . address , weth . address , l1ChainId , l2ChainId ) ;
1933
2034 dai = await ( await getContractFactory ( "PolygonERC20Test" , owner ) ) . deploy ( ) ;
2135 await dai . addMember ( TokenRolesEnum . MINTER , owner . address ) ;
@@ -25,6 +39,7 @@ describe("Polygon Spoke Pool", function () {
2539 ) . deploy ( polygonTokenBridger . address , owner . address , hubPool . address , weth . address , fxChild . address , timer . address ) ;
2640
2741 await seedContract ( polygonSpokePool , relayer , [ dai ] , weth , amountHeldByPool ) ;
42+ await seedWallet ( owner , [ ] , weth , toWei ( "1" ) ) ;
2843 } ) ;
2944
3045 it ( "Only correct caller can set the cross domain admin" , async function ( ) {
@@ -196,9 +211,13 @@ describe("Polygon Spoke Pool", function () {
196211 } ) ;
197212
198213 it ( "PolygonTokenBridger retrieves and unwraps tokens correctly" , async function ( ) {
214+ const l1ChainId = await owner . getChainId ( ) ;
215+
216+ // Retrieve can only be performed on L1, so seed the L2 chainId with a non matching value.
217+ const l2ChainId = randomBigNumber ( ) ;
199218 const polygonTokenBridger = await (
200219 await getContractFactory ( "PolygonTokenBridger" , owner )
201- ) . deploy ( hubPool . address , weth . address ) ;
220+ ) . deploy ( hubPool . address , weth . address , l1ChainId , l2ChainId ) ;
202221
203222 await expect ( ( ) =>
204223 owner . sendTransaction ( { to : polygonTokenBridger . address , value : toWei ( "1" ) } )
@@ -210,4 +229,43 @@ describe("Polygon Spoke Pool", function () {
210229 [ toWei ( "1" ) . mul ( - 1 ) , toWei ( "1" ) ]
211230 ) ;
212231 } ) ;
232+
233+ it ( "PolygonTokenBridger doesn't allow L1 actions on L2" , async function ( ) {
234+ // Make sure the L1 chain is different from the chainId where this is deployed.
235+ const l1ChainId = randomBigNumber ( ) ;
236+ const l2ChainId = await owner . getChainId ( ) ;
237+
238+ const polygonTokenBridger = await (
239+ await getContractFactory ( "PolygonTokenBridger" , owner )
240+ ) . deploy ( hubPool . address , weth . address , l1ChainId , l2ChainId ) ;
241+
242+ // Cannot send ETH directly into the contract on L2.
243+ await expect ( owner . sendTransaction ( { to : polygonTokenBridger . address , value : toWei ( "1" ) } ) ) . to . be . revertedWith (
244+ "Cannot run method on this chain"
245+ ) ;
246+
247+ // Cannot call retrieve on the contract on L2.
248+ await weth . connect ( owner ) . transfer ( polygonTokenBridger . address , toWei ( "1" ) ) ;
249+ await expect ( polygonTokenBridger . connect ( owner ) . retrieve ( weth . address ) ) . to . be . revertedWith (
250+ "Cannot run method on this chain"
251+ ) ;
252+ } ) ;
253+
254+ it ( "PolygonTokenBridger doesn't allow L2 actions on L1" , async function ( ) {
255+ const l1ChainId = await owner . getChainId ( ) ;
256+
257+ // Make sure the L1 chain is different from the chainId where this is deployed.
258+ const l2ChainId = randomBigNumber ( ) ;
259+
260+ const polygonTokenBridger = await (
261+ await getContractFactory ( "PolygonTokenBridger" , owner )
262+ ) . deploy ( hubPool . address , weth . address , l1ChainId , l2ChainId ) ;
263+
264+ await weth . connect ( owner ) . approve ( polygonTokenBridger . address , toWei ( "1" ) ) ;
265+
266+ // Cannot call send on the contract on L1.
267+ await expect ( polygonTokenBridger . connect ( owner ) . send ( weth . address , toWei ( "1" ) , false ) ) . to . be . revertedWith (
268+ "Cannot run method on this chain"
269+ ) ;
270+ } ) ;
213271} ) ;
0 commit comments