Skip to content

Commit

Permalink
did the needed constructor function change and added the correspondin…
Browse files Browse the repository at this point in the history
…g test
  • Loading branch information
SoarinSkySagar committed Oct 28, 2024
1 parent 455aba1 commit f95306f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
15 changes: 9 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "apps/blockchain/contracts/ethereum/lib/forge-std"]
path = apps/blockchain/ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "apps/blockchain/contracts/ethereum/lib/openzeppelin-contracts"]
path = apps/blockchain/ethereum/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "apps/blockchain/contracts/ethereum/lib/forge-std"]
path = apps/blockchain/ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "apps/blockchain/contracts/ethereum/lib/openzeppelin-contracts"]
path = apps/blockchain/ethereum/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable"]
path = apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
11 changes: 9 additions & 2 deletions apps/blockchain/ethereum/src/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "./UUPSProxied.sol";
import "starknet/IStarknetMessaging.sol";

import "./IStarklaneEvent.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

error NotSupportedYetError();
error CollectionMappingError();
Expand All @@ -36,7 +37,8 @@ contract Starklane is
StarklaneState,
StarklaneEscrow,
StarklaneMessaging,
CollectionManager
CollectionManager,
Initializable
{
// Mapping (collectionAddress => bool)
mapping(address => bool) _whiteList;
Expand All @@ -48,18 +50,23 @@ contract Starklane is
// This value serves as a flexible baseline, allowing for real-time adjustments to reflect gas changes.
uint256 _minimumGasFee = 5e13;// 0.00005 ETH

constructor() {
_disableInitializers();
}

/**
* @notice Initializes the implementation, only callable once.
*
* @param data Data to init the implementation.
*/
function initialize(bytes calldata data) public onlyInit {
function initialize(bytes calldata data) public initializer {
(
address owner,
IStarknetMessaging starknetCoreAddress,
uint256 starklaneL2Address,
uint256 starklaneL2Selector
) = abi.decode(data, (address, IStarknetMessaging, uint256, uint256));

_enabled = false;
_starknetCoreAddress = starknetCoreAddress;

Expand Down
19 changes: 19 additions & 0 deletions apps/blockchain/ethereum/test/Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.0;

import "openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

import "forge-std/Test.sol";
import "../src/IStarklane.sol";
Expand Down Expand Up @@ -55,6 +56,24 @@ contract BridgeTest is Test, IStarklaneEvent {
IStarklane(bridge).enableBridge(true);
}

//
function test_initializersDisabled() public {
// Deploy a new instance of Starklane
Starklane newStarklane = new Starklane();

// Try to initialize the contract directly
bytes memory initData = abi.encode(
address(this),
address(0), // Mock Starknet Core address
uint256(0), // Mock Starklane L2 address
uint256(0) // Mock Starklane L2 selector
);

// Expect the initialization to revert
vm.expectRevert(Initializable.InvalidInitialization.selector);
newStarklane.initialize(initData);
}

//
function testFail_invalidIds() public {
uint256[] memory ids = new uint256[](0);
Expand Down

0 comments on commit f95306f

Please sign in to comment.