Skip to content

Commit

Permalink
sui-field-count: test in sui-field-count instead and consolidate crat…
Browse files Browse the repository at this point in the history
…es (#20136)

## Description 

title, followup pr of comment on
#20126

## Test plan 

added new tests for sui-field-count

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
gegaowp authored Nov 1, 2024
1 parent ae9d809 commit 26a0e6f
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 102 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ members = [
"crates/sui-faucet",
"crates/sui-field-count",
"crates/sui-field-count-derive",
"crates/sui-field-count-main",
"crates/sui-framework",
"crates/sui-framework-snapshot",
"crates/sui-framework-tests",
Expand Down Expand Up @@ -636,7 +635,6 @@ sui-e2e-tests = { path = "crates/sui-e2e-tests" }
sui-enum-compat-util = { path = "crates/sui-enum-compat-util" }
sui-faucet = { path = "crates/sui-faucet" }
sui-field-count = { path = "crates/sui-field-count" }
sui-field-count-main = { path = "crates/sui-field-count-main" }
sui-field-count-derive = { path = "crates/sui-field-count-derive" }
sui-framework = { path = "crates/sui-framework" }
sui-framework-snapshot = { path = "crates/sui-framework-snapshot" }
Expand Down
7 changes: 0 additions & 7 deletions crates/sui-field-count-main/Cargo.toml

This file was deleted.

6 changes: 0 additions & 6 deletions crates/sui-field-count-main/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/sui-field-count/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ edition = "2021"

[dependencies]
sui-field-count-derive.workspace = true
sui-field-count-main.workspace = true
65 changes: 64 additions & 1 deletion crates/sui-field-count/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,67 @@
// SPDX-License-Identifier: Apache-2.0

pub use sui_field_count_derive::*;
pub use sui_field_count_main::*;

pub trait FieldCount {
fn field_count() -> usize;
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_basic_field_count() {
#[derive(FieldCount)]
struct EmptyStruct {}
#[derive(FieldCount)]
struct BasicStruct {
_field1: String,
_field2: i32,
_field3: bool,
}

assert_eq!(BasicStruct::field_count(), 3);
assert_eq!(EmptyStruct::field_count(), 0);
}

#[test]
fn test_lifetime_field_count() {
#[derive(FieldCount)]
struct LifetimeStruct<'a> {
_field1: &'a str,
_field2: &'a [u8],
_field3: &'a Vec<String>,
}

assert_eq!(LifetimeStruct::field_count(), 3);
}

#[test]
fn test_generic_type_field_count() {
#[derive(FieldCount)]
struct GenericStruct<T> {
_field1: T,
_field2: Vec<T>,
_field3: Option<T>,
}

assert_eq!(GenericStruct::<String>::field_count(), 3);
assert_eq!(GenericStruct::<i32>::field_count(), 3);
}

#[test]
fn test_where_clause_field_count() {
#[derive(FieldCount)]
struct WhereStruct<T>
where
T: Clone,
{
_field1: T,
_field2: Vec<T>,
}

assert_eq!(WhereStruct::<String>::field_count(), 2);
assert_eq!(WhereStruct::<i32>::field_count(), 2);
}
}
10 changes: 0 additions & 10 deletions crates/sui-indexer-alt/src/models/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,3 @@ pub struct StoredCheckpoint {
/// BCS serialized CheckpointContents
pub checkpoint_contents: Vec<u8>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_stored_checkpoint_field_count() {
assert_eq!(StoredCheckpoint::field_count(), 3);
}
}
15 changes: 0 additions & 15 deletions crates/sui-indexer-alt/src/models/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,3 @@ pub struct StoredEvStructInst {
pub tx_sequence_number: i64,
pub sender: Vec<u8>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_stored_event_field_count() {
assert_eq!(StoredEvEmitMod::field_count(), 4);
}

#[test]
fn test_stored_struct_inst_field_count() {
assert_eq!(StoredEvStructInst::field_count(), 6);
}
}
20 changes: 0 additions & 20 deletions crates/sui-indexer-alt/src/models/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,3 @@ where
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_stored_owner_kind_field_count() {
assert_eq!(StoredObject::field_count(), 3);
}

#[test]
fn test_stored_sum_coin_balance_field_count() {
assert_eq!(StoredSumCoinBalance::field_count(), 5);
}

#[test]
fn test_stored_sum_obj_type_field_count() {
assert_eq!(StoredSumObjType::field_count(), 8);
}
}
20 changes: 0 additions & 20 deletions crates/sui-indexer-alt/src/models/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,3 @@ pub struct StoredTxBalanceChange {
pub tx_sequence_number: i64,
pub balance_changes: Vec<u8>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_stored_transaction_field_count() {
assert_eq!(StoredTransaction::field_count(), 6);
}

#[test]
fn test_stored_tx_affected_object_field_count() {
assert_eq!(StoredTxAffectedObject::field_count(), 3);
}

#[test]
fn test_stored_tx_balance_change_field_count() {
assert_eq!(StoredTxBalanceChange::field_count(), 2);
}
}
15 changes: 0 additions & 15 deletions crates/sui-indexer-alt/src/models/watermarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,3 @@ impl<'p> From<CommitterWatermark<'p>> for StoredWatermark {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_stored_watermark_field_count() {
assert_eq!(StoredWatermark::field_count(), 9);
}

#[test]
fn test_committer_watermark_field_count() {
assert_eq!(CommitterWatermark::<'static>::field_count(), 5);
}
}

0 comments on commit 26a0e6f

Please sign in to comment.