forked from storyprotocol/protocol-core-v1
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* setup e2e * update e2e struct * add IP Assets tests * update test struct * add ipa test * add tests for register license terms * add tests for register license terms * add common methods in setup * update common methods * add test for attach license terms * add tests for mint license tokens * add permission test * update permission test * update var name * update common and ipa tests * update test config * Update .env.example * Create README.md * Add file level comment and fix review comment * Update README.md * Update README.md --------- Co-authored-by: Jacqueline Zhang <[email protected]> Co-authored-by: jia57b <[email protected]>
- Loading branch information
1 parent
622a862
commit e03d3f7
Showing
15 changed files
with
644 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,6 @@ typechain | |
# converage | ||
lcov.info | ||
|
||
# test | ||
mochawesome-report | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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: 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 at project root. | ||
|
||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This is the deployed protocol address constants file. | ||
|
||
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"; | ||
|
||
// Mock ERC721 contract address | ||
export const MockERC721 = process.env.DEVNET_ERC721 as string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Test: Group IP Asset | ||
|
||
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) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Test: IP Asset | ||
|
||
import "../setup" | ||
import { expect } from "chai" | ||
import { mintNFT } from "../utils/nftHelper" | ||
import hre from "hardhat"; | ||
import { MockERC721 } from "../constants"; | ||
|
||
describe("IP Asset", function () { | ||
let signers:any; | ||
|
||
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]); | ||
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 isRegistered = await expect( | ||
connectedRegistry.isRegistered(ipId) | ||
).not.to.be.rejectedWith(Error); | ||
|
||
expect(isRegistered).to.equal(true); | ||
}); | ||
|
||
it("Non-NFT owner register IP asset with an NFT token", async function () { | ||
const tokenId = await mintNFT(signers[0]); | ||
const connectedRegistry = this.ipAssetRegistry.connect(signers[1]); | ||
|
||
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 isRegistered = await expect( | ||
connectedRegistry.isRegistered(ipId) | ||
).not.to.be.rejectedWith(Error); | ||
|
||
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]); | ||
|
||
// 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(this.chainId, MockERC721, tokenId) | ||
).to.be.rejectedWith(`insufficient funds`, `"code": -32000, "message": "insufficient funds for gas * price + value: balance 0`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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 = { | ||
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: "", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Test: Permission | ||
|
||
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; | ||
|
||
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); | ||
const ALLOW_permission = 1; | ||
const DENY_permission = 2; | ||
let permissionAfter: number; | ||
let result: any; | ||
|
||
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 connecedAccessController = this.accessController.connect(signers[0]); | ||
|
||
const permissionBefore = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); | ||
expect(permissionBefore).to.equal(0); | ||
|
||
// add ALLOW permission | ||
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(); | ||
|
||
// check the permission | ||
permissionAfter = await connecedAccessController.getPermission(ipId, signers[0].address, LicensingModule, func); | ||
expect(permissionAfter).to.equal(ALLOW_permission); | ||
|
||
// Change to 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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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"; | ||
import { terms } from "./licenseTermsTemplate"; | ||
|
||
before(async function () { | ||
console.log(`================= Load Contract =================`); | ||
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); | ||
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(); | ||
|
||
console.log(`================= Chain ID =================`); | ||
const networkConfig = network.config; | ||
this.chainId = networkConfig.chainId; | ||
console.log("chainId: ", this.chainId); | ||
|
||
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); | ||
|
||
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); | ||
|
||
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); | ||
}); |
Oops, something went wrong.