Skip to content

Commit

Permalink
tests seem to work
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed Nov 17, 2021
1 parent 4c421a1 commit c4d1894
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 58 deletions.
1 change: 1 addition & 0 deletions contracts.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"DIDRegistry",
"NFTUpgradeable",
"ConditionStoreManager",
"TemplateStoreManager",
"AgreementStoreManager",
Expand Down
3 changes: 2 additions & 1 deletion contracts/registry/DIDFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ contract DIDFactory is OwnableUpgradeable, ProvenanceRegistry {
* Initialize Ownable. Only on contract creation.
* @param _owner refers to the owner of the contract.
*/
/*
function initialize(
address _owner
)
Expand All @@ -151,7 +152,7 @@ contract DIDFactory is OwnableUpgradeable, ProvenanceRegistry {
OwnableUpgradeable.__Ownable_init();
transferOwnership(_owner);
manager = _owner;
}
}*/

/**
* Sets the manager role. Should be the TransferCondition contract address
Expand Down
6 changes: 4 additions & 2 deletions contracts/registry/DIDRegistryLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ library DIDRegistryLibrary {
{
// If (did.creator == did.owner) - It means the DID is still a first sale so no royalties needed
// returns true;
if (_self.didRegisters[_did].owner == _self.didRegisters[_did].creator)
if (_self.didRegisters[_did].owner == _self.didRegisters[_did].creator) {
return true;
}

// If there are no royalties everything is good
if (_self.didRegisters[_did].royalties == 0)
if (_self.didRegisters[_did].royalties == 0) {
return true;
}

// If (sum(_amounts) == 0) - It means there is no payment so everything is valid
// returns true;
Expand Down
11 changes: 10 additions & 1 deletion scripts/deploy/truffle-wrapper/deploy/initializeContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ async function initializeContracts({
return addressBook[contract] || proxies[contract]
}

if (contracts.indexOf('NFTUpgradeable') > -1) {
addressBook.NFTUpgradeable = await zosCreate({
contract: 'NFTUpgradeable',
cache,
args: [''],
verbose
})
}

if (contracts.indexOf('DIDRegistry') > -1) {
addressBook.DIDRegistry = await zosCreate({
contract: 'DIDRegistry',
cache,
args: [roles.deployer],
args: [roles.deployer, addressBook.NFTUpgradeable || ZeroAddress],
libraries: { DIDRegistryLibrary: didRegistryLibrary },
verbose
})
Expand Down
15 changes: 12 additions & 3 deletions scripts/deploy/truffle-wrapper/deploy/setupContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ async function setupContracts({
})
}

if (addressBook.NFTUpgradeable && addressBook.DIDRegistry) {
const NFTInstance = artifacts.NFTUpgradeable

console.log('Set NFT minter : ' + addressBook.NFTUpgradeable)
const tx = await NFTInstance.addMinter(
addressBook.DIDRegistry, { from: roles.deployer })
await tx.wait()
}

if (addressBook.TransferDIDOwnershipCondition && addressBook.DIDRegistry) {
const DIDRegistryInstance = artifacts.DIDRegistry

Expand All @@ -203,11 +212,11 @@ async function setupContracts({
await tx.wait()
}

if (addressBook.TransferNFTCondition && addressBook.DIDRegistry) {
const DIDRegistryInstance = artifacts.DIDRegistry
if (addressBook.TransferNFTCondition && addressBook.NFTUpgradeable) {
const NFTInstance = artifacts.NFTUpgradeable

console.log('TransferNFTCondition : ' + addressBook.TransferNFTCondition)
const tx = await DIDRegistryInstance.setProxyApproval(
const tx = await NFTInstance.setProxyApproval(
addressBook.TransferNFTCondition, true, { from: roles.deployer })
await tx.wait()
}
Expand Down
8 changes: 7 additions & 1 deletion test/helpers/deployManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ConditionStoreManager = artifacts.require('ConditionStoreManager')
const TemplateStoreManager = artifacts.require('TemplateStoreManager')
const AgreementStoreManager = artifacts.require('AgreementStoreManager')
const NeverminedToken = artifacts.require('NeverminedToken')
const NFT = artifacts.require('NFTUpgradeable')

let linked = false

Expand All @@ -22,8 +23,12 @@ const deployManagers = async function(deployer, owner) {
const token = await NeverminedToken.new({ from: deployer })
await token.initialize(owner, owner)

const nft = await NFT.new()
await nft.initialize('')

const didRegistry = await DIDRegistry.new()
await didRegistry.initialize(owner)
await didRegistry.initialize(owner, nft.address)
await nft.addMinter(didRegistry.address)

const conditionStoreManager = await ConditionStoreManager.new({ from: deployer })

Expand Down Expand Up @@ -53,6 +58,7 @@ const deployManagers = async function(deployer, owner) {
agreementStoreManager,
conditionStoreManager,
templateStoreManager,
nft,
deployer,
owner
}
Expand Down
6 changes: 4 additions & 2 deletions test/int/agreement/DynamicAccessAgreement.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ contract('Dynamic Access Template integration test', (accounts) => {
templateStoreManager,
dynamicAccessTemplate,
accessCondition,
nftHolderCondition
nftHolderCondition,
nft

const Activities = {
GENERATED: '0x1',
Expand All @@ -39,6 +40,7 @@ contract('Dynamic Access Template integration test', (accounts) => {
didRegistry,
agreementStoreManager,
conditionStoreManager,
nft,
templateStoreManager
} = await deployManagers(
deployer,
Expand Down Expand Up @@ -148,7 +150,7 @@ contract('Dynamic Access Template integration test', (accounts) => {

// Mint and Transfer
await didRegistry.mint(agreement.did, 10, { from: receiver })
await didRegistry.safeTransferFrom(
await nft.safeTransferFrom(
receiver, holder, BigInt(agreement.did), 10, '0x', { from: receiver })

// Conditions need to be added to the template
Expand Down
4 changes: 3 additions & 1 deletion test/int/agreement/NFTAccessAgreement.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const NFTAccessCondition = artifacts.require('NFTAccessCondition')

contract('NFT Access integration test', (accounts) => {
let token,
nft,
didRegistry,
agreementStoreManager,
conditionStoreManager,
Expand All @@ -32,6 +33,7 @@ contract('NFT Access integration test', (accounts) => {
} = {}) {
({
token,
nft,
didRegistry,
agreementStoreManager,
conditionStoreManager,
Expand Down Expand Up @@ -148,7 +150,7 @@ contract('NFT Access integration test', (accounts) => {

// mint and transfer the nft
await didRegistry.mint(agreement.did, nftAmount, { from: sender })
await didRegistry.safeTransferFrom(
await nft.safeTransferFrom(
sender, receiver, BigInt(agreement.did), nftAmount, '0x', { from: sender })

// fulfill nft holder condition
Expand Down
34 changes: 20 additions & 14 deletions test/int/nft/NFTWithEther_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const TemplateStoreManager = artifacts.require('TemplateStoreManager')
const AgreementStoreManager = artifacts.require('AgreementStoreManager')
const NFTAccessCondition = artifacts.require('NFTAccessCondition')
const NFTHolderCondition = artifacts.require('NFTHolderCondition')
const NFT = artifacts.require('NFTUpgradeable')

const constants = require('../../helpers/constants.js')
const testUtils = require('../../helpers/utils.js')
Expand Down Expand Up @@ -80,6 +81,7 @@ contract('End to End NFT Scenarios', (accounts) => {

let
didRegistry,
nft,
agreementStoreManager,
conditionStoreManager,
templateStoreManager,
Expand All @@ -94,8 +96,12 @@ contract('End to End NFT Scenarios', (accounts) => {
accessCondition

async function setupTest() {
nft = await NFT.new()
await nft.initialize('')

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

conditionStoreManager = await ConditionStoreManager.new()

Expand Down Expand Up @@ -128,7 +134,7 @@ contract('End to End NFT Scenarios', (accounts) => {
await transferCondition.initialize(
owner,
conditionStoreManager.address,
didRegistry.address,
nft.address,
market,
{ from: deployer }
)
Expand Down Expand Up @@ -177,7 +183,7 @@ contract('End to End NFT Scenarios', (accounts) => {
)

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

await templateStoreManager.proposeTemplate(nftSalesTemplate.address)
await templateStoreManager.approveTemplate(nftSalesTemplate.address, { from: owner })
Expand All @@ -186,7 +192,8 @@ contract('End to End NFT Scenarios', (accounts) => {
await templateStoreManager.approveTemplate(nftAccessTemplate.address, { from: owner })

return {
didRegistry
didRegistry,
nft
}
}

Expand Down Expand Up @@ -262,14 +269,14 @@ contract('End to End NFT Scenarios', (accounts) => {

describe('As an artist I want to register a new artwork', () => {
it('I want to register a new artwork and tokenize (via NFT). I want to get 10% of royalties', async () => {
const { didRegistry } = await setupTest()
const { didRegistry, nft } = await setupTest()

did = await didRegistry.hashDID(didSeed, artist)

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

const balance = await didRegistry.balanceOf(artist, did)
assert.strictEqual(5, balance.toNumber())
Expand Down Expand Up @@ -324,15 +331,15 @@ contract('End to End NFT Scenarios', (accounts) => {
const nftBalanceArtistBefore = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorBefore = await didRegistry.balanceOf(collector1, did)

await didRegistry.setApprovalForAll(transferCondition.address, true, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })
await transferCondition.methods['fulfill(bytes32,bytes32,address,uint256,bytes32)'](
agreementId,
did,
collector1,
numberNFTs,
nftSalesAgreement.conditionIds[0],
{ from: artist })
await didRegistry.setApprovalForAll(transferCondition.address, false, { from: artist })
await nft.setApprovalForAll(transferCondition.address, false, { from: artist })

const { state } = await conditionStoreManager.getCondition(
nftSalesAgreement.conditionIds[1])
Expand Down Expand Up @@ -446,17 +453,16 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[0])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

await didRegistry.setApprovalForAll(transferCondition.address, true, { from: collector1 })
// Collector1: Transfer the NFT
await didRegistry.setApprovalForAll(transferCondition.address, true, { from: collector1 })
await nft.setApprovalForAll(transferCondition.address, true, { from: collector1 })
await transferCondition.methods['fulfill(bytes32,bytes32,address,uint256,bytes32)'](
agreementId2,
did,
collector2,
numberNFTs2,
nftSalesAgreement.conditionIds[0],
{ from: collector1 })
await didRegistry.setApprovalForAll(transferCondition.address, true, { from: collector1 })
await nft.setApprovalForAll(transferCondition.address, true, { from: collector1 })

let condition = await conditionStoreManager.getCondition(
nftSalesAgreement.conditionIds[1])
Expand Down Expand Up @@ -536,14 +542,14 @@ contract('End to End NFT Scenarios', (accounts) => {

describe('As market I want to be able to transfer nfts and release rewards on behalf of the artist', () => {
it('Artist registers a new artwork and tokenize (via NFT)', async () => {
const { didRegistry } = await setupTest()
const { didRegistry, nft } = await setupTest()

did = await didRegistry.hashDID(didSeed, artist)

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

const balance = await didRegistry.balanceOf(artist, did)
assert.strictEqual(5, balance.toNumber())
Expand Down Expand Up @@ -596,7 +602,7 @@ contract('End to End NFT Scenarios', (accounts) => {
const nftBalanceArtistBefore = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorBefore = await didRegistry.balanceOf(collector1, did)

await didRegistry.setApprovalForAll(market, true, { from: artist })
await nft.setApprovalForAll(market, true, { from: artist })
await transferCondition.fulfillForMarket(
agreementId,
did,
Expand Down

0 comments on commit c4d1894

Please sign in to comment.