Skip to content

Commit

Permalink
first nft test working
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed May 4, 2022
1 parent 475fd15 commit 14e0b76
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 119 deletions.
4 changes: 2 additions & 2 deletions scripts/deploy/truffle-wrapper/deploy/initializeContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ async function initializeContracts({
contract: 'TransferNFTCondition',
ctx,
args: [
roles.ownerWallet,
roles.deployer,
getAddress('ConditionStoreManager'),
getAddress('DIDRegistry'),
getAddress('NFTUpgradeable'),
Expand Down Expand Up @@ -493,7 +493,7 @@ async function initializeContracts({
contract: 'TransferNFT721Condition',
ctx,
args: [
roles.ownerWallet,
roles.deployer,
getAddress('ConditionStoreManager'),
getAddress('DIDRegistry'),
getAddress('NFT721Upgradeable'),
Expand Down
33 changes: 32 additions & 1 deletion scripts/deploy/truffle-wrapper/deploy/setupContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async function setupContracts({
addresses.stage = 4
}

if (addresses.stage < 5 && addresses.stage < 5) {
if (addressBook.AgreementStoreManager && addresses.stage < 5) {
const agreements = [
'NFTAccessTemplate',
'NFTSalesTemplate',
Expand Down Expand Up @@ -474,6 +474,37 @@ async function setupContracts({

addresses.stage = 15
}

if (addressBook.TransferNFTCondition && addressBook.AgreementStoreManager && addresses.stage < 16) {
console.log('Set transfer nft condition proxy : ' + addressBook.TransferNFTCondition)
const tx = await artifacts.TransferNFTCondition.connect(ethers.provider.getSigner(roles.deployer)).grantProxyRole(
addressBook.AgreementStoreManager, { from: roles.deployer })
await tx.wait()

await transferOwnership({
ContractInstance: artifacts.TransferNFTCondition,
name: 'TransferNFTCondition',
roles,
verbose
})

addresses.stage = 16
}

if (addressBook.TransferNFT721Condition && addressBook.AgreementStoreManager && addresses.stage < 17) {
console.log('Set transfer nft721 condition proxy : ' + addressBook.TransferNFT721Condition)
const tx = await artifacts.TransferNFT721Condition.connect(ethers.provider.getSigner(roles.deployer)).grantProxyRole(
addressBook.AgreementStoreManager, { from: roles.deployer })
await tx.wait()
await transferOwnership({
ContractInstance: artifacts.TransferNFT721Condition,
name: 'TransferNFT721Condition',
roles,
verbose
})
addresses.stage = 17
}

}

module.exports = setupContracts
1 change: 1 addition & 0 deletions test/helpers/deployConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const deployConditions = async function(
accessCondition,
accessProofCondition,
escrowPaymentCondition,
escrowCondition: escrowPaymentCondition,
lockPaymentCondition,
computeExecutionCondition
}
Expand Down
174 changes: 58 additions & 116 deletions test/int/nft/NFT_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,25 @@ 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('TransferNFTCondition')
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('NFTHolderCondition')
const NFT = artifacts.require('NFTUpgradeable')
const { getTokenBalance, getCheckpoint } = require('../../helpers/getBalance.js')

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

contract('End to End NFT Scenarios', (accounts) => {
const royalties = 10 // 10% of royalties in the secondary market
const cappedAmount = 5
const didSeed = testUtils.generateId()
const didSeed2 = testUtils.generateId()
let did
let agreementId

const checksum = testUtils.generateId()
const url = 'https://raw.githubusercontent.com/nevermined-io/assets/main/images/logo/banner_logo.png'

const [
owner,
deployer,
artist,
collector1,
collector2,
Expand All @@ -50,6 +34,9 @@ contract('End to End NFT Scenarios', (accounts) => {
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 Down Expand Up @@ -77,127 +64,82 @@ contract('End to End NFT Scenarios', (accounts) => {
transferCondition,
escrowCondition,
nftHolderCondition,
accessCondition

before(async () => {
const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link(epochLibrary)
const didRegistryLibrary = await DIDRegistryLibrary.new()
await DIDRegistry.link(didRegistryLibrary)
})
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 NFT.new()
await nft.initialize('')

didRegistry = await DIDRegistry.new()
await didRegistry.initialize(owner, nft.address, constants.address.zero)
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)'](
owner,
conditionStoreManager.address,
templateStoreManager.address,
didRegistry.address,
{ from: deployer }
)

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

lockPaymentCondition = await LockPaymentCondition.new()
await lockPaymentCondition.initialize(
({
token,
didRegistry,
agreementStoreManager,
conditionStoreManager,
templateStoreManager,
nft
} = await deployManagers(
deployer,
owner
));

({
lockPaymentCondition,
escrowCondition
} = await deployConditions(
deployer,
owner,
conditionStoreManager.address,
didRegistry.address,
{ from: deployer }
)
await lockPaymentCondition.grantProxyRole(agreementStoreManager.address, { from: owner })
agreementStoreManager,
conditionStoreManager,
didRegistry,
token
))

transferCondition = await TransferNFTCondition.new()
await transferCondition.initialize(
owner,
transferCondition = await testUtils.deploy('TransferNFTCondition', [owner,
conditionStoreManager.address,
didRegistry.address,
nft.address,
market,
{ 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('NFTHolderCondition', [
owner,
conditionStoreManager.address,
didRegistry.address,
{ from: deployer }
)
nft.address], deployer)

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

nftSalesTemplate = await NFTSalesTemplate.new()
await nftSalesTemplate.methods['initialize(address,address,address,address,address)'](
nftSalesTemplate = await testUtils.deploy('NFTSalesTemplate', [
owner,
agreementStoreManager.address,
lockPaymentCondition.address,
transferCondition.address,
escrowCondition.address,
{ from: deployer }
)
await agreementStoreManager.grantProxyRole(nftSalesTemplate.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('NFTAccessTemplate', [
owner,
agreementStoreManager.address,
nftHolderCondition.address,
accessCondition.address,
{ from: deployer }
)
accessCondition.address,], deployer)

await conditionStoreManager.grantProxyRole(
escrowCondition.address,
{ 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 })

// IMPORTANT: Here we give ERC1155 transfer grants to the TransferNFTCondition condition
await nft.setProxyApproval(transferCondition.address, true, { 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 })

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 })
}

const checkpoint = await getCheckpoint(token, [artist, collector1, collector2, market, gallery, someone, lockPaymentCondition.address, escrowCondition.address])
getBalance = async (a, b) => getTokenBalance(a, b, checkpoint)

return {
didRegistry,
Expand Down Expand Up @@ -520,10 +462,10 @@ contract('End to End NFT Scenarios', (accounts) => {
it('Artist registers a new artwork and tokenize (via NFT)', async () => {
const { didRegistry, nft } = await setupTest()

did = await didRegistry.hashDID(didSeed, artist)
did = await didRegistry.hashDID(didSeed2, artist)

await didRegistry.registerMintableDID(
didSeed, checksum, [], url, cappedAmount, royalties, constants.activities.GENERATED, '', { from: artist })
didSeed2, checksum, [], url, cappedAmount, royalties, constants.activities.GENERATED, '', { from: artist })
await didRegistry.mint(did, 5, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })

Expand Down

0 comments on commit 14e0b76

Please sign in to comment.