Original Repository:
smartcontractkit/ccip-cross-chain-name-service
Forked Repository Reason:
I forked this repository to implement tests for the Cross Chain Name Service project using the CCIPLocalSimulator.
Issue Encountered:
While using CCIPLocalSimulator for testing, I encountered the following issue, referenced in GitHub issue #17. The primary challenge is that even after resolving the Unauthorized()
error, an AlreadyTaken()
error would occur. This happens because CCIPLocalSimulator simulates cross-chain behavior on the same blockchain, which leads to duplicate calls when attempting to register a name.
To overcome this, I made the following modifications:
-
Installing Foundry in the Hardhat Project:
npm install --save-dev @nomicfoundation/hardhat-foundry
-
Changes to the CrossChainNameServiceLookup Contract:
- I updated the
onlyCrossChainNameService
modifier to hardcode the address ofccnsRegister
. This ensures thatccnsRegister
is authorized to call theregister()
function. - Updated Modifier:
modifier onlyCrossChainNameService() { if (msg.sender != s_crossChainNameService && msg.sender != 0xF62849F9A0B5Bf2913b396098F7c7019b51A820a) { revert Unauthorized(); } _; }
- I updated the
-
Changes to the CrossChainNameServiceRegister Contract:
- I removed the last line from the
register()
function:i_lookup.register(_name, msg.sender);
- Reasoning: This avoids the duplication of registration calls on the source chain, which would otherwise result in an
AlreadyTaken
error when attempting to register the same name twice. The registration on the source chain now only happens via cross-chain messages to avoid conflicts.
- I removed the last line from the
-
Testing Contract:
- I created a test contract
CrossChainNameServiceTest
to verify the implementation of cross-chain name registration using the modified contracts and the CCIPLocalSimulator.
- I created a test contract
The modified approach ensures that name registration is completed only via cross-chain messages, without redundant calls on the source chain. This prevents the AlreadyTaken
error and allows the CCIPLocalSimulator to simulate cross-chain behavior more effectively, even though it operates on the same blockchain for testing purposes.