diff --git a/.github/workflows/move-tests.yml b/.github/workflows/move-tests.yml index 3ef31c84..ef2d8af1 100644 --- a/.github/workflows/move-tests.yml +++ b/.github/workflows/move-tests.yml @@ -11,6 +11,18 @@ on: - move/** jobs: + prettier_move: + name: Check and fix formatting for Move files + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./move + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm i @mysten/prettier-plugin-move + - run: npx prettier-move -c **/*.move + run-tests: name: Run Tests runs-on: ubuntu-latest diff --git a/move/walrus_site/sources/site.move b/move/walrus_site/sources/site.move index 0c66c2bd..61886491 100644 --- a/move/walrus_site/sources/site.move +++ b/move/walrus_site/sources/site.move @@ -1,8 +1,7 @@ /// The module exposes the functionality to create and update Walrus sites. module walrus_site::site { - use sui::dynamic_field as df; use std::string::String; - use sui::vec_map; + use sui::{dynamic_field as df, vec_map}; /// The name of the dynamic field containing the routes. const ROUTES_FIELD: vector = b"routes"; @@ -19,7 +18,7 @@ module walrus_site::site { } /// A resource in a site. - public struct Resource has store, drop { + public struct Resource has drop, store { path: String, // Response, Representation and Payload headers // regarding the contents of the resource. @@ -36,20 +35,20 @@ module walrus_site::site { range: Option, } - public struct Range has store, drop { + public struct Range has drop, store { start: Option, // inclusive lower bound - end: Option // exclusive upper bound + end: Option, // exclusive upper bound } /// Representation of the resource path. /// /// Ensures there are no namespace collisions in the dynamic fields. - public struct ResourcePath has copy, store, drop { + public struct ResourcePath has copy, drop, store { path: String, } /// The routes for a site. - public struct Routes has store, drop { + public struct Routes has drop, store { route_list: vec_map::VecMap, } @@ -72,10 +71,7 @@ module walrus_site::site { /// Creates a new Range object. /// /// aborts if both range_start and range_end are none. - public fun new_range( - range_start: Option, - range_end: Option - ): Range { + public fun new_range(range_start: Option, range_end: Option): Range { let start_is_defined = range_start.is_some(); let end_is_defined = range_end.is_some(); @@ -91,7 +87,7 @@ module walrus_site::site { Range { start: range_start, - end: range_end + end: range_end, } } @@ -100,14 +96,14 @@ module walrus_site::site { path: String, blob_id: u256, blob_hash: u256, - range: Option + range: Option, ): Resource { Resource { path, headers: vec_map::empty(), blob_id, blob_hash, - range + range, } } @@ -135,13 +131,13 @@ module walrus_site::site { /// Removes a resource from a site. /// /// Aborts if the resource does not exist. - public fun remove_resource(site: &mut Site, path: String): Resource{ + public fun remove_resource(site: &mut Site, path: String): Resource { let path_obj = new_path(path); df::remove(&mut site.id, path_obj) } /// Removes a resource from a site if it exists. - public fun remove_resource_if_exists(site: &mut Site, path: String): Option{ + public fun remove_resource_if_exists(site: &mut Site, path: String): Option { let path_obj = new_path(path); df::remove_if_exists(&mut site.id, path_obj) } @@ -212,7 +208,7 @@ module walrus_site::site { public fun burn(site: Site) { let Site { id, - .. + .., } = site; id.delete(); } diff --git a/move/walrus_site/tests/site_tests.move b/move/walrus_site/tests/site_tests.move index cf1b4068..ec252746 100644 --- a/move/walrus_site/tests/site_tests.move +++ b/move/walrus_site/tests/site_tests.move @@ -1,45 +1,41 @@ #[test_only] module walrus_site::site_tests { - use walrus_site::site::{ - ERangeStartGreaterThanRangeEnd, - EStartAndEndRangeAreNone, - Site, Range - }; + use walrus_site::site::{ERangeStartGreaterThanRangeEnd, EStartAndEndRangeAreNone, Site, Range}; #[test] #[expected_failure(abort_code = EStartAndEndRangeAreNone)] fun test_new_range_no_bounds_defined() { walrus_site::site::new_range( option::none(), - option::none() + option::none(), ); } #[test] fun test_new_range_both_bounds_defined() { walrus_site::site::new_range( option::some(0), - option::some(1) + option::some(1), ); } #[test] fun test_new_range_only_upper_bound_defined() { walrus_site::site::new_range( option::none(), - option::some(1024) + option::some(1024), ); } #[test] fun test_new_range_only_lower_bound_defined() { walrus_site::site::new_range( option::some(1024), - option::none() + option::none(), ); } #[test] fun test_new_range_lower_bound_can_be_zero() { walrus_site::site::new_range( option::some(0), - option::none() + option::none(), ); } #[test] @@ -47,7 +43,7 @@ module walrus_site::site_tests { fun test_new_range_upper_cannot_be_less_than_lower_bound() { walrus_site::site::new_range( option::some(2), - option::some(1) + option::some(1), ); } @@ -61,7 +57,8 @@ module walrus_site::site_tests { // Create a site. { let site = walrus_site::site::new_site( - b"Example".to_string(), scenario.ctx() + b"Example".to_string(), + scenario.ctx(), ); transfer::public_transfer(site, owner) }; @@ -74,10 +71,10 @@ module walrus_site::site_tests { walrus_site::site::update_name(&mut site, b"Fancy Example".to_string()); // Create a resource. let mut resource = walrus_site::site::new_resource( - b"index.html".to_string(), - 601749199, - 124794210, - option::none() + b"index.html".to_string(), + 601749199, + 124794210, + option::none(), ); // Add a header to the resource. walrus_site::site::add_header( @@ -95,7 +92,8 @@ module walrus_site::site_tests { ); // Delete the resource. walrus_site::site::remove_resource( - &mut site, b"styles.css".to_string() + &mut site, + b"styles.css".to_string(), ); scenario.return_to_sender(site); }; @@ -111,10 +109,10 @@ module walrus_site::site_tests { // This is needed for the insert_route to work, // since objects from previous transactions are lost. let resource = walrus_site::site::new_resource( - b"index.html".to_string(), - 601749199, - 124794210, - option::none() + b"index.html".to_string(), + 601749199, + 124794210, + option::none(), ); walrus_site::site::add_resource(&mut site, resource); @@ -122,12 +120,12 @@ module walrus_site::site_tests { walrus_site::site::insert_route( &mut site, b"/path1".to_string(), - b"index.html".to_string() + b"index.html".to_string(), ); walrus_site::site::insert_route( &mut site, b"/path2".to_string(), - b"index.html".to_string() + b"index.html".to_string(), ); // Delete the last route. walrus_site::site::remove_route( @@ -148,6 +146,4 @@ module walrus_site::site_tests { }; scenario.end(); } - - }