From 8627e16e4dae2111de116e5cc5c7ea2ee4f5aad2 Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Fri, 29 Nov 2024 14:32:56 +0800 Subject: [PATCH 01/21] setup e2e --- .gitignore | 3 + hardhat.config.ts | 13 +- package.json | 10 +- test/hardhat/e2e/fixtures.ts | 7 + test/hardhat/e2e/ipa/ipa.test.ts | 30 +++ test/hardhat/e2e/utils/nftHelper.ts | 32 +++ test/hardhat/test.js | 27 --- yarn.lock | 292 +++++++++++++++++++++++++--- 8 files changed, 352 insertions(+), 62 deletions(-) create mode 100644 test/hardhat/e2e/fixtures.ts create mode 100644 test/hardhat/e2e/ipa/ipa.test.ts create mode 100644 test/hardhat/e2e/utils/nftHelper.ts delete mode 100644 test/hardhat/test.js diff --git a/.gitignore b/.gitignore index c2c31fad8..853a5bdb1 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ typechain # converage lcov.info +# test +mochawesome-report + diff --git a/hardhat.config.ts b/hardhat.config.ts index a130c0efd..37566427e 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -12,6 +12,7 @@ import { HardhatConfig, HardhatUserConfig } from "hardhat/types" import "hardhat-contract-sizer" // npx hardhat size-contracts import "solidity-coverage" import "solidity-docgen" +import "@nomicfoundation/hardhat-chai-matchers" require("dotenv").config() @@ -30,6 +31,10 @@ const USE_TENDERLY = process.env.USE_TENDERLY === "true" const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "key" const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "key" +const DEVNET_URL = process.env.DEVNET_URL || "http://" +const DEVNET_CHAINID = Number(process.env.DEVNET_CHAINID) || 1513 +const DEVNET_PRIVATEKEY = process.env.DEVNET_PRIVATEKEY || "0xkey" + if (USE_TENDERLY) { tdly.setup({ automaticVerifications: true, @@ -41,7 +46,7 @@ const config: HardhatUserConfig = { solidity: { compilers: [ { - version: "0.8.23", + version: "0.8.26", }, ], settings: { @@ -62,6 +67,11 @@ const config: HardhatUserConfig = { hardhat: { chainId: 31337, }, + odyssey: { + chainId: DEVNET_CHAINID, + url: DEVNET_URL, + accounts: [DEVNET_PRIVATEKEY], + }, localhost: { chainId: 31337, url: "http://127.0.0.1:8545/", @@ -102,6 +112,7 @@ const config: HardhatUserConfig = { }, mocha: { timeout: 20_000, + reporter: "mochawesome", }, etherscan: { apiKey: ETHERSCAN_API_KEY, diff --git a/package.json b/package.json index 45c35069a..b21165f21 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "docgen": "hardhat docgen" }, "devDependencies": { + "@nomicfoundation/hardhat-chai-matchers": "^2.0.8", "@nomicfoundation/hardhat-ethers": "^3.0.5", "@nomicfoundation/hardhat-foundry": "^1.1.1", "@nomicfoundation/hardhat-verify": "^2.0.3", @@ -29,8 +30,11 @@ "@tenderly/hardhat-tenderly": "^2.2.1", "@typechain/ethers-v6": "^0.5.1", "@typechain/hardhat": "^9.1.0", + "@types/chai": "4", + "@types/mocha": "^10.0.10", + "@types/node": "^22.10.0", "base64-sol": "^1.1.0", - "chai": "^5.0.3", + "chai": "4", "dotenv": "^16.4.1", "ds-test": "https://github.com/dapphub/ds-test", "eslint": "^8.56.0", @@ -45,6 +49,7 @@ "husky": "^8.0.0", "minimatch": "^9.0.3", "mocha": "^10.2.0", + "mochawesome": "^7.1.3", "prettier": "^3.0.0", "prettier-plugin-solidity": "^1.1.0", "solhint": "^4.1.1", @@ -53,7 +58,8 @@ "solidity-coverage": "^0.8.6", "solidity-docgen": "^0.6.0-beta.36", "ts-node": "^10.9.2", - "typechain": "^8.3.2" + "typechain": "^8.3.2", + "typescript": "^5.7.2" }, "dependencies": { "@openzeppelin/contracts": "5.0.2", diff --git a/test/hardhat/e2e/fixtures.ts b/test/hardhat/e2e/fixtures.ts new file mode 100644 index 000000000..206ff6e9b --- /dev/null +++ b/test/hardhat/e2e/fixtures.ts @@ -0,0 +1,7 @@ +import hre from "hardhat"; + +export async function getIpAssetRegistry() { + const contractAddress = "0x28E59E91C0467e89fd0f0438D47Ca839cDfEc095"; + const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", contractAddress); + return ipAssetRegistry; +}; \ No newline at end of file diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts new file mode 100644 index 000000000..d95eb303b --- /dev/null +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -0,0 +1,30 @@ +import { expect } from "chai" +import { getIpAssetRegistry } from "../fixtures" +import { mintNFT } from "../utils/nftHelper" + +describe.only("IPA", function () { + it("Create ipa", async function () { + + const tokenId = await mintNFT(); + const ipaContract = await getIpAssetRegistry(); + + const ipId = await expect( + ipaContract.register(1315, "0x7411143ef90b7744fc8233f01cce0b2c379651b3", tokenId) + ).not.to.be.rejectedWith(Error); + + console.log("ipa", ipId) + + const isRegistered = await expect( + ipaContract.isRegistered(ipId) + ).not.to.be.rejectedWith(Error) + + expect(isRegistered).to.equal(true) + + // const paused = await ipaContract.paused(); + // const authority = await ipaContract.authority(); + // console.log("authority", authority); + // assert that the value is correct + // expect(paused).to.equal(false); + }) +}) + diff --git a/test/hardhat/e2e/utils/nftHelper.ts b/test/hardhat/e2e/utils/nftHelper.ts new file mode 100644 index 000000000..6497da699 --- /dev/null +++ b/test/hardhat/e2e/utils/nftHelper.ts @@ -0,0 +1,32 @@ +import { ethers } from "ethers" +import hre from "hardhat" + +export async function mintNFT(walletAddress?: string, wallet?: ethers.Wallet): Promise { + let tokenId: any + const contractAbi = [ + { + inputs: [{ internalType: "address", name: "to", type: "address" }], + name: "mint", + outputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }], + stateMutability: "nonpayable", + type: "function", + }, + ] + + const nftContract = await hre.ethers.getContractAt(contractAbi, "0x7411143ef90b7744fc8233f01cce0b2c379651b3"); + + const [owner] = await hre.ethers.getSigners(); + const address = walletAddress || owner.address + + const tx = await nftContract.mint(address) + const receipt = await tx.wait() + + const logs = receipt.logs + + if (logs[0].topics[3]) { + tokenId = parseInt(logs[0].topics[3], 16) + console.log(`Minted NFT tokenId: ${tokenId}`) + } + + return tokenId +} diff --git a/test/hardhat/test.js b/test/hardhat/test.js deleted file mode 100644 index 4c7f233e8..000000000 --- a/test/hardhat/test.js +++ /dev/null @@ -1,27 +0,0 @@ -const { expect } = require("chai") -const { ethers } = require("hardhat") - -describe("Counter.sol: Unit Test", function () { - let Counter - let counter - beforeEach(async function () { - // Get the ContractFactory and Signers here. - Counter = await ethers.getContractFactory("Counter") - counter = await Counter.deploy() - counter.setNumber(0) - }) - - describe("Test Increment", function () { - it("Increase counter", async function () { - counter.increment() - expect(await counter.number()).to.equal(1) - }) - }) - - describe("Test Set Number", function () { - it("Set number", async function () { - counter.setNumber(2) - expect(await counter.number()).to.equal(2) - }) - }) -}) diff --git a/yarn.lock b/yarn.lock index 7a2df0de8..b80341a1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -745,6 +745,16 @@ mcl-wasm "^0.7.1" rustbn.js "~0.2.0" +"@nomicfoundation/hardhat-chai-matchers@^2.0.8": + version "2.0.8" + resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-chai-matchers/-/hardhat-chai-matchers-2.0.8.tgz#9c7cfc4ad0f0a5e9cf16aba8ab668c02f6e273aa" + integrity sha512-Z5PiCXH4xhNLASROlSUOADfhfpfhYO6D7Hn9xp8PddmHey0jq704cr6kfU8TRrQ4PUZbpfsZadPj+pCfZdjPIg== + dependencies: + "@types/chai-as-promised" "^7.1.3" + chai-as-promised "^7.1.1" + deep-eql "^4.0.1" + ordinal "^1.0.3" + "@nomicfoundation/hardhat-ethers@^3.0.4", "@nomicfoundation/hardhat-ethers@^3.0.5": version "3.0.5" resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-ethers/-/hardhat-ethers-3.0.5.tgz#0422c2123dec7c42e7fb2be8e1691f1d9708db56" @@ -1169,6 +1179,25 @@ dependencies: "@types/node" "*" +"@types/chai-as-promised@^7.1.3": + version "7.1.8" + resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz#f2b3d82d53c59626b5d6bbc087667ccb4b677fe9" + integrity sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw== + dependencies: + "@types/chai" "*" + +"@types/chai@*": + version "5.0.1" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-5.0.1.tgz#2c3705555cf11f5f59c836a84c44afcfe4e5689d" + integrity sha512-5T8ajsg3M/FOncpLYW7sdOcD6yf4+722sze/tc4KQV0P8Z2rAr3SAuHCIkYmYpt8VbcQlnz8SxlOlPQYefe4cA== + dependencies: + "@types/deep-eql" "*" + +"@types/chai@4": + version "4.3.20" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.20.tgz#cb291577ed342ca92600430841a00329ba05cecc" + integrity sha512-/pC9HAB5I/xMlc5FP77qjCnI16ChlJfW0tGa0IUcFn38VJrTV6DeZ60NU5KZBtaOZqjdpwTWohz5HU1RrhiYxQ== + "@types/concat-stream@^1.6.0": version "1.6.1" resolved "https://registry.yarnpkg.com/@types/concat-stream/-/concat-stream-1.6.1.tgz#24bcfc101ecf68e886aaedce60dfd74b632a1b74" @@ -1176,6 +1205,11 @@ dependencies: "@types/node" "*" +"@types/deep-eql@*": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@types/deep-eql/-/deep-eql-4.0.2.tgz#334311971d3a07121e7eb91b684a605e7eea9cbd" + integrity sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw== + "@types/form-data@0.0.33": version "0.0.33" resolved "https://registry.yarnpkg.com/@types/form-data/-/form-data-0.0.33.tgz#c9ac85b2a5fd18435b8c85d9ecb50e6d6c893ff8" @@ -1206,6 +1240,11 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== +"@types/mocha@^10.0.10": + version "10.0.10" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.10.tgz#91f62905e8d23cbd66225312f239454a23bebfa0" + integrity sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q== + "@types/node@*": version "20.11.16" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.16.tgz#4411f79411514eb8e2926f036c86c9f0e4ec6708" @@ -1223,6 +1262,13 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.60.tgz#35f3d6213daed95da7f0f73e75bcc6980e90597b" integrity sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw== +"@types/node@^22.10.0": + version "22.10.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.0.tgz#89bfc9e82496b9c7edea3382583fa94f75896e81" + integrity sha512-XC70cRZVElFHfIUB40FgZOBbgJYFKKMa5nb9lxcwYstFG/Mi+/Y0bGS+rs6Dmhmkpq4pnNiLiuZAbc02YCOnmA== + dependencies: + undici-types "~6.20.0" + "@types/node@^8.0.0": version "8.10.66" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.66.tgz#dd035d409df322acc83dff62a602f12a5783bbb3" @@ -1515,10 +1561,10 @@ asap@~2.0.6: resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" integrity sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA== -assertion-error@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-2.0.1.tgz#f641a196b335690b1070bf00b6e7593fec190bf7" - integrity sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA== +assertion-error@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" + integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== ast-parents@^0.0.1: version "0.0.1" @@ -1821,16 +1867,25 @@ cbor@^9.0.0: dependencies: nofilter "^3.1.0" -chai@^5.0.3: - version "5.0.3" - resolved "https://registry.yarnpkg.com/chai/-/chai-5.0.3.tgz#db8e109373b86e7fb33d3ef0d0116f0fa8019066" - integrity sha512-wKGCtYv2kVY5WEjKqQ3fSIZWtTFveZCtzinhTZbx3/trVkxefiwovhpU9kRVCwxvKKCEjTWXPdM1/T7zPoDgow== +chai-as-promised@^7.1.1: + version "7.1.2" + resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.2.tgz#70cd73b74afd519754161386421fb71832c6d041" + integrity sha512-aBDHZxRzYnUYuIAIPBH2s511DjlKPzXNlXSGFC8CwmroWQLfrW0LtE1nK3MAwwNhJPa9raEjNCmRoFpG0Hurdw== + dependencies: + check-error "^1.0.2" + +chai@4: + version "4.5.0" + resolved "https://registry.yarnpkg.com/chai/-/chai-4.5.0.tgz#707e49923afdd9b13a8b0b47d33d732d13812fd8" + integrity sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw== dependencies: - assertion-error "^2.0.1" - check-error "^2.0.0" - deep-eql "^5.0.1" - loupe "^3.1.0" - pathval "^2.0.0" + assertion-error "^1.1.0" + check-error "^1.0.3" + deep-eql "^4.1.3" + get-func-name "^2.0.2" + loupe "^2.3.6" + pathval "^1.1.1" + type-detect "^4.1.0" chalk@^2.4.2: version "2.4.2" @@ -1854,10 +1909,12 @@ chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" integrity sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA== -check-error@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/check-error/-/check-error-2.0.0.tgz#589a4f201b6256fd93a2d165089fe43d2676d8c6" - integrity sha512-tjLAOBHKVxtPoHe/SA7kNOMvhCRdCJ3vETdeY0RuAc9popf+hyaSV6ZEg9hr4cpWF7jmo/JSWEnLDrnijS9Tog== +check-error@^1.0.2, check-error@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.3.tgz#a6502e4312a7ee969f646e83bb3ddd56281bd694" + integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg== + dependencies: + get-func-name "^2.0.2" chokidar@3.5.3: version "3.5.3" @@ -1951,6 +2008,15 @@ cliui@^7.0.2: strip-ansi "^6.0.0" wrap-ansi "^7.0.0" +cliui@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa" + integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.1" + wrap-ansi "^7.0.0" + color-convert@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" @@ -2127,6 +2193,11 @@ cross-spawn@^7.0.2: resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow== +dateformat@^4.5.1: + version "4.6.3" + resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5" + integrity sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA== + death@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/death/-/death-1.1.0.tgz#01aa9c401edd92750514470b8266390c66c67318" @@ -2151,10 +2222,12 @@ decompress-response@^6.0.0: dependencies: mimic-response "^3.1.0" -deep-eql@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-5.0.1.tgz#21ea2c0d561a4d08cdd99c417ac584e0fb121385" - integrity sha512-nwQCf6ne2gez3o1MxWifqkciwt0zhl0LO1/UwVu4uMBuPmflWM4oQ70XMqHqnBJA+nhzncaqL9HVL6KkHJ28lw== +deep-eql@^4.0.1, deep-eql@^4.1.3: + version "4.1.4" + resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.4.tgz#d0d3912865911bb8fac5afb4e3acfa6a28dc72b7" + integrity sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg== + dependencies: + type-detect "^4.0.0" deep-extend@^0.6.0, deep-extend@~0.6.0: version "0.6.0" @@ -2223,6 +2296,11 @@ diff@^4.0.1: resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +diff@^5.0.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531" + integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A== + difflib@^0.2.4: version "0.2.4" resolved "https://registry.yarnpkg.com/difflib/-/difflib-0.2.4.tgz#b5e30361a6db023176d562892db85940a718f47e" @@ -2381,6 +2459,11 @@ escalade@^3.1.1: resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27" integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA== +escape-html@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + integrity sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow== + escape-string-regexp@4.0.0, escape-string-regexp@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" @@ -2905,6 +2988,11 @@ fsevents@~2.3.2: resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== +fsu@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/fsu/-/fsu-1.1.1.tgz#bd36d3579907c59d85b257a75b836aa9e0c31834" + integrity sha512-xQVsnjJ/5pQtcKh+KjUoZGzVWn4uNkchxTF6Lwjr4Gf7nQr8fmUfhKJ62zE77+xQg9xnxi5KUps7XGs+VC986A== + function-bind@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" @@ -2935,7 +3023,7 @@ get-caller-file@^2.0.5: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-func-name@^2.0.1: +get-func-name@^2.0.1, get-func-name@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41" integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== @@ -3689,7 +3777,7 @@ js-sha3@0.8.0, js-sha3@^0.8.0: resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840" integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q== -js-tokens@^4.0.0: +"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== @@ -3734,6 +3822,11 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw== +json-stringify-safe@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" + integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA== + jsonfile@^2.1.0: version "2.4.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" @@ -3870,11 +3963,31 @@ lodash.clonedeep@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" integrity sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ== +lodash.isempty@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e" + integrity sha512-oKMuF3xEeqDltrGMfDxAPGIVMSSRv8tbRSODbrs4KGsRRLEhrW8N8Rd4DRgB2+621hY8A8XwwrTVhXWpxFvMzg== + lodash.isequal@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ== +lodash.isfunction@^3.0.9: + version "3.0.9" + resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051" + integrity sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw== + +lodash.isobject@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-3.0.2.tgz#3c8fb8d5b5bf4bf90ae06e14f2a530a4ed935e1d" + integrity sha512-3/Qptq2vr7WeJbB4KHUSKlq8Pl7ASXi3UG6CMbBm8WRtXi8+GHm7mKaU3urfpSEzWe2wCIChs6/sdocUsTKJiA== + +lodash.isstring@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + integrity sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw== + lodash.merge@^4.6.2: version "4.6.2" resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" @@ -3898,10 +4011,17 @@ log-symbols@4.1.0: chalk "^4.1.0" is-unicode-supported "^0.1.0" -loupe@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/loupe/-/loupe-3.1.0.tgz#46ef1a4ffee73145f5c0a627536d754787c1ea2a" - integrity sha512-qKl+FrLXUhFuHUoDJG7f8P8gEMHq9NFS0c6ghXG1J0rldmZFQZoNVv/vyirE9qwCIhWZDsvEFd1sbFu3GvRQFg== +loose-envify@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" + integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== + dependencies: + js-tokens "^3.0.0 || ^4.0.0" + +loupe@^2.3.6: + version "2.3.7" + resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.7.tgz#6e69b7d4db7d3ab436328013d37d1c8c3540c697" + integrity sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA== dependencies: get-func-name "^2.0.1" @@ -4101,6 +4221,40 @@ mocha@^10.0.0, mocha@^10.2.0: yargs-parser "20.2.4" yargs-unparser "2.0.0" +mochawesome-report-generator@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/mochawesome-report-generator/-/mochawesome-report-generator-6.2.0.tgz#65a30a11235ba7a68e1cf0ca1df80d764b93ae78" + integrity sha512-Ghw8JhQFizF0Vjbtp9B0i//+BOkV5OWcQCPpbO0NGOoxV33o+gKDYU0Pr2pGxkIHnqZ+g5mYiXF7GMNgAcDpSg== + dependencies: + chalk "^4.1.2" + dateformat "^4.5.1" + escape-html "^1.0.3" + fs-extra "^10.0.0" + fsu "^1.1.1" + lodash.isfunction "^3.0.9" + opener "^1.5.2" + prop-types "^15.7.2" + tcomb "^3.2.17" + tcomb-validation "^3.3.0" + validator "^13.6.0" + yargs "^17.2.1" + +mochawesome@^7.1.3: + version "7.1.3" + resolved "https://registry.yarnpkg.com/mochawesome/-/mochawesome-7.1.3.tgz#07b358138f37f5b07b51a1b255d84babfa36fa83" + integrity sha512-Vkb3jR5GZ1cXohMQQ73H3cZz7RoxGjjUo0G5hu0jLaW+0FdUxUwg3Cj29bqQdh0rFcnyV06pWmqmi5eBPnEuNQ== + dependencies: + chalk "^4.1.2" + diff "^5.0.0" + json-stringify-safe "^5.0.1" + lodash.isempty "^4.4.0" + lodash.isfunction "^3.0.9" + lodash.isobject "^3.0.2" + lodash.isstring "^4.0.1" + mochawesome-report-generator "^6.2.0" + strip-ansi "^6.0.1" + uuid "^8.3.2" + module-error@^1.0.1, module-error@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/module-error/-/module-error-1.0.2.tgz#8d1a48897ca883f47a45816d4fb3e3c6ba404d86" @@ -4199,7 +4353,7 @@ number-to-bn@1.7.0: bn.js "4.11.6" strip-hex-prefix "1.0.0" -object-assign@^4.1.0: +object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg== @@ -4245,6 +4399,11 @@ open@^8.4.0: is-docker "^2.1.1" is-wsl "^2.2.0" +opener@^1.5.2: + version "1.5.2" + resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598" + integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A== + optionator@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" @@ -4269,6 +4428,11 @@ optionator@^0.9.3: prelude-ls "^1.2.1" type-check "^0.4.0" +ordinal@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/ordinal/-/ordinal-1.0.3.tgz#1a3c7726a61728112f50944ad7c35c06ae3a0d4d" + integrity sha512-cMddMgb2QElm8G7vdaa02jhUNbTSrhsgAGUz1OokD83uJTwSUn+nKoNoKVVaRa08yF6sgfO7Maou1+bgLd9rdQ== + os-tmpdir@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -4381,10 +4545,10 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -pathval@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/pathval/-/pathval-2.0.0.tgz#7e2550b422601d4f6b8e26f1301bc8f15a741a25" - integrity sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA== +pathval@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d" + integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ== pbkdf2@^3.0.17: version "3.1.2" @@ -4468,6 +4632,15 @@ prompts@^2.4.2: kleur "^3.0.3" sisteransi "^1.0.5" +prop-types@^15.7.2: + version "15.8.1" + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" + integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== + dependencies: + loose-envify "^1.4.0" + object-assign "^4.1.1" + react-is "^16.13.1" + proper-lockfile@^4.1.1: version "4.1.2" resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-4.1.2.tgz#c8b9de2af6b2f1601067f98e01ac66baa223141f" @@ -4536,6 +4709,11 @@ rc@1.2.8: minimist "^1.2.0" strip-json-comments "~2.0.1" +react-is@^16.13.1: + version "16.13.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" + integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== + readable-stream@^2.2.2: version "2.3.8" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b" @@ -5265,6 +5443,18 @@ table@^6.8.0, table@^6.8.1: string-width "^4.2.3" strip-ansi "^6.0.1" +tcomb-validation@^3.3.0: + version "3.4.1" + resolved "https://registry.yarnpkg.com/tcomb-validation/-/tcomb-validation-3.4.1.tgz#a7696ec176ce56a081d9e019f8b732a5a8894b65" + integrity sha512-urVVMQOma4RXwiVCa2nM2eqrAomHROHvWPuj6UkDGz/eb5kcy0x6P0dVt6kzpUZtYMNoAqJLWmz1BPtxrtjtrA== + dependencies: + tcomb "^3.0.0" + +tcomb@^3.0.0, tcomb@^3.2.17: + version "3.2.29" + resolved "https://registry.yarnpkg.com/tcomb/-/tcomb-3.2.29.tgz#32404fe9456d90c2cf4798682d37439f1ccc386c" + integrity sha512-di2Hd1DB2Zfw6StGv861JoAF5h/uQVu/QJp2g8KVbtfKnoHdBQl5M32YWq6mnSYBQ1vFFrns5B1haWJL7rKaOQ== + tenderly@^0.9.0: version "0.9.0" resolved "https://registry.yarnpkg.com/tenderly/-/tenderly-0.9.0.tgz#7c661f02b1587d35923d54b62250789d027dfca5" @@ -5407,6 +5597,11 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" +type-detect@^4.0.0, type-detect@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.1.0.tgz#deb2453e8f08dcae7ae98c626b13dddb0155906c" + integrity sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw== + type-fest@^0.20.2: version "0.20.2" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" @@ -5487,6 +5682,11 @@ typescript@^5.2.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== +typescript@^5.7.2: + version "5.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.2.tgz#3169cf8c4c8a828cde53ba9ecb3d2b1d5dd67be6" + integrity sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg== + typical@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/typical/-/typical-4.0.0.tgz#cbeaff3b9d7ae1e2bbfaf5a4e6f11eccfde94fc4" @@ -5517,6 +5717,11 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== +undici-types@~6.20.0: + version "6.20.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433" + integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg== + undici@^5.14.0, undici@^5.28.2: version "5.28.4" resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" @@ -5571,6 +5776,11 @@ v8-compile-cache-lib@^3.0.1: resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== +validator@^13.6.0: + version "13.12.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f" + integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg== + web3-utils@^1.3.6: version "1.10.4" resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-1.10.4.tgz#0daee7d6841641655d8b3726baf33b08eda1cbec" @@ -5718,6 +5928,11 @@ yargs-parser@^20.2.2: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== +yargs-parser@^21.1.1: + version "21.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" + integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== + yargs-unparser@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-2.0.0.tgz#f131f9226911ae5d9ad38c432fe809366c2325eb" @@ -5741,6 +5956,19 @@ yargs@16.2.0: y18n "^5.0.5" yargs-parser "^20.2.2" +yargs@^17.2.1: + version "17.7.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269" + integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w== + dependencies: + cliui "^8.0.1" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.3" + y18n "^5.0.5" + yargs-parser "^21.1.1" + yn@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" From d97881fbdb32377dc00bf29a4337abd706b96baa Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Fri, 29 Nov 2024 17:02:29 +0800 Subject: [PATCH 02/21] update e2e struct --- test/hardhat/e2e/fixtures.ts | 7 ------- test/hardhat/e2e/ipa/ipa.test.ts | 19 +++++++++++-------- test/hardhat/e2e/license/license.test.ts | 9 +++++++++ test/hardhat/e2e/setup.ts | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 15 deletions(-) delete mode 100644 test/hardhat/e2e/fixtures.ts create mode 100644 test/hardhat/e2e/license/license.test.ts create mode 100644 test/hardhat/e2e/setup.ts diff --git a/test/hardhat/e2e/fixtures.ts b/test/hardhat/e2e/fixtures.ts deleted file mode 100644 index 206ff6e9b..000000000 --- a/test/hardhat/e2e/fixtures.ts +++ /dev/null @@ -1,7 +0,0 @@ -import hre from "hardhat"; - -export async function getIpAssetRegistry() { - const contractAddress = "0x28E59E91C0467e89fd0f0438D47Ca839cDfEc095"; - const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", contractAddress); - return ipAssetRegistry; -}; \ No newline at end of file diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts index d95eb303b..1bb1309bc 100644 --- a/test/hardhat/e2e/ipa/ipa.test.ts +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -1,21 +1,19 @@ +import "../setup" import { expect } from "chai" -import { getIpAssetRegistry } from "../fixtures" import { mintNFT } from "../utils/nftHelper" -describe.only("IPA", function () { +describe("IP Asset", function () { it("Create ipa", async function () { const tokenId = await mintNFT(); - const ipaContract = await getIpAssetRegistry(); - const ipId = await expect( - ipaContract.register(1315, "0x7411143ef90b7744fc8233f01cce0b2c379651b3", tokenId) - ).not.to.be.rejectedWith(Error); + this.ipAssetRegistry.register(1315, "0x7411143ef90b7744fc8233f01cce0b2c379651b3", tokenId) + ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); - console.log("ipa", ipId) + console.log("ipId", ipId) const isRegistered = await expect( - ipaContract.isRegistered(ipId) + this.ipAssetRegistry.isRegistered(ipId) ).not.to.be.rejectedWith(Error) expect(isRegistered).to.equal(true) @@ -26,5 +24,10 @@ describe.only("IPA", function () { // assert that the value is correct // expect(paused).to.equal(false); }) + + it("get ipa", async function () { + const paused = await this.ipAssetRegistry.paused(); + expect(paused).to.equal(false); + }) }) diff --git a/test/hardhat/e2e/license/license.test.ts b/test/hardhat/e2e/license/license.test.ts new file mode 100644 index 000000000..018f8a3b7 --- /dev/null +++ b/test/hardhat/e2e/license/license.test.ts @@ -0,0 +1,9 @@ +import "../setup"; +import { expect } from "chai"; + +describe("License", function () { + it("license", async function () { + const name = await this.licensingModule.name(); + expect(name).to.equal("LICENSING_MODULE"); + }); +}) \ No newline at end of file diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts new file mode 100644 index 000000000..8cfd71271 --- /dev/null +++ b/test/hardhat/e2e/setup.ts @@ -0,0 +1,22 @@ +import hre from "hardhat"; + +before(async function () { + console.log(`================= Load Contract =================`); + const ipAssetRegistryAddress = "0x28E59E91C0467e89fd0f0438D47Ca839cDfEc095"; + this.ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", ipAssetRegistryAddress); + + const licenseRegistryAddress = "0xBda3992c49E98392e75E78d82B934F3598bA495f"; + this.licenseRegistry = await hre.ethers.getContractAt("LicenseRegistry", licenseRegistryAddress); + + const licenseTokenAddress = "0xB138aEd64814F2845554f9DBB116491a077eEB2D"; + this.licenseToken = await hre.ethers.getContractAt("LicenseToken", licenseTokenAddress); + + const licensingModule = "0x5a7D9Fa17DE09350F481A53B470D798c1c1aabae"; + this.licensingModule = await hre.ethers.getContractAt("LicensingModule", licensingModule); + + const groupNftAddress = "0x5d7C6e71290f034bED4C241eD78642204ad1178A"; + this.groupNft = await hre.ethers.getContractAt("GroupNFT", groupNftAddress); + + const groupingModuleAddress = "0xa731948cfE05135ad77d48C71f75066333Da78Bf"; + this.groupingModule = await hre.ethers.getContractAt("GroupingModule", groupingModuleAddress); +}); \ No newline at end of file From 2a0bcd5c254d74b75c55cc4a493795b84292af80 Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 11:10:26 +0800 Subject: [PATCH 03/21] add IP Assets tests --- test/hardhat/e2e/ipa/ipa.test.ts | 59 +++++++++++++++++++---------- test/hardhat/e2e/utils/nftHelper.ts | 6 ++- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts index 1bb1309bc..619b0c470 100644 --- a/test/hardhat/e2e/ipa/ipa.test.ts +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -1,33 +1,52 @@ import "../setup" import { expect } from "chai" import { mintNFT } from "../utils/nftHelper" +import hre from "hardhat"; describe("IP Asset", function () { - it("Create ipa", async function () { + let signers:any; + const chainId: number = 1315; + const erc721ContractAddress: string = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; + + this.beforeAll("Get Signers", async function () { + // Get the signers + signers = await hre.ethers.getSigners(); + }) + + it("NFT owner register IP Asset with an NFT token", async function () { + const tokenId = await mintNFT(signers[0].address); + const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); - const tokenId = await mintNFT(); const ipId = await expect( - this.ipAssetRegistry.register(1315, "0x7411143ef90b7744fc8233f01cce0b2c379651b3", tokenId) + connectedRegistry.register(chainId, erc721ContractAddress, tokenId) ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); + console.log("ipId:", ipId); - console.log("ipId", ipId) + expect(ipId).to.not.be.empty.and.to.be.a("HexString"); const isRegistered = await expect( - this.ipAssetRegistry.isRegistered(ipId) - ).not.to.be.rejectedWith(Error) - - expect(isRegistered).to.equal(true) - - // const paused = await ipaContract.paused(); - // const authority = await ipaContract.authority(); - // console.log("authority", authority); - // assert that the value is correct - // expect(paused).to.equal(false); - }) + connectedRegistry.isRegistered(ipId) + ).not.to.be.rejectedWith(Error); - it("get ipa", async function () { - const paused = await this.ipAssetRegistry.paused(); - expect(paused).to.equal(false); - }) -}) + expect(isRegistered).to.equal(true); + }); + + it("Non-NFT owner register IP asset with an NFT token", async function () { + const tokenId = await mintNFT(signers[0].address); + const connectedRegistry = this.ipAssetRegistry.connect(signers[1]); + + const ipId = await expect( + connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); + console.log("ipId:", ipId); + + expect(ipId).to.not.be.empty.and.to.be.a("HexString"); + + const isRegistered = await expect( + connectedRegistry.isRegistered(ipId) + ).not.to.be.rejectedWith(Error); + + expect(isRegistered).to.equal(true); + }); +}); diff --git a/test/hardhat/e2e/utils/nftHelper.ts b/test/hardhat/e2e/utils/nftHelper.ts index 6497da699..8553d3e4f 100644 --- a/test/hardhat/e2e/utils/nftHelper.ts +++ b/test/hardhat/e2e/utils/nftHelper.ts @@ -1,7 +1,9 @@ import { ethers } from "ethers" import hre from "hardhat" -export async function mintNFT(walletAddress?: string, wallet?: ethers.Wallet): Promise { + +export async function mintNFT(walletAddress?: string): Promise { + const erc721ContractAddress: string = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; let tokenId: any const contractAbi = [ { @@ -13,7 +15,7 @@ export async function mintNFT(walletAddress?: string, wallet?: ethers.Wallet): P }, ] - const nftContract = await hre.ethers.getContractAt(contractAbi, "0x7411143ef90b7744fc8233f01cce0b2c379651b3"); + const nftContract = await hre.ethers.getContractAt(contractAbi, erc721ContractAddress); const [owner] = await hre.ethers.getSigners(); const address = walletAddress || owner.address From a950814323460b6cd0e5978d3a39fecc3870123f Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Mon, 2 Dec 2024 11:26:53 +0800 Subject: [PATCH 04/21] update test struct --- hardhat.config.ts | 3 ++- test/hardhat/e2e/constants.ts | 23 ++++++++++++++++++ test/hardhat/e2e/grouping/group.ipa.test.ts | 22 +++++++++++++++++ test/hardhat/e2e/setup.ts | 26 +++++++-------------- 4 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 test/hardhat/e2e/constants.ts create mode 100644 test/hardhat/e2e/grouping/group.ipa.test.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 37566427e..4bf1c4d1a 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -34,6 +34,7 @@ const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "key" const DEVNET_URL = process.env.DEVNET_URL || "http://" const DEVNET_CHAINID = Number(process.env.DEVNET_CHAINID) || 1513 const DEVNET_PRIVATEKEY = process.env.DEVNET_PRIVATEKEY || "0xkey" +const DEVNET_USER1 = process.env.DEVNET_USER1 || "0xkey" if (USE_TENDERLY) { tdly.setup({ @@ -70,7 +71,7 @@ const config: HardhatUserConfig = { odyssey: { chainId: DEVNET_CHAINID, url: DEVNET_URL, - accounts: [DEVNET_PRIVATEKEY], + accounts: [DEVNET_PRIVATEKEY, DEVNET_USER1], }, localhost: { chainId: 31337, diff --git a/test/hardhat/e2e/constants.ts b/test/hardhat/e2e/constants.ts new file mode 100644 index 000000000..d05f001ba --- /dev/null +++ b/test/hardhat/e2e/constants.ts @@ -0,0 +1,23 @@ +export const AccessController = "0xf709c8001E94e2ca6F98b7fFBCd5BD3943E46D81"; +export const CoreMetadataModule = "0x89630Ccf23277417FBdfd3076C702F5248267e78"; +export const CoreMetadataViewModule = "0x6839De4A647eE2311bd765f615E09f7bd930ed25"; +export const DisputeModule = "0x692B47fa72eE7Ac0Ec617ea384a0cAD41098F712"; +export const EvenSplitGroupPool = "0xC384B56fD62d6679Cd62A2fE0dA3fe4560f33391"; +export const GroupNFT = "0x5d7C6e71290f034bED4C241eD78642204ad1178A"; +export const GroupingModule = "0xa731948cfE05135ad77d48C71f75066333Da78Bf"; +export const IPAccountImpl = "0x24F08796561d6E1AC08e82b68BF4d9500B374Af6"; +export const IPAssetRegistry = "0x28E59E91C0467e89fd0f0438D47Ca839cDfEc095"; +export const IPGraphACL = "0x680E66e4c7Df9133a7AFC1ed091089B32b89C4ae"; +export const IpRoyaltyVaultBeacon = "0x1F9CEDe79f5Af0a0A8E527Ad84e6C74f57D5F926"; +export const IpRoyaltyVaultImpl = "0x1081250219B16cc3903Aa2d2d1403A75c6A2F9f5"; +export const LicenseRegistry = "0xBda3992c49E98392e75E78d82B934F3598bA495f"; +export const LicenseToken = "0xB138aEd64814F2845554f9DBB116491a077eEB2D"; +export const LicensingModule = "0x5a7D9Fa17DE09350F481A53B470D798c1c1aabae"; +export const MockERC20 = "0x12A8b0DcC6e3bB0915638361D9D49942Da07F455"; +export const ModuleRegistry = "0x9F18c5723BC4Ee447CF9B01a8543D3b08b7F09C7"; +export const PILicenseTemplate = "0x58E2c909D557Cd23EF90D14f8fd21667A5Ae7a93"; +export const ProtocolAccessManager = "0xD22ff1C7e88aF45166aEFe000C4C0c4873Afa284"; +export const ProtocolPauseAdmin = "0x65C6Ec6Cc074eaf7ba3970C540b4379C9BcA8A67"; +export const RoyaltyModule = "0xEa6eD700b11DfF703665CCAF55887ca56134Ae3B"; +export const RoyaltyPolicyLAP = "0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6"; +export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd" \ No newline at end of file diff --git a/test/hardhat/e2e/grouping/group.ipa.test.ts b/test/hardhat/e2e/grouping/group.ipa.test.ts new file mode 100644 index 000000000..fcdd6c57d --- /dev/null +++ b/test/hardhat/e2e/grouping/group.ipa.test.ts @@ -0,0 +1,22 @@ +import "../setup" +import { expect } from "chai" +import { EvenSplitGroupPool } from "../constants" + +describe("Group IPA", function () { + it("Register Group IPA with whitelisted group pool", async function () { + + const groupId = await expect( + this.groupingModule.registerGroup(EvenSplitGroupPool) + ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[5].args[0]); + + console.log("groupId", groupId) + expect(groupId).to.be.properHex(40); + }); + + it("Register Group IPA with non-whitelisted group pool", async function () { + const nonWhitelistedGroupPool = "0xC384B56fD62d6679Cd62A2fE0dA3fe4560f33300" + await expect( + this.groupingModule.registerGroup(nonWhitelistedGroupPool) + ).to.be.rejectedWith(Error) + }); +}); \ No newline at end of file diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 8cfd71271..ee7422183 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -1,22 +1,14 @@ import hre from "hardhat"; +import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule } from "./constants"; before(async function () { console.log(`================= Load Contract =================`); - const ipAssetRegistryAddress = "0x28E59E91C0467e89fd0f0438D47Ca839cDfEc095"; - this.ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", ipAssetRegistryAddress); - - const licenseRegistryAddress = "0xBda3992c49E98392e75E78d82B934F3598bA495f"; - this.licenseRegistry = await hre.ethers.getContractAt("LicenseRegistry", licenseRegistryAddress); - - const licenseTokenAddress = "0xB138aEd64814F2845554f9DBB116491a077eEB2D"; - this.licenseToken = await hre.ethers.getContractAt("LicenseToken", licenseTokenAddress); - - const licensingModule = "0x5a7D9Fa17DE09350F481A53B470D798c1c1aabae"; - this.licensingModule = await hre.ethers.getContractAt("LicensingModule", licensingModule); - - const groupNftAddress = "0x5d7C6e71290f034bED4C241eD78642204ad1178A"; - this.groupNft = await hre.ethers.getContractAt("GroupNFT", groupNftAddress); - - const groupingModuleAddress = "0xa731948cfE05135ad77d48C71f75066333Da78Bf"; - this.groupingModule = await hre.ethers.getContractAt("GroupingModule", groupingModuleAddress); + this.ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", IPAssetRegistry); + this.licenseRegistry = await hre.ethers.getContractAt("LicenseRegistry", LicenseRegistry); + this.licenseToken = await hre.ethers.getContractAt("LicenseToken", LicenseToken); + this.licensingModule = await hre.ethers.getContractAt("LicensingModule", LicensingModule); + this.groupingModule = await hre.ethers.getContractAt("GroupingModule", GroupingModule); + + console.log(`================= Load Users =================`); + [this.owner, this.user1] = await hre.ethers.getSigners(); }); \ No newline at end of file From cea9a7096e82d1227c75befa4878be359c3aa80b Mon Sep 17 00:00:00 2001 From: jia57b Date: Mon, 2 Dec 2024 14:52:32 +0800 Subject: [PATCH 05/21] add ipa test --- test/hardhat/e2e/ipa/ipa.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts index 619b0c470..f38e038e8 100644 --- a/test/hardhat/e2e/ipa/ipa.test.ts +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -48,5 +48,18 @@ describe("IP Asset", function () { expect(isRegistered).to.equal(true); }); + + it("Register IP asset, the caller doesn’t have enough IP token", async function () { + const tokenId = await mintNFT(signers[0].address); + + // generate random wallet + const randomWallet = hre.ethers.Wallet.createRandom(); + const randomSigner = randomWallet.connect(hre.ethers.provider); + const connectedRegistry = this.ipAssetRegistry.connect(randomSigner); + + await expect( + connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + ).to.be.rejectedWith(`insufficient funds`, `"code": -32000, "message": "insufficient funds for gas * price + value: balance 0`); + }); }); From a1e59e44f1fab17752daa359172413afd66e92f8 Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 14:54:43 +0800 Subject: [PATCH 06/21] add tests for register license terms --- .../e2e/license/registerLicenseTerms.ts | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 test/hardhat/e2e/license/registerLicenseTerms.ts diff --git a/test/hardhat/e2e/license/registerLicenseTerms.ts b/test/hardhat/e2e/license/registerLicenseTerms.ts new file mode 100644 index 000000000..c4f3e29ca --- /dev/null +++ b/test/hardhat/e2e/license/registerLicenseTerms.ts @@ -0,0 +1,116 @@ +import "../setup"; +import { expect } from "chai"; +import hre from "hardhat"; +import { MockERC20, RoyaltyPolicyLAP, RoyaltyPolicyLRP } from "../constants"; + +const terms = { + transferable: true, + royaltyPolicy: hre.ethers.ZeroAddress, + defaultMintingFee: 0, + expiration: 0, + commercialUse: false, + commercialAttribution: false, + commercializerChecker: hre.ethers.ZeroAddress, + commercializerCheckerData: hre.ethers.ZeroAddress, + commercialRevShare: 0, + commercialRevCeiling: 0, + derivativesAllowed: true, + derivativesAttribution: false, + derivativesApproval: false, + derivativesReciprocal: false, + derivativeRevCeiling: 0, + currency: hre.ethers.ZeroAddress, + uri: "", +}; + +describe.only("License", function () { + let signers:any; + + this.beforeAll("Get Signers", async function () { + // Get the signers + signers = await hre.ethers.getSigners(); + }); + + it("Register non-commercial PIL license terms", async function () { + const connectedLicense = this.licenseTemplate.connect(signers[0]); + const tx = await expect( + connectedLicense.registerLicenseTerms(terms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(terms); + console.log("licenseTermsId: ", licenseTermsId); + + expect(licenseTermsId).and.to.be.a("bigint"); + }); + + it("Register commercial use license terms", async function () { + const testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLAP; + testTerms.defaultMintingFee = 30; + testTerms.commercialUse = true; + testTerms.currency = MockERC20; + console.log(testTerms); + + const connectedLicense = this.licenseTemplate.connect(signers[0]); + const tx = await expect( + connectedLicense.registerLicenseTerms(testTerms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(terms); + console.log("licenseTermsId: ", licenseTermsId); + + expect(licenseTermsId).and.to.be.a("bigint"); + }); + + it("Register commercial remix license terms", async function () { + const testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLRP; + testTerms.defaultMintingFee = 60; + testTerms.commercialUse = true; + testTerms.commercialRevShare = 100; + testTerms.currency = MockERC20; + console.log(testTerms); + + const connectedLicense = this.licenseTemplate.connect(signers[0]); + const tx = await expect( + connectedLicense.registerLicenseTerms(terms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); + console.log("licenseTermsId: ", licenseTermsId); + + expect(licenseTermsId).and.to.be.a("bigint"); + }); + + it.only("Register commercial remix license terms with commercialRevShare larger than max value", async function () { + const testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLAP; + testTerms.defaultMintingFee = 160; + testTerms.commercialUse = true; + testTerms.commercialRevShare = 101 * 10 ** 6; + testTerms.currency = MockERC20; + console.log(testTerms); + + const connectedLicense = this.licenseTemplate.connect(signers[0]); + const tx = await expect( + connectedLicense.registerLicenseTerms(terms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); + console.log("licenseTermsId: ", licenseTermsId); + + expect(licenseTermsId).and.to.be.a("bigint"); + }); +}); From 25f4f4839f18867e94babd5983673737ceb95116 Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 14:58:20 +0800 Subject: [PATCH 07/21] add tests for register license terms --- test/hardhat/e2e/license/registerLicenseTerms.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hardhat/e2e/license/registerLicenseTerms.ts b/test/hardhat/e2e/license/registerLicenseTerms.ts index c4f3e29ca..b37482794 100644 --- a/test/hardhat/e2e/license/registerLicenseTerms.ts +++ b/test/hardhat/e2e/license/registerLicenseTerms.ts @@ -23,7 +23,7 @@ const terms = { uri: "", }; -describe.only("License", function () { +describe("Register license terms", function () { let signers:any; this.beforeAll("Get Signers", async function () { @@ -91,7 +91,7 @@ describe.only("License", function () { expect(licenseTermsId).and.to.be.a("bigint"); }); - it.only("Register commercial remix license terms with commercialRevShare larger than max value", async function () { + it("Register commercial remix license terms with commercialRevShare larger than max value", async function () { const testTerms = terms; testTerms.royaltyPolicy = RoyaltyPolicyLAP; testTerms.defaultMintingFee = 160; From 9f2f8b88e6e568f0e60417c4c79791d52ba84374 Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 15:32:19 +0800 Subject: [PATCH 08/21] add common methods in setup --- test/hardhat/e2e/constants.ts | 3 +- test/hardhat/e2e/licenseTermsTemplate.ts | 21 ++++++++ test/hardhat/e2e/setup.ts | 67 +++++++++++++++++++++++- 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 test/hardhat/e2e/licenseTermsTemplate.ts diff --git a/test/hardhat/e2e/constants.ts b/test/hardhat/e2e/constants.ts index d05f001ba..c1553a46c 100644 --- a/test/hardhat/e2e/constants.ts +++ b/test/hardhat/e2e/constants.ts @@ -20,4 +20,5 @@ export const ProtocolAccessManager = "0xD22ff1C7e88aF45166aEFe000C4C0c4873Afa284 export const ProtocolPauseAdmin = "0x65C6Ec6Cc074eaf7ba3970C540b4379C9BcA8A67"; export const RoyaltyModule = "0xEa6eD700b11DfF703665CCAF55887ca56134Ae3B"; export const RoyaltyPolicyLAP = "0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6"; -export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd" \ No newline at end of file +export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd"; +export const MockERC721 = "0x12A8b0DcC6e3bB0915638361D9D49942Da07F455"; diff --git a/test/hardhat/e2e/licenseTermsTemplate.ts b/test/hardhat/e2e/licenseTermsTemplate.ts new file mode 100644 index 000000000..b19c2586c --- /dev/null +++ b/test/hardhat/e2e/licenseTermsTemplate.ts @@ -0,0 +1,21 @@ +import hre from "hardhat"; + +export const terms = { + transferable: true, + royaltyPolicy: hre.ethers.ZeroAddress, + defaultMintingFee: 0, + expiration: 0, + commercialUse: false, + commercialAttribution: false, + commercializerChecker: hre.ethers.ZeroAddress, + commercializerCheckerData: hre.ethers.ZeroAddress, + commercialRevShare: 0, + commercialRevCeiling: 0, + derivativesAllowed: true, + derivativesAttribution: false, + derivativesApproval: false, + derivativesReciprocal: false, + derivativeRevCeiling: 0, + currency: hre.ethers.ZeroAddress, + uri: "", +}; \ No newline at end of file diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index ee7422183..aefe9cd6d 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -1,5 +1,7 @@ import hre from "hardhat"; -import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule } from "./constants"; +import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP } from "./constants"; +import { expect } from "chai"; +import { terms } from "./licenseTermsTemplate"; before(async function () { console.log(`================= Load Contract =================`); @@ -8,7 +10,68 @@ before(async function () { this.licenseToken = await hre.ethers.getContractAt("LicenseToken", LicenseToken); this.licensingModule = await hre.ethers.getContractAt("LicensingModule", LicensingModule); this.groupingModule = await hre.ethers.getContractAt("GroupingModule", GroupingModule); + this.licenseTemplate = await hre.ethers.getContractAt("PILicenseTemplate", PILicenseTemplate); console.log(`================= Load Users =================`); [this.owner, this.user1] = await hre.ethers.getSigners(); -}); \ No newline at end of file + + it("Register non-commercial PIL license terms", async function () { + console.log(`================= Register non-commercial PIL license terms =================`); + const signers = await hre.ethers.getSigners(); + const connectedLicense = this.licenseTemplate.connect(signers[0]); + const tx = await expect( + connectedLicense.registerLicenseTerms(terms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(terms); + console.log("Non-commercial licenseTermsId: ", licenseTermsId); + }); + + it("Register non-commercial PIL license terms", async function () { + console.log(`================= Register commercial-use PIL license terms =================`); + const signers = await hre.ethers.getSigners(); + const connectedLicense = this.licenseTemplate.connect(signers[0]); + + const testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLAP; + testTerms.defaultMintingFee = 30; + testTerms.commercialUse = true; + testTerms.currency = MockERC20; + + const tx = await expect( + connectedLicense.registerLicenseTerms(testTerms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); + console.log("Commercial-use licenseTermsId: ", licenseTermsId); + }); + + it("Register non-commercial PIL license terms", async function () { + console.log(`================= Register commercial-remix PIL license terms =================`); + const signers = await hre.ethers.getSigners(); + const connectedLicense = this.licenseTemplate.connect(signers[0]); + + const testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLRP; + testTerms.defaultMintingFee = 80; + testTerms.commercialUse = true; + testTerms.commercialRevShare = 100; + testTerms.currency = MockERC20; + + const tx = await expect( + connectedLicense.registerLicenseTerms(testTerms) + ).to.not.be.rejectedWith(Error); + + console.log("Transaction hash: ", tx.hash); + expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + + const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); + console.log("Commercial-remix licenseTermsId: ", licenseTermsId); + }); +}); From 1f01b4878d21f2dd0aae7f6b15da56581783dcfb Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 15:46:36 +0800 Subject: [PATCH 09/21] update common methods --- test/hardhat/e2e/setup.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index aefe9cd6d..6f2762006 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -17,24 +17,19 @@ before(async function () { it("Register non-commercial PIL license terms", async function () { console.log(`================= Register non-commercial PIL license terms =================`); - const signers = await hre.ethers.getSigners(); - const connectedLicense = this.licenseTemplate.connect(signers[0]); const tx = await expect( - connectedLicense.registerLicenseTerms(terms) + this.licenseTemplate.registerLicenseTerms(terms) ).to.not.be.rejectedWith(Error); console.log("Transaction hash: ", tx.hash); expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - const licenseTermsId = await connectedLicense.getLicenseTermsId(terms); - console.log("Non-commercial licenseTermsId: ", licenseTermsId); + this.nonCommericialLicenseId = await this.licenseTemplate.getLicenseTermsId(terms); + console.log("Non-commercial licenseTermsId: ", this.nonCommericialLicenseId); }); it("Register non-commercial PIL license terms", async function () { console.log(`================= Register commercial-use PIL license terms =================`); - const signers = await hre.ethers.getSigners(); - const connectedLicense = this.licenseTemplate.connect(signers[0]); - const testTerms = terms; testTerms.royaltyPolicy = RoyaltyPolicyLAP; testTerms.defaultMintingFee = 30; @@ -42,21 +37,18 @@ before(async function () { testTerms.currency = MockERC20; const tx = await expect( - connectedLicense.registerLicenseTerms(testTerms) + this.licenseTemplate.registerLicenseTerms(testTerms) ).to.not.be.rejectedWith(Error); console.log("Transaction hash: ", tx.hash); expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); - console.log("Commercial-use licenseTermsId: ", licenseTermsId); + this.commericialUseLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms); + console.log("Commercial-use licenseTermsId: ", this.commericialUseLicenseId); }); it("Register non-commercial PIL license terms", async function () { console.log(`================= Register commercial-remix PIL license terms =================`); - const signers = await hre.ethers.getSigners(); - const connectedLicense = this.licenseTemplate.connect(signers[0]); - const testTerms = terms; testTerms.royaltyPolicy = RoyaltyPolicyLRP; testTerms.defaultMintingFee = 80; @@ -65,13 +57,13 @@ before(async function () { testTerms.currency = MockERC20; const tx = await expect( - connectedLicense.registerLicenseTerms(testTerms) + this.licenseTemplate.registerLicenseTerms(testTerms) ).to.not.be.rejectedWith(Error); console.log("Transaction hash: ", tx.hash); expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); - console.log("Commercial-remix licenseTermsId: ", licenseTermsId); + this.commericialRemixLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms); + console.log("Commercial-remix licenseTermsId: ", this.commericialRemixLicenseId); }); }); From a6b5540e35ff64a081ce0875a73fefe8d3567b0d Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 16:01:33 +0800 Subject: [PATCH 10/21] add test for attach license terms --- test/hardhat/e2e/constants.ts | 2 +- .../e2e/license/attachLicenseTerms.test.ts | 59 +++++++++++++++++++ ...eTerms.ts => registerLicenseTerms.test.ts} | 1 - test/hardhat/e2e/setup.ts | 4 +- 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 test/hardhat/e2e/license/attachLicenseTerms.test.ts rename test/hardhat/e2e/license/{registerLicenseTerms.ts => registerLicenseTerms.test.ts} (99%) diff --git a/test/hardhat/e2e/constants.ts b/test/hardhat/e2e/constants.ts index c1553a46c..519315a28 100644 --- a/test/hardhat/e2e/constants.ts +++ b/test/hardhat/e2e/constants.ts @@ -21,4 +21,4 @@ export const ProtocolPauseAdmin = "0x65C6Ec6Cc074eaf7ba3970C540b4379C9BcA8A67"; export const RoyaltyModule = "0xEa6eD700b11DfF703665CCAF55887ca56134Ae3B"; export const RoyaltyPolicyLAP = "0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6"; export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd"; -export const MockERC721 = "0x12A8b0DcC6e3bB0915638361D9D49942Da07F455"; +export const MockERC721 = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; diff --git a/test/hardhat/e2e/license/attachLicenseTerms.test.ts b/test/hardhat/e2e/license/attachLicenseTerms.test.ts new file mode 100644 index 000000000..b1feb02db --- /dev/null +++ b/test/hardhat/e2e/license/attachLicenseTerms.test.ts @@ -0,0 +1,59 @@ +import "../setup"; +import { expect } from "chai"; +import { network } from "hardhat"; +import hre from "hardhat"; +import { MockERC20, MockERC721, PILicenseTemplate, RoyaltyPolicyLAP, RoyaltyPolicyLRP } from "../constants"; +import { mintNFT } from "../utils/nftHelper"; + +const terms = { + transferable: true, + royaltyPolicy: hre.ethers.ZeroAddress, + defaultMintingFee: 0, + expiration: 0, + commercialUse: false, + commercialAttribution: false, + commercializerChecker: hre.ethers.ZeroAddress, + commercializerCheckerData: hre.ethers.ZeroAddress, + commercialRevShare: 0, + commercialRevCeiling: 0, + derivativesAllowed: true, + derivativesAttribution: false, + derivativesApproval: false, + derivativesReciprocal: false, + derivativeRevCeiling: 0, + currency: hre.ethers.ZeroAddress, + uri: "", +}; + +describe("Attach license terms", function () { + let signers: any; + let chainId: number; + + this.beforeAll("Get Signers", async function () { + // Get the signers + signers = await hre.ethers.getSigners(); + const networkConfig = network.config; + chainId = networkConfig.chainId || 1516; + console.log(chainId); + }); + + it("IP Asset attach a license except for default one", async function () { + const tokenId = await mintNFT(signers[0].address); + const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); + + const ipId = await expect( + connectedRegistry.register(1315, MockERC721, tokenId) + ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); + console.log("ipId:", ipId); + expect(ipId).to.not.be.empty.and.to.be.a("HexString"); + + const connectedLicensingModule = this.licensingModule.connect(signers[0]); + console.log(this.nonCommericialLicenseId); + + const attachLicenseTx = await expect( + connectedLicensingModule.attachLicenseTerms(ipId, PILicenseTemplate, this.commericialUseLicenseId) + ).not.to.be.rejectedWith(Error); + console.log(attachLicenseTx.hash); + expect(attachLicenseTx.hash).to.not.be.empty.and.to.be.a("HexString"); + }); +}); diff --git a/test/hardhat/e2e/license/registerLicenseTerms.ts b/test/hardhat/e2e/license/registerLicenseTerms.test.ts similarity index 99% rename from test/hardhat/e2e/license/registerLicenseTerms.ts rename to test/hardhat/e2e/license/registerLicenseTerms.test.ts index b37482794..1f92ba472 100644 --- a/test/hardhat/e2e/license/registerLicenseTerms.ts +++ b/test/hardhat/e2e/license/registerLicenseTerms.test.ts @@ -52,7 +52,6 @@ describe("Register license terms", function () { testTerms.defaultMintingFee = 30; testTerms.commercialUse = true; testTerms.currency = MockERC20; - console.log(testTerms); const connectedLicense = this.licenseTemplate.connect(signers[0]); const tx = await expect( diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 6f2762006..00ed513c0 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -28,7 +28,7 @@ before(async function () { console.log("Non-commercial licenseTermsId: ", this.nonCommericialLicenseId); }); - it("Register non-commercial PIL license terms", async function () { + it("Register commercial use PIL license terms", async function () { console.log(`================= Register commercial-use PIL license terms =================`); const testTerms = terms; testTerms.royaltyPolicy = RoyaltyPolicyLAP; @@ -47,7 +47,7 @@ before(async function () { console.log("Commercial-use licenseTermsId: ", this.commericialUseLicenseId); }); - it("Register non-commercial PIL license terms", async function () { + it("Register commercial remix PIL license terms", async function () { console.log(`================= Register commercial-remix PIL license terms =================`); const testTerms = terms; testTerms.royaltyPolicy = RoyaltyPolicyLRP; From 1b0c1013d6df94c274a85f304ddd24b5f066af5f Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Mon, 2 Dec 2024 18:17:23 +0800 Subject: [PATCH 11/21] add tests for mint license tokens --- .../e2e/license/attachLicenseTerms.test.ts | 29 ++------------- test/hardhat/e2e/license/license.test.ts | 9 ----- .../e2e/license/mintLicenseTokens.test.ts | 36 +++++++++++++++++++ test/hardhat/e2e/setup.ts | 6 ++++ .../e2e/utils/mintNFTAndRegisterIPA.ts | 36 +++++++++++++++++++ test/hardhat/e2e/utils/nftHelper.ts | 5 ++- 6 files changed, 82 insertions(+), 39 deletions(-) delete mode 100644 test/hardhat/e2e/license/license.test.ts create mode 100644 test/hardhat/e2e/license/mintLicenseTokens.test.ts create mode 100644 test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts diff --git a/test/hardhat/e2e/license/attachLicenseTerms.test.ts b/test/hardhat/e2e/license/attachLicenseTerms.test.ts index b1feb02db..06dd4db33 100644 --- a/test/hardhat/e2e/license/attachLicenseTerms.test.ts +++ b/test/hardhat/e2e/license/attachLicenseTerms.test.ts @@ -1,40 +1,15 @@ import "../setup"; import { expect } from "chai"; -import { network } from "hardhat"; import hre from "hardhat"; -import { MockERC20, MockERC721, PILicenseTemplate, RoyaltyPolicyLAP, RoyaltyPolicyLRP } from "../constants"; +import { MockERC721, PILicenseTemplate } from "../constants"; import { mintNFT } from "../utils/nftHelper"; -const terms = { - transferable: true, - royaltyPolicy: hre.ethers.ZeroAddress, - defaultMintingFee: 0, - expiration: 0, - commercialUse: false, - commercialAttribution: false, - commercializerChecker: hre.ethers.ZeroAddress, - commercializerCheckerData: hre.ethers.ZeroAddress, - commercialRevShare: 0, - commercialRevCeiling: 0, - derivativesAllowed: true, - derivativesAttribution: false, - derivativesApproval: false, - derivativesReciprocal: false, - derivativeRevCeiling: 0, - currency: hre.ethers.ZeroAddress, - uri: "", -}; - describe("Attach license terms", function () { let signers: any; - let chainId: number; this.beforeAll("Get Signers", async function () { // Get the signers signers = await hre.ethers.getSigners(); - const networkConfig = network.config; - chainId = networkConfig.chainId || 1516; - console.log(chainId); }); it("IP Asset attach a license except for default one", async function () { @@ -42,7 +17,7 @@ describe("Attach license terms", function () { const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); const ipId = await expect( - connectedRegistry.register(1315, MockERC721, tokenId) + connectedRegistry.register(this.chainId, MockERC721, tokenId) ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); console.log("ipId:", ipId); expect(ipId).to.not.be.empty.and.to.be.a("HexString"); diff --git a/test/hardhat/e2e/license/license.test.ts b/test/hardhat/e2e/license/license.test.ts deleted file mode 100644 index 018f8a3b7..000000000 --- a/test/hardhat/e2e/license/license.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import "../setup"; -import { expect } from "chai"; - -describe("License", function () { - it("license", async function () { - const name = await this.licensingModule.name(); - expect(name).to.equal("LICENSING_MODULE"); - }); -}) \ No newline at end of file diff --git a/test/hardhat/e2e/license/mintLicenseTokens.test.ts b/test/hardhat/e2e/license/mintLicenseTokens.test.ts new file mode 100644 index 000000000..d24193449 --- /dev/null +++ b/test/hardhat/e2e/license/mintLicenseTokens.test.ts @@ -0,0 +1,36 @@ +import "../setup"; +import { expect } from "chai"; +import hre from "hardhat"; +import { mintNFTAndRegisterIPA } from "../utils/mintNFTAndRegisterIPA"; +import { PILicenseTemplate } from "../constants"; + +describe("LicensingModule - mintLicenseTokens", function () { + let signers: any; + + this.beforeAll("Get Signers", async function () { + // Get the signers + signers = await hre.ethers.getSigners(); + }); + + it("should mint license tokens", async function () { + const { tokenId, ipId } = await mintNFTAndRegisterIPA(signers[0], signers[0]); + console.log("tokenId: ", tokenId); + console.log("ipId: ", ipId); + + const connectedLicensingModule = this.licensingModule.connect(signers[0]); + + const attachLicenseTx = await expect( + connectedLicensingModule.attachLicenseTerms(ipId, PILicenseTemplate, this.nonCommericialLicenseId) + ).not.to.be.rejectedWith(Error); + expect(attachLicenseTx.hash).to.not.be.empty.and.to.be.a("HexString"); + + const mintLicenseTokensTx = await expect( + connectedLicensingModule.mintLicenseTokens(ipId, PILicenseTemplate, this.nonCommericialLicenseId, 2, signers[0].address, hre.ethers.ZeroAddress, 100) + ).not.to.be.rejectedWith(Error); + expect(mintLicenseTokensTx.hash).to.not.be.empty.and.to.be.a("HexString"); + + const startLicenseTokenId = await mintLicenseTokensTx.wait().then((receipt:any) => receipt.logs[4].args[6]); + console.log(startLicenseTokenId); + expect(startLicenseTokenId).to.be.a("bigint"); + }); +}); diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 00ed513c0..b3ac768c2 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -1,4 +1,5 @@ import hre from "hardhat"; +import { network } from "hardhat"; import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP } from "./constants"; import { expect } from "chai"; import { terms } from "./licenseTermsTemplate"; @@ -14,6 +15,11 @@ before(async function () { console.log(`================= Load Users =================`); [this.owner, this.user1] = await hre.ethers.getSigners(); + + console.log(`================= Chain ID =================`); + const networkConfig = network.config; + this.chainId = networkConfig.chainId; + console.log("chainId: ", this.chainId); it("Register non-commercial PIL license terms", async function () { console.log(`================= Register non-commercial PIL license terms =================`); diff --git a/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts b/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts new file mode 100644 index 000000000..cabd5ab94 --- /dev/null +++ b/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts @@ -0,0 +1,36 @@ +import "../setup"; +import { mintNFT } from "./nftHelper"; +import { MockERC721, IPAssetRegistry } from "../constants"; +import { expect } from "chai"; +import hre from "hardhat"; +import { network } from "hardhat"; +import { HexString } from "ethers/lib.commonjs/utils/data"; + +export async function mintNFTAndRegisterIPA(mintNFTSigner: any, registerIPASigner: any): Promise<{ tokenId: number; ipId: HexString }> { + const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", IPAssetRegistry); + const networkConfig = network.config; + const chainId = networkConfig.chainId; + + const tokenId = await mintNFT(mintNFTSigner.address); + const connectedRegistry = ipAssetRegistry.connect(registerIPASigner); + + // Register the IP Asset + const ipId = await expect( + connectedRegistry.register(chainId, MockERC721, tokenId) + ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); + + console.log("ipId:", ipId); + + expect(ipId).to.not.be.empty.and.to.be.a("HexString"); + + // Check if the IP Asset is registered + const isRegistered = await expect( + connectedRegistry.isRegistered(ipId) + ).not.to.be.rejectedWith(Error); + + expect(isRegistered).to.equal(true); + + // Return both tokenId and ipId as an object + return { tokenId, ipId }; +}; + diff --git a/test/hardhat/e2e/utils/nftHelper.ts b/test/hardhat/e2e/utils/nftHelper.ts index 8553d3e4f..4a8955309 100644 --- a/test/hardhat/e2e/utils/nftHelper.ts +++ b/test/hardhat/e2e/utils/nftHelper.ts @@ -1,9 +1,8 @@ -import { ethers } from "ethers" import hre from "hardhat" +import { MockERC721 } from "../constants"; export async function mintNFT(walletAddress?: string): Promise { - const erc721ContractAddress: string = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; let tokenId: any const contractAbi = [ { @@ -15,7 +14,7 @@ export async function mintNFT(walletAddress?: string): Promise { }, ] - const nftContract = await hre.ethers.getContractAt(contractAbi, erc721ContractAddress); + const nftContract = await hre.ethers.getContractAt(contractAbi, MockERC721); const [owner] = await hre.ethers.getSigners(); const address = walletAddress || owner.address From 53600c483d9a98a37b415c5d90cbadc5832d57b1 Mon Sep 17 00:00:00 2001 From: jia57b Date: Tue, 3 Dec 2024 09:24:38 +0800 Subject: [PATCH 12/21] add permission test --- .../hardhat/e2e/permission/permission.test.ts | 57 +++++++++++++++++++ test/hardhat/e2e/setup.ts | 3 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/hardhat/e2e/permission/permission.test.ts diff --git a/test/hardhat/e2e/permission/permission.test.ts b/test/hardhat/e2e/permission/permission.test.ts new file mode 100644 index 000000000..91bebe7ae --- /dev/null +++ b/test/hardhat/e2e/permission/permission.test.ts @@ -0,0 +1,57 @@ +import "../setup" +import { expect } from "chai" +import { mintNFT } from "../utils/nftHelper" +import hre from "hardhat"; + +describe("Permission", function () { + let signers:any; + const chainId: number = 1315; + const erc721ContractAddress: string = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; + + this.beforeAll("Get Signers", async function () { + // Get the signers + signers = await hre.ethers.getSigners(); + console.log("signers:", signers[0].address); + }) + + it("Add a new ALLOW permission of IP asset for an signer and change the permission to DENY", async function () { + const tokenId = await mintNFT(signers[0].address); + const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); + const func = hre.ethers.encodeBytes32String("attachLicenseTerms").slice(0, 10); + console.log(func); + const ALLOW_permission = 1; + const DENY_permission = 2; + + const ipId = await expect( + connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); + console.log("ipId:", ipId); + expect(ipId).to.not.be.empty.and.to.be.a("HexString"); + + const connecedAccessController = this.accessController.connect(signers[0]); + + const permissionBefore = await connecedAccessController.getPermission(ipId, signers[0].address, this.licensingModule.target, func); + console.log("permissionBefore:", permissionBefore); + expect(permissionBefore).to.equal(0); + + // add ALLOW permission + const result1 = await connecedAccessController.setPermission(ipId, signers[0].address, this.licensingModule.target, func, ALLOW_permission); + expect(result1.hash).to.not.be.empty.and.to.be.a("HexString"); + await result1.wait(); + + // get the permission + const permissionAfter1 = await connecedAccessController.getPermission(ipId, signers[0].address, this.licensingModule.target, func); + console.log("permissionAfter:", permissionAfter1); + expect(permissionAfter1).to.equal(ALLOW_permission); + + // Change to DENY permission + const result2 = await connecedAccessController.setPermission(ipId, signers[0].address, this.licensingModule.target, func, DENY_permission); + expect(result2.hash).to.not.be.empty.and.to.be.a("HexString"); + await result2.wait(); + + // get the permission + const permissionAfter2 = await connecedAccessController.getPermission(ipId, signers[0].address, this.licensingModule.target, func); + console.log("permissionAfter:", permissionAfter2); + expect(permissionAfter2).to.equal(DENY_permission); + }); +}); \ No newline at end of file diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index b3ac768c2..6b7912043 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -1,6 +1,6 @@ import hre from "hardhat"; import { network } from "hardhat"; -import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP } from "./constants"; +import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP, AccessController } from "./constants"; import { expect } from "chai"; import { terms } from "./licenseTermsTemplate"; @@ -12,6 +12,7 @@ before(async function () { this.licensingModule = await hre.ethers.getContractAt("LicensingModule", LicensingModule); this.groupingModule = await hre.ethers.getContractAt("GroupingModule", GroupingModule); this.licenseTemplate = await hre.ethers.getContractAt("PILicenseTemplate", PILicenseTemplate); + this.accessController = await hre.ethers.getContractAt("AccessController", AccessController); console.log(`================= Load Users =================`); [this.owner, this.user1] = await hre.ethers.getSigners(); From c13f694023b077f21b450cce3d47404a39a92c57 Mon Sep 17 00:00:00 2001 From: jia57b Date: Tue, 3 Dec 2024 09:34:20 +0800 Subject: [PATCH 13/21] update permission test --- test/hardhat/e2e/permission/permission.test.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/hardhat/e2e/permission/permission.test.ts b/test/hardhat/e2e/permission/permission.test.ts index 91bebe7ae..881d489ce 100644 --- a/test/hardhat/e2e/permission/permission.test.ts +++ b/test/hardhat/e2e/permission/permission.test.ts @@ -2,11 +2,10 @@ import "../setup" import { expect } from "chai" import { mintNFT } from "../utils/nftHelper" import hre from "hardhat"; +import { LicensingModule, MockERC721 } from "../constants"; describe("Permission", function () { let signers:any; - const chainId: number = 1315; - const erc721ContractAddress: string = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; this.beforeAll("Get Signers", async function () { // Get the signers @@ -23,34 +22,34 @@ describe("Permission", function () { const DENY_permission = 2; const ipId = await expect( - connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + connectedRegistry.register(this.chainId, MockERC721, tokenId) ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); console.log("ipId:", ipId); expect(ipId).to.not.be.empty.and.to.be.a("HexString"); const connecedAccessController = this.accessController.connect(signers[0]); - const permissionBefore = await connecedAccessController.getPermission(ipId, signers[0].address, this.licensingModule.target, func); + const permissionBefore = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); console.log("permissionBefore:", permissionBefore); expect(permissionBefore).to.equal(0); // add ALLOW permission - const result1 = await connecedAccessController.setPermission(ipId, signers[0].address, this.licensingModule.target, func, ALLOW_permission); + const result1 = await connecedAccessController.setPermission(ipId, signers[0].address, LicensingModule, func, ALLOW_permission); expect(result1.hash).to.not.be.empty.and.to.be.a("HexString"); await result1.wait(); // get the permission - const permissionAfter1 = await connecedAccessController.getPermission(ipId, signers[0].address, this.licensingModule.target, func); + const permissionAfter1 = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); console.log("permissionAfter:", permissionAfter1); expect(permissionAfter1).to.equal(ALLOW_permission); // Change to DENY permission - const result2 = await connecedAccessController.setPermission(ipId, signers[0].address, this.licensingModule.target, func, DENY_permission); + const result2 = await connecedAccessController.setPermission(ipId, signers[0].address, LicensingModule, func, DENY_permission); expect(result2.hash).to.not.be.empty.and.to.be.a("HexString"); await result2.wait(); // get the permission - const permissionAfter2 = await connecedAccessController.getPermission(ipId, signers[0].address, this.licensingModule.target, func); + const permissionAfter2 = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); console.log("permissionAfter:", permissionAfter2); expect(permissionAfter2).to.equal(DENY_permission); }); From 402c9f20c85d824529fbbf72f079d7aebdc1dc2b Mon Sep 17 00:00:00 2001 From: jia57b Date: Tue, 3 Dec 2024 10:12:43 +0800 Subject: [PATCH 14/21] update var name --- .../hardhat/e2e/permission/permission.test.ts | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/test/hardhat/e2e/permission/permission.test.ts b/test/hardhat/e2e/permission/permission.test.ts index 881d489ce..d55979f36 100644 --- a/test/hardhat/e2e/permission/permission.test.ts +++ b/test/hardhat/e2e/permission/permission.test.ts @@ -17,9 +17,10 @@ describe("Permission", function () { const tokenId = await mintNFT(signers[0].address); const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); const func = hre.ethers.encodeBytes32String("attachLicenseTerms").slice(0, 10); - console.log(func); const ALLOW_permission = 1; const DENY_permission = 2; + let permissionAfter: number; + let result: any; const ipId = await expect( connectedRegistry.register(this.chainId, MockERC721, tokenId) @@ -30,27 +31,24 @@ describe("Permission", function () { const connecedAccessController = this.accessController.connect(signers[0]); const permissionBefore = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); - console.log("permissionBefore:", permissionBefore); expect(permissionBefore).to.equal(0); // add ALLOW permission - const result1 = await connecedAccessController.setPermission(ipId, signers[0].address, LicensingModule, func, ALLOW_permission); - expect(result1.hash).to.not.be.empty.and.to.be.a("HexString"); - await result1.wait(); + result = await connecedAccessController.setPermission(ipId, signers[0].address, LicensingModule, func, ALLOW_permission); + expect(result.hash).to.not.be.empty.and.to.be.a("HexString"); + await result.wait(); - // get the permission - const permissionAfter1 = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); - console.log("permissionAfter:", permissionAfter1); - expect(permissionAfter1).to.equal(ALLOW_permission); + // check the permission + permissionAfter = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); + expect(permissionAfter).to.equal(ALLOW_permission); // Change to DENY permission - const result2 = await connecedAccessController.setPermission(ipId, signers[0].address, LicensingModule, func, DENY_permission); - expect(result2.hash).to.not.be.empty.and.to.be.a("HexString"); - await result2.wait(); - - // get the permission - const permissionAfter2 = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); - console.log("permissionAfter:", permissionAfter2); - expect(permissionAfter2).to.equal(DENY_permission); + result = await connecedAccessController.setPermission(ipId, signers[0].address, LicensingModule, func, DENY_permission); + expect(result.hash).to.not.be.empty.and.to.be.a("HexString"); + await result.wait(); + + // check the permission + permissionAfter = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); + expect(permissionAfter).to.equal(DENY_permission); }); }); \ No newline at end of file From 9bb8451712dabcda87d89f0be203ea5aa5eff67b Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang Date: Tue, 3 Dec 2024 13:58:32 +0800 Subject: [PATCH 15/21] update common and ipa tests --- test/hardhat/e2e/constants.ts | 2 +- test/hardhat/e2e/ipa/ipa.test.ts | 12 +- .../e2e/license/attachLicenseTerms.test.ts | 34 ------ .../e2e/license/mintLicenseTokens.test.ts | 36 ------ .../e2e/license/registerLicenseTerms.test.ts | 115 ------------------ test/hardhat/e2e/setup.ts | 5 +- 6 files changed, 10 insertions(+), 194 deletions(-) delete mode 100644 test/hardhat/e2e/license/attachLicenseTerms.test.ts delete mode 100644 test/hardhat/e2e/license/mintLicenseTokens.test.ts delete mode 100644 test/hardhat/e2e/license/registerLicenseTerms.test.ts diff --git a/test/hardhat/e2e/constants.ts b/test/hardhat/e2e/constants.ts index 519315a28..be11f0b7e 100644 --- a/test/hardhat/e2e/constants.ts +++ b/test/hardhat/e2e/constants.ts @@ -21,4 +21,4 @@ export const ProtocolPauseAdmin = "0x65C6Ec6Cc074eaf7ba3970C540b4379C9BcA8A67"; export const RoyaltyModule = "0xEa6eD700b11DfF703665CCAF55887ca56134Ae3B"; export const RoyaltyPolicyLAP = "0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6"; export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd"; -export const MockERC721 = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; +export const MockERC721 = "0x7a23aad16b2ac6ad74f76990a814b0f82bec83b8"; diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts index f38e038e8..22ba11dda 100644 --- a/test/hardhat/e2e/ipa/ipa.test.ts +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -2,11 +2,10 @@ import "../setup" import { expect } from "chai" import { mintNFT } from "../utils/nftHelper" import hre from "hardhat"; +import { MockERC721 } from "../constants"; -describe("IP Asset", function () { +describe.only("IP Asset", function () { let signers:any; - const chainId: number = 1315; - const erc721ContractAddress: string = "0x7411143ef90b7744fc8233f01cce0b2c379651b3"; this.beforeAll("Get Signers", async function () { // Get the signers @@ -18,7 +17,7 @@ describe("IP Asset", function () { const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); const ipId = await expect( - connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + connectedRegistry.register(this.chainId, MockERC721, tokenId) ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); console.log("ipId:", ipId); @@ -36,7 +35,7 @@ describe("IP Asset", function () { const connectedRegistry = this.ipAssetRegistry.connect(signers[1]); const ipId = await expect( - connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + connectedRegistry.register(this.chainId, MockERC721, tokenId) ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); console.log("ipId:", ipId); @@ -58,8 +57,7 @@ describe("IP Asset", function () { const connectedRegistry = this.ipAssetRegistry.connect(randomSigner); await expect( - connectedRegistry.register(chainId, erc721ContractAddress, tokenId) + connectedRegistry.register(this.chainId, MockERC721, tokenId) ).to.be.rejectedWith(`insufficient funds`, `"code": -32000, "message": "insufficient funds for gas * price + value: balance 0`); }); }); - diff --git a/test/hardhat/e2e/license/attachLicenseTerms.test.ts b/test/hardhat/e2e/license/attachLicenseTerms.test.ts deleted file mode 100644 index 06dd4db33..000000000 --- a/test/hardhat/e2e/license/attachLicenseTerms.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import "../setup"; -import { expect } from "chai"; -import hre from "hardhat"; -import { MockERC721, PILicenseTemplate } from "../constants"; -import { mintNFT } from "../utils/nftHelper"; - -describe("Attach license terms", function () { - let signers: any; - - this.beforeAll("Get Signers", async function () { - // Get the signers - signers = await hre.ethers.getSigners(); - }); - - it("IP Asset attach a license except for default one", async function () { - const tokenId = await mintNFT(signers[0].address); - const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); - - const ipId = await expect( - connectedRegistry.register(this.chainId, MockERC721, tokenId) - ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); - console.log("ipId:", ipId); - expect(ipId).to.not.be.empty.and.to.be.a("HexString"); - - const connectedLicensingModule = this.licensingModule.connect(signers[0]); - console.log(this.nonCommericialLicenseId); - - const attachLicenseTx = await expect( - connectedLicensingModule.attachLicenseTerms(ipId, PILicenseTemplate, this.commericialUseLicenseId) - ).not.to.be.rejectedWith(Error); - console.log(attachLicenseTx.hash); - expect(attachLicenseTx.hash).to.not.be.empty.and.to.be.a("HexString"); - }); -}); diff --git a/test/hardhat/e2e/license/mintLicenseTokens.test.ts b/test/hardhat/e2e/license/mintLicenseTokens.test.ts deleted file mode 100644 index d24193449..000000000 --- a/test/hardhat/e2e/license/mintLicenseTokens.test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import "../setup"; -import { expect } from "chai"; -import hre from "hardhat"; -import { mintNFTAndRegisterIPA } from "../utils/mintNFTAndRegisterIPA"; -import { PILicenseTemplate } from "../constants"; - -describe("LicensingModule - mintLicenseTokens", function () { - let signers: any; - - this.beforeAll("Get Signers", async function () { - // Get the signers - signers = await hre.ethers.getSigners(); - }); - - it("should mint license tokens", async function () { - const { tokenId, ipId } = await mintNFTAndRegisterIPA(signers[0], signers[0]); - console.log("tokenId: ", tokenId); - console.log("ipId: ", ipId); - - const connectedLicensingModule = this.licensingModule.connect(signers[0]); - - const attachLicenseTx = await expect( - connectedLicensingModule.attachLicenseTerms(ipId, PILicenseTemplate, this.nonCommericialLicenseId) - ).not.to.be.rejectedWith(Error); - expect(attachLicenseTx.hash).to.not.be.empty.and.to.be.a("HexString"); - - const mintLicenseTokensTx = await expect( - connectedLicensingModule.mintLicenseTokens(ipId, PILicenseTemplate, this.nonCommericialLicenseId, 2, signers[0].address, hre.ethers.ZeroAddress, 100) - ).not.to.be.rejectedWith(Error); - expect(mintLicenseTokensTx.hash).to.not.be.empty.and.to.be.a("HexString"); - - const startLicenseTokenId = await mintLicenseTokensTx.wait().then((receipt:any) => receipt.logs[4].args[6]); - console.log(startLicenseTokenId); - expect(startLicenseTokenId).to.be.a("bigint"); - }); -}); diff --git a/test/hardhat/e2e/license/registerLicenseTerms.test.ts b/test/hardhat/e2e/license/registerLicenseTerms.test.ts deleted file mode 100644 index 1f92ba472..000000000 --- a/test/hardhat/e2e/license/registerLicenseTerms.test.ts +++ /dev/null @@ -1,115 +0,0 @@ -import "../setup"; -import { expect } from "chai"; -import hre from "hardhat"; -import { MockERC20, RoyaltyPolicyLAP, RoyaltyPolicyLRP } from "../constants"; - -const terms = { - transferable: true, - royaltyPolicy: hre.ethers.ZeroAddress, - defaultMintingFee: 0, - expiration: 0, - commercialUse: false, - commercialAttribution: false, - commercializerChecker: hre.ethers.ZeroAddress, - commercializerCheckerData: hre.ethers.ZeroAddress, - commercialRevShare: 0, - commercialRevCeiling: 0, - derivativesAllowed: true, - derivativesAttribution: false, - derivativesApproval: false, - derivativesReciprocal: false, - derivativeRevCeiling: 0, - currency: hre.ethers.ZeroAddress, - uri: "", -}; - -describe("Register license terms", function () { - let signers:any; - - this.beforeAll("Get Signers", async function () { - // Get the signers - signers = await hre.ethers.getSigners(); - }); - - it("Register non-commercial PIL license terms", async function () { - const connectedLicense = this.licenseTemplate.connect(signers[0]); - const tx = await expect( - connectedLicense.registerLicenseTerms(terms) - ).to.not.be.rejectedWith(Error); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - - const licenseTermsId = await connectedLicense.getLicenseTermsId(terms); - console.log("licenseTermsId: ", licenseTermsId); - - expect(licenseTermsId).and.to.be.a("bigint"); - }); - - it("Register commercial use license terms", async function () { - const testTerms = terms; - testTerms.royaltyPolicy = RoyaltyPolicyLAP; - testTerms.defaultMintingFee = 30; - testTerms.commercialUse = true; - testTerms.currency = MockERC20; - - const connectedLicense = this.licenseTemplate.connect(signers[0]); - const tx = await expect( - connectedLicense.registerLicenseTerms(testTerms) - ).to.not.be.rejectedWith(Error); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - - const licenseTermsId = await connectedLicense.getLicenseTermsId(terms); - console.log("licenseTermsId: ", licenseTermsId); - - expect(licenseTermsId).and.to.be.a("bigint"); - }); - - it("Register commercial remix license terms", async function () { - const testTerms = terms; - testTerms.royaltyPolicy = RoyaltyPolicyLRP; - testTerms.defaultMintingFee = 60; - testTerms.commercialUse = true; - testTerms.commercialRevShare = 100; - testTerms.currency = MockERC20; - console.log(testTerms); - - const connectedLicense = this.licenseTemplate.connect(signers[0]); - const tx = await expect( - connectedLicense.registerLicenseTerms(terms) - ).to.not.be.rejectedWith(Error); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - - const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); - console.log("licenseTermsId: ", licenseTermsId); - - expect(licenseTermsId).and.to.be.a("bigint"); - }); - - it("Register commercial remix license terms with commercialRevShare larger than max value", async function () { - const testTerms = terms; - testTerms.royaltyPolicy = RoyaltyPolicyLAP; - testTerms.defaultMintingFee = 160; - testTerms.commercialUse = true; - testTerms.commercialRevShare = 101 * 10 ** 6; - testTerms.currency = MockERC20; - console.log(testTerms); - - const connectedLicense = this.licenseTemplate.connect(signers[0]); - const tx = await expect( - connectedLicense.registerLicenseTerms(terms) - ).to.not.be.rejectedWith(Error); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - - const licenseTermsId = await connectedLicense.getLicenseTermsId(testTerms); - console.log("licenseTermsId: ", licenseTermsId); - - expect(licenseTermsId).and.to.be.a("bigint"); - }); -}); diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 6b7912043..18557f4ef 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -27,6 +27,7 @@ before(async function () { const tx = await expect( this.licenseTemplate.registerLicenseTerms(terms) ).to.not.be.rejectedWith(Error); + await tx.wait(); console.log("Transaction hash: ", tx.hash); expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); @@ -39,13 +40,14 @@ before(async function () { console.log(`================= Register commercial-use PIL license terms =================`); const testTerms = terms; testTerms.royaltyPolicy = RoyaltyPolicyLAP; - testTerms.defaultMintingFee = 30; + testTerms.defaultMintingFee = 10; testTerms.commercialUse = true; testTerms.currency = MockERC20; const tx = await expect( this.licenseTemplate.registerLicenseTerms(testTerms) ).to.not.be.rejectedWith(Error); + await tx.wait(); console.log("Transaction hash: ", tx.hash); expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); @@ -66,6 +68,7 @@ before(async function () { const tx = await expect( this.licenseTemplate.registerLicenseTerms(testTerms) ).to.not.be.rejectedWith(Error); + await tx.wait(); console.log("Transaction hash: ", tx.hash); expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); From 7d101a52a8a36f7330d606ddc91797a7ab0dd324 Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Tue, 3 Dec 2024 14:56:34 +0800 Subject: [PATCH 16/21] update test config --- hardhat.config.ts | 2 +- test/hardhat/e2e/ipa/ipa.test.ts | 8 +- test/hardhat/e2e/setup.ts | 76 ++++++------------- .../e2e/utils/mintNFTAndRegisterIPA.ts | 13 ++-- test/hardhat/e2e/utils/nftHelper.ts | 12 ++- 5 files changed, 40 insertions(+), 71 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 4bf1c4d1a..c13fbd4af 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -112,7 +112,7 @@ const config: HardhatUserConfig = { coinmarketcap: COINMARKETCAP_API_KEY, }, mocha: { - timeout: 20_000, + timeout: 60_000, reporter: "mochawesome", }, etherscan: { diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts index 22ba11dda..6c014a346 100644 --- a/test/hardhat/e2e/ipa/ipa.test.ts +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -4,7 +4,7 @@ import { mintNFT } from "../utils/nftHelper" import hre from "hardhat"; import { MockERC721 } from "../constants"; -describe.only("IP Asset", function () { +describe("IP Asset", function () { let signers:any; this.beforeAll("Get Signers", async function () { @@ -13,7 +13,7 @@ describe.only("IP Asset", function () { }) it("NFT owner register IP Asset with an NFT token", async function () { - const tokenId = await mintNFT(signers[0].address); + const tokenId = await mintNFT(signers[0]); const connectedRegistry = this.ipAssetRegistry.connect(signers[0]); const ipId = await expect( @@ -31,7 +31,7 @@ describe.only("IP Asset", function () { }); it("Non-NFT owner register IP asset with an NFT token", async function () { - const tokenId = await mintNFT(signers[0].address); + const tokenId = await mintNFT(signers[0]); const connectedRegistry = this.ipAssetRegistry.connect(signers[1]); const ipId = await expect( @@ -49,7 +49,7 @@ describe.only("IP Asset", function () { }); it("Register IP asset, the caller doesn’t have enough IP token", async function () { - const tokenId = await mintNFT(signers[0].address); + const tokenId = await mintNFT(signers[0]); // generate random wallet const randomWallet = hre.ethers.Wallet.createRandom(); diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 18557f4ef..88ef79d3e 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -1,7 +1,6 @@ import hre from "hardhat"; import { network } from "hardhat"; import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP, AccessController } from "./constants"; -import { expect } from "chai"; import { terms } from "./licenseTermsTemplate"; before(async function () { @@ -22,58 +21,29 @@ before(async function () { this.chainId = networkConfig.chainId; console.log("chainId: ", this.chainId); - it("Register non-commercial PIL license terms", async function () { - console.log(`================= Register non-commercial PIL license terms =================`); - const tx = await expect( - this.licenseTemplate.registerLicenseTerms(terms) - ).to.not.be.rejectedWith(Error); - await tx.wait(); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - - this.nonCommericialLicenseId = await this.licenseTemplate.getLicenseTermsId(terms); - console.log("Non-commercial licenseTermsId: ", this.nonCommericialLicenseId); - }); + console.log(`================= Register non-commercial PIL license terms =================`); + await this.licenseTemplate.registerLicenseTerms(terms); + this.nonCommericialLicenseId = await this.licenseTemplate.getLicenseTermsId(terms); + console.log("Non-commercial licenseTermsId: ", this.nonCommericialLicenseId); - it("Register commercial use PIL license terms", async function () { - console.log(`================= Register commercial-use PIL license terms =================`); - const testTerms = terms; - testTerms.royaltyPolicy = RoyaltyPolicyLAP; - testTerms.defaultMintingFee = 10; - testTerms.commercialUse = true; - testTerms.currency = MockERC20; - - const tx = await expect( - this.licenseTemplate.registerLicenseTerms(testTerms) - ).to.not.be.rejectedWith(Error); - await tx.wait(); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); - - this.commericialUseLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms); - console.log("Commercial-use licenseTermsId: ", this.commericialUseLicenseId); - }); - - it("Register commercial remix PIL license terms", async function () { - console.log(`================= Register commercial-remix PIL license terms =================`); - const testTerms = terms; - testTerms.royaltyPolicy = RoyaltyPolicyLRP; - testTerms.defaultMintingFee = 80; - testTerms.commercialUse = true; - testTerms.commercialRevShare = 100; - testTerms.currency = MockERC20; - - const tx = await expect( - this.licenseTemplate.registerLicenseTerms(testTerms) - ).to.not.be.rejectedWith(Error); - await tx.wait(); - - console.log("Transaction hash: ", tx.hash); - expect(tx.hash).not.to.be.empty.and.to.be.a("HexString"); + console.log(`================= Register commercial-use PIL license terms =================`); + let testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLAP; + testTerms.defaultMintingFee = 30; + testTerms.commercialUse = true; + testTerms.currency = MockERC20; + await this.licenseTemplate.registerLicenseTerms(testTerms); + this.commericialUseLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms); + console.log("Commercial-use licenseTermsId: ", this.commericialUseLicenseId); - this.commericialRemixLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms); - console.log("Commercial-remix licenseTermsId: ", this.commericialRemixLicenseId); - }); + console.log(`================= Register commercial-remix PIL license terms =================`); + testTerms = terms; + testTerms.royaltyPolicy = RoyaltyPolicyLRP; + testTerms.defaultMintingFee = 80; + testTerms.commercialUse = true; + testTerms.commercialRevShare = 100; + testTerms.currency = MockERC20; + await this.licenseTemplate.registerLicenseTerms(testTerms); + this.commericialRemixLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms); + console.log("Commercial-remix licenseTermsId: ", this.commericialRemixLicenseId); }); diff --git a/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts b/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts index cabd5ab94..60bcfc34f 100644 --- a/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts +++ b/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts @@ -6,17 +6,18 @@ import hre from "hardhat"; import { network } from "hardhat"; import { HexString } from "ethers/lib.commonjs/utils/data"; -export async function mintNFTAndRegisterIPA(mintNFTSigner: any, registerIPASigner: any): Promise<{ tokenId: number; ipId: HexString }> { - const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", IPAssetRegistry); +export async function mintNFTAndRegisterIPA(mintNFTSigner?: any, registerIPASigner?: any): Promise<{ tokenId: number; ipId: HexString }> { const networkConfig = network.config; const chainId = networkConfig.chainId; - const tokenId = await mintNFT(mintNFTSigner.address); - const connectedRegistry = ipAssetRegistry.connect(registerIPASigner); + const tokenId = await mintNFT(mintNFTSigner); + + const signer = registerIPASigner || (await hre.ethers.getSigners())[0]; + const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", IPAssetRegistry, signer); // Register the IP Asset const ipId = await expect( - connectedRegistry.register(chainId, MockERC721, tokenId) + ipAssetRegistry.register(chainId, MockERC721, tokenId) ).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]); console.log("ipId:", ipId); @@ -25,7 +26,7 @@ export async function mintNFTAndRegisterIPA(mintNFTSigner: any, registerIPASigne // Check if the IP Asset is registered const isRegistered = await expect( - connectedRegistry.isRegistered(ipId) + ipAssetRegistry.isRegistered(ipId) ).not.to.be.rejectedWith(Error); expect(isRegistered).to.equal(true); diff --git a/test/hardhat/e2e/utils/nftHelper.ts b/test/hardhat/e2e/utils/nftHelper.ts index 4a8955309..08490dbf1 100644 --- a/test/hardhat/e2e/utils/nftHelper.ts +++ b/test/hardhat/e2e/utils/nftHelper.ts @@ -1,8 +1,9 @@ import hre from "hardhat" import { MockERC721 } from "../constants"; +import { ethers } from "ethers"; -export async function mintNFT(walletAddress?: string): Promise { +export async function mintNFT(singer?: ethers.Wallet): Promise { let tokenId: any const contractAbi = [ { @@ -14,12 +15,9 @@ export async function mintNFT(walletAddress?: string): Promise { }, ] - const nftContract = await hre.ethers.getContractAt(contractAbi, MockERC721); - - const [owner] = await hre.ethers.getSigners(); - const address = walletAddress || owner.address - - const tx = await nftContract.mint(address) + const caller = singer || (await hre.ethers.getSigners())[0] + const nftContract = await hre.ethers.getContractAt(contractAbi, MockERC721, caller); + const tx = await nftContract.mint(caller.address) const receipt = await tx.wait() const logs = receipt.logs From efa31ba0ea6e8bffbaec0bf3af30020c1f8eb5af Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Tue, 3 Dec 2024 15:06:15 +0800 Subject: [PATCH 17/21] Update .env.example --- .env.example | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 007cb0960..e3cdc0e8b 100644 --- a/.env.example +++ b/.env.example @@ -12,4 +12,10 @@ TENDERLY_URL = TENDERLY_PRIVATEKEY = # ETHERSCAN APIY KEY -ETHERSCAN_API_KEY = ETHERSCANAPIKEYETHERSCANAPIKEY \ No newline at end of file +ETHERSCAN_API_KEY = ETHERSCANAPIKEYETHERSCANAPIKEY + +# TESTNET +DEVNET_URL = http:// +DEVNET_CHAINID = 1315 +DEVNET_PRIVATEKEY = +DEVNET_USER1 = \ No newline at end of file From 4e0ebfd1226d03428a8a8608115bde67b1ae64ae Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Tue, 3 Dec 2024 16:30:07 +0800 Subject: [PATCH 18/21] Create README.md --- test/hardhat/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/hardhat/README.md diff --git a/test/hardhat/README.md b/test/hardhat/README.md new file mode 100644 index 000000000..584f36f07 --- /dev/null +++ b/test/hardhat/README.md @@ -0,0 +1,26 @@ +# Story Protocol End-to-End Testing + +This folder contains story protocol end-to-end test scripts. + +## Requirements + +Please install the following: + +- [Foundry / Foundryup](https://github.com/gakonst/foundry) +- [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) + +## Quickstart + +Install the dependencies: + +```sh +yarn # this installs packages +``` + +You'll need to add the variables refer to the .env.example to a .env file + +Then, run the tests with: + +```sh +npx hardhat test --network odyssey +``` From 6fa05b1fbba3901575769e50b60bafe2f4891603 Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Tue, 3 Dec 2024 16:50:43 +0800 Subject: [PATCH 19/21] Add file level comment and fix review comment --- .env.example | 3 ++- test/hardhat/e2e/constants.ts | 6 +++++- test/hardhat/e2e/grouping/group.ipa.test.ts | 4 +++- test/hardhat/e2e/ipa/ipa.test.ts | 2 ++ test/hardhat/e2e/licenseTermsTemplate.ts | 2 ++ test/hardhat/e2e/permission/permission.test.ts | 2 ++ test/hardhat/e2e/setup.ts | 2 ++ test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts | 2 ++ test/hardhat/e2e/utils/nftHelper.ts | 2 ++ 9 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index e3cdc0e8b..932ed2749 100644 --- a/.env.example +++ b/.env.example @@ -18,4 +18,5 @@ ETHERSCAN_API_KEY = ETHERSCANAPIKEYETHERSCANAPIKEY DEVNET_URL = http:// DEVNET_CHAINID = 1315 DEVNET_PRIVATEKEY = -DEVNET_USER1 = \ No newline at end of file +DEVNET_USER1 = +DEVNET_ERC721 = diff --git a/test/hardhat/e2e/constants.ts b/test/hardhat/e2e/constants.ts index be11f0b7e..3c1015401 100644 --- a/test/hardhat/e2e/constants.ts +++ b/test/hardhat/e2e/constants.ts @@ -1,3 +1,5 @@ +// This is the deployed protocol address constants file. + export const AccessController = "0xf709c8001E94e2ca6F98b7fFBCd5BD3943E46D81"; export const CoreMetadataModule = "0x89630Ccf23277417FBdfd3076C702F5248267e78"; export const CoreMetadataViewModule = "0x6839De4A647eE2311bd765f615E09f7bd930ed25"; @@ -21,4 +23,6 @@ export const ProtocolPauseAdmin = "0x65C6Ec6Cc074eaf7ba3970C540b4379C9BcA8A67"; export const RoyaltyModule = "0xEa6eD700b11DfF703665CCAF55887ca56134Ae3B"; export const RoyaltyPolicyLAP = "0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6"; export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd"; -export const MockERC721 = "0x7a23aad16b2ac6ad74f76990a814b0f82bec83b8"; + +// Mock ERC721 contract address +export const MockERC721 = process.env.DEVNET_ERC721 as string; diff --git a/test/hardhat/e2e/grouping/group.ipa.test.ts b/test/hardhat/e2e/grouping/group.ipa.test.ts index fcdd6c57d..365305a29 100644 --- a/test/hardhat/e2e/grouping/group.ipa.test.ts +++ b/test/hardhat/e2e/grouping/group.ipa.test.ts @@ -1,3 +1,5 @@ +// Test: Group IP Asset + import "../setup" import { expect } from "chai" import { EvenSplitGroupPool } from "../constants" @@ -19,4 +21,4 @@ describe("Group IPA", function () { this.groupingModule.registerGroup(nonWhitelistedGroupPool) ).to.be.rejectedWith(Error) }); -}); \ No newline at end of file +}); diff --git a/test/hardhat/e2e/ipa/ipa.test.ts b/test/hardhat/e2e/ipa/ipa.test.ts index 6c014a346..df0a909f8 100644 --- a/test/hardhat/e2e/ipa/ipa.test.ts +++ b/test/hardhat/e2e/ipa/ipa.test.ts @@ -1,3 +1,5 @@ +// Test: IP Asset + import "../setup" import { expect } from "chai" import { mintNFT } from "../utils/nftHelper" diff --git a/test/hardhat/e2e/licenseTermsTemplate.ts b/test/hardhat/e2e/licenseTermsTemplate.ts index b19c2586c..364776283 100644 --- a/test/hardhat/e2e/licenseTermsTemplate.ts +++ b/test/hardhat/e2e/licenseTermsTemplate.ts @@ -1,3 +1,5 @@ +// This file is used to define the terms of a license that will be used in the tests. + import hre from "hardhat"; export const terms = { diff --git a/test/hardhat/e2e/permission/permission.test.ts b/test/hardhat/e2e/permission/permission.test.ts index d55979f36..1fb5843d5 100644 --- a/test/hardhat/e2e/permission/permission.test.ts +++ b/test/hardhat/e2e/permission/permission.test.ts @@ -1,3 +1,5 @@ +// Test: Permission + import "../setup" import { expect } from "chai" import { mintNFT } from "../utils/nftHelper" diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 88ef79d3e..4ce985110 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -1,3 +1,5 @@ +// This file is a root hook used to setup preconditions before running the tests. + import hre from "hardhat"; import { network } from "hardhat"; import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP, AccessController } from "./constants"; diff --git a/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts b/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts index 60bcfc34f..ca3dd99ce 100644 --- a/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts +++ b/test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts @@ -1,3 +1,5 @@ +// Purpose: Helper function to mint an NFT and register it as an IP Asset. + import "../setup"; import { mintNFT } from "./nftHelper"; import { MockERC721, IPAssetRegistry } from "../constants"; diff --git a/test/hardhat/e2e/utils/nftHelper.ts b/test/hardhat/e2e/utils/nftHelper.ts index 08490dbf1..313fcfd06 100644 --- a/test/hardhat/e2e/utils/nftHelper.ts +++ b/test/hardhat/e2e/utils/nftHelper.ts @@ -1,3 +1,5 @@ +// Purpose: Helper function to mint a new NFT and return the tokenId + import hre from "hardhat" import { MockERC721 } from "../constants"; import { ethers } from "ethers"; From e30075b2c5d7ed6e88f0a93c29b1846e64ccf527 Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Wed, 4 Dec 2024 15:05:57 +0800 Subject: [PATCH 20/21] Update README.md --- test/hardhat/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/hardhat/README.md b/test/hardhat/README.md index 584f36f07..79f713aeb 100644 --- a/test/hardhat/README.md +++ b/test/hardhat/README.md @@ -11,15 +11,15 @@ Please install the following: ## Quickstart -Install the dependencies: +Install the dependencies: run yarn command at project root. If you encounter any issues, try to remove node-modules and yarn.lock then run yarn again. ```sh yarn # this installs packages ``` -You'll need to add the variables refer to the .env.example to a .env file +You'll need to add the variables refer to the .env.example to a .env file at project root. -Then, run the tests with: +Then, at project root run the tests with command: ```sh npx hardhat test --network odyssey From 9e5a5990a40de713b03af81c65f9626827ad3347 Mon Sep 17 00:00:00 2001 From: Tina-57blocks Date: Wed, 4 Dec 2024 15:49:02 +0800 Subject: [PATCH 21/21] Update README.md --- test/hardhat/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/hardhat/README.md b/test/hardhat/README.md index 79f713aeb..5c0819e38 100644 --- a/test/hardhat/README.md +++ b/test/hardhat/README.md @@ -24,3 +24,9 @@ Then, at project root run the tests with command: ```sh npx hardhat test --network odyssey ``` + +You can specify the file path if you want to run test on a specific file: + +```sh +npx hardhat test [file-path] --network odyssey +```