Skip to content

Commit

Permalink
Adds method to update the token metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jagracar committed Aug 15, 2023
1 parent 5118f4c commit 161c6b2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
20 changes: 17 additions & 3 deletions python/contracts/daoToken.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,20 @@ def set_metadata(self, params):
# Update the contract metadata
self.data.metadata[params.k] = params.v

@sp.entry_point
def set_token_metadata(self, token_metadata):
"""Updates the token metadata.
"""
# Define the input parameter data type
sp.set_type(token_metadata, sp.TBytes)

# Check that the administrator executed the entry point
self.check_is_administrator()

# Update the token metadata
self.data.token_metadata[0].token_info[""] = token_metadata

@sp.entry_point
def add_max_share_exception(self, exception):
"""Adds or removes an exception to the set of addresses that can own
Expand Down Expand Up @@ -545,9 +559,9 @@ def token_metadata(self, token_id):
).inject_into_smartpy(sp).add_base_metadata(DAOToken)

sp.add_compilation_target("daoToken", DAOToken(
administrator=sp.address("tz1gnL9CeM5h5kRzWZztFYLypCNnVQZjndBN"),
administrator=sp.address("tz1RssrimWo3B8TpCajiNjqBD3MfhUwEgxod"),
metadata=sp.utils.metadata_of_url("ipfs://QmbmLBSisoZYXr7F7nFBeZMYUmf2Vnd4QKP77FyHPTdWMX"),
token_metadata=sp.utils.bytes_of_string("ipfs://QmXkMe3tPtZ7jz3swpBXbubAM8UCcmSsDcrbuZNMeXHFf8"),
initial_owner=sp.address("tz1gnL9CeM5h5kRzWZztFYLypCNnVQZjndBN"),
token_metadata=sp.utils.bytes_of_string("ipfs://Qmf63CUkCGjJWM8YKsp8XDiauPVhVEdArmozrjzTtKhd8z"),
initial_owner=sp.address("KT1StiWr1bqAfu7y1pLUkUC8zhwLmHpvJuJ7"),
supply=8000000000000,
max_share=400000000000))
10 changes: 5 additions & 5 deletions python/contracts/daoTokenDrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ def claimed_tokens(self, address):


sp.add_compilation_target("daoTokenDrop", DAOTokenDrop(
administrator=sp.address("tz1gnL9CeM5h5kRzWZztFYLypCNnVQZjndBN"),
administrator=sp.address("tz1RssrimWo3B8TpCajiNjqBD3MfhUwEgxod"),
metadata=sp.utils.metadata_of_url("ipfs://QmNhC5Uucwh8TRfzL8xxo2y7RbJVkShuVr8dXCfoFoVCZ5"),
token=sp.address("KT1Bdh3NcpSnTy9kPGQLzBr9u51KHfPYqCnN"),
treasury=sp.address("tz1gnL9CeM5h5kRzWZztFYLypCNnVQZjndBN"),
merkle_root=sp.bytes("0x00"),
expiration_date=sp.timestamp_from_utc(2023, 5, 30, 23, 59, 59)))
token=sp.address("KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton"),
treasury=sp.address("KT1J9FYz29RBQi1oGLw8uXyACrzXzV1dHuvb"),
merkle_root=sp.bytes("0x09b3bfe2615514519988b05eb69b9cb69383ed9e060bec3693a3fc8801dbf2b3"),
expiration_date=sp.timestamp_from_utc(2023, 11, 22, 23, 59, 59)))
22 changes: 22 additions & 0 deletions python/tests/daoToken_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,28 @@ def test_set_metadata():
scenario.verify(fa2.data.metadata[extra_metadata.k] == extra_metadata.v)


@sp.add_test(name="Test set token metadata")
def test_set_token_metadata():
# Get the test environment
testEnvironment = get_test_environment()
scenario = testEnvironment["scenario"]
admin = testEnvironment["admin"]
user1 = testEnvironment["user1"]
fa2 = testEnvironment["fa2"]

# Check that the initial token metadata is correct
original_token_metadata = sp.utils.bytes_of_string("ipfs://bbb")
scenario.verify(fa2.data.token_metadata[0].token_info[""] == original_token_metadata)

# Check that only the admin can update the token metadata
new_token_metadata = sp.utils.bytes_of_string("ipfs://zzzz")
fa2.set_token_metadata(new_token_metadata).run(valid=False, sender=user1, exception="FA2_NOT_ADMIN")
fa2.set_token_metadata(new_token_metadata).run(sender=admin)

# Check that the token metadata is updated
scenario.verify(fa2.data.token_metadata[0].token_info[""] == new_token_metadata)


@sp.add_test(name="Test add max share exception")
def test_add_max_share_exception():
# Get the test environment
Expand Down

0 comments on commit 161c6b2

Please sign in to comment.