Skip to content

Commit

Permalink
applied suggestions fixed documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gerceboss committed Jul 15, 2024
1 parent 04b1917 commit f3d4273
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added (2024-07-10)

- ERC721URIStorage (2024-07-10) in `/src/token/erc721/extensions`
- ERC721URIStorage mock in `/src/tests/mocks/`
- ERC721URIStorage tests in `/src/tests/token/erc721/`
- Documentation for ERC721URIStorage extension in `/docs/modules/ROOT/api/erc721`
- ERC721URIStorage (#1031)

## 0.14.0 (2024-06-14)

Expand Down
14 changes: 7 additions & 7 deletions docs/modules/ROOT/pages/api/erc721.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,14 @@ use openzeppelin::token::extensions::ERC721URIStorageComponent;

:MetadataUpdated: xref:ERC721URIStorageComponent-MetadataUpdated[MetadataUpdated]

Extension of ERC721 to support dynamic NFTs.
Extension of ERC721 to support storage-based URI management.
It is an implementation of <<IERC721Metadata, IERC721Metadata>> but with a different `token_uri` behavior.

NOTE: Implementing xref:#ERC721Component[ERC721Component] is a requirement for this component to be implemented.

This extension keeps a track of URIs of each token id of a particular ERC721 token. The URI of any `token_id` can be set by calling the
internal function, xref:#ERC721URIStorageComponent-set_token_uri[set_token_uri]. Updated `token_uri` can be queried through the external function
xref:#ERC721URIStorageComponent-token_uri[token_uri].
The ERC721URIStorage component provides a flexible IERC721Metadata implementation that enables storage-based token URI management.
The URI of any `token_id` can be set by calling the internal function, xref:#ERC721URIStorageComponent-set_token_uri[set_token_uri].
Updated `token_uri` can be queried through the external function xref:#ERC721URIStorageComponent-token_uri[token_uri].

[.contract-index#ERC721URIStorageComponent-Embeddable-Impls]
.Embeddable Implementations
Expand Down Expand Up @@ -757,11 +757,11 @@ See <<IERC721Metadata-symbol,IERC721::symbol>>.
Returns the Uniform Resource Identifier (URI) for the `token_id` token.


If a base URI is set and the token URI is set , the resulting URI for each token will be the concatenation of the base URI and the token URI.
If a base URI is set and the token URI is set, the resulting URI for each token will be the concatenation of the base URI and the token URI.

If a base URI is set and the token URI is not set , the resulting URI for each token will be the concatenation of the base URI and the `token_id`.
If a base URI is set and the token URI is not set, the resulting URI for each token will be the concatenation of the base URI and the `token_id`.

If a base URI is not set and the token URI is set , the resulting URI for each token will be the token URI.
If a base URI is not set and the token URI is set, the resulting URI for each token will be the token URI.

If the base URI and token URI are not set for `token_id`, the return value will be an empty `ByteArray`.

Expand Down
5 changes: 2 additions & 3 deletions src/tests/token/erc721/test_erc721_uri_storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn COMPONENT_STATE() -> ComponentState {
ERC721URIStorageComponent::component_state_for_testing()
}

//constructor is inside only
fn setup() -> ComponentState {
let mut state = COMPONENT_STATE();
let mut mock_state = CONTRACT_STATE();
Expand Down Expand Up @@ -73,7 +72,7 @@ fn test_set_token_uri_nonexistent() {
assert_only_event_metadata_update(ZERO(), TOKEN_ID_2);

let mut mock_contract_state = CONTRACT_STATE();
//check accessible after minting
// Check that the URI is accessible after minting
mock_contract_state.erc721.mint(RECIPIENT(), TOKEN_ID_2);

let expected = SAMPLE_URI();
Expand Down Expand Up @@ -142,7 +141,7 @@ fn test_token_uri_persists_when_burned_and_minted() {
// Helpers
//

pub fn assert_event_metadata_update(contract: ContractAddress, token_id: u256) {
fn assert_event_metadata_update(contract: ContractAddress, token_id: u256) {
let event = utils::pop_log::<ERC721URIStorageComponent::Event>(contract).unwrap();
let expected = ERC721URIStorageComponent::Event::MetadataUpdated(MetadataUpdated { token_id });
assert!(event == expected);
Expand Down
1 change: 0 additions & 1 deletion src/tests/utils/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub(crate) fn BASE_URI_2() -> ByteArray {
"https://api.example.com/v2/"
}


pub(crate) fn SAMPLE_URI() -> ByteArray {
"mock://mytoken"
}
Expand Down
12 changes: 5 additions & 7 deletions src/token/erc721/extensions/erc721_uri_storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

/// # ERC721URIStorage Component
///
/// The ERC721URIStorage component enhances ERC721 tokens by keeping track of unique URIs with each token id,
/// and providing a functionality of metadata updates. Each token's URI, set during minting, is immutable, ensuring
/// the integrity of the metadata. It provides a reliable mechanism for linking on-chain tokens to off-chain metadata.

/// The ERC721URIStorage component provides a flexible IERC721Metadata implementation that enables
/// storage-based token URI management.
#[starknet::component]
pub mod ERC721URIStorageComponent {
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -64,12 +62,12 @@ pub mod ERC721URIStorageComponent {
let base_uri: ByteArray = ERC721Impl::_base_uri(erc721_component);
let token_uri: ByteArray = self.ERC721URIStorage_token_uris.read(token_id);

// If there is no base_uri, return the token_uri.
// If there is no base_uri, return the token_uri
if base_uri.len() == 0 {
return token_uri;
}

// If both are set, concatenate the base_uri and token_uri.
// If both are set, concatenate the base_uri and token_uri
if token_uri.len() > 0 {
return format!("{}{}", base_uri, token_uri);
}
Expand All @@ -91,7 +89,7 @@ pub mod ERC721URIStorageComponent {
+ERC721Component::HasComponent<TContractState>,
+Drop<TContractState>
> of InternalTrait<TContractState> {
/// Sets or updates the `token_uri` for the respective `token_id`
/// Sets or updates the `token_uri` for the respective `token_id`.
///
/// Emits `MetadataUpdated` event.
fn set_token_uri(
Expand Down

0 comments on commit f3d4273

Please sign in to comment.