forked from matter-labs/era-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
519729e
commit 7673edf
Showing
6 changed files
with
81 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import {DataEncoding} from "../../common/libraries/DataEncoding.sol"; | |
import {BridgedStandardERC20} from "../BridgedStandardERC20.sol"; | ||
import {BridgeHelper} from "../BridgeHelper.sol"; | ||
|
||
import {EmptyDeposit, Unauthorized, TokensWithFeesNotSupported, TokenNotSupported, NonEmptyMsgValue, ValueMismatch, AddressMismatch, AssetIdMismatch, AmountMustBeGreaterThanZero, ZeroAddress, DeployingBridgedTokenForNativeToken} from "../../common/L1ContractErrors.sol"; | ||
import {AssetIdAlreadyRegistered, EmptyDeposit, Unauthorized, TokensWithFeesNotSupported, TokenNotSupported, NonEmptyMsgValue, ValueMismatch, AddressMismatch, AssetIdMismatch, AmountMustBeGreaterThanZero, ZeroAddress, DeployingBridgedTokenForNativeToken} from "../../common/L1ContractErrors.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -92,6 +92,9 @@ abstract contract NativeTokenVault is INativeTokenVault, IAssetHandler, Ownable2 | |
revert TokenNotSupported(WETH_TOKEN); | ||
} | ||
require(_nativeToken.code.length > 0, "NTV: empty token"); | ||
if (assetId[_nativeToken] != bytes32(0)) { | ||
revert AssetIdAlreadyRegistered(); | ||
} | ||
_unsafeRegisterNativeToken(_nativeToken); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
l1-contracts/test/foundry/l1/unit/concrete/Bridges/NativeTokenVault/L1NativeTokenVault.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {StdStorage, stdStorage} from "forge-std/Test.sol"; | ||
import {Test} from "forge-std/Test.sol"; | ||
import {Vm} from "forge-std/Vm.sol"; | ||
|
||
import {L1NativeTokenVault} from "contracts/bridge/ntv/L1NativeTokenVault.sol"; | ||
import {L1AssetRouter} from "contracts/bridge/asset-router/L1AssetRouter.sol"; | ||
import {IL1Nullifier} from "contracts/bridge/interfaces/IL1Nullifier.sol"; | ||
import {AssetIdAlreadyRegistered} from "contracts/common/L1ContractErrors.sol"; | ||
|
||
contract SomeToken { | ||
constructor() {} | ||
|
||
function name() external { | ||
// Just some function so that the bytecode is not empty, | ||
// the actional functionality is not used. | ||
} | ||
} | ||
|
||
contract L1NativeTokenVaultTest is Test { | ||
address assetRouter; | ||
|
||
L1NativeTokenVault ntv; | ||
SomeToken token; | ||
|
||
function setUp() public { | ||
assetRouter = makeAddr("assetRouter"); | ||
|
||
ntv = new L1NativeTokenVault(makeAddr("wethToken"), assetRouter, uint256(0), IL1Nullifier(address(0))); | ||
|
||
token = new SomeToken(); | ||
} | ||
|
||
function test_revertWhenRegisteringSameAddressTwice() external { | ||
vm.mockCall( | ||
assetRouter, | ||
abi.encodeCall( | ||
L1AssetRouter.setAssetHandlerAddressThisChain, | ||
(bytes32(uint256(uint160(address(token)))), address(ntv)) | ||
), | ||
hex"" | ||
); | ||
ntv.registerToken(address(token)); | ||
|
||
vm.expectRevert(AssetIdAlreadyRegistered.selector); | ||
ntv.registerToken(address(token)); | ||
} | ||
} |