Skip to content

Commit

Permalink
Adds the SetMetadataEvent (#265)
Browse files Browse the repository at this point in the history
## Type of change

<!--Delete points that do not apply-->

- New feature

## Changes

The following changes have been made:

- Adds a `SetMetadataEvent` struct
- Emits `SetMetadataEvent` when `_set_metadata()` is called
- Enables the metadata tests now that the SDK supports wrapped heap
types.

## Notes

- This was requested by an external member.

## Related Issues

<!--Delete everything after the "#" symbol and replace it with a number.
No spaces between hash and number-->

Closes #264 

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
- [x] I have updated the changelog to reflect the changes on this PR.
  • Loading branch information
bitzoic authored Jul 24, 2024
1 parent 8d97fb3 commit 76cf2cc
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 39 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Description of the upcoming release here.
### Added

- [#259](https://github.com/FuelLabs/sway-libs/pull/259) Adds a new upgradability library, including associated tests and documentation.
- [#265](https://github.com/FuelLabs/sway-libs/pull/265) Adds the `SetMetadataEvent` and emits `SetMetadataEvent` when the `_set_metadata()` function is called.

### Changed

- Something changed here 1
- Something changed here 2
- [#265](https://github.com/FuelLabs/sway-libs/pull/265) Enables the metadata events now that the Rust SDK supports wrapped heap types.

### Fixed

Expand Down
19 changes: 19 additions & 0 deletions libs/src/asset/metadata.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library;

use standards::src7::Metadata;
use std::{
auth::msg_sender,
bytes::Bytes,
hash::{
Hash,
Expand All @@ -18,6 +19,18 @@ use std::{
string::String,
};

/// The event emitted when metadata is set via the `_set_metadata()` function.
pub struct SetMetadataEvent {
/// The asset for which metadata is set.
asset: AssetId,
/// The `Identity` of the caller that set the metadata.
sender: Identity,
/// The Metadata that is set.
metadata: Metadata,
/// The key used for the metadata.
key: String,
}

/// A persistent storage type to store the SRC-7; Metadata Standard type.
///
/// # Additional Information
Expand Down Expand Up @@ -166,6 +179,12 @@ pub fn _set_metadata(
key: String,
metadata: Metadata,
) {
log(SetMetadataEvent {
asset,
sender: msg_sender().unwrap(),
metadata,
key,
});
metadata_key.insert(asset, key, metadata);
}

Expand Down
9 changes: 4 additions & 5 deletions tests/src/native_asset/tests/functions/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod success {

use super::*;

#[ignore]
#[tokio::test]
async fn gets_one_asset() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
Expand All @@ -26,7 +25,6 @@ mod success {
);
}

#[ignore]
#[tokio::test]
async fn gets_multiple_assets() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
Expand Down Expand Up @@ -60,16 +58,17 @@ mod success {
);
}

#[ignore]
#[tokio::test]
async fn gets_multiple_types() {
let (owner_wallet, other_wallet, id, instance_1, _instance_2) = setup().await;
let (asset_id_1, _asset_id_2, _sub_id_1, _sub_id_2, _identity1, _other_identity) =
defaults(id, owner_wallet, other_wallet.clone());
let metadata1 = Metadata::String(String::from("Fuel NFT Metadata 1"));
let metadata2 = Metadata::Int(1);
let metadata3 =
Metadata::Bytes(Bytes::from_hex_str("bytes").expect("failed to conver to bytes"));
let metadata3 = Metadata::Bytes(
Bytes::from_hex_str("0101010101010101010101010101010101010101010101010101010101010101")
.expect("failed to convert to bytes"),
);
let key1 = String::from("key1");
let key2 = String::from("key2");
let key3 = String::from("key3");
Expand Down
Loading

0 comments on commit 76cf2cc

Please sign in to comment.