Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Nov 25, 2024
1 parent 2b54930 commit bd8fe8d
Showing 1 changed file with 104 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Diamond} from "contracts/state-transition/libraries/Diamond.sol";
import {ChainCreationParams} from "contracts/state-transition/IStateTransitionManager.sol";
import {FeeParams} from "contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol";
import "contracts/dev-contracts/test/DummyHyperchain.sol";
import {TestnetERC20Token} from "contracts/dev-contracts/TestnetERC20Token.sol";

contract ChainRegistrarTest is Test {
DummyBridgehub private bridgeHub;
Expand Down Expand Up @@ -115,20 +116,116 @@ contract ChainRegistrarTest is Test {
_gasPriceMultiplierNominator: 1,
_gasPriceMultiplierDenominator: 1
});
Vm.Log[] memory proposeLogs = vm.getRecordedLogs();
registerChainAndVerify(author, 1);
}

function test_CustomBaseToken() public {
address author = makeAddr("author");
vm.prank(author);
vm.recordLogs();
TestnetERC20Token token = new TestnetERC20Token("test", "test", 18);
token.mint(author, 100 ether);
vm.prank(author);
token.approve(address(chainRegistrar), 10 ether);
vm.prank(author);
chainRegistrar.proposeChainRegistration({
_chainId: 1,
_pubdataPricingMode: PubdataPricingMode.Validium,
_blobOperator: makeAddr("blobOperator"),
_operator: makeAddr("operator"),
_governor: makeAddr("governor"),
_baseTokenAddress: address(token),
_tokenMultiplierSetter: makeAddr("setter"),
_gasPriceMultiplierNominator: 10,
_gasPriceMultiplierDenominator: 1
});
registerChainAndVerify(author, 1);
}

function test_PreTransferErc20Token() public {
address author = makeAddr("author");
vm.startPrank(author);
vm.recordLogs();
TestnetERC20Token token = new TestnetERC20Token("test", "test", 18);
token.mint(author, 100 ether);
token.transfer(chainRegistrar.l2Deployer(), 10 ether);
chainRegistrar.proposeChainRegistration({
_chainId: 1,
_pubdataPricingMode: PubdataPricingMode.Validium,
_blobOperator: makeAddr("blobOperator"),
_operator: makeAddr("operator"),
_governor: makeAddr("governor"),
_baseTokenAddress: address(token),
_tokenMultiplierSetter: makeAddr("setter"),
_gasPriceMultiplierNominator: 10,
_gasPriceMultiplierDenominator: 1
});
vm.stopPrank();
registerChainAndVerify(author, 1);
}

function test_PreTransferNotEnough() public {
address author = makeAddr("author");
vm.startPrank(author);
vm.recordLogs();
TestnetERC20Token token = new TestnetERC20Token("test", "test", 18);
token.mint(author, 100 ether);
token.transfer(chainRegistrar.l2Deployer(), 1 ether);
vm.expectRevert();
chainRegistrar.proposeChainRegistration({
_chainId: 1,
_pubdataPricingMode: PubdataPricingMode.Validium,
_blobOperator: makeAddr("blobOperator"),
_operator: makeAddr("operator"),
_governor: makeAddr("governor"),
_baseTokenAddress: address(token),
_tokenMultiplierSetter: makeAddr("setter"),
_gasPriceMultiplierNominator: 10,
_gasPriceMultiplierDenominator: 1
});
}

function test_ApproveNotEnough() public {
address author = makeAddr("author");
vm.startPrank(author);
vm.recordLogs();
TestnetERC20Token token = new TestnetERC20Token("test", "test", 18);
token.mint(author, 100 ether);
token.approve(chainRegistrar.l2Deployer(), 1 ether);
vm.expectRevert();
chainRegistrar.proposeChainRegistration({
_chainId: 1,
_pubdataPricingMode: PubdataPricingMode.Validium,
_blobOperator: makeAddr("blobOperator"),
_operator: makeAddr("operator"),
_governor: makeAddr("governor"),
_baseTokenAddress: address(token),
_tokenMultiplierSetter: makeAddr("setter"),
_gasPriceMultiplierNominator: 10,
_gasPriceMultiplierDenominator: 1
});
}

function registerChainAndVerify(address author, uint256 chainId) internal {
DummyHyperchain hyperchain = new DummyHyperchain(address(bridgeHub), 270);
hyperchain.initialize(admin);
vm.prank(admin);
stm.setHyperchain(1, address(hyperchain));
bridgeHub.setStateTransitionManager(1, address(stm));
vm.prank(admin);
sharedBridge.initializeChainGovernance(1, makeAddr("l2bridge"));
vm.recordLogs();
bridgeHub.setStateTransitionManager(chainId, address(stm));
vm.prank(admin);
ChainRegistrar.RegisteredChainConfig memory registeredConfig = chainRegistrar.getRegisteredChainConfig(1);
sharedBridge.initializeChainGovernance(chainId, makeAddr("l2bridge"));
ChainRegistrar.RegisteredChainConfig memory registeredConfig = chainRegistrar.getRegisteredChainConfig(chainId);
(
uint256 proposedChainId,
ChainRegistrar.BaseToken memory baseToken,
address blobOperator,
address operator,
address governor,
PubdataPricingMode pubdataPricingMode
) = chainRegistrar.proposedChains(author, chainId);
require(registeredConfig.diamondProxy != address(0));
require(registeredConfig.chainAdmin != address(0));
require(registeredConfig.l2BridgeAddress != address(0));
require(registeredConfig.pendingChainAdmin != address(0));
require(proposedChainId == chainId);
}
}

0 comments on commit bd8fe8d

Please sign in to comment.