Skip to content

Commit

Permalink
feat(github-actions): add prettier formatting in the move-tests workf…
Browse files Browse the repository at this point in the history
…low (#329)
  • Loading branch information
Tzal3x authored Dec 17, 2024
1 parent f83a9c4 commit ab0f389
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 42 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/move-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 13 additions & 17 deletions move/walrus_site/sources/site.move
Original file line number Diff line number Diff line change
@@ -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<u8> = b"routes";
Expand All @@ -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.
Expand All @@ -36,20 +35,20 @@ module walrus_site::site {
range: Option<Range>,
}

public struct Range has store, drop {
public struct Range has drop, store {
start: Option<u64>, // inclusive lower bound
end: Option<u64> // exclusive upper bound
end: Option<u64>, // 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<String, String>,
}

Expand All @@ -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<u64>,
range_end: Option<u64>
): Range {
public fun new_range(range_start: Option<u64>, range_end: Option<u64>): Range {
let start_is_defined = range_start.is_some();
let end_is_defined = range_end.is_some();

Expand All @@ -91,7 +87,7 @@ module walrus_site::site {

Range {
start: range_start,
end: range_end
end: range_end,
}
}

Expand All @@ -100,14 +96,14 @@ module walrus_site::site {
path: String,
blob_id: u256,
blob_hash: u256,
range: Option<Range>
range: Option<Range>,
): Resource {
Resource {
path,
headers: vec_map::empty(),
blob_id,
blob_hash,
range
range,
}
}

Expand Down Expand Up @@ -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<Resource>{
public fun remove_resource_if_exists(site: &mut Site, path: String): Option<Resource> {
let path_obj = new_path(path);
df::remove_if_exists(&mut site.id, path_obj)
}
Expand Down Expand Up @@ -212,7 +208,7 @@ module walrus_site::site {
public fun burn(site: Site) {
let Site {
id,
..
..,
} = site;
id.delete();
}
Expand Down
46 changes: 21 additions & 25 deletions move/walrus_site/tests/site_tests.move
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
#[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]
#[expected_failure(abort_code = ERangeStartGreaterThanRangeEnd)]
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),
);
}

Expand All @@ -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)
};
Expand All @@ -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<Range>()
b"index.html".to_string(),
601749199,
124794210,
option::none<Range>(),
);
// Add a header to the resource.
walrus_site::site::add_header(
Expand All @@ -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>(site);
};
Expand All @@ -111,23 +109,23 @@ 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<Range>()
b"index.html".to_string(),
601749199,
124794210,
option::none<Range>(),
);
walrus_site::site::add_resource(&mut site, resource);

// Add some rerouting pairs.
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(
Expand All @@ -148,6 +146,4 @@ module walrus_site::site_tests {
};
scenario.end();
}


}

0 comments on commit ab0f389

Please sign in to comment.