You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SPDX-License-Identifier: MITpragma solidity0.8.19;
import {CrossChainNameServiceLookup} from"contracts/CrossChainNameServiceLookup.sol";
import {CrossChainNameServiceReceiver} from"contracts/CrossChainNameServiceReceiver.sol";
import {CrossChainNameServiceRegister} from"contracts/CrossChainNameServiceRegister.sol";
import {Test, console} from"lib/forge-std/src/Test.sol";
import {CCIPLocalSimulator} from"lib/chainlink-local/src/ccip/CCIPLocalSimulator.sol";
import {
IRouterClient, WETH9, LinkToken, BurnMintERC677Helper
} from"lib/chainlink-local/src/ccip/CCIPLocalSimulator.sol";
contractCrossChainNameServiceTestisTest {
CCIPLocalSimulator public ccipLocalSimulator;
CrossChainNameServiceRegister public ccnsRegister;
CrossChainNameServiceReceiver public ccnsReveiver;
CrossChainNameServiceLookup public ccnsLookup;
uint256public constant GAS_LIMIT =200000;
uint256public constant REQUEST_LINK_AMOUT =1ether;
addresspublic Alice =makeAddr("Alice");
uint64public chainSelector;
IRouterClient public sourceRouter;
IRouterClient public destinationRouter;
WETH9 public wrappedNative;
LinkToken public linkToken;
BurnMintERC677Helper public ccipBnM;
BurnMintERC677Helper public ccipLnM;
function setUp() public {
ccipLocalSimulator =newCCIPLocalSimulator();
(chainSelector, sourceRouter, destinationRouter, wrappedNative, linkToken, ccipBnM, ccipLnM) =
ccipLocalSimulator.configuration();
ccnsLookup =newCrossChainNameServiceLookup();
ccnsRegister =newCrossChainNameServiceRegister(address(sourceRouter), address(ccnsLookup));
ccnsReveiver =newCrossChainNameServiceReceiver(address(destinationRouter), address(ccnsLookup), chainSelector);
ccnsLookup.setCrossChainNameServiceAddress(address(ccnsReveiver));
console.log("Authorized address set to:", address(ccnsReveiver));
}
function testCCNSSuccess() public {
// Arrange
ccnsRegister.enableChain(chainSelector, address(ccnsReveiver), GAS_LIMIT);
ccipLocalSimulator.requestLinkFromFaucet(address(ccnsRegister), REQUEST_LINK_AMOUT);
// ACT
vm.prank(Alice);
ccnsRegister.register("alice.ccns");
address expectAddress = ccnsLookup.lookup("alice.ccns");
// Assertassert(expectAddress == Alice);
}
}
Problem:
While using CCIPLocalSimulator for local testing, it seems that both sending and receiving occur on the same chain, simulating cross-chain behavior. When the following part of the test is executed:
However, during the execution of ccnsRegister.register("alice.ccns");, the CrossChainNameServiceRegister contract first calls the MockCCIPRouter to send the message. The CrossChainNameServiceReceiver contract’s ccipReceive function receives the message. The CrossChainNameServiceReceiver then calls the CrossChainNameServiceLookup contract's register function to map the domain name and user address to the destination chain.
Once the registration is completed on all destination chains, it tries to call i_lookup.register(_name, msg.sender) on the source chain. At this point, the CrossChainNameServiceAddress is still set to CrossChainNameServiceReceiver (ccnsReveiver), not CrossChainNameServiceRegister (ccnsRegister), causing the function to revert with an Unauthorized() error.
Addition:
If I remove the onlyCrossChainNameService modifier from the CrossChainNameServiceLookup contract’s register function and run the test again, it throws a [Revert] AlreadyTaken() error, proving that the issue exists.
Expected Solution:
Cross-chain registration should be split into two functions: one for source chain registration and another for handling cross-chain registration. Alternatively, the authorization mechanism should be adjusted to accommodate the multi-chain registration process.
The text was updated successfully, but these errors were encountered:
Issue: Unauthorized Error during Local Testing with CCIPLocalSimulator in CrossChainNameService Project
Description:
When I clone the
smartcontractkit/ccip-cross-chain-name-service
repository: https://github.com/smartcontractkit/ccip-cross-chain-name-service into VSCode and follow the documentation Hardhat and Foundry Integration, I install Foundry in the Hardhat project using:I wanted to use
CCIPLocalSimulator
for local testing of the CrossChainNameService project. After running:I wrote the following test code:
Problem:
While using
CCIPLocalSimulator
for local testing, it seems that both sending and receiving occur on the same chain, simulating cross-chain behavior. When the following part of the test is executed:An issue arises.
The
CrossChainNameServiceLookup
contract'sregister
function has amodifier onlyCrossChainNameService
, and we need to set:However, during the execution of
ccnsRegister.register("alice.ccns");
, theCrossChainNameServiceRegister
contract first calls theMockCCIPRouter
to send the message. TheCrossChainNameServiceReceiver
contract’sccipReceive
function receives the message. TheCrossChainNameServiceReceiver
then calls theCrossChainNameServiceLookup
contract'sregister
function to map the domain name and user address to the destination chain.Once the registration is completed on all destination chains, it tries to call
i_lookup.register(_name, msg.sender)
on the source chain. At this point, theCrossChainNameServiceAddress
is still set toCrossChainNameServiceReceiver (ccnsReveiver)
, notCrossChainNameServiceRegister (ccnsRegister)
, causing the function to revert with anUnauthorized()
error.Addition:
If I remove the
onlyCrossChainNameService
modifier from theCrossChainNameServiceLookup
contract’sregister
function and run the test again, it throws a[Revert] AlreadyTaken()
error, proving that the issue exists.Expected Solution:
Cross-chain registration should be split into two functions: one for source chain registration and another for handling cross-chain registration. Alternatively, the authorization mechanism should be adjusted to accommodate the multi-chain registration process.
The text was updated successfully, but these errors were encountered: