Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed Sep 14, 2023
1 parent fb07437 commit 55c8e82
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 105 deletions.
2 changes: 2 additions & 0 deletions contracts/Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import './governance/INVMConfig.sol';

import 'hardhat/console.sol';

/**
* @title Common functions
* @author Nevermined
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/INVMConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ abstract contract INVMConfig {
* @param _address The address to validate
* @return true if is a governor
*/
function isOperator(address _address)
function hasNVMOperatorRole(address _address)
external view virtual returns (bool);
}
6 changes: 3 additions & 3 deletions contracts/governance/NeverminedConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ INVMConfig
return hasRole(GOVERNOR_ROLE, _address);
}

function setOperator(address _address) external onlyOwner {
function grantNVMOperatorRole(address _address) external onlyOwner {
_grantRole(NVM_OPERATOR_ROLE, _address);
}

function revokeOperator(address _address) external onlyOwner {
function revokeNVMOperatorRole(address _address) external onlyOwner {
_revokeRole(NVM_OPERATOR_ROLE, _address);
}

function isOperator(
function hasNVMOperatorRole(
address _address
)
external
Expand Down
4 changes: 1 addition & 3 deletions contracts/token/NFTBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import '@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol
import '@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol';

import 'hardhat/console.sol';

/**
* @title Nevermined NFT Base
* @author Nevermined
Expand Down Expand Up @@ -232,7 +230,7 @@ abstract contract NFTBase is IERC2981Upgradeable, CommonOwnable, AccessControlUp
if (nvmConfig == address(0)) {
return AccessControlUpgradeable.hasRole(NVM_OPERATOR_ROLE, operator);
}
return NeverminedConfig(nvmConfig).isOperator(operator) || AccessControlUpgradeable.hasRole(NVM_OPERATOR_ROLE, operator);
return NeverminedConfig(nvmConfig).hasNVMOperatorRole(operator) || AccessControlUpgradeable.hasRole(NVM_OPERATOR_ROLE, operator);
}

function _msgSender() internal override(CommonOwnable,ContextUpgradeable) virtual view returns (address ret) {
Expand Down
2 changes: 0 additions & 2 deletions contracts/token/erc721/NFT721Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import '@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol';
import '../../interfaces/IExternalRegistry.sol';

import 'hardhat/console.sol';

/**
*
* @dev Implementation of the basic standard multi-token.
Expand Down
53 changes: 9 additions & 44 deletions scripts/deploy/setupContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ async function setupContracts({

if (addressBook.TransferDIDOwnershipCondition && addressBook.DIDRegistry && addresses.stage < 9) {
console.log('TransferDIDOwnershipCondition : ' + addressBook.TransferDIDOwnershipCondition)
await callContract(artifacts.DIDRegistry, a => a.grantRegistryOperatorRole(addressBook.TransferDIDOwnershipCondition))
// await callContract(artifacts.DIDRegistry, a => a.grantRegistryOperatorRole(addressBook.TransferDIDOwnershipCondition))
addresses.stage = 9
}

if (addressBook.TransferNFTCondition && addressBook.NFT1155Upgradeable && addresses.stage < 10) {
if (addressBook.TransferNFTCondition && addressBook.NeverminedConfig && addresses.stage < 10) {
console.log('TransferNFTCondition : ' + addressBook.TransferNFTCondition)
await callContract(artifacts.NFT1155Upgradeable, a => a.grantOperatorRole(addressBook.TransferNFTCondition))
await callContract(artifacts.NeverminedConfig, a => a.grantNVMOperatorRole(addressBook.TransferNFTCondition))
addresses.stage = 10
}

Expand All @@ -268,9 +268,9 @@ async function setupContracts({
addresses.stage = 11
}

if (addressBook.TransferNFT721Condition && addressBook.NFT721Upgradeable && addresses.stage < 12) {
if (addressBook.TransferNFT721Condition && addressBook.NeverminedConfig && addresses.stage < 12) {
console.log('TransferNFT721Condition : ' + addressBook.TransferNFT721Condition)
await callContract(artifacts.NFT721Upgradeable, a => a.grantOperatorRole(addressBook.TransferNFT721Condition))
await callContract(artifacts.NeverminedConfig, a => a.grantNVMOperatorRole(addressBook.TransferNFT721Condition))
addresses.stage = 12
}

Expand Down Expand Up @@ -393,21 +393,15 @@ async function setupContracts({
addresses.stage = 19
}

if (addressBook.NFTLockCondition && addressBook.NFT1155Upgradeable && addresses.stage < 20) {
console.log('Grant Proxy Approval (NFT1155Upgradeable) : ' + addressBook.NFTLockCondition)
await callContract(artifacts.NFT1155Upgradeable, a => a.grantOperatorRole(addressBook.NFTLockCondition))
addresses.stage = 20
}

if (addressBook.NFTLockCondition && addressBook.NFT721Upgradeable && addresses.stage < 21) {
if (addressBook.NFTLockCondition && addressBook.NeverminedConfig && addresses.stage < 21) {
console.log('Grant Proxy Approval (NFT721Upgradeable): ' + addressBook.NFTLockCondition)
await callContract(artifacts.NFT721Upgradeable, a => a.grantOperatorRole(addressBook.NFTLockCondition))
await callContract(artifacts.NeverminedConfig, a => a.grantNVMOperatorRole(addressBook.NFTLockCondition))
addresses.stage = 21
}

if (addressBook.NFT721Upgradeable && addressBook.NFT721LockCondition && addresses.stage < 22) {
if (addressBook.NeverminedConfig && addressBook.NFT721LockCondition && addresses.stage < 22) {
console.log('Grant Proxy Approval (NFT721Upgradeable): ' + addressBook.NFT721LockCondition)
await callContract(artifacts.NFT721Upgradeable, a => a.grantOperatorRole(addressBook.NFT721LockCondition))
await callContract(artifacts.NeverminedConfig, a => a.grantNVMOperatorRole(addressBook.NFT721LockCondition))
addresses.stage = 22
}

Expand Down Expand Up @@ -454,35 +448,6 @@ async function setupContracts({
addresses.stage = 24
}

Check failure on line 449 in scripts/deploy/setupContracts.js

View workflow job for this annotation

GitHub Actions / tests

Block must not be padded by blank lines

if (addressBook.TransferNFTCondition && addressBook.NFT1155SubscriptionUpgradeable && addresses.stage < 25) {
console.log('TransferNFTCondition : ' + addressBook.TransferNFTCondition)
await callContract(artifacts.NFT1155SubscriptionUpgradeable, a => a.grantOperatorRole(addressBook.TransferNFTCondition))
addresses.stage = 25
}

if (addressBook.TransferNFT721Condition && addressBook.NFT721SubscriptionUpgradeable && addresses.stage < 26) {
console.log('TransferNFT721Condition : ' + addressBook.TransferNFT721Condition)
await callContract(artifacts.NFT721SubscriptionUpgradeable, a => a.grantOperatorRole(addressBook.TransferNFT721Condition))
addresses.stage = 26
}

if (addressBook.NFTLockCondition && addressBook.NFT1155SubscriptionUpgradeable && addresses.stage < 27) {
console.log('Grant Proxy Approval (NFT1155SubscriptionUpgradeable) : ' + addressBook.NFTLockCondition)
await callContract(artifacts.NFT1155SubscriptionUpgradeable, a => a.grantOperatorRole(addressBook.NFTLockCondition))
addresses.stage = 27
}

if (addressBook.NFTLockCondition && addressBook.NFT721SubscriptionUpgradeable && addresses.stage < 28) {
console.log('Grant Proxy Approval (NFT721SubscriptionUpgradeable): ' + addressBook.NFTLockCondition)
await callContract(artifacts.NFT721SubscriptionUpgradeable, a => a.grantOperatorRole(addressBook.NFTLockCondition))
addresses.stage = 28
}

if (addressBook.NFT721SubscriptionUpgradeable && addressBook.NFT721LockCondition && addresses.stage < 29) {
console.log('Grant Proxy Approval (NFT721SubscriptionUpgradeable): ' + addressBook.NFT721LockCondition)
await callContract(artifacts.NFT721SubscriptionUpgradeable, a => a.grantOperatorRole(addressBook.NFT721LockCondition))
addresses.stage = 29
}
}

module.exports = setupContracts
6 changes: 3 additions & 3 deletions test/helpers/deployManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const deployManagers = async function(deployer, owner, governor = owner, subscri
)

if (testUtils.deploying) {
await nvmConfig.setOperator(didRegistry.address, { from: owner })
await nvmConfig.setOperator(owner, { from: owner })
await nvmConfig.setOperator(deployer, { from: owner })
await nvmConfig.grantNVMOperatorRole(didRegistry.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(owner, { from: owner })
await nvmConfig.grantNVMOperatorRole(deployer, { from: owner })
await nft.setNvmConfigAddress(nvmConfig.address, { from: deployer })
await nft721.setNvmConfigAddress(nvmConfig.address, { from: deployer })
await conditionStoreManager.delegateCreateRole(
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const utils = {
await nft.initialize(owner, didRegistry.address, 'NFT1155', 'NVM', '')
const conditionStoreManager = await ConditionStoreManager.new()
await conditionStoreManager.initialize(createRole, owner, nvmConfig.address, { from: owner })
await nvmConfig.setOperator(owner, { from: owner })
await nvmConfig.setOperator(didRegistry.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(owner, { from: owner })
await nvmConfig.grantNVMOperatorRole(didRegistry.address, { from: owner })
await nft.setNvmConfigAddress(nvmConfig.address, { from: owner })
return {
didRegistry,
Expand Down
2 changes: 1 addition & 1 deletion test/int/market/Subscriptions_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ contract('End to End NFT721 Scenarios', (accounts) => {
await templateStoreManager.approveTemplate(nftAccessTemplate.address, { from: owner })

// IMPORTANT: Here we give ERC-721 transfer grants to the TransferNFTCondition condition
await nvmConfig.setOperator(transferCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(transferCondition.address, { from: owner })
}

const checkpoint = await getCheckpoint(token, [artist, collector1, collector2, gallery, someone, lockPaymentCondition.address, escrowCondition.address])
Expand Down
4 changes: 2 additions & 2 deletions test/int/nft/NFTAccessSwapAgreement.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ contract('NFT Sales with Access Proof Template integration test', (accounts) =>
await templateStoreManager.proposeTemplate(nftTemplate.address)
await templateStoreManager.approveTemplate(nftTemplate.address, { from: owner })
}
await nvmConfig.setOperator(lockPaymentCondition.address, { from: owner })
await nvmConfig.setOperator(escrowCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(lockPaymentCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(escrowCondition.address, { from: owner })
}

async function prepareAgreement({
Expand Down
2 changes: 1 addition & 1 deletion test/int/nft/NFTSalesWithAccessProofAgreement.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract('NFT Sales with Access Proof Template integration test', (accounts) =>
)

if (testUtils.deploying) {
await nvmConfig.setOperator(transferCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(transferCondition.address, { from: owner })
await templateStoreManager.proposeTemplate(nftSalesTemplate.address)
await templateStoreManager.approveTemplate(nftSalesTemplate.address, { from: owner })
}
Expand Down
2 changes: 1 addition & 1 deletion test/int/nft/NFTWithEther_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract('End to End NFT Scenarios (with Ether)', (accounts) => {

if (testUtils.deploying) {
// IMPORTANT: Here we give ERC1155 transfer grants to the TransferNFTCondition condition
await nvmConfig.setOperator(transferCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(transferCondition.address, { from: owner })

await conditionStoreManager.grantProxyRole(
escrowCondition.address,
Expand Down
2 changes: 1 addition & 1 deletion test/int/nft/NFT_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract('End to End NFT Scenarios', (accounts) => {
await templateStoreManager.approveTemplate(nftAccessTemplate.address, { from: owner })

// IMPORTANT: Here we give ERC1155 transfer grants to the TransferNFTCondition condition
await nvmConfig.setOperator(transferCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(transferCondition.address, { from: owner })
}

const checkpoint = await getCheckpoint(token, [artist, collector1, collector2, market, gallery, someone, lockPaymentCondition.address, escrowCondition.address])
Expand Down
2 changes: 1 addition & 1 deletion test/unit/conditions/NFT721LockCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract('NFT721LockCondition', (accounts) => {
await erc721.setNvmConfigAddress(nvmConfig.address, { from: createRole })
// ERC-721 deployed on address `nftTokenAddress`
// Approving NFT721LockCondition as proxy in the NFT contract
await nvmConfig.setOperator(lockCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(lockCondition.address, { from: owner })
}

describe('fulfill correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/conditions/NFTLockCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ contract('NFTLockCondition', (accounts) => {
{ from: createRole }
)
console.log(await nft.getNvmConfigAddress())
await nvmConfig.setOperator(lockCondition.address, { from: owner })
await nvmConfig.setOperator(accounts[0], { from: owner })
await nvmConfig.grantNVMOperatorRole(lockCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(accounts[0], { from: owner })
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/conditions/NFTMarkedLockCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract('NFTMarkedLockCondition', (accounts) => {
nft.address,
{ from: createRole }
)
await nvmConfig.setOperator(lockCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(lockCondition.address, { from: owner })
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/conditions/TransferNFTCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ contract('TransferNFT Condition', (accounts) => {

// We allow DIDRegistry and TransferCondition to mint NFTs
await nft.setNvmConfigAddress(nvmConfig.address, { from: owner })
await nvmConfig.setOperator(didRegistry.address, { from: owner })
await nvmConfig.setOperator(owner, { from: owner })
await nvmConfig.setOperator(seller, { from: owner })
await nvmConfig.setOperator(transferCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(didRegistry.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(owner, { from: owner })
await nvmConfig.grantNVMOperatorRole(seller, { from: owner })
await nvmConfig.grantNVMOperatorRole(transferCondition.address, { from: owner })
}

const did = await didRegistry.hashDID(didSeed, seller)
Expand Down
18 changes: 4 additions & 14 deletions test/unit/conditions/rewards/EscrowPayment.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ function escrowTest(EscrowPaymentCondition, LockPaymentCondition, Token, nft, nf
{ from: owner }
)

await nvmConfig.setOperator(owner, { from: owner })
await nvmConfig.setOperator(didRegistry.address, { from: owner })
await nvmConfig.setOperator(lockPaymentCondition.address, { from: owner })
await nvmConfig.setOperator(escrowPayment.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(owner, { from: owner })
await nvmConfig.grantNVMOperatorRole(didRegistry.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(lockPaymentCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(escrowPayment.address, { from: owner })
}

return {
Expand Down Expand Up @@ -222,16 +222,6 @@ function escrowTest(EscrowPaymentCondition, LockPaymentCondition, Token, nft, nf
{ from: sender })
}

/*
if (nft) {
await testUtils.approveProxy('NFT1155Upgradeable', owner, token.address, lockPaymentCondition.address)
await testUtils.approveProxy('NFT1155Upgradeable', owner, token.address, escrowPayment.address)
}
if (nft721) {
await testUtils.approveProxy('NFT721Upgradeable', owner, token.address, lockPaymentCondition.address)
await testUtils.approveProxy('NFT721Upgradeable', owner, token.address, escrowPayment.address)
} */

await lockPaymentCondition.fulfillWrap(agreementId, did, escrowPayment.address, token.address, amounts, receivers)

assert.strictEqual(await token.getBalance(lockPaymentCondition.address), 0)
Expand Down
8 changes: 4 additions & 4 deletions test/unit/conditions/rewards/MultiEscrowPayment.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ function testMultiEscrow(EscrowPaymentCondition, LockPaymentCondition, Token, nf
escrowPayment.address,
{ from: owner }
)
await nvmConfig.setOperator(owner, { from: owner })
await nvmConfig.setOperator(didRegistry.address, { from: owner })
await nvmConfig.setOperator(lockPaymentCondition.address, { from: owner })
await nvmConfig.setOperator(escrowPayment.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(owner, { from: owner })
await nvmConfig.grantNVMOperatorRole(didRegistry.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(lockPaymentCondition.address, { from: owner })
await nvmConfig.grantNVMOperatorRole(escrowPayment.address, { from: owner })
}

return {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/registry/CurveRoyalties.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ contract('CurveRoyalties', (accounts) => {
await didRegistry.registerRoyaltiesChecker(royalties.address, { from: owner })

await nft.setNvmConfigAddress(config.address, { from: owner })
await config.setOperator(didRegistry.address, { from: owner })
await config.setOperator(owner, { from: owner })
await config.grantNVMOperatorRole(didRegistry.address, { from: owner })
await config.grantNVMOperatorRole(owner, { from: owner })
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/registry/Mintable721DIDRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ contract('Mintable DIDRegistry (ERC-721)', (accounts) => {
await nft.initialize(owner, didRegistry.address, '', '', nftMetadataURL, 0, { from: deployer })

await nft.setNvmConfigAddress(config.address, { from: owner })
await config.setOperator(didRegistry.address, { from: owner })
await config.setOperator(owner, { from: owner })
await config.grantNVMOperatorRole(didRegistry.address, { from: owner })
await config.grantNVMOperatorRole(owner, { from: owner })
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/registry/MintableDIDRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ contract('Mintable DIDRegistry', (accounts) => {
await nft.initialize(owner, didRegistry.address, 'NFT1155', 'NVM', '', { from: deployer })

await nft.setNvmConfigAddress(config.address, { from: owner })
await config.setOperator(didRegistry.address, { from: owner })
await config.setOperator(owner, { from: owner })
await config.grantNVMOperatorRole(didRegistry.address, { from: owner })
await config.grantNVMOperatorRole(owner, { from: owner })
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/token/NFT1155Subscription.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ contract('NFT1155 Subscription', (accounts) => {
await nft.initialize(owner, didRegistry.address, 'TestERC1155', 'TEST', '', { from: owner })

await nft.setNvmConfigAddress(config.address, { from: owner })
await config.setOperator(didRegistry.address, { from: owner })
await config.setOperator(owner, { from: owner })
await config.setOperator(minter, { from: owner })
await config.grantNVMOperatorRole(didRegistry.address, { from: owner })
await config.grantNVMOperatorRole(owner, { from: owner })
await config.grantNVMOperatorRole(minter, { from: owner })
}

describe('As a minter I want to use NFTs as subscriptions', () => {
Expand Down
Loading

0 comments on commit 55c8e82

Please sign in to comment.