Skip to content

Commit

Permalink
Add test for setTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Nov 2, 2023
1 parent 2fd26ac commit 3e83644
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crosschain-resolver/contracts/L1Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ contract L1Resolver is EVMFetchTarget {
// isApprovedForAll
// isApprovedFor
address owner = ens.owner(node);
if (owner == address(nameWrapper)) {
owner = nameWrapper.ownerOf(uint256(node));
if (owner != address(0) && owner == address(nameWrapper)) {
owner = nameWrapper.ownerOf(uint256(node));
}
return owner == msg.sender;
}
Expand Down
21 changes: 17 additions & 4 deletions crosschain-resolver/test/testResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe('Crosschain Resolver', () => {
let verifier: Contract;
let target: Contract;
let l2contract: Contract;
let signerAddress
let ens: Contract;
let signerAddress, resolverAddress

before(async () => {
// Hack to get a 'real' ethers provider from hardhat. The default `HardhatProvider`
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('Crosschain Resolver', () => {
'ENSRegistry',
signer
);
const ens = await ensFactory.deploy();
ens = await ensFactory.deploy();
const ensAddress = await ens.getAddress()
const l1VerifierFactory = await ethers.getContractFactory(
'L1Verifier',
Expand All @@ -101,6 +102,7 @@ describe('Crosschain Resolver', () => {
await tx.wait()
const logs = await l2factoryContract.queryFilter("NewDelegatableResolver")
const [resolver] = logs[0].args
resolverAddress = resolver
const testL1Factory = await ethers.getContractFactory(
'L1Resolver',
signer
Expand All @@ -112,10 +114,21 @@ describe('Crosschain Resolver', () => {

// Mine an empty block so we have something to prove against
await provider.send('evm_mine', []);
l2contract = impl.attach(resolver)
await target.setTarget(node, resolver)
l2contract = impl.attach(resolverAddress)
await target.setTarget(node, resolverAddress)
});

it("should not allow non owner to set target", async() => {
const incorrectnode = ethers.namehash('notowned.eth')
// For some reason expect().to.be.reverted isn't working
// Throwing Error: missing revert data (action="estimateGas"...
try{
await target.setTarget(incorrectnode, resolverAddress)
}catch(e){
}
expect(await target.getTarget(incorrectnode)).to.equal(EMPTY_ADDRESS);
})

it("should test empty ETH Address", async() => {
const addr = '0x0000000000000000000000000000000000000000'
await l2contract.clearRecords(node)
Expand Down

0 comments on commit 3e83644

Please sign in to comment.