Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Alston authored and Rashad Alston committed Aug 16, 2023
1 parent 80e105a commit e8d5044
Show file tree
Hide file tree
Showing 48 changed files with 444 additions and 487 deletions.
17 changes: 15 additions & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ members = [
"examples/hello-world/hello-indexer",
"examples/hello-world/hello-world-data",
"examples/hello-world/hello-world-node",
"packages/fuel-indexer",
"packages/fuel-indexer-api-server",
"packages/fuel-indexer-benchmarks",
"packages/fuel-indexer-database",
Expand All @@ -22,10 +21,12 @@ members = [
"packages/fuel-indexer-schema",
"packages/fuel-indexer-tests",
"packages/fuel-indexer-tests/components/fuel-node",
"packages/fuel-indexer-tests/indexers/fuel-indexer-test",
"packages/fuel-indexer-tests/components/web-api",
"packages/fuel-indexer-tests/indexers/fuel-indexer-test",
"packages/fuel-indexer-tests/indexers/simple-wasm/simple-wasm",
"packages/fuel-indexer-types",
"packages/fuel-indexer-utils",
"packages/fuel-indexer",
"plugins/forc-index",
"plugins/forc-postgres",
]
Expand Down
8 changes: 7 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ The test suite follows the Rust cargo standards.
Testing is simply done using Cargo:

```sh
RUSTFLAGS='-D warnings' SQLX_OFFLINE=1 cargo test --locked --all-targets --all-features
RUSTFLAGS='-D warnings' cargo test --locked --all-targets --all-features
```

To run `trybuild` tests.

```sh
RUSTFLAGS='-D warnings' TRYBUILD=overwrite cargo test --locked --all-targets --all-features
```

## Contribution flow
Expand Down
28 changes: 20 additions & 8 deletions examples/fuel-explorer/fuel-explorer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ impl From<Bytes32> for ContractIdFragment {
fn from(hash: Bytes32) -> Self {
// Since the ID will just be derived from the hash, rather than using `::new()`,
// just manaully derived the ID, then use `::get_or_create()`.
Self { id: id(hash), hash }.get_or_create()
Self {
id: uid(hash),
hash,
}
.get_or_create()
}
}

Expand All @@ -155,7 +159,7 @@ impl From<ContractId> for ContractIdFragment {
// Since the ID will just be derived from the hash, rather than using `::new()`,
// just manaully derived the ID, then use `::get_or_create()`.
Self {
id: id(hash),
id: uid(hash),
hash: Bytes32::from(<[u8; 32]>::from(hash)),
}
.get_or_create()
Expand All @@ -166,15 +170,23 @@ impl From<Bytes32> for BlockIdFragment {
fn from(hash: Bytes32) -> Self {
// Since the ID will just be derived from the hash, rather than using `::new()`,
// just manaully derived the ID, then use `::get_or_create()`.
Self { id: id(hash), hash }.get_or_create()
Self {
id: uid(hash),
hash,
}
.get_or_create()
}
}

impl From<Bytes32> for TransactionIdFragment {
fn from(hash: Bytes32) -> Self {
// Since the ID will just be derived from the hash, rather than using `::new()`,
// just manaully derived the ID, then use `::get_or_create()`.
Self { id: id(hash), hash }.get_or_create()
Self {
id: uid(hash),
hash,
}
.get_or_create()
}
}

Expand Down Expand Up @@ -245,7 +257,7 @@ impl From<fuel::Input> for Input {
tx_pointer.id,
// Don't need to load the object here since the `ContractIdFragment.id` is
// just `id(ContractId)`
id(contract_id),
uid(contract_id),
InputLabel::Contract.into(),
true,
);
Expand Down Expand Up @@ -410,7 +422,7 @@ impl From<fuel::TransactionStatus> for TransactionStatus {
} => {
// Don't need to load the object here since the `BlockFragment.id` is
// just `id(hash)
let block_id = id(block);
let block_id = uid(block);
let program_state = program_state.map(|p| p.into());

let status = FailureStatus::new(
Expand All @@ -431,7 +443,7 @@ impl From<fuel::TransactionStatus> for TransactionStatus {
} => {
// Don't need to load the object here since the `BlockFragment.id` is
// just `id(hash)
let block_id = id(block);
let block_id = uid(block);
let program_state = program_state.map(|p| p.into());

let status = SuccessStatus::new(
Expand Down Expand Up @@ -888,7 +900,7 @@ pub mod explorer_index {
.collect::<Vec<UID>>();

let block = Block {
id: id(block_data.header.id),
id: uid(block_data.header.id),
block_id: block_data.header.id,
header: header.id,
consensus: consensus.id,
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-database/database-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ async-graphql-parser = { workspace = true }
async-graphql-value = { workspace = true }
chrono = { version = "0.4.24", features = ["serde"] }
fuel-indexer-lib = { workspace = true, default-features = true }
fuel-indexer-types = { workspace = true }
serde = { features = ["derive", "alloc"], workspace = true }
strum = { version = "0.24", default-features = false, features = ["derive"] }
7 changes: 4 additions & 3 deletions packages/fuel-indexer-database/database-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use fuel_indexer_lib::{
types::{IdCol, ObjectCol},
JoinTableMeta, ParsedGraphQLSchema,
},
type_id, MAX_ARRAY_LENGTH,
MAX_ARRAY_LENGTH,
};
use fuel_indexer_types::type_id;
use serde::{Deserialize, Serialize};
use std::{
collections::HashSet,
Expand Down Expand Up @@ -1437,7 +1438,7 @@ type Wallet @entity {
column_name: "wallet_id".to_string(),
ref_tablename: "wallet".to_string(),
ref_colname: "id".to_string(),
ref_coltype: ColumnType::UInt8.to_string(),
ref_coltype: ColumnType::UID.to_string(),
on_delete: OnDelete::NoAction,
on_update: OnUpdate::NoAction,
})
Expand All @@ -1452,7 +1453,7 @@ type Wallet @entity {
column_name: "account_id".to_string(),
ref_tablename: "account".to_string(),
ref_colname: "id".to_string(),
ref_coltype: ColumnType::UInt8.to_string(),
ref_coltype: ColumnType::UID.to_string(),
on_delete: OnDelete::NoAction,
on_update: OnUpdate::NoAction,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ anyhow = "1.0"
async-graphql-parser = { workspace = true }
bincode = { workspace = true }
clap = { features = ["cargo", "derive", "env"], workspace = true }
fuels = { workspace = true }
fuel-indexer-types = { workspace = true }
http = { version = "0.2", default-features = false }
lazy_static = { version = "1.4" }
proc-macro2 = "1.0"
Expand Down
36 changes: 1 addition & 35 deletions packages/fuel-indexer-lib/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ pub use parser::{JoinTableMeta, ParsedError, ParsedGraphQLSchema};
pub use validator::GraphQLSchemaValidator;

use async_graphql_parser::types::FieldDefinition;
use fuels::types::SizedAsciiString;
use serde::{Deserialize, Serialize};
use fuel_indexer_types::graphql::IndexMetadata;
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use types::IdCol;
Expand All @@ -24,39 +23,6 @@ pub fn schema_version(schema: &str) -> String {
format!("{:x}", Sha256::digest(schema.as_bytes()))
}

/// Native GraphQL `TypeDefinition` used to keep track of chain metadata.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct IndexMetadata {
/// Metadata identifier.
pub id: SizedAsciiString<64>,

/// Time of metadata.
pub time: u64,

/// Block height of metadata.
pub block_height: u32,

/// Block ID of metadata.
pub block_id: String,
}

impl IndexMetadata {
/// Return the GraphQL schema fragment for the `IndexMetadata` type.
///
/// The structure of this fragment should always match `fuel_indexer_types::IndexMetadata`.
pub fn schema_fragment() -> &'static str {
r#"
type IndexMetadataEntity @entity {
id: ID!
time: UInt8!
block_height: UInt4!
block_id: Bytes32!
}
"#
}
}

/// Inject native entities into the GraphQL schema.
fn inject_native_entities_into_schema(schema: &str) -> String {
if !schema.contains("type IndexMetadataEntity") {
Expand Down
10 changes: 0 additions & 10 deletions packages/fuel-indexer-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod utils;

use proc_macro2::TokenStream;
use quote::quote;
use sha2::{Digest, Sha256};

/// Max size of Postgres array types.
pub const MAX_ARRAY_LENGTH: usize = 2500;
Expand All @@ -36,15 +35,6 @@ impl ExecutionSource {
}
}

/// Derive a type ID from a namespace and given abstraction name.
pub fn type_id(namespace: &str, name: &str) -> i64 {
// IMPORTANT: https://github.com/launchbadge/sqlx/issues/499
let mut bytes = [0u8; 8];
let digest = Sha256::digest(format!("{name}:{namespace}").as_bytes());
bytes[..8].copy_from_slice(&digest[..8]);
i64::from_be_bytes(bytes)
}

/// Return a fully qualified indexer namespace.
pub fn fully_qualified_namespace(namespace: &str, identifier: &str) -> String {
format!("{}_{}", namespace, identifier)
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ syn = { version = "2.0", features = ["full"] }

[dev-dependencies]
fuel-indexer-plugin = { workspace = true }
fuel-indexer-utils = { workspace = true }
fuels-macros = { version = "0.46", default-features = false }
serde = { workspace = true }
trybuild = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/fuel-indexer-macros/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use fuel_indexer_lib::{
field_id, types::IdCol, GraphQLSchemaValidator, ParsedGraphQLSchema,
MAX_FOREIGN_KEY_LIST_FIELDS,
},
type_id, ExecutionSource,
ExecutionSource,
};
use fuel_indexer_types::type_id;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use std::collections::{BTreeMap, HashSet};
Expand Down
4 changes: 2 additions & 2 deletions packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
};
use fuel_abi_types::abi::program::TypeDeclaration;
use fuel_indexer_lib::{
graphql::GraphQLSchemaValidator, manifest::ContractIds, manifest::Manifest, type_id,
graphql::GraphQLSchemaValidator, manifest::ContractIds, manifest::Manifest,
utils::local_repository_root, ExecutionSource,
};
use fuel_indexer_types::FUEL_TYPES_NAMESPACE;
use fuel_indexer_types::{type_id, FUEL_TYPES_NAMESPACE};
use fuels::{core::codec::resolve_fn_selector, types::param_types::ParamType};
use fuels_code_gen::{Abigen, AbigenTarget, ProgramType};
use proc_macro::TokenStream;
Expand Down
3 changes: 1 addition & 2 deletions packages/fuel-indexer-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ pub fn indexer(attrs: TokenStream, item: TokenStream) -> TokenStream {

#[cfg(test)]
mod tests {
#[allow(unused)]
#[ignore = "Currently fails due to dependency issues in fuel-indexer-macros"]
#[test]
fn test_success_and_failure_macros() {
let t = trybuild::TestCases::new();
let manifest_dir = env!("CARGO_MANIFEST_DIR");
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-plugin/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub trait Entity<'a>: Sized + PartialEq + Eq + std::fmt::Debug {
unsafe {
let buff = bincode::serialize(&id.to_string()).unwrap();
let mut bufflen = (buff.len() as u32).to_le_bytes();

let ptr = ff_get_object(Self::TYPE_ID, buff.as_ptr(), bufflen.as_mut_ptr());

if !ptr.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern crate alloc;

use fuel_indexer_lib::MAX_ARRAY_LENGTH;
use fuel_indexer_types::{fuel::*, scalar::UID, Identity};
use fuel_indexer_types::{fuel::*, scalar::*, Identity};
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand Down
Loading

0 comments on commit e8d5044

Please sign in to comment.