@@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
2
2
const { expect } = require ( 'chai' ) ;
3
3
const { loadFixture } = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4
4
5
+ const { impersonate } = require ( '@openzeppelin/contracts/test/helpers/account' ) ;
6
+
5
7
const AxelarHelper = require ( './axelar/AxelarHelper' ) ;
6
8
7
9
const buildBridgeHash = ( ...chains ) => {
@@ -153,4 +155,29 @@ describe('ERC7802Bridge', function () {
153
155
await expect ( this . tokenA . balanceOf ( this . endpointA ) ) . to . eventually . equal ( 0n ) ;
154
156
await expect ( this . tokenA . balanceOf ( this . endpointB ) ) . to . eventually . equal ( 0n ) ;
155
157
} ) ;
158
+
159
+ it ( 'cannot call endpoint directly to mint tokens' , async function ( ) {
160
+ const [ receiver , malicious ] = this . accounts ;
161
+ const value = 1_000_000_000n ;
162
+
163
+ // Deploy endpoint (that is whitelisted by tokenB)
164
+ await this . bridgeB . getBridgeEndpoint ( this . id ) ;
165
+
166
+ const tx = {
167
+ to : this . endpointB ,
168
+ data : ethers . concat ( [
169
+ this . tokenB . target ,
170
+ this . tokenB . interface . encodeFunctionData ( 'crosschainMint' , [ receiver . address , value ] ) ,
171
+ ] ) ,
172
+ } ;
173
+
174
+ // The bridge is able to make that call
175
+ const bridgeAsWallet = await impersonate ( this . bridgeB . target ) ;
176
+ await expect ( bridgeAsWallet . sendTransaction ( tx ) )
177
+ . to . emit ( this . tokenB , 'Transfer' )
178
+ . withArgs ( ethers . ZeroAddress , receiver , value ) ;
179
+
180
+ // An malicious user cannot
181
+ await expect ( malicious . sendTransaction ( tx ) ) . to . be . revertedWithoutReason ( ) ;
182
+ } ) ;
156
183
} ) ;
0 commit comments