diff --git a/contracts/PushComm/PushCommEthStorageV2.sol b/contracts/PushComm/PushCommEthStorageV2.sol index 4394ae06..0f4a6d4b 100644 --- a/contracts/PushComm/PushCommEthStorageV2.sol +++ b/contracts/PushComm/PushCommEthStorageV2.sol @@ -35,7 +35,6 @@ contract PushCommEthStorageV2 { // New State Variables address public PUSH_TOKEN_ADDRESS; - mapping(address => CommTypes.ChatDetails) public userChatData; mapping(bytes32 => string) public walletToPGP; uint256 FEE_AMOUNT; } diff --git a/contracts/PushComm/PushCommStorageV2.sol b/contracts/PushComm/PushCommStorageV2.sol index 13efa8c8..59659fee 100644 --- a/contracts/PushComm/PushCommStorageV2.sol +++ b/contracts/PushComm/PushCommStorageV2.sol @@ -41,7 +41,6 @@ contract PushCommStorageV2 { // New State Variables IERC20 public PUSH_NTT; - mapping(address => CommTypes.ChatDetails) public userChatData; mapping(bytes32 => string) public walletToPGP; // WORMHOLE CROSS-CHAIN STATE VARIABLES diff --git a/contracts/PushComm/PushCommV3.sol b/contracts/PushComm/PushCommV3.sol index cad7bb29..fbfa3935 100644 --- a/contracts/PushComm/PushCommV3.sol +++ b/contracts/PushComm/PushCommV3.sol @@ -579,7 +579,10 @@ contract PushCommV3 is Initializable, PushCommStorageV2, IPushCommV3, PausableUp whenNotPaused { // Implement restrictions based on functionType - if (functionType == CrossChainRequestTypes.CrossChainFunction.AddChannel) { + + if (functionType == CrossChainRequestTypes.CrossChainFunction.AddChannel || + functionType == CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings || + functionType == CrossChainRequestTypes.CrossChainFunction.ReactivateChannel ) { if (amount < ADD_CHANNEL_MIN_FEES) { revert Errors.InvalidArg_LessThanExpected(ADD_CHANNEL_MIN_FEES, amount); } @@ -591,10 +594,7 @@ contract PushCommV3 is Initializable, PushCommStorageV2, IPushCommV3, PausableUp if (amount == 0) { revert Errors.InvalidArg_LessThanExpected(1, amount); } - } else { - revert Errors.Comm_InvalidCrossChain_Function(); } - bytes memory requestPayload = abi.encode(functionType, payload, amount, msg.sender); // Call the internal function to create the cross-chain request @@ -614,25 +614,28 @@ contract PushCommV3 is Initializable, PushCommStorageV2, IPushCommV3, PausableUp uint256 messageBridgeCost = quoteMsgRelayCost(recipientChain, gasLimit); uint256 tokenBridgeCost = quoteTokenBridgingCost(); - if (msg.value < (messageBridgeCost + tokenBridgeCost)) { + address coreAddress = EPNSCoreAddress; + if (amount != 0) { + if (msg.value < (messageBridgeCost + tokenBridgeCost)) { + revert Errors.InsufficientFunds(); + } + IERC20 PushNtt = PUSH_NTT; + INttManager NttManager = NTT_MANAGER; + + PushNtt.transferFrom(msg.sender, address(this), amount); + PushNtt.approve(address(NttManager), amount); + NttManager.transfer{ value: tokenBridgeCost }( + amount, + recipientChain, + BaseHelper.addressToBytes32(coreAddress), + BaseHelper.addressToBytes32(msg.sender), + false, + new bytes(1) + ); + } else if (msg.value < (messageBridgeCost)) { revert Errors.InsufficientFunds(); } - IERC20 PushNtt = PUSH_NTT; - INttManager NttManager = NTT_MANAGER; - address coreAddress = EPNSCoreAddress; - - PushNtt.transferFrom(msg.sender, address(this), amount); - PushNtt.approve(address(NttManager), amount); - NttManager.transfer{ value: tokenBridgeCost }( - amount, - recipientChain, - BaseHelper.addressToBytes32(coreAddress), - BaseHelper.addressToBytes32(msg.sender), - false, - new bytes(1) - ); - // Relay the RequestData Payload WORMHOLE_RELAYER.sendPayloadToEvm{ value: messageBridgeCost }( recipientChain, diff --git a/contracts/PushCore/PushCoreStorageV2.sol b/contracts/PushCore/PushCoreStorageV2.sol index ab73c051..77e7d77a 100644 --- a/contracts/PushCore/PushCoreStorageV2.sol +++ b/contracts/PushCore/PushCoreStorageV2.sol @@ -11,7 +11,7 @@ contract PushCoreStorageV2 { ); mapping(address => uint256) public nonces; // NOT IN USE Anymore - mapping(address => uint256) public channelUpdateCounter; + mapping(address => uint256) public oldChannelUpdateCounter;//NOT in use anymore /** * Staking V2 state variables * */ @@ -36,9 +36,6 @@ contract PushCoreStorageV2 { */ mapping(address => uint256) public celebUserFunds; - /* *** v2.5 State variables *** */ - address public feePoolStakingContract; - /* *** V3 State variables *** */ // WORMHOLE Cross-Chain State @@ -48,5 +45,6 @@ contract PushCoreStorageV2 { mapping(address => uint256) public arbitraryReqFees; // ToDo: Could be replaced with nonces(unused) mapping instead // of adding new state - mapping(bytes32 => CoreTypes.Channel) public channelInfo; + mapping(bytes32 => CoreTypes.Channel) public channelInfo; + mapping(bytes32 => uint256) public channelUpdateCounter; } diff --git a/contracts/PushCore/PushCoreV3.sol b/contracts/PushCore/PushCoreV3.sol index 81779e7e..57c02da9 100644 --- a/contracts/PushCore/PushCoreV3.sol +++ b/contracts/PushCore/PushCoreV3.sol @@ -15,7 +15,6 @@ import { PushCoreStorageV1_5 } from "./PushCoreStorageV1_5.sol"; import { PushCoreStorageV2 } from "./PushCoreStorageV2.sol"; import "../interfaces/IPUSH.sol"; import { IPushCoreV3 } from "../interfaces/IPushCoreV3.sol"; -import { IPushCommV3 } from "../interfaces/IPushCommV3.sol"; import { BaseHelper } from "../libraries/BaseHelper.sol"; import { Errors } from "../libraries/Errors.sol"; import { CoreTypes, CrossChainRequestTypes, GenericTypes } from "../libraries/DataTypes.sol"; @@ -68,17 +67,16 @@ contract PushCoreV3 is } } - function onlyActivatedChannels(address _channel) private view { - bytes32 _channelBytesID = BaseHelper.addressToBytes32(_channel); + function onlyActivatedChannels(bytes32 _channel) private view { - if (channelInfo[_channelBytesID].channelState != 1) { + if (channelInfo[_channel].channelState != 1) { revert Errors.Core_InvalidChannel(); } } function addSubGraph(bytes calldata _subGraphData) external { - onlyActivatedChannels(msg.sender); - emit AddSubGraph(msg.sender, _subGraphData); + onlyActivatedChannels(BaseHelper.addressToBytes32(msg.sender)); + emit AddSubGraph(BaseHelper.addressToBytes32(msg.sender), _subGraphData); } function setEpnsCommunicatorAddress(address _commAddress) external { @@ -158,15 +156,15 @@ contract PushCoreV3 is **************************************/ ///@inheritdoc IPushCoreV3 - // ToDo: Check if updateChannelMeta is required for Cross-Chain-Req feature. If yes, it needs its own private - // function - function updateChannelMeta(address _channel, bytes calldata _newIdentity, uint256 _amount) external whenNotPaused { - onlyActivatedChannels(_channel); + function updateChannelMeta(bytes calldata _newIdentity, uint256 _amount) external whenNotPaused { + bytes32 _channel = BaseHelper.addressToBytes32(msg.sender); - if (msg.sender != _channel) { - revert Errors.UnauthorizedCaller(msg.sender); - } + IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(msg.sender, address(this), _amount); + _updateChannelMeta(_channel, _newIdentity, _amount); + } + function _updateChannelMeta(bytes32 _channel, bytes memory _newIdentity, uint256 _amount) internal { + onlyActivatedChannels(_channel); uint256 updateCounter = channelUpdateCounter[_channel] + 1; uint256 requiredFees = ADD_CHANNEL_MIN_FEES * updateCounter; @@ -177,11 +175,9 @@ contract PushCoreV3 is PROTOCOL_POOL_FEES = PROTOCOL_POOL_FEES + _amount; channelUpdateCounter[_channel] = updateCounter; - bytes32 _channelBytesID = BaseHelper.addressToBytes32(msg.sender); - channelInfo[_channelBytesID].channelUpdateBlock = block.number; + channelInfo[_channel].channelUpdateBlock = block.number; - IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(_channel, address(this), _amount); - emit UpdateChannel(_channelBytesID, _newIdentity, _amount); + emit UpdateChannel(_channel, _newIdentity, _amount); } /// @inheritdoc IPushCoreV3 @@ -268,25 +264,27 @@ contract PushCoreV3 is ) external { - onlyActivatedChannels(msg.sender); + onlyActivatedChannels(BaseHelper.addressToBytes32(msg.sender)); if (_amountDeposited < ADD_CHANNEL_MIN_FEES) { revert Errors.InvalidArg_LessThanExpected(ADD_CHANNEL_MIN_FEES, _amountDeposited); } - PROTOCOL_POOL_FEES = PROTOCOL_POOL_FEES + _amountDeposited; + IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(msg.sender, address(this), _amountDeposited); bytes32 _channelBytesID = BaseHelper.addressToBytes32(msg.sender); - _createSettings(_channelBytesID, _notifOptions, _notifSettings, _notifDescription); + _createSettings(_channelBytesID, _notifOptions, _amountDeposited, _notifSettings, _notifDescription); } function _createSettings( bytes32 _channel, uint256 _notifOptions, - string calldata _notifSettings, - string calldata _notifDescription + uint256 _amountDeposited, + string memory _notifSettings, + string memory _notifDescription ) private { + PROTOCOL_POOL_FEES = PROTOCOL_POOL_FEES + _amountDeposited; string memory notifSetting = string(abi.encodePacked(Strings.toString(_notifOptions), "+", _notifSettings)); emit ChannelNotifcationSettingsAdded(_channel, _notifOptions, notifSetting, _notifDescription); @@ -297,19 +295,27 @@ contract PushCoreV3 is // Check channel's current state bytes32 _channelBytesID = BaseHelper.addressToBytes32(msg.sender); + if(channelInfo[_channelBytesID].channelState == 2) { + IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(msg.sender, address(this), _amount); + _reactivateChannel( _channelBytesID, _amount); + }else { + _deactivateChannel( _channelBytesID, msg.sender); + } + } + + function _deactivateChannel(bytes32 _channelBytesID, address recipient) internal { + CoreTypes.Channel storage channelData = channelInfo[_channelBytesID]; uint8 channelCurrentState = channelData.channelState; // Prevent INACTIVE or BLOCKED Channels - if (channelCurrentState != 1 && channelCurrentState != 2) { + if (channelCurrentState != 1) { revert Errors.Core_InvalidChannel(); } uint256 minPoolContribution = MIN_POOL_CONTRIBUTION; // If Active State , Enter the Time-Bound Deletion/Deactivate Channel Phase - if (channelCurrentState == 1) { uint256 totalRefundableAmount; - bool isTimeBound = channelData.channelType == CoreTypes.ChannelType.TimeBound; - if (!isTimeBound) { + if (!(channelData.channelType == CoreTypes.ChannelType.TimeBound)) { // DEACTIVATION PHASE totalRefundableAmount = channelData.poolContribution - minPoolContribution; @@ -317,7 +323,6 @@ contract PushCoreV3 is channelData.channelState = 2; channelData.channelWeight = _newChannelWeight; channelData.poolContribution = minPoolContribution; - emit ChannelStateUpdate(_channelBytesID, totalRefundableAmount, 0); } else { // TIME-BOUND CHANNEL DELETION PHASE if (channelData.expiryTime >= block.timestamp) { @@ -326,17 +331,17 @@ contract PushCoreV3 is totalRefundableAmount = channelData.poolContribution; channelsCount = channelsCount - 1; delete channelInfo[_channelBytesID]; - emit ChannelStateUpdate(_channelBytesID, totalRefundableAmount, 0); } + emit ChannelStateUpdate(_channelBytesID, totalRefundableAmount, 0); CHANNEL_POOL_FUNDS = CHANNEL_POOL_FUNDS - totalRefundableAmount; - IERC20(PUSH_TOKEN_ADDRESS).safeTransfer(msg.sender, totalRefundableAmount); - } // RE-ACTIVATION PHASE - else { + IERC20(PUSH_TOKEN_ADDRESS).safeTransfer(recipient, totalRefundableAmount); + } + + function _reactivateChannel(bytes32 _channelBytesID, uint256 _amount) internal { if (_amount < ADD_CHANNEL_MIN_FEES) { revert Errors.InvalidArg_LessThanExpected(ADD_CHANNEL_MIN_FEES, _amount); } - - IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(msg.sender, address(this), _amount); + CoreTypes.Channel storage channelData = channelInfo[_channelBytesID]; uint256 poolFeeAmount = FEE_AMOUNT; uint256 poolFundAmount = _amount - poolFeeAmount; //store funds in pool_funds & pool_fees @@ -344,24 +349,22 @@ contract PushCoreV3 is PROTOCOL_POOL_FEES = PROTOCOL_POOL_FEES + poolFeeAmount; uint256 _newPoolContribution = channelData.poolContribution + poolFundAmount; - uint256 _newChannelWeight = (_newPoolContribution * ADJUST_FOR_FLOAT) / minPoolContribution; + uint256 _newChannelWeight = (_newPoolContribution * ADJUST_FOR_FLOAT) / MIN_POOL_CONTRIBUTION; channelData.channelState = 1; channelData.poolContribution = _newPoolContribution; channelData.channelWeight = _newChannelWeight; emit ChannelStateUpdate(_channelBytesID, 0, _amount); - } } /// @inheritdoc IPushCoreV3 - function blockChannel(address _channelAddress) external whenNotPaused { + function blockChannel(bytes32 _channelAddress) external whenNotPaused { onlyGovernance(); - bytes32 _channelBytesID = BaseHelper.addressToBytes32(_channelAddress); - if (((channelInfo[_channelBytesID].channelState == 3) || (channelInfo[_channelBytesID].channelState == 0))) { + if (((channelInfo[_channelAddress].channelState == 3) || (channelInfo[_channelAddress].channelState == 0))) { revert Errors.Core_InvalidChannel(); } uint256 minPoolContribution = MIN_POOL_CONTRIBUTION; - CoreTypes.Channel storage channelData = channelInfo[_channelBytesID]; + CoreTypes.Channel storage channelData = channelInfo[_channelAddress]; // add channel's currentPoolContribution to PoolFees - (no refunds if Channel is blocked) // Decrease CHANNEL_POOL_FUNDS by currentPoolContribution uint256 currentPoolContribution = channelData.poolContribution - minPoolContribution; @@ -376,7 +379,7 @@ contract PushCoreV3 is channelData.channelUpdateBlock = block.number; channelData.poolContribution = minPoolContribution; - emit ChannelBlocked(_channelBytesID); + emit ChannelBlocked(_channelAddress); } /* ************** @@ -384,14 +387,13 @@ contract PushCoreV3 is *************** */ /// @inheritdoc IPushCoreV3 - function getChannelVerfication(address _channel) public view returns (uint8 verificationStatus) { - bytes32 _channelBytesID = BaseHelper.addressToBytes32(_channel); + function getChannelVerfication(bytes32 _channel) public view returns (uint8 verificationStatus) { - address verifiedBy = channelInfo[_channelBytesID].verifiedBy; + address verifiedBy = channelInfo[_channel].verifiedBy; bool logicComplete = false; // Check if it's primary verification - if (verifiedBy == pushChannelAdmin || _channel == pushChannelAdmin) { + if (verifiedBy == pushChannelAdmin || _channel == BaseHelper.addressToBytes32(pushChannelAdmin)) { // primary verification, mark and exit verificationStatus = 1; } else { @@ -415,7 +417,7 @@ contract PushCoreV3 is function batchVerification( uint256 _startIndex, uint256 _endIndex, - address[] calldata _channelList + bytes32[] calldata _channelList ) external returns (bool) @@ -432,10 +434,10 @@ contract PushCoreV3 is } /// @inheritdoc IPushCoreV3 - function verifyChannel(address _channel) public { + function verifyChannel(bytes32 _channel) public { onlyActivatedChannels(_channel); // Check if caller is verified first - uint8 callerVerified = getChannelVerfication(msg.sender); + uint8 callerVerified = getChannelVerfication(BaseHelper.addressToBytes32(msg.sender)); if (callerVerified == 0) { revert Errors.UnauthorizedCaller(msg.sender); } @@ -447,25 +449,23 @@ contract PushCoreV3 is } // Verify channel - bytes32 _channelBytesID = BaseHelper.addressToBytes32(_channel); - channelInfo[_channelBytesID].verifiedBy = msg.sender; + channelInfo[_channel].verifiedBy = msg.sender; // Emit event - emit ChannelVerified(_channelBytesID, msg.sender); + emit ChannelVerified(_channel, BaseHelper.addressToBytes32(msg.sender)); } /// @inheritdoc IPushCoreV3 - function unverifyChannel(address _channel) public { - bytes32 _channelBytesID = BaseHelper.addressToBytes32(_channel); - if (!(channelInfo[_channelBytesID].verifiedBy == msg.sender || msg.sender == pushChannelAdmin)) { + function unverifyChannel(bytes32 _channel) public { + if (!(channelInfo[_channel].verifiedBy == msg.sender || msg.sender == pushChannelAdmin)) { revert Errors.CallerNotAdmin(); } // Unverify channel - channelInfo[_channelBytesID].verifiedBy = address(0x0); + channelInfo[_channel].verifiedBy = address(0x0); // Emit Event - emit ChannelVerificationRevoked(_channelBytesID, msg.sender); + emit ChannelVerificationRevoked(_channel, BaseHelper.addressToBytes32(msg.sender)); } /** @@ -767,6 +767,7 @@ contract PushCoreV3 is if (amount < FEE_AMOUNT) { revert Errors.InvalidArg_LessThanExpected(FEE_AMOUNT, amount); } + if (requestReceiver == address(0)) { revert Errors.InvalidArgument_WrongAddress(requestReceiver); } @@ -775,7 +776,7 @@ contract PushCoreV3 is IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(msg.sender, address(this), amount); // Process the incentivized chat request - _handleIncentivizedChat(msg.sender, requestReceiver, amount); + _handleIncentivizedChat(BaseHelper.addressToBytes32(msg.sender), requestReceiver, amount); } /** @@ -786,7 +787,7 @@ contract PushCoreV3 is * @param requestReceiver The address of the receiver who is the target of the chat request. * @param amount The total amount sent by the sender for the incentivized chat. */ - function _handleIncentivizedChat(address requestSender, address requestReceiver, uint256 amount) private { + function _handleIncentivizedChat(bytes32 requestSender, address requestReceiver, uint256 amount) private { uint256 poolFeeAmount = FEE_AMOUNT; uint256 requestReceiverAmount = amount - poolFeeAmount; @@ -794,7 +795,7 @@ contract PushCoreV3 is PROTOCOL_POOL_FEES = PROTOCOL_POOL_FEES + poolFeeAmount; emit IncentivizedChatReqReceived( - requestSender, requestReceiver, requestReceiverAmount, poolFeeAmount, block.timestamp + requestSender, BaseHelper.addressToBytes32(requestReceiver), requestReceiverAmount, poolFeeAmount, block.timestamp ); } @@ -807,7 +808,7 @@ contract PushCoreV3 is celebUserFunds[msg.sender] -= _amount; IERC20(PUSH_TOKEN_ADDRESS).safeTransfer(msg.sender, _amount); - emit ChatIncentiveClaimed(msg.sender, _amount); + emit ChatIncentiveClaimed(BaseHelper.addressToBytes32(msg.sender), _amount); } /* ***************************** @@ -862,26 +863,41 @@ contract PushCoreV3 is CrossChainRequestTypes.CrossChainFunction functionType, bytes memory structPayload, uint256 amount, - address sender - ) = abi.decode(payload, (CrossChainRequestTypes.CrossChainFunction, bytes, uint256, address)); + bytes32 sender + ) = abi.decode(payload, (CrossChainRequestTypes.CrossChainFunction, bytes, uint256, bytes32)); if (functionType == CrossChainRequestTypes.CrossChainFunction.AddChannel) { // Specific Request: Add Channel (CoreTypes.ChannelType channelType, bytes memory channelIdentity, uint256 channelExpiry) = abi.decode(structPayload, (CoreTypes.ChannelType, bytes, uint256)); - bytes32 _channelBytesID = BaseHelper.addressToBytes32(sender); - emit ChannelCreated(_channelBytesID, channelType, channelIdentity); - _createChannel(_channelBytesID, channelType, amount, channelExpiry); + emit ChannelCreated(sender, channelType, channelIdentity); + _createChannel(sender, channelType, amount, channelExpiry); } else if (functionType == CrossChainRequestTypes.CrossChainFunction.IncentivizedChat) { // Specific Request: Incentivized Chat - (address amountRecipient) = abi.decode(structPayload, (address)); - _handleIncentivizedChat(sender, amountRecipient, amount); + (bytes32 amountRecipient) = abi.decode(structPayload, (bytes32)); + _handleIncentivizedChat( + sender, BaseHelper.bytes32ToAddress(amountRecipient), amount + ); + } else if (functionType == CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings) { + (uint256 _notifOptions, string memory _notifSettings, string memory _notifDescription) = + abi.decode(structPayload, (uint256, string, string)); + _createSettings(sender, _notifOptions, amount, _notifSettings, _notifDescription); + } else if (functionType == CrossChainRequestTypes.CrossChainFunction.UpdateChannelMeta) { + (bytes memory _newIdentity) = abi.decode(structPayload, (bytes)); + _updateChannelMeta(sender, _newIdentity, amount); + } else if (functionType == CrossChainRequestTypes.CrossChainFunction.DeactivateChannel) { + // Specific Request: Deactivating or Deleting Channel + (address recipient) = abi.decode(structPayload, (address)); + _deactivateChannel(sender, recipient); + } else if (functionType == CrossChainRequestTypes.CrossChainFunction.ReactivateChannel) { + // Specific Request: Deactivating or Deleting Channel + _reactivateChannel(sender, amount); } else if (functionType == CrossChainRequestTypes.CrossChainFunction.ArbitraryRequest) { // Arbitrary Request - (uint8 feeId, GenericTypes.Percentage memory feePercentage, address amountRecipient) = - abi.decode(structPayload, (uint8, GenericTypes.Percentage, address)); + (uint8 feeId, GenericTypes.Percentage memory feePercentage, bytes32 amountRecipient) = + abi.decode(structPayload, (uint8, GenericTypes.Percentage, bytes32)); - _handleArbitraryRequest(sender, feeId, feePercentage, amountRecipient, amount); + _handleArbitraryRequest(sender, feeId, feePercentage, BaseHelper.bytes32ToAddress(amountRecipient), amount); } else if (functionType == CrossChainRequestTypes.CrossChainFunction.AdminRequest_AddPoolFee) { // Admin Request PROTOCOL_POOL_FEES += amount; @@ -908,7 +924,7 @@ contract PushCoreV3 is IERC20(PUSH_TOKEN_ADDRESS).safeTransferFrom(msg.sender, address(this), amount); // Call the private function to process the arbitrary request - _handleArbitraryRequest(msg.sender, feeId, feePercentage, amountRecipient, amount); + _handleArbitraryRequest(BaseHelper.addressToBytes32(msg.sender), feeId, feePercentage, amountRecipient, amount); } /** @@ -921,7 +937,7 @@ contract PushCoreV3 is * @param amount The total amount sent by the sender for the arbitrary request. */ function _handleArbitraryRequest( - address sender, + bytes32 sender, uint8 feeId, GenericTypes.Percentage memory feePercentage, address amountRecipient, @@ -937,7 +953,7 @@ contract PushCoreV3 is arbitraryReqFees[amountRecipient] += amount - feeAmount; // Emit an event for the arbitrary request - emit ArbitraryRequest(sender, amountRecipient, amount, feePercentage, feeId); + emit ArbitraryRequest(sender, BaseHelper.addressToBytes32(amountRecipient), amount, feePercentage, feeId); } /** @@ -959,7 +975,7 @@ contract PushCoreV3 is arbitraryReqFees[msg.sender] = userFeesBalance - _amount; IERC20(PUSH_TOKEN_ADDRESS).safeTransfer(msg.sender, _amount); - emit ArbitraryRequestFeesClaimed(msg.sender, _amount); + emit ArbitraryRequestFeesClaimed(BaseHelper.addressToBytes32(msg.sender), _amount); } function migrateAddressToBytes32(address[] calldata _channels) external whenPaused { diff --git a/contracts/interfaces/IPushCoreV3.sol b/contracts/interfaces/IPushCoreV3.sol index cceb78d8..d275458f 100644 --- a/contracts/interfaces/IPushCoreV3.sol +++ b/contracts/interfaces/IPushCoreV3.sol @@ -12,9 +12,9 @@ interface IPushCoreV3 { /// @notice emits whenever a channel updates its metadata event UpdateChannel(bytes32 indexed channel, bytes identity, uint256 indexed amountDeposited); /// @notice emits whenever a channel is verified either by admin or any otherchannel with primary verification - event ChannelVerified(bytes32 indexed channel, address indexed verifier); + event ChannelVerified(bytes32 indexed channel, bytes32 indexed verifier); /// @notice emits whenever the verification is revoked for a channel - event ChannelVerificationRevoked(bytes32 indexed channel, address indexed revoker); + event ChannelVerificationRevoked(bytes32 indexed channel, bytes32 indexed revoker); /// @notice emits whenever any channel is blocked by admin event ChannelBlocked(bytes32 indexed channel); /// @notice emits whenever a new channel is created - ToDo: Remove this event @@ -26,7 +26,7 @@ interface IPushCoreV3 { bytes32 _channel, uint256 totalNotifOptions, string _notifSettings, string _notifDescription ); /// @notice emits whenever a subgraph is added(handled by backend) - event AddSubGraph(address indexed channel, bytes _subGraphData); + event AddSubGraph(bytes32 indexed channel, bytes _subGraphData); /// @notice emits whenever any time bound channel is deleted permanently // event TimeBoundChannelDestroyed(address indexed channel, uint256 indexed amountRefunded); /// @notice emits whenever a user stakes in the staking program @@ -37,27 +37,27 @@ interface IPushCoreV3 { event RewardsHarvested(address indexed user, uint256 indexed rewardAmount, uint256 fromEpoch, uint256 tillEpoch); /// @notice emits whenever any user receives an incentivized chat request from another user event IncentivizedChatReqReceived( - address requestSender, - address requestReceiver, + bytes32 requestSender, + bytes32 requestReceiver, uint256 amountForReqReceiver, uint256 feePoolAmount, uint256 timestamp ); /// @notice emits whenever a user claims the remianing funds that they got from incentivized chat - event ChatIncentiveClaimed(address indexed user, uint256 indexed amountClaimed); + event ChatIncentiveClaimed(bytes32 indexed user, uint256 indexed amountClaimed); /// @notice emits when the state of a channel is updated from Active State to either Deactivated, Reactivated, /// Blocked or Deleted event ChannelStateUpdate(bytes32 indexed channel, uint256 amountRefunded, uint256 amountDeposited); /// @notice emits when arbitray cross chain request is received event ArbitraryRequest( - address indexed sender, - address indexed receiver, + bytes32 indexed sender, + bytes32 indexed receiver, uint256 amountDeposited, GenericTypes.Percentage feePercent, uint256 indexed feeId ); /// @notice emits whenever a user claims the funds that they got from arbirary request fees - event ArbitraryRequestFeesClaimed(address indexed user, uint256 indexed amountClaimed); + event ArbitraryRequestFeesClaimed(bytes32 indexed user, uint256 indexed amountClaimed); /* ***************************** @@ -67,12 +67,12 @@ interface IPushCoreV3 { /** * @notice Function is designed to tell if a channel is verified or not * @dev Get if channel is verified or not - * @param _channel Address of the channel to be Verified + * @param _channel Address of the channel to be Verified, in bytes32 format * @return verificationStatus Returns 0 for not verified, 1 for primary verification, 2 for secondary * verification * */ - function getChannelVerfication(address _channel) external view returns (uint8 verificationStatus); + function getChannelVerfication(bytes32 _channel) external view returns (uint8 verificationStatus); /* ***************************** @@ -99,12 +99,11 @@ interface IPushCoreV3 { * Records the Block Number of the Block at which the Channel is being updated * Emits an event with the new identity for the respective Channel Address * - * @param _channel address of the Channel * @param _newIdentity bytes Value for the New Identity of the Channel * @param _amount amount of PUSH Token required for updating channel details. * */ - function updateChannelMeta(address _channel, bytes calldata _newIdentity, uint256 _amount) external; + function updateChannelMeta(bytes calldata _newIdentity, uint256 _amount) external; /** * @notice An external function that allows users to Create their Own Channels by depositing a valid amount of PUSH @@ -212,27 +211,27 @@ interface IPushCoreV3 { * - Since there is no refund, the channel's poolContribution is added to PROTOCOL_POOL_FEES and Removed * from CHANNEL_POOL_FUNDS * - Emit 'ChannelBlocked' Event - * @param _channelAddress Address of the Channel to be blocked + * @param _channelAddress Address of the Channel to be blocked, in bytes32 format * */ - function blockChannel(address _channelAddress) external; + function blockChannel(bytes32 _channelAddress) external; /** * @notice Function is designed to verify a channel * @dev Channel will be verified by primary or secondary verification, will fail or upgrade if already * verified - * @param _channel Address of the channel to be Verified + * @param _channel Address of the channel to be Verified, in bytes32 format * */ - function verifyChannel(address _channel) external; + function verifyChannel(bytes32 _channel) external; /** * @notice Function is designed to unverify a channel * @dev Channel who verified this channel or Push Channel Admin can only revoke - * @param _channel Address of the channel to be unverified + * @param _channel Address of the channel to be unverified, in bytes32 format * */ - function unverifyChannel(address _channel) external; + function unverifyChannel(bytes32 _channel) external; /** * @notice Designed to handle the incoming Incentivized Chat Request Data and PUSH tokens. diff --git a/contracts/libraries/BaseHelper.sol b/contracts/libraries/BaseHelper.sol index 0c31f51c..2ae4c27f 100644 --- a/contracts/libraries/BaseHelper.sol +++ b/contracts/libraries/BaseHelper.sol @@ -32,6 +32,20 @@ library BaseHelper { return bytes32(uint256(uint160(_addr))); } + /** + * @notice This function converts a bytes32 value to an address + * @dev This function performs type casting to convert a bytes32 to an address. + * It first converts the bytes32 to a uint256, then to a uint160, and finally to an address. + * This conversion involves truncation from left side. + * For example, given a bytes32 value of 0x111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFFCCCC: + * - Using address(uint160(uint256(b))) results in an address of 0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc + * @param _bytes The bytes32 value to be converted to an address + * @return address The address representation of the bytes32 value + */ + function bytes32ToAddress(bytes32 _bytes) internal pure returns (address) { + return address(uint160(uint256(_bytes))); + } + /** * @notice This function calculates the percentage of a given amount using a Percentage struct. * @dev This function performs a simple percentage calculation. diff --git a/contracts/libraries/DataTypes.sol b/contracts/libraries/DataTypes.sol index c09c50e5..c0fa7f03 100644 --- a/contracts/libraries/DataTypes.sol +++ b/contracts/libraries/DataTypes.sol @@ -86,12 +86,6 @@ library CommTypes { ///@notice Maps ID to the Channel mapping(uint256 => address) mapAddressSubscribed; } - - struct ChatDetails { - address requestSender; - uint256 timestamp; - uint256 amountDeposited; - } } library StakingTypes { @@ -114,9 +108,13 @@ library CrossChainRequestTypes { // Payload enum CrossChainFunction { AddChannel, + CreateChannelSettings, + ReactivateChannel, IncentivizedChat, ArbitraryRequest, - AdminRequest_AddPoolFee + AdminRequest_AddPoolFee, + DeactivateChannel, + UpdateChannelMeta } } diff --git a/test/BaseTest.t.sol b/test/BaseTest.t.sol index fdd0f492..20031f08 100644 --- a/test/BaseTest.t.sol +++ b/test/BaseTest.t.sol @@ -216,4 +216,8 @@ abstract contract BaseTest is Test, Constants, Events { function createChannelCreatorsID(address _actor) internal pure returns (bytes32 _channelCreatorBytes32) { _channelCreatorBytes32 = BaseHelper.addressToBytes32(_actor); } + + function toWormholeFormat(address addr) internal pure returns (bytes32) { + return bytes32(uint256(uint160(addr))); + } } diff --git a/test/CCR/ArbitraryRequest/ArbitraryRequest.t.sol b/test/CCR/ArbitraryRequest/ArbitraryRequest.t.sol index 6be20c09..8a1fb630 100644 --- a/test/CCR/ArbitraryRequest/ArbitraryRequest.t.sol +++ b/test/CCR/ArbitraryRequest/ArbitraryRequest.t.sol @@ -20,11 +20,14 @@ contract ArbitraryRequesttsol is BaseCCRTest { (_payload, requestPayload) = getSpecificPayload( CrossChainRequestTypes.CrossChainFunction.ArbitraryRequest, - actor.charlie_channel_owner, + BaseHelper.addressToBytes32(actor.charlie_channel_owner), amount, 1, percentage, - actor.bob_channel_owner + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) ); } @@ -141,7 +144,7 @@ contract ArbitraryRequesttsol is BaseCCRTest { changePrank(DestChain.WORMHOLE_RELAYER_DEST); vm.expectEmit(true, true, false, true); - emit ArbitraryRequest(actor.bob_channel_owner, actor.charlie_channel_owner, amount, percentage, 1); + emit ArbitraryRequest(BaseHelper.addressToBytes32(actor.bob_channel_owner), BaseHelper.addressToBytes32(actor.charlie_channel_owner), amount, percentage, 1); coreProxy.receiveWormholeMessages( requestPayload, additionalVaas, sourceAddress, SourceChain.SourceChainId, deliveryHash @@ -164,6 +167,8 @@ contract ArbitraryRequesttsol is BaseCCRTest { (bytes memory transceiverMessage, bytes32 hash) = getRequestPayload(_amount, recipient, recipientChain, sourceNttManager); + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); + changePrank(DestChain.WORMHOLE_RELAYER_DEST); DestChain.wormholeTransceiverChain2.receiveWormholeMessages( transceiverMessage, // Verified @@ -173,7 +178,7 @@ contract ArbitraryRequesttsol is BaseCCRTest { hash // Hash of the VAA being used ); - assertEq(pushToken.balanceOf(address(coreProxy)), amount); + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); } function test_when_UserTries_ClaimingArbitraryTokens() external { diff --git a/test/CCR/CCRutils/CCRConfig.sol b/test/CCR/CCRutils/CCRConfig.sol index eaa93c65..b40dfb53 100644 --- a/test/CCR/CCRutils/CCRConfig.sol +++ b/test/CCR/CCRutils/CCRConfig.sol @@ -24,6 +24,7 @@ contract CCRConfig { address NTT_MANAGER; address WORMHOLE_RELAYER_DEST; address PUSH_NTT_DEST; + address DestPushHolder; uint16 DestChainId; string rpc; } @@ -41,60 +42,16 @@ contract CCRConfig { "https://sepolia-rollup.arbitrum.io/rpc" ); - // SourceConfig ArbSepolia = SourceConfig( - // IWormhole(0x6b9C8671cdDC8dEab9c719bB87cBd3e782bA6a35), - // IWormholeTransceiver(0xEFBeAAF530653576acf8a78a19fB7b28b085AF9F), - // 0xFAB6A0Cb264D34B939A7eDcF83f5e8D447C21812, - // 0xEFBeAAF530653576acf8a78a19fB7b28b085AF9F, - // 0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470, - // 0xa58F4F5FB4977151E99291FCa5b92d95021be0f4, - // 0x778D3206374f8AC265728E18E3fE2Ae6b93E4ce4, - // 10_003, - // "https://sepolia-rollup.arbitrum.io/rpc" - // ); - DestConfig EthSepolia = DestConfig( IWormhole(0x4a8bc80Ed5a4067f1CCf107057b8270E0cC11A78), IWormholeTransceiver(0x9D85E6467d5069A7144E4f251E540bf9fA7ea5C6), 0xCFA54a96fE19d9EB9395642225C62d0abe6Cd835, 0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470, 0xe1327FE9b457Ad1b4601FdD2afcAdAef198d6BA6, + 0x778D3206374f8AC265728E18E3fE2Ae6b93E4ce4, 10_002, "https://eth-sepolia.public.blastapi.io" ); - // DestConfig BaseSepolia = DestConfig( - // IWormhole(0x4a8bc80Ed5a4067f1CCf107057b8270E0cC11A78), - // IWormholeTransceiver(0xE175E3aBa428d028D2CEdE8e1cB338D1f1D50d13), - // 0x63Dd783A353ad0f8a654ba7a21D7Fd8637E278a1, - // 0x93BAD53DDfB6132b0aC8E37f6029163E63372cEE, - // 0x527F3692F5C53CfA83F7689885995606F93b6164, - // 10004, - // "https://sepolia.base.org" - // ); - - /// NEWEST DEPLOYED CONTRACT /// - - // SourceConfig ArbSepolia = SourceConfig( - // IWormhole(0x6b9C8671cdDC8dEab9c719bB87cBd3e782bA6a35), - // IWormholeTransceiver(0x4F532db1ce4f33170b21F6a97A8973e9499BbD75), - // 0x5e1989B8681C91A90F33A82b22cf51210a7C31C0, - // 0x4F532db1ce4f33170b21F6a97A8973e9499BbD75, - // 0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470, - // 0x70c3C79d33A9b08F1bc1e7DB113D1588Dad7d8Bc, - // 0x778D3206374f8AC265728E18E3fE2Ae6b93E4ce4, - // 10_003, - // "https://sepolia-rollup.arbitrum.io/rpc" - // ); - - // DestConfig EthSepolia = DestConfig( - // IWormhole(0x4a8bc80Ed5a4067f1CCf107057b8270E0cC11A78), - // IWormholeTransceiver(0x3cc5553e0ABfF03743c9c2cc785D184e72D45852), - // 0x76c636cb502Aa7eed6784Fde38b955bC15CC6bc1, - // 0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470, - // 0xe1327FE9b457Ad1b4601FdD2afcAdAef198d6BA6, - // 10_002, - // "https://eth-sepolia.public.blastapi.io" - // ); // chain agnostic constants // ToDo: to be changed diff --git a/test/CCR/CCRutils/Helper.sol b/test/CCR/CCRutils/Helper.sol index 914386cc..1817beb2 100644 --- a/test/CCR/CCRutils/Helper.sol +++ b/test/CCR/CCRutils/Helper.sol @@ -16,6 +16,7 @@ import { EPNS } from "contracts/token/EPNS.sol"; contract Helper is BasePushCommTest, CCRConfig { // Set Source and dest chains + bytes _newTestChannelIdentity = bytes("test-updated-channel-hello-world"); SourceConfig SourceChain = ArbSepolia; DestConfig DestChain = EthSepolia; @@ -36,12 +37,21 @@ contract Helper is BasePushCommTest, CCRConfig { vm.createSelectFork(url); } - function getPushTokenOnfork(address _addr, uint256 _amount) public { - changePrank(SourceChain.PushHolder); - pushNttToken.transfer(_addr, _amount); + function getPushTokenOnfork(address _addr, uint256 _amount, address _token) public { + if(_token == SourceChain.PUSH_NTT_SOURCE){ - changePrank(_addr); - pushNttToken.approve(address(commProxy), type(uint256).max); + changePrank(SourceChain.PushHolder); + pushNttToken.transfer(_addr, _amount); + + changePrank(_addr); + pushNttToken.approve(address(commProxy), type(uint256).max); + } else if(_token == DestChain.PUSH_NTT_DEST){ + changePrank(DestChain.DestPushHolder); + pushToken.transfer(_addr, _amount); + + changePrank(_addr); + pushToken.approve(address(coreProxy), type(uint256).max); + } } function setUpSourceChain() internal { @@ -49,8 +59,8 @@ contract Helper is BasePushCommTest, CCRConfig { BasePushCommTest.setUp(); pushNttToken = Push(SourceChain.PUSH_NTT_SOURCE); - getPushTokenOnfork(actor.bob_channel_owner, 1000e18); - getPushTokenOnfork(actor.charlie_channel_owner, 1000e18); + getPushTokenOnfork(actor.bob_channel_owner, 1000e18, address(pushNttToken)); + getPushTokenOnfork(actor.charlie_channel_owner, 1000e18,address(pushNttToken)); changePrank(actor.admin); commProxy.setBridgeConfig( @@ -66,14 +76,17 @@ contract Helper is BasePushCommTest, CCRConfig { switchChains(DestChain.rpc); BasePushCommTest.setUp(); pushToken = EPNS(DestChain.PUSH_NTT_DEST); + changePrank(actor.admin); coreProxy.setWormholeRelayer(DestChain.WORMHOLE_RELAYER_DEST); coreProxy.setEpnsTokenAddress(address(pushToken)); coreProxy.setRegisteredSender(SourceChain.SourceChainId, toWormholeFormat(address(commProxy))); - } - function toWormholeFormat(address addr) internal pure returns (bytes32) { - return bytes32(uint256(uint160(addr))); + getPushTokenOnfork(actor.bob_channel_owner, 1000e18, address(pushToken)); + getPushTokenOnfork(actor.charlie_channel_owner, 1000e18,address(pushToken)); + changePrank(actor.bob_channel_owner); + coreProxy.createChannelWithPUSH(CoreTypes.ChannelType.InterestBearingOpen, _testChannelIdentity, 50e18, 0); + changePrank(actor.admin); } function getPoolFundsAndFees(uint256 _amountDeposited) @@ -90,29 +103,42 @@ contract Helper is BasePushCommTest, CCRConfig { function getSpecificPayload( CrossChainRequestTypes.CrossChainFunction typeOfReq, - address amountRecipient, + bytes32 amountRecipient, uint256 amount, uint8 _feeId, GenericTypes.Percentage memory _percentage, - address sender + uint256 _notifOptions, + string memory _notifSettings, + string memory _notifDescription, + bytes32 sender ) internal - pure + view returns (bytes memory payload, bytes memory reqPayload) { if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.AddChannel) { payload = abi.encode(CoreTypes.ChannelType.InterestBearingMutual, _testChannelUpdatedIdentity, 0); - reqPayload = abi.encode(typeOfReq, payload, amount, sender); } else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.IncentivizedChat) { payload = abi.encode(amountRecipient); + + } else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings) { + payload = abi.encode(_notifOptions, _notifSettings, _notifDescription); - reqPayload = abi.encode(typeOfReq, payload, amount, sender); - } else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.ArbitraryRequest) { + }else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.ArbitraryRequest) { payload = abi.encode(_feeId, _percentage, amountRecipient); - reqPayload = abi.encode(typeOfReq, payload, amount, sender); + }else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.DeactivateChannel) { + payload = abi.encode(amountRecipient); + } + else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.ReactivateChannel) { + payload = new bytes(0); + + }else if (typeOfReq == CrossChainRequestTypes.CrossChainFunction.UpdateChannelMeta) { + + payload = abi.encode(_newTestChannelIdentity); } + reqPayload = abi.encode(typeOfReq, payload, amount, sender); } function receiveWormholeMessage(bytes memory _requestPayload) internal { diff --git a/test/CCR/SpecificRequest/CreateChannelCCR/CreateChannelCCR.t.sol b/test/CCR/SpecificRequest/CreateChannelCCR/CreateChannelCCR.t.sol index 75c8f622..13582640 100644 --- a/test/CCR/SpecificRequest/CreateChannelCCR/CreateChannelCCR.t.sol +++ b/test/CCR/SpecificRequest/CreateChannelCCR/CreateChannelCCR.t.sol @@ -5,6 +5,7 @@ import { BaseCCRTest } from "../../BaseCCR.t.sol"; import { CoreTypes, CrossChainRequestTypes } from "contracts/libraries/DataTypes.sol"; import { Errors } from "contracts/libraries/Errors.sol"; import { console } from "forge-std/console.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; import { IRateLimiter } from "contracts/interfaces/wormhole/IRateLimiter.sol"; contract CreateChannelCCR is BaseCCRTest { @@ -15,11 +16,14 @@ contract CreateChannelCCR is BaseCCRTest { sourceAddress = toWormholeFormat(address(commProxy)); (_payload, requestPayload) = getSpecificPayload( CrossChainRequestTypes.CrossChainFunction.AddChannel, - address(0), + BaseHelper.addressToBytes32(address(0)), amount, 0, percentage, - actor.charlie_channel_owner + 0, + "", + "", + BaseHelper.addressToBytes32(actor.charlie_channel_owner) ); } @@ -165,12 +169,12 @@ contract CreateChannelCCR is BaseCCRTest { (address sourceNttManager, bytes32 recipient, uint256 _amount, uint16 recipientChain) = getMessagefromLog(vm.getRecordedLogs()); - console.log(pushToken.balanceOf(address(coreProxy))); - bytes[] memory a; (bytes memory transceiverMessage, bytes32 hash) = getRequestPayload(_amount, recipient, recipientChain, sourceNttManager); + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); + changePrank(DestChain.WORMHOLE_RELAYER_DEST); DestChain.wormholeTransceiverChain2.receiveWormholeMessages( transceiverMessage, // Verified @@ -180,6 +184,6 @@ contract CreateChannelCCR is BaseCCRTest { hash // Hash of the VAA being used ); - assertEq(pushToken.balanceOf(address(coreProxy)), amount); + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); } } diff --git a/test/CCR/SpecificRequest/CreateChannelSettingsCCR/CreateChannelSettingsCCR.t.sol b/test/CCR/SpecificRequest/CreateChannelSettingsCCR/CreateChannelSettingsCCR.t.sol new file mode 100644 index 00000000..2379841a --- /dev/null +++ b/test/CCR/SpecificRequest/CreateChannelSettingsCCR/CreateChannelSettingsCCR.t.sol @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import { BaseCCRTest } from "../../BaseCCR.t.sol"; +import "forge-std/console.sol"; +import {CrossChainRequestTypes } from "contracts/libraries/DataTypes.sol"; +import { Errors } from "contracts/libraries/Errors.sol"; +import { console } from "forge-std/console.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; +import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; + +contract CreateChannelSettingsCCR is BaseCCRTest { + uint256 amount = ADD_CHANNEL_MIN_FEES; + uint256 notifOptions = 2; + string notifSettings = "1-0+2-50-20-100"; + string notifDescription = "description"; + + function setUp() public override { + BaseCCRTest.setUp(); + sourceAddress = toWormholeFormat(address(commProxy)); + (_payload, requestPayload) = getSpecificPayload( + CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings, + BaseHelper.addressToBytes32(address(0)), + amount, + 0, + percentage, + notifOptions, + notifSettings, + notifDescription, + BaseHelper.addressToBytes32(actor.charlie_channel_owner) + ); + } + + modifier whenCreateChannelSettingsIsCalled() { + _; + } + + function test_WhenContractIsPaused() external whenCreateChannelSettingsIsCalled { + // it should Revert + + changePrank(actor.admin); + commProxy.pauseContract(); + vm.expectRevert("Pausable: paused"); + changePrank(actor.charlie_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings, _payload, amount, GasLimit + ); + } + + function test_RevertWhen_AmountIsLessThanMinimumFees() external whenCreateChannelSettingsIsCalled { + // it should revert + amount = 49e18; + vm.expectRevert( + abi.encodeWithSelector(Errors.InvalidArg_LessThanExpected.selector, ADD_CHANNEL_MIN_FEES, amount) + ); + changePrank(actor.charlie_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings, _payload, amount, GasLimit + ); + } + + function test_RevertWhen_EtherPassedIsLess() external whenCreateChannelSettingsIsCalled { + // it should revert + vm.expectRevert(abi.encodeWithSelector(Errors.InsufficientFunds.selector)); + changePrank(actor.charlie_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings, _payload, amount, GasLimit + ); + } + + function test_WhenAllChecksPasses() public whenCreateChannelSettingsIsCalled { + // it should successfully create the CCR + + vm.expectEmit(true, false, false, false); + emit LogMessagePublished(SourceChain.WORMHOLE_RELAYER_SOURCE, 2105, 0, requestPayload, 15); + changePrank(actor.charlie_channel_owner); + commProxy.createCrossChainRequest{ value: 1e18 }( + CrossChainRequestTypes.CrossChainFunction.CreateChannelSettings, _payload, amount, GasLimit + ); + } + + modifier whenReceiveFunctionIsCalledInCore() { + test_WhenAllChecksPasses(); + + setUpDestChain(); + _; + } + + function test_WhenSenderIsNotRegistered() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + //set sender to zero address + coreProxy.setRegisteredSender(SourceChain.SourceChainId, toWormholeFormat(address(0))); + + vm.expectRevert("Not registered sender"); + receiveWormholeMessage(requestPayload); + } + + function test_WhenSenderIsNotRelayer() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + coreProxy.setWormholeRelayer(address(0)); + vm.expectRevert(abi.encodeWithSelector(Errors.CallerNotAdmin.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_WhenDeliveryHashIsUsedAlreadyw() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + receiveWormholeMessage(requestPayload); + vm.expectRevert(abi.encodeWithSelector(Errors.Payload_Duplicacy_Error.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_whenReceiveChecksPass() public whenReceiveFunctionIsCalledInCore { + + uint256 PROTOCOL_POOL_FEES = coreProxy.PROTOCOL_POOL_FEES(); + changePrank(DestChain.WORMHOLE_RELAYER_DEST); + + string memory notifSettingRes = string(abi.encodePacked(Strings.toString(notifOptions), "+", notifSettings)); + + vm.expectEmit(true, true, false, true); + emit ChannelNotifcationSettingsAdded(BaseHelper.addressToBytes32(actor.charlie_channel_owner), notifOptions, notifSettingRes, notifDescription); + + coreProxy.receiveWormholeMessages( + requestPayload, additionalVaas, sourceAddress, SourceChain.SourceChainId, deliveryHash + ); + // Update states based on Fee Percentage calculation + assertEq(coreProxy.PROTOCOL_POOL_FEES(), PROTOCOL_POOL_FEES + amount); + } + + function test_whenTokensAreTransferred() external { + vm.recordLogs(); + test_whenReceiveChecksPass(); + + (address sourceNttManager, bytes32 recipient, uint256 _amount, uint16 recipientChain) = + getMessagefromLog(vm.getRecordedLogs()); + + bytes[] memory a; + (bytes memory transceiverMessage, bytes32 hash) = + getRequestPayload(_amount, recipient, recipientChain, sourceNttManager); + + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); + + changePrank(DestChain.WORMHOLE_RELAYER_DEST); + DestChain.wormholeTransceiverChain2.receiveWormholeMessages( + transceiverMessage, // Verified + a, // Should be zero + bytes32(uint256(uint160(address(SourceChain.wormholeTransceiverChain1)))), // Must be a wormhole peers + 10_003, // ChainID from the call + hash // Hash of the VAA being used + ); + + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); + } +} diff --git a/test/CCR/SpecificRequest/CreateChannelSettingsCCR/CreateChannelSettingsCCR.tree b/test/CCR/SpecificRequest/CreateChannelSettingsCCR/CreateChannelSettingsCCR.tree new file mode 100644 index 00000000..1f27c54c --- /dev/null +++ b/test/CCR/SpecificRequest/CreateChannelSettingsCCR/CreateChannelSettingsCCR.tree @@ -0,0 +1,19 @@ +CreateChannelSettingsCCR.t.sol +├── when createChannelSettings is called +│ ├── when contract is paused +│ │ └── it should Revert +│ ├── when amount is less than minimum fees +│ │ └── it should revert +│ ├── when ether passed is less +│ │ └── it should revert +│ ├── when all checks passes +│ │ └── it should successfully create the channel settings +└── when receive function is called in core + ├── when sender is not registered + │ └── it should Revert + ├── when sender is not relayer + │ └── it should Revert + ├── when deliveryHash is used already + │ └── it should Revert + └── when all checks pass + └── it should emit event and create channel settings \ No newline at end of file diff --git a/test/CCR/SpecificRequest/CreateChatCCR/CreateChatCCR.t.sol b/test/CCR/SpecificRequest/CreateChatCCR/CreateChatCCR.t.sol index 87a6bc0b..d1b6d25b 100644 --- a/test/CCR/SpecificRequest/CreateChatCCR/CreateChatCCR.t.sol +++ b/test/CCR/SpecificRequest/CreateChatCCR/CreateChatCCR.t.sol @@ -5,7 +5,8 @@ import { BaseCCRTest } from "../../BaseCCR.t.sol"; import { Errors } from "contracts/libraries/Errors.sol"; import { console } from "forge-std/console.sol"; -import { CrossChainRequestTypes } from "../../../../contracts/libraries/DataTypes.sol"; +import { CrossChainRequestTypes } from "contracts/libraries/DataTypes.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; import { IRateLimiter } from "contracts/interfaces/wormhole/IRateLimiter.sol"; contract CreateChatCCR is BaseCCRTest { @@ -16,11 +17,14 @@ contract CreateChatCCR is BaseCCRTest { sourceAddress = toWormholeFormat(address(commProxy)); (_payload, requestPayload) = getSpecificPayload( CrossChainRequestTypes.CrossChainFunction.IncentivizedChat, - actor.charlie_channel_owner, + BaseHelper.addressToBytes32(actor.charlie_channel_owner), amount, 0, percentage, - actor.bob_channel_owner + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) ); } @@ -123,7 +127,7 @@ contract CreateChatCCR is BaseCCRTest { vm.expectEmit(false, false, false, true); emit IncentivizedChatReqReceived( - actor.bob_channel_owner, actor.charlie_channel_owner, amount - poolFeeAmount, poolFeeAmount, block.timestamp + BaseHelper.addressToBytes32(actor.bob_channel_owner), BaseHelper.addressToBytes32(actor.charlie_channel_owner), amount - poolFeeAmount, poolFeeAmount, block.timestamp ); receiveWormholeMessage(requestPayload); @@ -138,7 +142,7 @@ contract CreateChatCCR is BaseCCRTest { (address sourceNttManager, bytes32 recipient, uint256 _amount, uint16 recipientChain) = getMessagefromLog(vm.getRecordedLogs()); - console.log(pushToken.balanceOf(address(coreProxy))); + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); bytes[] memory a; (bytes memory transceiverMessage, bytes32 hash) = @@ -153,7 +157,7 @@ contract CreateChatCCR is BaseCCRTest { hash // Hash of the VAA being used ); - assertEq(pushToken.balanceOf(address(coreProxy)), amount); + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); } function test_when_celebUserTries_ClaimingTokens() external { diff --git a/test/CCR/SpecificRequest/UpdateChannelMetaCCR/UpdateChannelMetaCCR.t.sol b/test/CCR/SpecificRequest/UpdateChannelMetaCCR/UpdateChannelMetaCCR.t.sol new file mode 100644 index 00000000..f3b6aff9 --- /dev/null +++ b/test/CCR/SpecificRequest/UpdateChannelMetaCCR/UpdateChannelMetaCCR.t.sol @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import { BaseCCRTest } from "../../BaseCCR.t.sol"; +import { Errors } from ".././../../../contracts/libraries/Errors.sol"; +import { console } from "forge-std/console.sol"; + +import { CrossChainRequestTypes } from "../../../../contracts/libraries/DataTypes.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; + +contract UpdateChannelCCR is BaseCCRTest { + uint256 amount; + + function setUp() public override { + BaseCCRTest.setUp(); + amount = (coreProxy.channelUpdateCounter(toWormholeFormat(actor.bob_channel_owner)) + 1) * ADD_CHANNEL_MIN_FEES; + sourceAddress = toWormholeFormat(address(commProxy)); + (_payload, requestPayload) = getSpecificPayload( + CrossChainRequestTypes.CrossChainFunction.UpdateChannelMeta, + BaseHelper.addressToBytes32(address(0)), + amount, + 0, + percentage, + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) + ); + } + + modifier whencreateCrossChainReqIsCalled() { + _; + } + + function test_WhenContractIsPaused() external whencreateCrossChainReqIsCalled { + // it should Revert + + changePrank(actor.admin); + commProxy.pauseContract(); + vm.expectRevert("Pausable: paused"); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.UpdateChannelMeta, _payload, amount, GasLimit + ); + } + + function test_RevertWhen_EtherPassedIsLess() external whencreateCrossChainReqIsCalled { + // it should revert + vm.expectRevert(abi.encodeWithSelector(Errors.InsufficientFunds.selector)); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.UpdateChannelMeta, _payload, amount, GasLimit + ); + } + + function test_WhenAllChecksPasses() public whencreateCrossChainReqIsCalled { + // it should successfully create the CCR + vm.expectEmit(true, false, false, false); + emit LogMessagePublished(SourceChain.WORMHOLE_RELAYER_SOURCE, 2105, 0, requestPayload, 15); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest{ value: 1e18 }( + CrossChainRequestTypes.CrossChainFunction.UpdateChannelMeta, _payload, amount, GasLimit + ); + } + + modifier whenReceiveFunctionIsCalledInCore() { + test_WhenAllChecksPasses(); + setUpDestChain(); + _; + } + + function test_WhenSenderIsNotRegistered() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + //set sender to zero address + coreProxy.setRegisteredSender(SourceChain.SourceChainId, toWormholeFormat(address(0))); + + vm.expectRevert("Not registered sender"); + receiveWormholeMessage(requestPayload); + } + + function test_WhenSenderIsNotRelayer() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + coreProxy.setWormholeRelayer(address(0)); + vm.expectRevert(abi.encodeWithSelector(Errors.CallerNotAdmin.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_WhenDeliveryHashIsUsedAlready() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + receiveWormholeMessage(requestPayload); + vm.expectRevert(abi.encodeWithSelector(Errors.Payload_Duplicacy_Error.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_whenReceiveChecksPass() public whenReceiveFunctionIsCalledInCore { + // it should emit event and create Channel + + uint256 PROTOCOL_POOL_FEES = coreProxy.PROTOCOL_POOL_FEES(); + uint256 oldCounter = coreProxy.channelUpdateCounter(toWormholeFormat(actor.bob_channel_owner)); + + vm.expectEmit(true, true, false, true); + emit UpdateChannel(toWormholeFormat(actor.bob_channel_owner), _newTestChannelIdentity, amount); + + receiveWormholeMessage(requestPayload); + ( + , + , + , + , + , + , + , + , + uint256 channelUpdateBlock, + , + ) = coreProxy.channelInfo(toWormholeFormat(actor.bob_channel_owner)); + assertEq(coreProxy.PROTOCOL_POOL_FEES(), PROTOCOL_POOL_FEES + amount); + assertEq(coreProxy.channelUpdateCounter(toWormholeFormat(actor.bob_channel_owner)), oldCounter + 1); + assertEq(channelUpdateBlock, block.number); + } + + function test_whenTokensAreTransferred() external { + vm.recordLogs(); + test_whenReceiveChecksPass(); + (address sourceNttManager, bytes32 recipient, uint256 _amount, uint16 recipientChain) = + getMessagefromLog(vm.getRecordedLogs()); + + + bytes[] memory a; + (bytes memory transceiverMessage, bytes32 hash) = + getRequestPayload(_amount, recipient, recipientChain, sourceNttManager); + + changePrank(DestChain.WORMHOLE_RELAYER_DEST); + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); + + DestChain.wormholeTransceiverChain2.receiveWormholeMessages( + transceiverMessage, // Verified + a, // Should be zero + bytes32(uint256(uint160(address(SourceChain.wormholeTransceiverChain1)))), // Must be a wormhole peers + 10_003, // ChainID from the call + hash // Hash of the VAA being used + ); + + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); + } +} diff --git a/test/CCR/SpecificRequest/UpdateChannelMetaCCR/UpdateChannelMetaCCR.tree b/test/CCR/SpecificRequest/UpdateChannelMetaCCR/UpdateChannelMetaCCR.tree new file mode 100644 index 00000000..b09c1a34 --- /dev/null +++ b/test/CCR/SpecificRequest/UpdateChannelMetaCCR/UpdateChannelMetaCCR.tree @@ -0,0 +1,17 @@ +UpdateChannelMetaCCR.t.sol +├── when createCrossChainReq is called +│ ├── when contract is paused +│ │ └── it should Revert +│ ├── when ether passed is less +│ │ └── it should revert +│ └── when all checks passes +│ └── it should successfully create the CCR +└── when receive function is called in core + ├── when sender is not registered + │ └── it should Revert + ├── when sender is not relayer + │ └── it should Revert + ├── when deliveryHash is used already + │ └── it should Revert + └── when all checks pass + └── it should emit event and update storage \ No newline at end of file diff --git a/test/CCR/SpecificRequest/UpdateChannelStateCCR/DeactivateDeleteChannelCCR/DeactivateDeleteChannelCCR.t.sol b/test/CCR/SpecificRequest/UpdateChannelStateCCR/DeactivateDeleteChannelCCR/DeactivateDeleteChannelCCR.t.sol new file mode 100644 index 00000000..a9b21755 --- /dev/null +++ b/test/CCR/SpecificRequest/UpdateChannelStateCCR/DeactivateDeleteChannelCCR/DeactivateDeleteChannelCCR.t.sol @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import { BaseCCRTest } from "../../../BaseCCR.t.sol"; +import { Errors } from "contracts/libraries/Errors.sol"; +import { console } from "forge-std/console.sol"; + +import { CrossChainRequestTypes } from "contracts/libraries/DataTypes.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; + +contract DeactivateChannelCCR is BaseCCRTest { + uint256 amount; + + function setUp() public override { + BaseCCRTest.setUp(); + sourceAddress = toWormholeFormat(address(commProxy)); + (_payload, requestPayload) = getSpecificPayload( + CrossChainRequestTypes.CrossChainFunction.DeactivateChannel, + BaseHelper.addressToBytes32(actor.bob_channel_owner), + amount, + 0, + percentage, + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) + ); + } + + modifier whencreateCrossChainReqIsCalled() { + _; + } + + function test_WhenContractIsPaused() external whencreateCrossChainReqIsCalled { + // it should Revert + + changePrank(actor.admin); + commProxy.pauseContract(); + vm.expectRevert("Pausable: paused"); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.DeactivateChannel, _payload, amount, GasLimit + ); + } + + function test_RevertWhen_EtherPassedIsLess() external whencreateCrossChainReqIsCalled { + // it should revert + vm.expectRevert(abi.encodeWithSelector(Errors.InsufficientFunds.selector)); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.DeactivateChannel, _payload, amount, GasLimit + ); + } + + function test_WhenAllChecksPasses() public whencreateCrossChainReqIsCalled { + // it should successfully create the CCR + vm.expectEmit(true, false, false, false); + emit LogMessagePublished(SourceChain.WORMHOLE_RELAYER_SOURCE, 2105, 0, requestPayload, 15); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest{ value: 1e18 }( + CrossChainRequestTypes.CrossChainFunction.DeactivateChannel, _payload, amount, GasLimit + ); + } + + modifier whenReceiveFunctionIsCalledInCore() { + test_WhenAllChecksPasses(); + setUpDestChain(); + _; + } + + function test_WhenSenderIsNotRegistered() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + //set sender to zero address + coreProxy.setRegisteredSender(SourceChain.SourceChainId, toWormholeFormat(address(0))); + + vm.expectRevert("Not registered sender"); + receiveWormholeMessage(requestPayload); + } + + function test_WhenSenderIsNotRelayer() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + coreProxy.setWormholeRelayer(address(0)); + vm.expectRevert(abi.encodeWithSelector(Errors.CallerNotAdmin.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_WhenDeliveryHashIsUsedAlready() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + receiveWormholeMessage(requestPayload); + vm.expectRevert(abi.encodeWithSelector(Errors.Payload_Duplicacy_Error.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_WhenChannelIsActive() public whenReceiveFunctionIsCalledInCore { + // it should deactivate Channel + uint256 CHANNEL_POOL_FUNDS = coreProxy.CHANNEL_POOL_FUNDS(); + + ( + , + , + , + uint256 poolContributionBefore, + , + , + , + , + , + , + ) = coreProxy.channelInfo(toWormholeFormat(actor.bob_channel_owner)); + + uint refundableAmount = poolContributionBefore - MIN_POOL_CONTRIBUTION; + + vm.expectEmit(true, true, false, true); + emit ChannelStateUpdate(toWormholeFormat(actor.bob_channel_owner), refundableAmount, amount); + + receiveWormholeMessage(requestPayload); + ( + , + uint8 channelState, + , + uint256 poolContribution, + , + , + , + , + , + uint256 channelWeight, + + ) = coreProxy.channelInfo(toWormholeFormat(actor.bob_channel_owner)); + assertEq(coreProxy.CHANNEL_POOL_FUNDS(), CHANNEL_POOL_FUNDS - refundableAmount,"Channel Pool Funcds"); + assertEq(channelState, 2, "Channel State"); + assertEq(poolContribution, MIN_POOL_CONTRIBUTION, "Pool contribution " ); + assertEq(channelWeight, (MIN_POOL_CONTRIBUTION * ADJUST_FOR_FLOAT)/MIN_POOL_CONTRIBUTION, "Channel Weight"); + } + function test_whenTokensAreTransferred() external { + amount = ADD_CHANNEL_MIN_FEES; + (_payload, requestPayload) = getSpecificPayload( + CrossChainRequestTypes.CrossChainFunction.DeactivateChannel, + BaseHelper.addressToBytes32(actor.bob_channel_owner), + amount, + 0, + percentage, + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) + ); + + changePrank(actor.bob_channel_owner); + vm.recordLogs(); + commProxy.createCrossChainRequest{ value: 1e18 }( + CrossChainRequestTypes.CrossChainFunction.DeactivateChannel, _payload, amount, GasLimit + ); + + (address sourceNttManager, bytes32 recipient, uint256 _amount, uint16 recipientChain) = + getMessagefromLog(vm.getRecordedLogs()); + + bytes[] memory a; + (bytes memory transceiverMessage, bytes32 hash) = + getRequestPayload(_amount, recipient, recipientChain, sourceNttManager); + + setUpDestChain(); + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); + + changePrank(DestChain.WORMHOLE_RELAYER_DEST); + DestChain.wormholeTransceiverChain2.receiveWormholeMessages( + transceiverMessage, // Verified + a, // Should be zero + bytes32(uint256(uint160(address(SourceChain.wormholeTransceiverChain1)))), // Must be a wormhole peers + 10_003, // ChainID from the call + hash // Hash of the VAA being used + ); + + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); + } +} diff --git a/test/CCR/SpecificRequest/UpdateChannelStateCCR/DeactivateDeleteChannelCCR/DeactivateDeleteChannelCCR.tree b/test/CCR/SpecificRequest/UpdateChannelStateCCR/DeactivateDeleteChannelCCR/DeactivateDeleteChannelCCR.tree new file mode 100644 index 00000000..2e25825f --- /dev/null +++ b/test/CCR/SpecificRequest/UpdateChannelStateCCR/DeactivateDeleteChannelCCR/DeactivateDeleteChannelCCR.tree @@ -0,0 +1,21 @@ +DeactivateChannelCCR.t.sol +├── when createCrossChainReq is called +│ ├── when contract is paused +│ │ └── it should Revert +│ ├── when ether passed is less +│ │ └── it should revert +│ └── when all checks passes +│ └── it should successfully create the CCR +└── when receive function is called in core + ├── when sender is not registered + │ └── it should Revert + ├── when sender is not relayer + │ └── it should Revert + ├── when deliveryHash is used already + │ └── it should Revert + ├── when Channel is active + │ └── it should deactivate Channel + ├── when channel is deactivated + │ └── it should activate Channel + └── when channel is timebound + └── it should delete channel \ No newline at end of file diff --git a/test/CCR/SpecificRequest/UpdateChannelStateCCR/ReactivateChannelCCR/ReactivateChannelCCR.t.sol b/test/CCR/SpecificRequest/UpdateChannelStateCCR/ReactivateChannelCCR/ReactivateChannelCCR.t.sol new file mode 100644 index 00000000..0f4d93a8 --- /dev/null +++ b/test/CCR/SpecificRequest/UpdateChannelStateCCR/ReactivateChannelCCR/ReactivateChannelCCR.t.sol @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import { BaseCCRTest } from "../../../BaseCCR.t.sol"; +import { Errors } from "contracts/libraries/Errors.sol"; +import { console } from "forge-std/console.sol"; + +import { CrossChainRequestTypes } from "contracts/libraries/DataTypes.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; + +contract ReactivateChannelCCR is BaseCCRTest { + uint256 amount = ADD_CHANNEL_MIN_FEES; + + function setUp() public override { + BaseCCRTest.setUp(); + sourceAddress = toWormholeFormat(address(commProxy)); + (_payload, requestPayload) = getSpecificPayload( + CrossChainRequestTypes.CrossChainFunction.ReactivateChannel, + BaseHelper.addressToBytes32(actor.bob_channel_owner), + amount, + 0, + percentage, + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) + ); + } + + modifier whencreateCrossChainReqIsCalled() { + _; + } + + function test_WhenContractIsPaused() external whencreateCrossChainReqIsCalled { + // it should Revert + + changePrank(actor.admin); + commProxy.pauseContract(); + vm.expectRevert("Pausable: paused"); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.ReactivateChannel, _payload, amount, GasLimit + ); + } + + function test_RevertWhen_EtherPassedIsLess() external whencreateCrossChainReqIsCalled { + // it should revert + vm.expectRevert(abi.encodeWithSelector(Errors.InsufficientFunds.selector)); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest( + CrossChainRequestTypes.CrossChainFunction.ReactivateChannel, _payload, amount, GasLimit + ); + } + + function test_WhenAllChecksPasses() public whencreateCrossChainReqIsCalled { + // it should successfully create the CCR + vm.expectEmit(true, false, false, false); + emit LogMessagePublished(SourceChain.WORMHOLE_RELAYER_SOURCE, 2105, 0, requestPayload, 15); + changePrank(actor.bob_channel_owner); + commProxy.createCrossChainRequest{ value: 1e18 }( + CrossChainRequestTypes.CrossChainFunction.ReactivateChannel, _payload, amount, GasLimit + ); + } + + modifier whenReceiveFunctionIsCalledInCore() { + test_WhenAllChecksPasses(); + setUpDestChain(); + _; + } + + function test_WhenSenderIsNotRegistered() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + //set sender to zero address + coreProxy.setRegisteredSender(SourceChain.SourceChainId, toWormholeFormat(address(0))); + + vm.expectRevert("Not registered sender"); + receiveWormholeMessage(requestPayload); + } + + function test_WhenSenderIsNotRelayer() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + coreProxy.setWormholeRelayer(address(0)); + vm.expectRevert(abi.encodeWithSelector(Errors.CallerNotAdmin.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_WhenDeliveryHashIsUsedAlready() external whenReceiveFunctionIsCalledInCore { + // it should Revert + + receiveWormholeMessage(requestPayload); + vm.expectRevert(abi.encodeWithSelector(Errors.Payload_Duplicacy_Error.selector)); + receiveWormholeMessage(requestPayload); + } + + function test_WhenChannelIsDeactivated() public whenReceiveFunctionIsCalledInCore { + // it should activate Channel + changePrank(actor.bob_channel_owner); + coreProxy.updateChannelState(0); + uint256 CHANNEL_POOL_FUNDS = coreProxy.CHANNEL_POOL_FUNDS(); + vm.expectEmit(true, true, false, true); + emit ChannelStateUpdate(toWormholeFormat(actor.bob_channel_owner), 0, amount); + + receiveWormholeMessage(requestPayload); + ( + , + uint8 channelState, + , + uint256 poolContribution, + , + , + , + , + , + uint256 channelWeight, + + ) = coreProxy.channelInfo(toWormholeFormat(actor.bob_channel_owner)); + assertEq(coreProxy.CHANNEL_POOL_FUNDS(), CHANNEL_POOL_FUNDS + ADD_CHANNEL_MIN_FEES - FEE_AMOUNT,"Channel Pool Funcds"); + assertEq(channelState, 1, "Channel State"); + assertEq(poolContribution, MIN_POOL_CONTRIBUTION + ADD_CHANNEL_MIN_FEES - FEE_AMOUNT, "Pool contribution " ); + assertEq(channelWeight, (poolContribution * ADJUST_FOR_FLOAT)/MIN_POOL_CONTRIBUTION, "Channel Weight"); + } + + function test_whenTokensAreTransferred() external { + amount = ADD_CHANNEL_MIN_FEES; + (_payload, requestPayload) = getSpecificPayload( + CrossChainRequestTypes.CrossChainFunction.ReactivateChannel, + BaseHelper.addressToBytes32(actor.bob_channel_owner), + amount, + 0, + percentage, + 0, + "", + "", + BaseHelper.addressToBytes32(actor.bob_channel_owner) + ); + + changePrank(actor.bob_channel_owner); + vm.recordLogs(); + commProxy.createCrossChainRequest{ value: 1e18 }( + CrossChainRequestTypes.CrossChainFunction.ReactivateChannel, _payload, amount, GasLimit + ); + + (address sourceNttManager, bytes32 recipient, uint256 _amount, uint16 recipientChain) = + getMessagefromLog(vm.getRecordedLogs()); + + bytes[] memory a; + (bytes memory transceiverMessage, bytes32 hash) = + getRequestPayload(_amount, recipient, recipientChain, sourceNttManager); + + setUpDestChain(); + + uint balanceCoreBefore = pushToken.balanceOf(address(coreProxy)); + + changePrank(DestChain.WORMHOLE_RELAYER_DEST); + DestChain.wormholeTransceiverChain2.receiveWormholeMessages( + transceiverMessage, // Verified + a, // Should be zero + bytes32(uint256(uint160(address(SourceChain.wormholeTransceiverChain1)))), // Must be a wormhole peers + 10_003, // ChainID from the call + hash // Hash of the VAA being used + ); + + assertEq(pushToken.balanceOf(address(coreProxy)), balanceCoreBefore + amount, "Tokens in Core"); + } +} diff --git a/test/CCR/SpecificRequest/UpdateChannelStateCCR/ReactivateChannelCCR/ReactivateChannelCCR.tree b/test/CCR/SpecificRequest/UpdateChannelStateCCR/ReactivateChannelCCR/ReactivateChannelCCR.tree new file mode 100644 index 00000000..f79d3703 --- /dev/null +++ b/test/CCR/SpecificRequest/UpdateChannelStateCCR/ReactivateChannelCCR/ReactivateChannelCCR.tree @@ -0,0 +1,18 @@ +ReactivateChannelCCR.t.sol +├── when createCrossChainReq is called +│ ├── when contract is paused +│ │ └── it should Revert +│ ├── when ether passed is less +│ │ └── it should revert +│ └── when all checks passes +│ └── it should successfully create the CCR +└── when receive function is called in core + ├── when sender is not registered + │ └── it should Revert + ├── when sender is not relayer + │ └── it should Revert + ├── when deliveryHash is used already + │ └── it should Revert + └── when channel is deactivated + └── it should activate Channel + \ No newline at end of file diff --git a/test/PushComm/unit_tests/BasePushCommTest.t.sol b/test/PushComm/unit_tests/BasePushCommTest.t.sol index b9d77e3d..06cc83e0 100644 --- a/test/PushComm/unit_tests/BasePushCommTest.t.sol +++ b/test/PushComm/unit_tests/BasePushCommTest.t.sol @@ -12,9 +12,6 @@ contract BasePushCommTest is BasePushCoreTest { BasePushCoreTest.setUp(); changePrank(actor.tim_push_holder); verifierContract = new SignatureVerifier(); - - changePrank(actor.bob_channel_owner); - coreProxy.createChannelWithPUSH(CoreTypes.ChannelType.InterestBearingOpen, _testChannelIdentity, 50e18, 0); } //Helper Functions diff --git a/test/PushCore/unit_tests/ChannelStateCycle/blockChannel/blockChannel.t.sol b/test/PushCore/unit_tests/ChannelStateCycle/blockChannel/blockChannel.t.sol index bda45d81..65a8397d 100644 --- a/test/PushCore/unit_tests/ChannelStateCycle/blockChannel/blockChannel.t.sol +++ b/test/PushCore/unit_tests/ChannelStateCycle/blockChannel/blockChannel.t.sol @@ -4,10 +4,14 @@ import { BasePushCoreTest } from "../../BasePushCoreTest.t.sol"; import { Errors } from "contracts/libraries/Errors.sol"; contract BlockChannel_Test is BasePushCoreTest { + bytes32 bobBytes; + bytes32 charlieBytes; function setUp() public virtual override { BasePushCoreTest.setUp(); _createChannel(actor.bob_channel_owner); + bobBytes = toWormholeFormat(actor.bob_channel_owner); + charlieBytes = toWormholeFormat(actor.charlie_channel_owner); } modifier whenNotPaused() { @@ -21,7 +25,7 @@ contract BlockChannel_Test is BasePushCoreTest { function test_Revertwhen_BlockCallerNotGovernance() public whenNotPaused whenCallerIsAdmin { vm.expectRevert(Errors.CallerNotGovernance.selector); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); } function test_AdminCanBlockActivatedChannel() public whenNotPaused whenCallerIsAdmin { @@ -29,7 +33,7 @@ contract BlockChannel_Test is BasePushCoreTest { emit ChannelBlocked(channelCreators.bob_channel_owner_Bytes32); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); } function test_AdminCanBlockDeactivatedChannel() public whenNotPaused whenCallerIsAdmin { @@ -40,28 +44,28 @@ contract BlockChannel_Test is BasePushCoreTest { emit ChannelBlocked(channelCreators.bob_channel_owner_Bytes32); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); } function test_Revertwhen_BlockInactiveChannel() public whenNotPaused whenCallerIsAdmin { vm.prank(actor.admin); vm.expectRevert(Errors.Core_InvalidChannel.selector); - coreProxy.blockChannel(actor.charlie_channel_owner); + coreProxy.blockChannel(charlieBytes); } function test_Revertwhen_AlreadyBlockedChannel() public whenNotPaused whenCallerIsAdmin { vm.startPrank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); vm.expectRevert(Errors.Core_InvalidChannel.selector); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); vm.stopPrank(); } function test_ChannelDetailsUpdation() public whenNotPaused whenCallerIsAdmin { uint256 channelsCountBeforeBlocked = coreProxy.channelsCount(); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); ( , @@ -96,7 +100,7 @@ contract BlockChannel_Test is BasePushCoreTest { uint256 poolFundsBeforeBlocked = coreProxy.CHANNEL_POOL_FUNDS(); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(bobBytes); uint256 actualChannelFundsAfterBlocked = coreProxy.CHANNEL_POOL_FUNDS(); uint256 actualPoolFeesAfterBlocked = coreProxy.PROTOCOL_POOL_FEES(); diff --git a/test/PushCore/unit_tests/ChannelStateCycle/deactivateChannel/deactivateChannel.t.sol b/test/PushCore/unit_tests/ChannelStateCycle/deactivateChannel/deactivateChannel.t.sol index 1b211cfb..9287e552 100644 --- a/test/PushCore/unit_tests/ChannelStateCycle/deactivateChannel/deactivateChannel.t.sol +++ b/test/PushCore/unit_tests/ChannelStateCycle/deactivateChannel/deactivateChannel.t.sol @@ -34,7 +34,7 @@ contract DeactivateChannel_Test is BasePushCoreTest { function test_Revertwhen_DeactivatingBlockedChannel() public whenNotPaused { vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(toWormholeFormat(actor.bob_channel_owner)); vm.prank(actor.bob_channel_owner); vm.expectRevert(Errors.Core_InvalidChannel.selector); diff --git a/test/PushCore/unit_tests/ChannelStateCycle/reactivateChannel/reactivateChannel.t.sol b/test/PushCore/unit_tests/ChannelStateCycle/reactivateChannel/reactivateChannel.t.sol index a3a37613..fe9a7d2c 100644 --- a/test/PushCore/unit_tests/ChannelStateCycle/reactivateChannel/reactivateChannel.t.sol +++ b/test/PushCore/unit_tests/ChannelStateCycle/reactivateChannel/reactivateChannel.t.sol @@ -20,7 +20,7 @@ contract ReactivateChannel_Test is BasePushCoreTest { approveTokens(actor.bob_channel_owner, address(coreProxy), ADD_CHANNEL_MIN_FEES); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(toWormholeFormat(actor.bob_channel_owner)); vm.prank(actor.bob_channel_owner); vm.expectRevert(Errors.Core_InvalidChannel.selector); diff --git a/test/PushCore/unit_tests/ChannelUpdation/updateChannelMeta.t.sol b/test/PushCore/unit_tests/ChannelUpdation/updateChannelMeta.t.sol index adbda38d..5fcc6d88 100644 --- a/test/PushCore/unit_tests/ChannelUpdation/updateChannelMeta.t.sol +++ b/test/PushCore/unit_tests/ChannelUpdation/updateChannelMeta.t.sol @@ -17,7 +17,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { vm.prank(actor.bob_channel_owner); vm.expectRevert(abi.encodeWithSelector(Errors.Core_InvalidChannel.selector)); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); } // Todo - fix updateChannelState function - Test case fails until then @@ -29,25 +29,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { vm.prank(actor.bob_channel_owner); vm.expectRevert(abi.encodeWithSelector(Errors.Core_InvalidChannel.selector)); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); - } - - function test_Revertwhen_CallerNotChannelOwner() public whenNotPaused { - uint256 _amountBeingTransferred = ADD_CHANNEL_MIN_FEES; - _createChannel(actor.bob_channel_owner); - - vm.prank(actor.charlie_channel_owner); - vm.expectRevert(abi.encodeWithSelector(Errors.UnauthorizedCaller.selector, actor.charlie_channel_owner)); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); - } - - function test_Revertwhen_UpdateZeroAddressChannel() public whenNotPaused { - uint256 _amountBeingTransferred = ADD_CHANNEL_MIN_FEES; - address _channelAddress = address(0x0); - - vm.prank(actor.bob_channel_owner); - vm.expectRevert(abi.encodeWithSelector(Errors.Core_InvalidChannel.selector)); - coreProxy.updateChannelMeta(_channelAddress, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); } function test_Revertwhen_AmountLessThanRequiredFees() public whenNotPaused { @@ -60,7 +42,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { Errors.InvalidArg_LessThanExpected.selector, ADD_CHANNEL_MIN_FEES, _amountBeingTransferred ) ); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); } function test_Revertwhen_AmountLessThanRequiredFeesForSecondUpdate() public whenNotPaused { @@ -68,14 +50,14 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { _createChannel(actor.bob_channel_owner); vm.startPrank(actor.bob_channel_owner); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); vm.expectRevert( abi.encodeWithSelector( Errors.InvalidArg_LessThanExpected.selector, ADD_CHANNEL_MIN_FEES * 2, _amountBeingTransferred ) ); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); vm.stopPrank(); } @@ -89,7 +71,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { approveTokens(actor.bob_channel_owner, address(coreProxy), _amountBeingTransferred); vm.prank(actor.bob_channel_owner); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); } } @@ -105,7 +87,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { uint256 _balanceOfPushTokensBeforeUpdateInProxy = pushToken.balanceOf(address(coreProxy)); vm.prank(actor.bob_channel_owner); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); uint256 _balanceOfPushTokensAfterUpdateInProxy = pushToken.balanceOf(address(coreProxy)); assertEq( @@ -125,9 +107,9 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { approveTokens(actor.bob_channel_owner, address(coreProxy), _amountBeingTransferred); vm.prank(actor.bob_channel_owner); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); - uint256 _channelUpdateCounterAfter = coreProxy.channelUpdateCounter(actor.bob_channel_owner); + uint256 _channelUpdateCounterAfter = coreProxy.channelUpdateCounter(toWormholeFormat(actor.bob_channel_owner)); uint256 _channelUpdateBlock = _getChannelUpdateBlock(actor.bob_channel_owner); assertEq(_channelUpdateCounterAfter, i + 1); assertEq(_channelUpdateBlock, block.number); @@ -142,7 +124,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { uint256 channelPoolFundsBeforeUpdate = coreProxy.CHANNEL_POOL_FUNDS(); vm.prank(actor.bob_channel_owner); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); uint256 expectedProtocolPoolFees = poolFeesBeforeUpdate + _amountBeingTransferred; uint256 expectedChannelPoolFunds = channelPoolFundsBeforeUpdate; @@ -161,7 +143,7 @@ contract UpdateChannelMeta_Test is BasePushCoreTest { ); vm.prank(actor.bob_channel_owner); - coreProxy.updateChannelMeta(actor.bob_channel_owner, _testChannelUpdatedIdentity, _amountBeingTransferred); + coreProxy.updateChannelMeta( _testChannelUpdatedIdentity, _amountBeingTransferred); } // Zero-Address Channel Support - Now Deprecated diff --git a/test/PushCore/unit_tests/ChannelVerifyTag/ChannelUnverification/ChannelUnverification.t.sol b/test/PushCore/unit_tests/ChannelVerifyTag/ChannelUnverification/ChannelUnverification.t.sol index 7187cf44..369e6060 100644 --- a/test/PushCore/unit_tests/ChannelVerifyTag/ChannelUnverification/ChannelUnverification.t.sol +++ b/test/PushCore/unit_tests/ChannelVerifyTag/ChannelUnverification/ChannelUnverification.t.sol @@ -4,27 +4,36 @@ import { BasePushCoreTest } from "../../BasePushCoreTest.t.sol"; import { Errors } from "contracts/libraries/Errors.sol"; contract ChannelUnverification_Test is BasePushCoreTest { + bytes32 bobBytes; + bytes32 aliceBytes; + bytes32 charlieBytes; + bytes32 adminBytes; function setUp() public virtual override { BasePushCoreTest.setUp(); _createChannel(actor.bob_channel_owner); _createChannel(actor.alice_channel_owner); _createChannel(actor.charlie_channel_owner); + + bobBytes = toWormholeFormat(actor.bob_channel_owner); + aliceBytes = toWormholeFormat(actor.alice_channel_owner); + charlieBytes = toWormholeFormat(actor.charlie_channel_owner); + adminBytes = toWormholeFormat(actor.admin); } function test_WhenAdminUnverifies_AChannelVerifiedBy_AdminItself() external { // it should be able to unverify changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + coreProxy.verifyChannel(bobBytes); - uint8 bobVerificationBefore = coreProxy.getChannelVerfication(actor.bob_channel_owner); + uint8 bobVerificationBefore = coreProxy.getChannelVerfication(bobBytes); assertEq(bobVerificationBefore, 1); changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerificationRevoked(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.unverifyChannel(actor.bob_channel_owner); + emit ChannelVerificationRevoked(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.unverifyChannel(bobBytes); - uint8 bobVerificationAfter = coreProxy.getChannelVerfication(actor.bob_channel_owner); + uint8 bobVerificationAfter = coreProxy.getChannelVerfication(bobBytes); assertEq(bobVerificationAfter, 0); address Bob_verifiedBy = _getVerifiedBy(actor.bob_channel_owner); @@ -34,19 +43,19 @@ contract ChannelUnverification_Test is BasePushCoreTest { function test_WhenAdminUnverifies_AChannelVerifiedBy_AnotherChannel() external { // it should be able to unverify changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerificationRevoked(channelCreators.alice_channel_owner_Bytes32, actor.admin); - coreProxy.unverifyChannel(actor.alice_channel_owner); + emit ChannelVerificationRevoked(channelCreators.alice_channel_owner_Bytes32, adminBytes); + coreProxy.unverifyChannel(aliceBytes); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationAfter, 0); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -56,19 +65,19 @@ contract ChannelUnverification_Test is BasePushCoreTest { function test_WhenAChannelUnverifies_ASecondaryVerifiedChannel_VerifiedByItself() external { // it should be able to unverify changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); changePrank(actor.bob_channel_owner); vm.expectEmit(true, true, false, false); - emit ChannelVerificationRevoked(channelCreators.alice_channel_owner_Bytes32, actor.bob_channel_owner); - coreProxy.unverifyChannel(actor.alice_channel_owner); + emit ChannelVerificationRevoked(channelCreators.alice_channel_owner_Bytes32, bobBytes); + coreProxy.unverifyChannel(aliceBytes); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationAfter, 0); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -78,20 +87,20 @@ contract ChannelUnverification_Test is BasePushCoreTest { function test_RevertWhen_AChannelUnverifies_ASecondaryVerifiedChannel_VerifiedByAnotherChannel() external { // it should REVERT changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.charlie_channel_owner); + coreProxy.verifyChannel(bobBytes); + coreProxy.verifyChannel(charlieBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); vm.expectRevert(Errors.CallerNotAdmin.selector); changePrank(actor.charlie_channel_owner); - coreProxy.unverifyChannel(actor.alice_channel_owner); + coreProxy.unverifyChannel(aliceBytes); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationAfter, 2); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -101,23 +110,23 @@ contract ChannelUnverification_Test is BasePushCoreTest { function test_WhenASecondaryVerifiedChannel_UnverifiesAnotherSecondaryChannel_VerifiedByItself() external { // it should unverify those channels changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.charlie_channel_owner); + coreProxy.verifyChannel(charlieBytes); changePrank(actor.charlie_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); changePrank(actor.charlie_channel_owner); vm.expectEmit(true, true, false, false); - emit ChannelVerificationRevoked(channelCreators.alice_channel_owner_Bytes32, actor.charlie_channel_owner); - coreProxy.unverifyChannel(actor.alice_channel_owner); + emit ChannelVerificationRevoked(channelCreators.alice_channel_owner_Bytes32, charlieBytes); + coreProxy.unverifyChannel(aliceBytes); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationAfter, 0); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -127,24 +136,24 @@ contract ChannelUnverification_Test is BasePushCoreTest { function test_WhenASecondaryVerifiedChannel_GetsUnverifed() external { // it should unverify any other secondary verified channel that is verified by this channel changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.charlie_channel_owner); + coreProxy.verifyChannel(charlieBytes); changePrank(actor.charlie_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); changePrank(actor.bob_channel_owner); vm.expectEmit(true, true, false, false); - emit ChannelVerificationRevoked(channelCreators.charlie_channel_owner_Bytes32, actor.bob_channel_owner); - coreProxy.unverifyChannel(actor.charlie_channel_owner); + emit ChannelVerificationRevoked(channelCreators.charlie_channel_owner_Bytes32, bobBytes); + coreProxy.unverifyChannel(charlieBytes); - uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(actor.charlie_channel_owner); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(charlieBytes); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(charlieVerificationAfter, 0, "charlie"); assertEq(aliceVerificationAfter, 0, "alice"); @@ -158,25 +167,25 @@ contract ChannelUnverification_Test is BasePushCoreTest { function test_WhenAdminUnverifies_AnyChannelPrimaryOrSecondary() external { // it should unverify all of them as well as any secondary channel verified by those channels changePrank(actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.charlie_channel_owner); + coreProxy.verifyChannel(charlieBytes); changePrank(actor.charlie_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerificationRevoked(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.unverifyChannel(actor.bob_channel_owner); + emit ChannelVerificationRevoked(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.unverifyChannel(bobBytes); - uint8 bobVerificationAfter = coreProxy.getChannelVerfication(actor.bob_channel_owner); - uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(actor.charlie_channel_owner); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 bobVerificationAfter = coreProxy.getChannelVerfication(bobBytes); + uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(charlieBytes); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(charlieVerificationAfter, 0, "charlie"); assertEq(aliceVerificationAfter, 0, "alice"); diff --git a/test/PushCore/unit_tests/ChannelVerifyTag/ChannelVerification/ChannelVerification.t.sol b/test/PushCore/unit_tests/ChannelVerifyTag/ChannelVerification/ChannelVerification.t.sol index 0177d7ff..50db9e24 100644 --- a/test/PushCore/unit_tests/ChannelVerifyTag/ChannelVerification/ChannelVerification.t.sol +++ b/test/PushCore/unit_tests/ChannelVerifyTag/ChannelVerification/ChannelVerification.t.sol @@ -4,11 +4,20 @@ import { BasePushCoreTest } from "../../BasePushCoreTest.t.sol"; import { Errors } from "contracts/libraries/Errors.sol"; contract ChannelVerification_Test is BasePushCoreTest { + bytes32 bobBytes; + bytes32 aliceBytes; + bytes32 charlieBytes; + bytes32 adminBytes; function setUp() public virtual override { BasePushCoreTest.setUp(); _createChannel(actor.bob_channel_owner); _createChannel(actor.alice_channel_owner); _createChannel(actor.charlie_channel_owner); + + bobBytes = toWormholeFormat(actor.bob_channel_owner); + aliceBytes = toWormholeFormat(actor.alice_channel_owner); + charlieBytes = toWormholeFormat(actor.charlie_channel_owner); + adminBytes = toWormholeFormat(actor.admin); } modifier whenCheckedTheDefaultVerificationStatus() { @@ -19,8 +28,8 @@ contract ChannelVerification_Test is BasePushCoreTest { external whenCheckedTheDefaultVerificationStatus { - uint8 adminVerification = coreProxy.getChannelVerfication(actor.admin); - uint8 zeroAddressVerification = coreProxy.getChannelVerfication(address(0)); + uint8 adminVerification = coreProxy.getChannelVerfication(toWormholeFormat(actor.admin)); + uint8 zeroAddressVerification = coreProxy.getChannelVerfication(toWormholeFormat(address(0))); assertEq(adminVerification, 1); @@ -34,8 +43,8 @@ contract ChannelVerification_Test is BasePushCoreTest { whenCheckedTheDefaultVerificationStatus { // it should return 0 for unverified Channels - uint8 bobVerification = coreProxy.getChannelVerfication(actor.bob_channel_owner); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 bobVerification = coreProxy.getChannelVerfication(bobBytes); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 0); assertEq(bobVerification, aliceVerification); @@ -51,9 +60,9 @@ contract ChannelVerification_Test is BasePushCoreTest { // it should return primary verified for channels verified by admin changePrank(actor.admin); vm.expectRevert(Errors.Core_InvalidChannel.selector); - coreProxy.verifyChannel(actor.tim_push_holder); + coreProxy.verifyChannel(toWormholeFormat(actor.tim_push_holder)); - uint8 timVerification = coreProxy.getChannelVerfication(actor.tim_push_holder); + uint8 timVerification = coreProxy.getChannelVerfication(toWormholeFormat(actor.tim_push_holder)); assertEq(timVerification, 0); address Tim_verifiedBy = _getVerifiedBy(actor.tim_push_holder); @@ -64,10 +73,10 @@ contract ChannelVerification_Test is BasePushCoreTest { // it should return primary verified for channels verified by admin changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(bobBytes); - uint8 bobVerification = coreProxy.getChannelVerfication(actor.bob_channel_owner); + uint8 bobVerification = coreProxy.getChannelVerfication(bobBytes); assertEq(bobVerification, 1); address Bob_verifiedBy = _getVerifiedBy(actor.bob_channel_owner); @@ -78,15 +87,15 @@ contract ChannelVerification_Test is BasePushCoreTest { // it should give secondary verification(2) to that channel changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, bobBytes); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -97,9 +106,9 @@ contract ChannelVerification_Test is BasePushCoreTest { // it should REVERT vm.expectRevert(abi.encodeWithSelector(Errors.UnauthorizedCaller.selector, actor.bob_channel_owner)); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 0); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -110,15 +119,15 @@ contract ChannelVerification_Test is BasePushCoreTest { // it should allow admin to give primary verification changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(bobBytes); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, actor.bob_channel_owner); + emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, bobBytes); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerificationBefore = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationBefore = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationBefore, 2); address Alice_verifiedByBefore = _getVerifiedBy(actor.alice_channel_owner); @@ -126,10 +135,10 @@ contract ChannelVerification_Test is BasePushCoreTest { changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.alice_channel_owner); + emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationAfter, 1); address Alice_verifiedByAfter = _getVerifiedBy(actor.alice_channel_owner); @@ -141,14 +150,14 @@ contract ChannelVerification_Test is BasePushCoreTest { changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(bobBytes); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.alice_channel_owner); + emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerificationBefore = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationBefore = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationBefore, 1); address Alice_verifiedByBefore = _getVerifiedBy(actor.alice_channel_owner); @@ -156,9 +165,9 @@ contract ChannelVerification_Test is BasePushCoreTest { vm.expectRevert(Errors.Core_InvalidChannel.selector); changePrank(actor.bob_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerificationAfter, 1); address Alice_verifiedByAfter = _getVerifiedBy(actor.alice_channel_owner); @@ -169,20 +178,20 @@ contract ChannelVerification_Test is BasePushCoreTest { // it should give secondary verification to that channel changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, actor.admin); - coreProxy.verifyChannel(actor.bob_channel_owner); + emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, adminBytes); + coreProxy.verifyChannel(bobBytes); changePrank(actor.bob_channel_owner); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.charlie_channel_owner_Bytes32, actor.bob_channel_owner); - coreProxy.verifyChannel(actor.charlie_channel_owner); + emit ChannelVerified(channelCreators.charlie_channel_owner_Bytes32, bobBytes); + coreProxy.verifyChannel(charlieBytes); changePrank(actor.charlie_channel_owner); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, actor.charlie_channel_owner); - coreProxy.verifyChannel(actor.alice_channel_owner); + emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, charlieBytes); + coreProxy.verifyChannel(aliceBytes); - uint8 aliceVerification = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 aliceVerification = coreProxy.getChannelVerfication(aliceBytes); assertEq(aliceVerification, 2); address Alice_verifiedBy = _getVerifiedBy(actor.alice_channel_owner); @@ -191,15 +200,15 @@ contract ChannelVerification_Test is BasePushCoreTest { function test_RevertWhen_NonAdminCalls_BatchVerification() external { // it should REVERT- not allowing anyone other than Admin - address[] memory _channels = new address[](2); - _channels[0] = actor.charlie_channel_owner; - _channels[1] = actor.alice_channel_owner; + bytes32[] memory _channels = new bytes32[](2); + _channels[0] = charlieBytes; + _channels[1] = aliceBytes; vm.expectRevert(Errors.CallerNotAdmin.selector); changePrank(actor.bob_channel_owner); coreProxy.batchVerification(0, 2, _channels); - uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(actor.charlie_channel_owner); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); + uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(charlieBytes); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); assertEq(charlieVerificationAfter, 0, "charlie"); assertEq(aliceVerificationAfter, 0, "alice"); @@ -207,23 +216,23 @@ contract ChannelVerification_Test is BasePushCoreTest { function test_WhenAdminCalls_BatchVerification() external { // it should execute and set the verifications to primary - address[] memory _channels = new address[](3); - _channels[0] = actor.charlie_channel_owner; - _channels[1] = actor.bob_channel_owner; - _channels[2] = actor.alice_channel_owner; + bytes32[] memory _channels = new bytes32[](3); + _channels[0] = charlieBytes; + _channels[1] = bobBytes; + _channels[2] = aliceBytes; changePrank(actor.admin); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.charlie_channel_owner_Bytes32, actor.admin); + emit ChannelVerified(channelCreators.charlie_channel_owner_Bytes32, adminBytes); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, actor.admin); + emit ChannelVerified(channelCreators.bob_channel_owner_Bytes32, adminBytes); vm.expectEmit(true, true, false, false); - emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, actor.admin); + emit ChannelVerified(channelCreators.alice_channel_owner_Bytes32, adminBytes); coreProxy.batchVerification(0, 3, _channels); - uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(actor.charlie_channel_owner); - uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(actor.alice_channel_owner); - uint8 bobVerificationAfter = coreProxy.getChannelVerfication(actor.bob_channel_owner); + uint8 charlieVerificationAfter = coreProxy.getChannelVerfication(charlieBytes); + uint8 aliceVerificationAfter = coreProxy.getChannelVerfication(aliceBytes); + uint8 bobVerificationAfter = coreProxy.getChannelVerfication(bobBytes); assertEq(charlieVerificationAfter, 1, "charlie"); assertEq(aliceVerificationAfter, 1, "alice"); diff --git a/test/PushCore/unit_tests/ContractPausability/contractPausability.t.sol b/test/PushCore/unit_tests/ContractPausability/contractPausability.t.sol index ee64c97c..4354bf86 100644 --- a/test/PushCore/unit_tests/ContractPausability/contractPausability.t.sol +++ b/test/PushCore/unit_tests/ContractPausability/contractPausability.t.sol @@ -83,7 +83,7 @@ contract ContractPausability_Test is BasePushCoreTest { vm.expectRevert("Pausable: paused"); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(toWormholeFormat(actor.bob_channel_owner)); } function test_ChannelFunctionsAfterPauseUnpause() public { @@ -99,6 +99,6 @@ contract ContractPausability_Test is BasePushCoreTest { vm.stopPrank(); vm.prank(actor.admin); - coreProxy.blockChannel(actor.bob_channel_owner); + coreProxy.blockChannel(toWormholeFormat(actor.bob_channel_owner)); } } diff --git a/test/PushCore/unit_tests/CreateIncentivizedChat/createIncentivizedChat.t.sol b/test/PushCore/unit_tests/CreateIncentivizedChat/createIncentivizedChat.t.sol index c97a4f91..9ed30d50 100644 --- a/test/PushCore/unit_tests/CreateIncentivizedChat/createIncentivizedChat.t.sol +++ b/test/PushCore/unit_tests/CreateIncentivizedChat/createIncentivizedChat.t.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import { BasePushCoreTest } from "../BasePushCoreTest.t.sol"; import { Errors } from "contracts/libraries/Errors.sol"; import { console } from "forge-std/console.sol"; +import { BaseHelper } from "contracts/libraries/BaseHelper.sol"; contract test_createIncentivizedChat is BasePushCoreTest { function setUp() public override { @@ -42,7 +43,7 @@ contract test_createIncentivizedChat is BasePushCoreTest { vm.expectEmit(false, false, false, true); emit IncentivizedChatReqReceived( - actor.bob_channel_owner, actor.charlie_channel_owner, 100e18 - FEE_AMOUNT, FEE_AMOUNT, block.timestamp + BaseHelper.addressToBytes32(actor.bob_channel_owner), BaseHelper.addressToBytes32(actor.charlie_channel_owner), 100e18 - FEE_AMOUNT, FEE_AMOUNT, block.timestamp ); coreProxy.createIncentivizedChatRequest(actor.charlie_channel_owner, 100e18); diff --git a/test/PushCore/unit_tests/HandleArbitraryRequest/HandleArbitraryReq.t.sol b/test/PushCore/unit_tests/HandleArbitraryRequest/HandleArbitraryReq.t.sol index 3322904b..e08fca1c 100644 --- a/test/PushCore/unit_tests/HandleArbitraryRequest/HandleArbitraryReq.t.sol +++ b/test/PushCore/unit_tests/HandleArbitraryRequest/HandleArbitraryReq.t.sol @@ -29,7 +29,7 @@ contract HandleArbitraryReq is BasePushCoreTest { uint256 arbitraryFees = coreProxy.arbitraryReqFees(actor.charlie_channel_owner); vm.expectEmit(true, true, false, true); - emit ArbitraryRequest(actor.bob_channel_owner, actor.charlie_channel_owner, amount, feePercentage, 1); + emit ArbitraryRequest(BaseHelper.addressToBytes32(actor.bob_channel_owner), BaseHelper.addressToBytes32(actor.charlie_channel_owner), amount, feePercentage, 1); changePrank(actor.bob_channel_owner); coreProxy.handleArbitraryRequestData(1, feePercentage, actor.charlie_channel_owner, amount); uint256 feeAmount = BaseHelper.calcPercentage(amount, feePercentage); diff --git a/test/gas_snapshots/CommGasSnapshots/CompleteGasReport b/test/gas_snapshots/CommGasSnapshots/CompleteGasReport index 0120c566..11092109 100644 --- a/test/gas_snapshots/CommGasSnapshots/CompleteGasReport +++ b/test/gas_snapshots/CommGasSnapshots/CompleteGasReport @@ -22,5 +22,4 @@ | subscribeViaCore | 44267 | 109255 | 139166 | 167566 | 432 | | transferPushChannelAdminControl | 7470 | 8332 | 7607 | 10645 | 4 | | unSubscribeViaCore | 4010 | 4010 | 4010 | 4010 | 30 | -| unsubscribeBySig | 9498 | 16569 | 16569 | 23641 | 2 | -| userChatData | 1342 | 4842 | 1342 | 11842 | 3 | \ No newline at end of file +| unsubscribeBySig | 9498 | 16569 | 16569 | 23641 | 2 | \ No newline at end of file diff --git a/test/utils/Events.sol b/test/utils/Events.sol index dd39eb68..7f7ca2a6 100644 --- a/test/utils/Events.sol +++ b/test/utils/Events.sol @@ -11,24 +11,25 @@ abstract contract CoreEvents { event ChannelBlocked(bytes32 indexed channel); event TimeBoundChannelDestroyed(address indexed channel, uint256 indexed amountRefunded); event IncentivizedChatReqReceived( - address requestSender, - address requestReceiver, + bytes32 requestSender, + bytes32 requestReceiver, uint256 amountForReqReceiver, uint256 feePoolAmount, uint256 timestamp ); event ChatIncentiveClaimed(address indexed user, uint256 indexed amountClaimed); - event ChannelVerified(bytes32 indexed channel, address indexed verifier); - event ChannelVerificationRevoked(bytes32 indexed channel, address indexed revoker); + event ChannelVerified(bytes32 indexed channel, bytes32 indexed verifier); + event ChannelVerificationRevoked(bytes32 indexed channel, bytes32 indexed revoker); event ChannelStateUpdate(bytes32 indexed channel, uint256 amountRefunded, uint256 amountDeposited); event ArbitraryRequest( - address indexed sender, - address indexed receiver, + bytes32 indexed sender, + bytes32 indexed receiver, uint256 amountDeposited, GenericTypes.Percentage feePercent, uint256 indexed feeId ); event ArbitraryRequestFeesClaimed(address indexed user, uint256 indexed amountClaimed); + event ChannelNotifcationSettingsAdded(bytes32 _channel, uint256 totalNotifOptions, string _notifSettings, string _notifDescription); } abstract contract CommEvents {