Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions movement-migration/validation-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ anyhow = { workspace = true }
aptos-config = { workspace = true }
aptos-db = { workspace = true }
aptos-rest-client = { workspace = true }
aptos-sdk = { workspace = true }
aptos-storage-interface = { workspace = true }
aptos-types = { workspace = true }
bcs = { workspace = true }
bytes = { workspace = true }
clap = { workspace = true }
either = { workspace = true }
hex = { workspace = true }
serde_json = { workspace = true }
move-core-types = { workspace = true }
thiserror = { workspace = true }
Expand Down
101 changes: 101 additions & 0 deletions movement-migration/validation-tool/script/clean_and_sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# Check if exactly 2 arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <folder_to_clean> <reference_folder>"
echo "Recursively deletes files from folder_to_clean that don't exist in reference_folder,"
echo "then syncs reference_folder to folder_to_clean using rsync"
exit 1
fi

folder_to_clean="$1"
reference_folder="$2"

# Check if both directories exist
if [ ! -d "$folder_to_clean" ]; then
echo "Error: Directory '$folder_to_clean' does not exist"
exit 1
fi

if [ ! -d "$reference_folder" ]; then
echo "Error: Directory '$reference_folder' does not exist"
exit 1
fi

# Convert to absolute paths to avoid issues
folder_to_clean=$(realpath "$folder_to_clean")
reference_folder=$(realpath "$reference_folder")

echo "Cleaning folder: $folder_to_clean"
echo "Reference folder: $reference_folder"
echo

# Ask for confirmation before proceeding
echo "This will:"
echo "1. Delete all files in '$folder_to_clean' that don't exist in '$reference_folder'"
echo "2. Remove empty directories"
echo "3. Sync '$reference_folder' to '$folder_to_clean' using rsync"
echo
read -p "Do you want to continue? (y/N): " -n 1 -r
echo

if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Operation cancelled."
exit 0
fi

echo

# Phase 1: Delete files that don't exist in reference folder
echo "=== Phase 1: Cleaning up files not in reference folder ==="
deleted_count=0

# Use find to get all files in folder_to_clean, preserving the relative path structure
while IFS= read -r -d '' file; do
# Get the relative path from folder_to_clean
relative_path="${file#"$folder_to_clean"/}"

# Check if this file exists in the same relative location in reference folder
reference_file="$reference_folder/$relative_path"

if [ ! -f "$reference_file" ]; then
echo "Deleting: $file"
rm "$file"
((deleted_count++))
fi
done < <(find "$folder_to_clean" -type f -print0)

echo "Files deleted: $deleted_count"
echo

# Phase 2: Remove empty directories
echo "=== Phase 2: Removing empty directories ==="
# Find and remove empty directories (bottom-up)
find "$folder_to_clean" -type d -empty -delete 2>/dev/null
echo "Empty directories removed"
echo

# Phase 3: Sync with rsync
echo "=== Phase 3: Syncing reference folder to cleaned folder ==="
echo "Running: rsync -av --progress \"$reference_folder/\" \"$folder_to_clean/\""
echo

# Use rsync to sync the reference folder to the cleaned folder
# -a: archive mode (preserves permissions, timestamps, etc.)
# -v: verbose
# --progress: show progress
# Note the trailing slashes are important for rsync behavior
rsync -av --progress "$reference_folder/" "$folder_to_clean/"

sync_exit_code=$?

if [ $sync_exit_code -eq 0 ]; then
echo
echo "=== Cleanup and sync completed successfully ==="
echo "The folder '$folder_to_clean' now matches '$reference_folder'"
else
echo
echo "=== WARNING: rsync failed with exit code $sync_exit_code ==="
echo "Please check the rsync output above for errors"
exit $sync_exit_code
fi
50 changes: 22 additions & 28 deletions movement-migration/validation-tool/src/checks/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,35 @@
// SPDX-License-Identifier: Apache-2.0

use crate::checks::api::active_feature_flags::GlobalFeatureCheck;
use crate::types::api::MovementAptosRestClient;
use clap::Parser;
use crate::checks::api::cmp_transactions::CompareTransactions;
use crate::checks::api::submit_transaction::SubmitTransaction;
use crate::checks::api::transactions::GetTransactions;
use clap::Subcommand;

mod active_feature_flags;
mod cmp_transactions;
mod submit_transaction;
mod transactions;

#[derive(Parser)]
#[derive(Subcommand)]
#[clap(
name = "migration-api-validation",
about = "Validates api conformity after movement migration."
name = "migration-api-tool",
about = "Validates api conformity after movement migration"
)]
pub struct Command {
// #[clap(long = "movement", help = "The url of the Movement REST endpoint.")]
// pub movement_rest_api_url: String,
#[clap(value_parser)]
#[clap(
long = "movement-aptos",
help = "The url of the Movement Aptos REST endpoint."
)]
pub movement_aptos_rest_api_url: String,
pub enum ApiTool {
ActiveFeatures(GlobalFeatureCheck),
Transactions(GetTransactions),
CompareTransactions(CompareTransactions),
SubmitTransaction(SubmitTransaction),
}

impl Command {
impl ApiTool {
pub async fn run(self) -> anyhow::Result<()> {
// let _movement_rest_client = MovementRestClient::new(&self.movement_rest_api_url)?;
let movement_aptos_rest_client =
MovementAptosRestClient::new(&self.movement_aptos_rest_api_url)?;

GlobalFeatureCheck::satisfies(&movement_aptos_rest_client).await?;

Ok(())
match self {
ApiTool::ActiveFeatures(tool) => tool.run().await,
ApiTool::Transactions(tool) => tool.run().await,
ApiTool::CompareTransactions(tool) => tool.run().await,
ApiTool::SubmitTransaction(tool) => tool.run().await,
}
}
}

#[test]
fn verify_tool() {
use clap::CommandFactory;
Command::command().debug_assert()
}
Loading
Loading