Skip to content

Commit

Permalink
Adds a correct default token uri. (#1225)
Browse files Browse the repository at this point in the history
* Adds a correct default token uri.
* Adds default token uri function pending DID.
  • Loading branch information
calina-c authored Jan 4, 2023
1 parent b5b6dcd commit c000c1d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
16 changes: 15 additions & 1 deletion ocean_lib/models/data_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Copyright 2022 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import json
import warnings
from base64 import b64encode
from enum import IntEnum, IntFlag
from typing import Optional

Expand Down Expand Up @@ -80,10 +82,22 @@ def __init__(
additional_datatoken_deployer or ZERO_ADDRESS
)
self.additional_metadata_updater = additional_metadata_updater or ZERO_ADDRESS
self.uri = uri or "https://oceanprotocol.com/nft/"
self.uri = uri or self.get_default_token_uri()
self.transferable = transferable or True
self.owner = owner

def get_default_token_uri(self):
data = {
"name": self.name,
"symbol": self.symbol,
"background_color": "141414",
"image_data": "data:image/svg+xml,%3Csvg viewBox='0 0 99 99' fill='undefined' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='%23ff409277' d='M0,99L0,29C9,24 19,19 31,19C42,18 55,23 67,25C78,26 88,23 99,21L99,99Z'/%3E%3Cpath fill='%23ff4092bb' d='M0,99L0,43C9,45 18,47 30,48C41,48 54,46 66,45C77,43 88,43 99,43L99,99Z'%3E%3C/path%3E%3Cpath fill='%23ff4092ff' d='M0,99L0,78C10,75 20,72 31,71C41,69 53,69 65,70C76,70 87,72 99,74L99,99Z'%3E%3C/path%3E%3C/svg%3E",
}

return b"data:application/json;base64," + b64encode(
json.dumps(data, separators=(",", ":")).encode("utf-8")
)

def deploy_contract(self, config_dict, tx_dict) -> DataNFT:
from ocean_lib.models.data_nft_factory import ( # isort:skip
DataNFTFactoryContract,
Expand Down
11 changes: 10 additions & 1 deletion ocean_lib/models/test/test_data_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Copyright 2022 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import json
from base64 import b64decode

import pytest
from web3 import Web3

Expand Down Expand Up @@ -32,7 +35,13 @@ def test_permissions(
data_nft.addManager(consumer_wallet.address, {"from": publisher_wallet})
assert data_nft.getPermissions(consumer_wallet.address)[DataNFTPermissions.MANAGER]

assert data_nft.tokenURI(1) == "https://oceanprotocol.com/nft/"
token_uri = data_nft.tokenURI(1).replace("data:application/json;base64,", "")
decoded_token_uri = json.loads(b64decode(token_uri))

assert decoded_token_uri["name"] == "NFT"
assert decoded_token_uri["symbol"] == "NFTSYMBOL"
assert decoded_token_uri["background_color"] == "141414"
assert decoded_token_uri["image_data"].startswith("data:image/svg+xm")

# Tests failing clearing permissions
with pytest.raises(Exception, match="not NFTOwner"):
Expand Down
2 changes: 1 addition & 1 deletion ocean_lib/web3_internal/test/test_contract_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_main(config):
1,
ZERO_ADDRESS,
ZERO_ADDRESS,
"https://oceanprotocol.com/nft/",
"http://someurl",
True,
alice_wallet.address,
{"from": alice_wallet},
Expand Down

0 comments on commit c000c1d

Please sign in to comment.