Skip to content

Commit

Permalink
most nft tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed May 5, 2022
1 parent 14e0b76 commit 0643176
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 194 deletions.
3 changes: 1 addition & 2 deletions scripts/deploy/truffle-wrapper/deploy/setupContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async function setupContracts({
roles,
verbose
})

addresses.stage = 16
}

Expand All @@ -504,7 +504,6 @@ async function setupContracts({
})
addresses.stage = 17
}

}

module.exports = setupContracts
7 changes: 5 additions & 2 deletions test/helpers/deployManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const EpochLibrary = artifacts.require('EpochLibrary')
const DIDRegistryLibrary = artifacts.require('DIDRegistryLibrary')

const constants = require('./constants')
const testUtils = require('./utils')

const deployManagers = async function(deployer, owner) {
Expand All @@ -12,8 +11,9 @@ const deployManagers = async function(deployer, owner) {
const token = await testUtils.deploy('NeverminedToken', [owner, owner], deployer)
const nvmConfig = await testUtils.deploy('NeverminedConfig', [owner, owner], deployer)
const nft = await testUtils.deploy('NFTUpgradeable', [''], deployer)
const nft721 = await testUtils.deploy('NFT721Upgradeable', [], deployer)

const didRegistry = await testUtils.deploy('DIDRegistry', [owner, nft.address, constants.address.zero], deployer, [didRegistryLibrary])
const didRegistry = await testUtils.deploy('DIDRegistry', [owner, nft.address, nft721.address], deployer, [didRegistryLibrary])

const templateStoreManager = await testUtils.deploy('TemplateStoreManager', [owner], deployer)

Expand All @@ -33,6 +33,8 @@ const deployManagers = async function(deployer, owner) {
if (testUtils.deploying) {
await nft.addMinter(didRegistry.address, { from: deployer })
await nft.setProxyApproval(didRegistry.address, true, { from: deployer })
await nft721.addMinter(didRegistry.address, { from: deployer })
await nft721.setProxyApproval(didRegistry.address, true, { from: deployer })
await conditionStoreManager.delegateCreateRole(
agreementStoreManager.address,
{ from: owner }
Expand All @@ -46,6 +48,7 @@ const deployManagers = async function(deployer, owner) {
conditionStoreManager,
templateStoreManager,
nft,
nft721,
deployer,
owner
}
Expand Down
180 changes: 61 additions & 119 deletions test/int/nft/NFT721_e2e.Test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
/* eslint-env mocha */
/* eslint-disable no-console */
/* global artifacts, contract, describe, it */
/* global contract, describe, it */

const chai = require('chai')
const { assert } = chai
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)

const NFTAccessTemplate = artifacts.require('NFTAccessTemplate')
const NFTSalesTemplate = artifacts.require('NFTSalesTemplate')

const NeverminedConfig = artifacts.require('NeverminedConfig')
const LockPaymentCondition = artifacts.require('LockPaymentCondition')
const TransferNFTCondition = artifacts.require('TransferNFT721Condition')
const EscrowPaymentCondition = artifacts.require('EscrowPaymentCondition')
const EpochLibrary = artifacts.require('EpochLibrary')
const DIDRegistryLibrary = artifacts.require('DIDRegistryLibrary')
const DIDRegistry = artifacts.require('DIDRegistry')
const ConditionStoreManager = artifacts.require('ConditionStoreManager')
const TemplateStoreManager = artifacts.require('TemplateStoreManager')
const AgreementStoreManager = artifacts.require('AgreementStoreManager')
const NeverminedToken = artifacts.require('NeverminedToken')
const NFTAccessCondition = artifacts.require('NFTAccessCondition')
const NFTHolderCondition = artifacts.require('NFT721HolderCondition')

const TestERC721 = artifacts.require('NFT721Upgradeable')

const constants = require('../../helpers/constants.js')
const { getBalance } = require('../../helpers/getBalance.js')
const testUtils = require('../../helpers/utils.js')

const { getTokenBalance, getCheckpoint } = require('../../helpers/getBalance.js')
const deployManagers = require('../../helpers/deployManagers.js')
const deployConditions = require('../../helpers/deployConditions.js')

contract('End to End NFT721 Scenarios', (accounts) => {
const royalties = 10 // 10% of royalties in the secondary market
const didSeed = testUtils.generateId()
Expand All @@ -39,15 +23,17 @@ contract('End to End NFT721 Scenarios', (accounts) => {
const url = 'https://raw.githubusercontent.com/nevermined-io/assets/main/images/logo/banner_logo.png'

const [
owner,
deployer,
artist,
collector1,
collector2,
gallery,
market,
someone
] = accounts

const owner = accounts[9]
const deployer = accounts[8]

// Configuration of First Sale:
// Artist -> Collector1, the gallery get a cut (25%)
const numberNFTs = 1
Expand All @@ -62,13 +48,6 @@ contract('End to End NFT721 Scenarios', (accounts) => {
const amounts2 = [90, 10]
const receivers2 = [collector1, artist]

before(async () => {
const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
})

let
didRegistry,
token,
Expand All @@ -82,120 +61,83 @@ contract('End to End NFT721 Scenarios', (accounts) => {
transferCondition,
escrowCondition,
nftHolderCondition,
accessCondition
accessCondition,
getBalance

async function setupTest() {
token = await NeverminedToken.new()
await token.initialize(owner, owner)

const nvmConfig = await NeverminedConfig.new()
await nvmConfig.initialize(owner, owner)

nft = await TestERC721.new({ from: deployer })
await nft.initialize({ from: owner })

didRegistry = await DIDRegistry.new()
await didRegistry.initialize(owner, constants.address.zero, nft.address)

await nft.addMinter(didRegistry.address)

conditionStoreManager = await ConditionStoreManager.new()

templateStoreManager = await TemplateStoreManager.new()
await templateStoreManager.initialize(owner, { from: deployer })

agreementStoreManager = await AgreementStoreManager.new()
await agreementStoreManager.methods['initialize(address,address,address,address)'](
let nft721
({
token,
didRegistry,
agreementStoreManager,
conditionStoreManager,
templateStoreManager,
nft721
} = await deployManagers(
deployer,
owner
))
nft = nft721;
({
lockPaymentCondition,
escrowCondition
} = await deployConditions(
deployer,
owner,
conditionStoreManager.address,
templateStoreManager.address,
didRegistry.address,
{ from: deployer }
)
agreementStoreManager,
conditionStoreManager,
didRegistry,
token
))

await conditionStoreManager.initialize(
agreementStoreManager.address,
owner,
nvmConfig.address,
{ from: deployer }
)

lockPaymentCondition = await LockPaymentCondition.new()
await lockPaymentCondition.initialize(
owner,
conditionStoreManager.address,
didRegistry.address,
{ from: deployer }
)
await lockPaymentCondition.grantProxyRole(agreementStoreManager.address, { from: owner })

transferCondition = await TransferNFTCondition.new()
await transferCondition.methods['initialize(address,address,address,address,address)'](
owner,
transferCondition = await testUtils.deploy('TransferNFT721Condition', [owner,
conditionStoreManager.address,
didRegistry.address,
nft.address,
lockPaymentCondition.address,
{ from: deployer }
)
await transferCondition.grantProxyRole(agreementStoreManager.address, { from: owner })
market], deployer)

escrowCondition = await EscrowPaymentCondition.new()
await escrowCondition.initialize(
accessCondition = await testUtils.deploy('NFTAccessCondition', [
owner,
conditionStoreManager.address,
{ from: deployer }
)
didRegistry.address], deployer)

accessCondition = await NFTAccessCondition.new()
await accessCondition.methods['initialize(address,address,address)'](
nftHolderCondition = await testUtils.deploy('NFT721HolderCondition', [
owner,
conditionStoreManager.address,
didRegistry.address,
{ from: deployer }
)

nftHolderCondition = await NFTHolderCondition.new({ from: deployer })
await nftHolderCondition.initialize(
owner,
conditionStoreManager.address,
{ from: deployer }
)
conditionStoreManager.address
], deployer)

nftSalesTemplate = await NFTSalesTemplate.new()
await nftSalesTemplate.methods['initialize(address,address,address,address,address)'](
nftSalesTemplate = await testUtils.deploy('NFT721SalesTemplate', [
owner,
agreementStoreManager.address,
lockPaymentCondition.address,
transferCondition.address,
escrowCondition.address,
{ from: deployer }
)
await agreementStoreManager.grantProxyRole(nftSalesTemplate.address, { from: owner })
await lockPaymentCondition.grantProxyRole(agreementStoreManager.address, { from: owner })
await conditionStoreManager.grantProxyRole(
escrowCondition.address,
{ from: owner }
)
escrowCondition.address], deployer)

// Setup NFT Access Template
nftAccessTemplate = await NFTAccessTemplate.new()
await nftAccessTemplate.methods['initialize(address,address,address,address)'](
nftAccessTemplate = await testUtils.deploy('NFT721AccessTemplate', [
owner,
agreementStoreManager.address,
nftHolderCondition.address,
accessCondition.address,
{ from: deployer }
)
accessCondition.address], deployer)

// IMPORTANT: Here we give ERC1155 transfer grants to the TransferNFTCondition condition
// await didRegistry.setProxyApproval(transferCondition.address, true, { from: owner })
if (testUtils.deploying) {
await lockPaymentCondition.grantProxyRole(agreementStoreManager.address, { from: owner })
await transferCondition.grantProxyRole(agreementStoreManager.address, { from: owner })
await agreementStoreManager.grantProxyRole(nftSalesTemplate.address, { from: owner })
await conditionStoreManager.grantProxyRole(escrowCondition.address, { from: owner })

await templateStoreManager.proposeTemplate(nftSalesTemplate.address)
await templateStoreManager.approveTemplate(nftSalesTemplate.address, { from: owner })
await templateStoreManager.proposeTemplate(nftSalesTemplate.address)
await templateStoreManager.approveTemplate(nftSalesTemplate.address, { from: owner })

await templateStoreManager.proposeTemplate(nftAccessTemplate.address)
await templateStoreManager.approveTemplate(nftAccessTemplate.address, { from: owner })

// IMPORTANT: Here we give ERC1155 transfer grants to the TransferNFTCondition condition
await nft.setProxyApproval(transferCondition.address, true, { from: deployer })
}

await templateStoreManager.proposeTemplate(nftAccessTemplate.address)
await templateStoreManager.approveTemplate(nftAccessTemplate.address, { from: owner })
const checkpoint = await getCheckpoint(token, [artist, collector1, collector2, gallery, someone, lockPaymentCondition.address, escrowCondition.address])
getBalance = async (a, b) => getTokenBalance(a, b, checkpoint)

return {
didRegistry
Expand Down
32 changes: 14 additions & 18 deletions test/int/nft/NFTAccessProofAgreement.Test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* eslint-env mocha */
/* eslint-disable no-console */
/* global artifacts, contract, describe, it, expect */
/* global contract, describe, it, expect */

const chai = require('chai')
const { assert } = chai
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)

const NFTAccessProofTemplate = artifacts.require('NFTAccessProofTemplate')
const NFTHolderCondition = artifacts.require('NFTHolderCondition')

const constants = require('../../helpers/constants.js')
const deployConditions = require('../../helpers/deployConditions.js')
const deployManagers = require('../../helpers/deployManagers.js')
Expand All @@ -34,12 +31,14 @@ contract('NFT Access Proof Template integration test', (accounts) => {
nftHolderCondition,
accessProofCondition
const [
owner,
deployer,
artist,
receiver,
someone
] = accounts

const owner = accounts[9]
const deployer = accounts[8]

async function setupTest() {
({
token,
Expand All @@ -63,27 +62,24 @@ contract('NFT Access Proof Template integration test', (accounts) => {
didRegistry,
token
))
nftHolderCondition = await NFTHolderCondition.new({ from: deployer })
await nftHolderCondition.initialize(

nftHolderCondition = await testUtils.deploy('NFTHolderCondition', [
owner,
conditionStoreManager.address,
nft.address,
{ from: deployer }
)
nft.address], deployer)

nftAccessTemplate = await NFTAccessProofTemplate.new()
await nftAccessTemplate.methods['initialize(address,address,address,address)'](
nftAccessTemplate = await testUtils.deploy('NFTAccessProofTemplate', [
owner,
agreementStoreManager.address,
nftHolderCondition.address,
accessProofCondition.address,
{ from: deployer }
)
accessProofCondition.address], deployer)

// propose and approve template
const templateId = nftAccessTemplate.address
await templateStoreManager.proposeTemplate(templateId)
await templateStoreManager.approveTemplate(templateId, { from: owner })
if (testUtils.deploying) {
await templateStoreManager.proposeTemplate(templateId)
await templateStoreManager.approveTemplate(templateId, { from: owner })
}

return {
templateId,
Expand Down

0 comments on commit 0643176

Please sign in to comment.