Skip to content

Commit

Permalink
removed useless methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed Dec 1, 2021
1 parent 9d69fa5 commit daa7ae1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 79 deletions.
27 changes: 0 additions & 27 deletions contracts/registry/DIDRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,31 +226,4 @@ contract DIDRegistry is DIDFactory {
_did, msg.sender, keccak256('burn721'), '', 'burn721');
}

function balanceOf(address account, bytes32 id) public view returns (uint) {
return erc1155.balanceOf(account, uint256(id));
}

/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public {
require(
from == _msgSender() || erc1155.isApprovedForAll(from, _msgSender()),
'ERC1155: caller is not owner nor approved'
);
erc1155.safeTransferFrom(from, to, id, amount, data);
}

function setApprovalForAll(address operator, bool approved) public virtual {
require(_msgSender() != operator, 'ERC1155: setting approval status for self');

erc1155.proxySetApprovalForAll(msg.sender, operator, approved);
}

}
19 changes: 1 addition & 18 deletions contracts/token/erc1155/NFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol'
*/
contract NFTUpgradeable is ERC1155Upgradeable, OwnableUpgradeable, AccessControlUpgradeable {

// Mapping from account to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;

// Mapping from account to proxy approvals
mapping (address => bool) private _proxyApprovals;

Expand Down Expand Up @@ -49,21 +46,7 @@ contract NFTUpgradeable is ERC1155Upgradeable, OwnableUpgradeable, AccessControl
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator] || _proxyApprovals[operator];
}

function setApprovalForAll(address operator, bool approved) public virtual override {
require(_msgSender() != operator, 'ERC1155: setting approval status for self');

_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}

function proxySetApprovalForAll(address account, address operator, bool approved) public virtual {
require(_proxyApprovals[_msgSender()], 'ERC1155: only for proxy');

_operatorApprovals[account][operator] = approved;
emit ApprovalForAll(account, operator, approved);
return super.isApprovedForAll(account, operator) || _proxyApprovals[operator];
}

function mint(address to, uint256 id, uint256 amount, bytes memory data) public {
Expand Down
2 changes: 1 addition & 1 deletion test/int/agreement/DynamicAccessAgreement.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,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: 2 additions & 2 deletions test/int/agreement/NFTAccessAgreement.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ contract('NFT Access integration test', (accounts) => {
(await conditionStoreManager.getConditionState(agreement.conditionIds[1])).toNumber(),
constants.condition.state.fulfilled)

const balanceSender = await didRegistry.balanceOf(sender, agreement.did)
const balanceSender = await nft.balanceOf(sender, agreement.did)
assert.strictEqual(0, balanceSender.toNumber())

const balanceReceiver = await didRegistry.balanceOf(receiver, agreement.did)
const balanceReceiver = await nft.balanceOf(receiver, agreement.did)
assert.strictEqual(nftAmount, balanceReceiver.toNumber())
})
})
Expand Down
24 changes: 12 additions & 12 deletions test/int/nft/NFTWithEther_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ contract('End to End NFT Scenarios', (accounts) => {
await didRegistry.mint(did, 5, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })

const balance = await didRegistry.balanceOf(artist, did)
const balance = await nft.balanceOf(artist, did)
assert.strictEqual(5, balance.toNumber())
})
})
Expand Down Expand Up @@ -328,8 +328,8 @@ contract('End to End NFT Scenarios', (accounts) => {
})

it('The artist can check the payment and transfer the NFT to the collector', async () => {
const nftBalanceArtistBefore = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorBefore = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistBefore = await nft.balanceOf(artist, did)
const nftBalanceCollectorBefore = await nft.balanceOf(collector1, did)

await nft.setApprovalForAll(transferCondition.address, true, { from: artist })
await transferCondition.methods['fulfill(bytes32,bytes32,address,uint256,bytes32)'](
Expand All @@ -345,8 +345,8 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[1])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

const nftBalanceArtistAfter = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorAfter = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistAfter = await nft.balanceOf(artist, did)
const nftBalanceCollectorAfter = await nft.balanceOf(collector1, did)

assert.strictEqual(nftBalanceArtistAfter.toNumber(), nftBalanceArtistBefore.toNumber() - numberNFTs)
assert.strictEqual(nftBalanceCollectorAfter.toNumber(), nftBalanceCollectorBefore.toNumber() + numberNFTs)
Expand Down Expand Up @@ -468,10 +468,10 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[1])
assert.strictEqual(condition[1].toNumber(), constants.condition.state.fulfilled)

const nftBalance1 = await didRegistry.balanceOf(collector1, did)
const nftBalance1 = await nft.balanceOf(collector1, did)
assert.strictEqual(nftBalance1.toNumber(), numberNFTs - numberNFTs2)

const nftBalance2 = await didRegistry.balanceOf(collector2, did)
const nftBalance2 = await nft.balanceOf(collector2, did)
assert.strictEqual(nftBalance2.toNumber(), numberNFTs2)

const receiver1Before = toEth(await getETHBalanceBN(receivers2[0]))
Expand Down Expand Up @@ -551,7 +551,7 @@ contract('End to End NFT Scenarios', (accounts) => {
await didRegistry.mint(did, 5, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })

const balance = await didRegistry.balanceOf(artist, did)
const balance = await nft.balanceOf(artist, did)
assert.strictEqual(5, balance.toNumber())
})

Expand Down Expand Up @@ -599,8 +599,8 @@ contract('End to End NFT Scenarios', (accounts) => {
})

it('The market can check the payment and can transfer the NFT to the collector', async () => {
const nftBalanceArtistBefore = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorBefore = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistBefore = await nft.balanceOf(artist, did)
const nftBalanceCollectorBefore = await nft.balanceOf(collector1, did)

await nft.setApprovalForAll(market, true, { from: artist })
await transferCondition.fulfillForDelegate(
Expand All @@ -617,8 +617,8 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[1])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

const nftBalanceArtistAfter = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorAfter = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistAfter = await nft.balanceOf(artist, did)
const nftBalanceCollectorAfter = await nft.balanceOf(collector1, did)

assert.strictEqual(nftBalanceArtistAfter.toNumber(), nftBalanceArtistBefore.toNumber() - numberNFTs)
assert.strictEqual(nftBalanceCollectorAfter.toNumber(), nftBalanceCollectorBefore.toNumber() + numberNFTs)
Expand Down
24 changes: 12 additions & 12 deletions test/int/nft/NFT_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ contract('End to End NFT Scenarios', (accounts) => {
await didRegistry.mint(did, 5, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })

const balance = await didRegistry.balanceOf(artist, did)
const balance = await nft.balanceOf(artist, did)
assert.strictEqual(5, balance.toNumber())
})
})
Expand Down Expand Up @@ -303,8 +303,8 @@ contract('End to End NFT Scenarios', (accounts) => {
})

it('The artist can check the payment and transfer the NFT to the collector', async () => {
const nftBalanceArtistBefore = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorBefore = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistBefore = await nft.balanceOf(artist, did)
const nftBalanceCollectorBefore = await nft.balanceOf(collector1, did)

await nft.setApprovalForAll(transferCondition.address, true, { from: artist })
await transferCondition.methods['fulfill(bytes32,bytes32,address,uint256,bytes32)'](
Expand All @@ -320,8 +320,8 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[1])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

const nftBalanceArtistAfter = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorAfter = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistAfter = await nft.balanceOf(artist, did)
const nftBalanceCollectorAfter = await nft.balanceOf(collector1, did)

assert.strictEqual(nftBalanceArtistAfter.toNumber(), nftBalanceArtistBefore.toNumber() - numberNFTs)
assert.strictEqual(nftBalanceCollectorAfter.toNumber(), nftBalanceCollectorBefore.toNumber() + numberNFTs)
Expand Down Expand Up @@ -438,10 +438,10 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[1])
assert.strictEqual(condition[1].toNumber(), constants.condition.state.fulfilled)

const nftBalance1 = await didRegistry.balanceOf(collector1, did)
const nftBalance1 = await nft.balanceOf(collector1, did)
assert.strictEqual(nftBalance1.toNumber(), numberNFTs - numberNFTs2)

const nftBalance2 = await didRegistry.balanceOf(collector2, did)
const nftBalance2 = await nft.balanceOf(collector2, did)
assert.strictEqual(nftBalance2.toNumber(), numberNFTs2)

// Collector1 & Artist: Get the payment
Expand Down Expand Up @@ -513,7 +513,7 @@ contract('End to End NFT Scenarios', (accounts) => {
await didRegistry.mint(did, 5, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })

const balance = await didRegistry.balanceOf(artist, did)
const balance = await nft.balanceOf(artist, did)
assert.strictEqual(5, balance.toNumber())
})

Expand Down Expand Up @@ -546,8 +546,8 @@ contract('End to End NFT Scenarios', (accounts) => {
})

it('The market can check the payment and can transfer the NFT to the collector', async () => {
const nftBalanceArtistBefore = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorBefore = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistBefore = await nft.balanceOf(artist, did)
const nftBalanceCollectorBefore = await nft.balanceOf(collector1, did)

await nft.setApprovalForAll(market, true, { from: artist })
await transferCondition.fulfillForDelegate(
Expand All @@ -564,8 +564,8 @@ contract('End to End NFT Scenarios', (accounts) => {
nftSalesAgreement.conditionIds[1])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

const nftBalanceArtistAfter = await didRegistry.balanceOf(artist, did)
const nftBalanceCollectorAfter = await didRegistry.balanceOf(collector1, did)
const nftBalanceArtistAfter = await nft.balanceOf(artist, did)
const nftBalanceCollectorAfter = await nft.balanceOf(collector1, did)

assert.strictEqual(nftBalanceArtistAfter.toNumber(), nftBalanceArtistBefore.toNumber() - numberNFTs)
assert.strictEqual(nftBalanceCollectorAfter.toNumber(), nftBalanceCollectorBefore.toNumber() + numberNFTs)
Expand Down
14 changes: 7 additions & 7 deletions test/unit/registry/MintableDIDRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract('Mintable DIDRegistry', (accounts) => {
await didRegistry.registerAttribute(
didSeed, checksum, [], value, { from: owner })

const balance = await didRegistry.balanceOf(owner, did)
const balance = await nft.balanceOf(owner, did)
assert.strictEqual(0, balance.toNumber())
})

Expand Down Expand Up @@ -110,7 +110,7 @@ contract('Mintable DIDRegistry', (accounts) => {
'TransferSingle'
) */

let balance = await didRegistry.balanceOf(owner, did)
let balance = await nft.balanceOf(owner, did)
assert.strictEqual(10, balance.toNumber())

await didRegistry.burn(did, 5,
Expand All @@ -119,7 +119,7 @@ contract('Mintable DIDRegistry', (accounts) => {
}
)

balance = await didRegistry.balanceOf(owner, did)
balance = await nft.balanceOf(owner, did)
assert.strictEqual(5, balance.toNumber())
})

Expand All @@ -132,7 +132,7 @@ contract('Mintable DIDRegistry', (accounts) => {

await didRegistry.mint(did, 10, { from: owner })

const balance = await didRegistry.balanceOf(owner, did)
const balance = await nft.balanceOf(owner, did)
assert.strictEqual(10, balance.toNumber())
})

Expand All @@ -145,7 +145,7 @@ contract('Mintable DIDRegistry', (accounts) => {

await didRegistry.enableAndMintDidNft(did, 5, 0, true, { from: owner })

const balanceOwner = await didRegistry.balanceOf(owner, did)
const balanceOwner = await nft.balanceOf(owner, did)
assert.strictEqual(5, balanceOwner.toNumber())
})

Expand All @@ -158,7 +158,7 @@ contract('Mintable DIDRegistry', (accounts) => {
didSeed, checksum, [], value, 0, 0, constants.activities.GENERATED, '', { from: owner })
await didRegistry.mint(did, 10, { from: owner })

const balance = await didRegistry.balanceOf(owner, did)
const balance = await nft.balanceOf(owner, did)
assert.strictEqual(10, balance.toNumber())
})

Expand All @@ -176,7 +176,7 @@ contract('Mintable DIDRegistry', (accounts) => {
)

await didRegistry.mint(did, 5, { from: owner })
const balance = await didRegistry.balanceOf(owner, did)
const balance = await nft.balanceOf(owner, did)
assert.strictEqual(5, balance.toNumber())

await assert.isRejected(
Expand Down

0 comments on commit daa7ae1

Please sign in to comment.