-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ensdomains/immutable-tokens-test
fixed tests
- Loading branch information
Showing
12 changed files
with
364 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Contract tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: "recursive" | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
|
||
- name: Use Bun 1.1.16 | ||
uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: 1.1.16 | ||
|
||
- run: bun install --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: bun --filter contracts test:hardhat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { HardhatUserConfig } from "hardhat/config"; | ||
|
||
import "@nomicfoundation/hardhat-foundry"; | ||
import "@nomicfoundation/hardhat-verify"; | ||
import "@nomicfoundation/hardhat-viem"; | ||
import "./tasks/esm_fix.cjs"; | ||
|
||
import("@ensdomains/hardhat-chai-matchers-viem"); | ||
|
||
const config = { | ||
solidity: { | ||
version: "0.8.25", | ||
settings: { | ||
evmVersion: "cancun", | ||
}, | ||
}, | ||
} satisfies HardhatUserConfig; | ||
|
||
export default config; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fs = require("fs/promises"); | ||
import task_names = require("hardhat/builtin-tasks/task-names"); | ||
import config = require("hardhat/config"); | ||
import path = require("path"); | ||
|
||
config | ||
.subtask(task_names.TASK_COMPILE_SOLIDITY) | ||
.setAction(async (_, { config }, runSuper) => { | ||
const superRes = await runSuper(); | ||
|
||
try { | ||
await fs.writeFile( | ||
path.join(config.paths.artifacts, "package.json"), | ||
'{ "type": "commonjs" }' | ||
); | ||
} catch (error) { | ||
console.error("Error writing package.json: ", error); | ||
} | ||
|
||
return superRes; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { loadFixture } from "@nomicfoundation/hardhat-toolbox-viem/network-helpers.js"; | ||
import { expect } from "chai"; | ||
import { fromHex, getAddress, labelhash, zeroAddress } from "viem"; | ||
import { deployEnsFixture, registerName } from "./fixtures/deployEnsFixture.js"; | ||
|
||
describe("ETHRegistry", function () { | ||
it("registers names", async () => { | ||
const { accounts, ethRegistry } = await loadFixture(deployEnsFixture); | ||
|
||
const tx = await registerName({ ethRegistry, label: "test2" }); | ||
const expectedId = | ||
fromHex(labelhash("test2"), "bigint") & | ||
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8n; | ||
|
||
await expect(ethRegistry) | ||
.transaction(tx) | ||
.toEmitEvent("TransferSingle") | ||
.withArgs( | ||
getAddress(accounts[0].address), | ||
zeroAddress, | ||
accounts[0].address, | ||
expectedId, | ||
1n | ||
); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId]) | ||
).resolves.toEqualAddress(accounts[0].address); | ||
}); | ||
|
||
it("registers locked names", async () => { | ||
const { accounts, ethRegistry } = await loadFixture(deployEnsFixture); | ||
|
||
const tx = await registerName({ | ||
ethRegistry, | ||
label: "test2", | ||
subregistryLocked: true, | ||
resolverLocked: true, | ||
}); | ||
const expectedId = | ||
(fromHex(labelhash("test2"), "bigint") & | ||
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8n) | | ||
3n; | ||
|
||
await expect(ethRegistry) | ||
.transaction(tx) | ||
.toEmitEvent("TransferSingle") | ||
.withArgs( | ||
getAddress(accounts[0].address), | ||
zeroAddress, | ||
accounts[0].address, | ||
expectedId, | ||
1n | ||
); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId]) | ||
).resolves.toEqualAddress(accounts[0].address); | ||
}); | ||
|
||
it("supports locking names", async () => { | ||
const { accounts, ethRegistry } = await loadFixture(deployEnsFixture); | ||
|
||
await registerName({ ethRegistry, label: "test2" }); | ||
const expectedId = | ||
fromHex(labelhash("test2"), "bigint") & | ||
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8n; | ||
|
||
await expect( | ||
ethRegistry.read.ownerOf([expectedId]) | ||
).resolves.toEqualAddress(accounts[0].address); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId | 3n]) | ||
).resolves.toEqualAddress(zeroAddress); | ||
await ethRegistry.write.lock([expectedId, 0x3]); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId | 3n]) | ||
).resolves.toEqualAddress(accounts[0].address); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId]) | ||
).resolves.toEqualAddress(zeroAddress); | ||
}); | ||
|
||
it("cannot unlock names", async () => { | ||
const { accounts, ethRegistry } = await loadFixture(deployEnsFixture); | ||
|
||
await registerName({ | ||
ethRegistry, | ||
label: "test2", | ||
subregistryLocked: true, | ||
resolverLocked: true, | ||
}); | ||
const expectedId = | ||
(fromHex(labelhash("test2"), "bigint") & | ||
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8n) | | ||
3n; | ||
|
||
await expect( | ||
ethRegistry.read.ownerOf([expectedId]) | ||
).resolves.toEqualAddress(accounts[0].address); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId ^ 3n]) | ||
).resolves.toEqualAddress(zeroAddress); | ||
|
||
await ethRegistry.write.lock([expectedId, 0x0]); | ||
|
||
await expect( | ||
ethRegistry.read.ownerOf([expectedId]) | ||
).resolves.toEqualAddress(accounts[0].address); | ||
await expect( | ||
ethRegistry.read.ownerOf([expectedId ^ 3n]) | ||
).resolves.toEqualAddress(zeroAddress); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.