Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Alston authored and Rashad Alston committed May 24, 2023
1 parent 5a52f42 commit 7942ab6
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 145 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
namespace: indexer
namespace: fuel
abi: ~
identifier: indexer
identifier: explorer
fuel_client: ~
graphql_schema: examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql
module:
wasm: target/wasm32-unknown-unknown/release/fuel_explorer.wasm
metrics: true
contract_id: ~
start_block: 30740
start_block: ~
resumable: true
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TxPointer {
tx_index: UInt4!
}

type Create {
type CreateTransaction {
id: ID!
gas_price: UInt8!
gas_limit: UInt8!
Expand All @@ -22,7 +22,7 @@ type Create {
# metadata: ScriptMetadata
}

type Script {
type ScriptTransaction {
id: ID!
gas_price: UInt8!
gas_limit: UInt8!
Expand All @@ -36,19 +36,19 @@ type Script {
}


type Mint {
type MintTransaction {
id: ID!
tx_pointer: TxPointer!
# outputs: [Output]!
# metadata: MintMetadata
}


type Transactions {
type Transaction {
id: ID!
create: Create
script: Script
mint: Mint
creates: CreateTransaction
scripts: ScriptTransaction
mints: MintTransaction
}

type Header {
Expand All @@ -67,7 +67,7 @@ type Header {
}

# TODO: Should this be a FK?
type GenesisConsensus {
type Genesis {
id: ID!
chain_config_hash: Bytes32!
coins_root: Bytes32!
Expand All @@ -77,32 +77,34 @@ type GenesisConsensus {


# TODO: Should this be a FK?
type PoAConsensus {
type PoA {
signature: Signature! @norelation
}

# TODO: Should this be a FK?
type UnknownConsensus {
type Unknown {
value: Boolean! @norelation
}

type BlockConensus {
# TODO: Should this be a FK?
type Consensus {
id: ID!
genesis: GenesisConsensus
poa: PoAConsensus
unknown: UnknownConsensus
genesis: Genesis
poa: PoA
unknown: Unknown
label: Charfield!
}

type TransactionIdFragment {
id: ID!
transaction_id: Transactions!
transaction_id: Transaction!
}

type Block {
id: ID!
block_id: BlockId!
header: Header!
consensus: BlockConensus!
consensus: Consensus!
# transactions: [TransactionIdFragment]!
}

Expand Down
41 changes: 30 additions & 11 deletions examples/fuel-explorer/fuel-explorer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,65 @@ extern crate alloc;
use fuel_indexer_macros::indexer;
use fuel_indexer_plugin::prelude::*;

pub enum ConsensusLabel {
Unknown,
Genesis,
PoA,
}

impl ToString for ConsensusLabel {
fn to_string(&self) -> String {
match self {
ConsensusLabel::Unknown => "Consensus::Unknown".to_string(),
ConsensusLabel::Genesis => "Consensus::Genesis".to_string(),
ConsensusLabel::PoA => "Consensus::PoA".to_string(),
}
}
}

// TODO: https://github.com/FuelLabs/fuel-indexer/issues/286
impl From<Consensus> for BlockConensus {
fn from(consensus: Consensus) -> Self {
impl From<ConsensusData> for Consensus {
fn from(consensus: ConsensusData) -> Self {
match consensus {
Consensus::Genesis(Genesis {
ConsensusData::Genesis(GenesisConsensus {
chain_config_hash,
coins_root,
contracts_root,
messages_root,
}) => {
let id = 1;
let genesis = GenesisConsensus::load(id).unwrap_or(GenesisConsensus {
let genesis = Genesis::load(id).unwrap_or(Genesis {
chain_config_hash,
coins_root,
contracts_root,
messages_root,
id,
});

BlockConensus {
Consensus {
unknown: None,
poa: None,
genesis: Some(genesis.id),
label: ConsensusLabel::Genesis.to_string(),
id: 1,
}
}
Consensus::PoA(poa) => BlockConensus {
ConsensusData::PoA(poa) => Consensus {
unknown: None,
genesis: None,
label: ConsensusLabel::PoA.to_string(),
poa: Some(
PoAConsensus {
PoA {
signature: poa.signature,
}
.into(),
),
id: 1,
},
Consensus::Unknown => BlockConensus {
unknown: Some(UnknownConsensus { value: true }.into()),
ConsensusData::UnknownConsensus => Consensus {
unknown: Some(Unknown { value: true }.into()),
genesis: None,
label: ConsensusLabel::Unknown.to_string(),
poa: None,
id: 1,
},
Expand Down Expand Up @@ -69,7 +88,7 @@ pub mod explorer_index {

header.save();

let consensus = BlockConensus::from(block.consensus);
let consensus = Consensus::from(block.consensus);
consensus.save();

let block = Block {
Expand All @@ -79,7 +98,7 @@ pub mod explorer_index {
consensus: consensus.id,
};

Logger::info("hello, john!");
Logger::info("hello, world!");

block.save();
}
Expand Down
5 changes: 5 additions & 0 deletions packages/fuel-indexer-database/database-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl NewColumn {
ColumnType::Int1 => "integer",
ColumnType::UInt1 => "integer",
ColumnType::NoRelation => "Json",
ColumnType::BlockId => "varchar(64)",
}
}
}
Expand Down Expand Up @@ -211,6 +212,7 @@ pub enum ColumnType {
Int1 = 31,
UInt1 = 32,
NoRelation = 33,
BlockId = 34,
}

impl From<ColumnType> for i32 {
Expand Down Expand Up @@ -250,6 +252,7 @@ impl From<ColumnType> for i32 {
ColumnType::Int1 => 31,
ColumnType::UInt1 => 32,
ColumnType::NoRelation => 33,
ColumnType::BlockId => 34,
}
}
}
Expand Down Expand Up @@ -297,6 +300,7 @@ impl From<i32> for ColumnType {
31 => ColumnType::Int1,
32 => ColumnType::UInt1,
33 => ColumnType::NoRelation,
34 => ColumnType::BlockId,
_ => panic!("Invalid column type."),
}
}
Expand Down Expand Up @@ -339,6 +343,7 @@ impl From<&str> for ColumnType {
"Int1" => ColumnType::Int1,
"UInt1" => ColumnType::UInt1,
"NoRelation" => ColumnType::NoRelation,
"BlockId" => ColumnType::BlockId,
_ => panic!("Invalid column type: '{name}'"),
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/fuel-indexer-database/postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ pub async fn columns_get_schema(
version: &str,
) -> sqlx::Result<Vec<ColumnInfo>> {
Ok(sqlx::query(
"
SELECT
"SELECT
c.type_id as type_id,
t.table_name as table_name,
c.column_position as column_position,
Expand Down
11 changes: 5 additions & 6 deletions packages/fuel-indexer-macros/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ lazy_static! {
"MessageId",
"Receipt",
"ScriptResult",
"Transaction",
"TransactionData",
"TransactionStatus",
"Transfer",
Expand Down Expand Up @@ -95,11 +94,11 @@ lazy_static! {
"UInt8",

// Temporary types: https://github.com/FuelLabs/fuel-indexer/issues/286
"Consensus",
"Genesis",
"Genesis",
"PoA",
"Unknown",
"ClientTransaction",
"ConsensusData",
"GenesisConensus",
"PoAConsensus",
"UnknownConsensus",

]);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/fuel-indexer-schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde = { default-features = false, features = ["derive"], workspace = true }
sha2 = "0.9"
sqlx = { version = "0.6", optional = true, features = ["postgres", "runtime-tokio-rustls", "bigdecimal"] }
thiserror = { workspace = true }
tracing = { workspace = true, optional = true }

[dev-dependencies]
insta = { version = "1.8", features = ["yaml"] }
Expand All @@ -28,5 +29,6 @@ default = ["db-models"]
db-models = [
"sqlx",
"fuel-indexer-database",
"tracing",
]

2 changes: 2 additions & 0 deletions packages/fuel-indexer-schema/src/db/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
utils::{inject_native_entities_into_schema, schema_version},
};
use fuel_indexer_database::{queries, IndexerConnection, IndexerConnectionPool};
use tracing::info;

pub struct SchemaManager {
pool: IndexerConnectionPool,
Expand All @@ -29,6 +30,7 @@ impl SchemaManager {
let version = schema_version(&schema);

if !queries::schema_exists(conn, namespace, identifier, &version).await? {
info!("Creating schema for Indexer({namespace}.{identifier}) with Version({version}).");
let _db_schema = SchemaBuilder::new(
namespace,
identifier,
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/fuel-indexer-tests/tests/e2e/graphql_api_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn test_can_return_query_response_with_all_fields_required_postgres() {
let resp = client
.post("http://127.0.0.1:29987/api/graph/fuel_indexer_test/index1")
.header(CONTENT_TYPE, "application/graphql".to_owned())
.body(r#"{ "query": "query { block { id height timestamp }}" }"#)
.body(r#"{ "query": "query { blockentity { id height timestamp }}" }"#)
.send()
.await
.unwrap();
Expand Down Expand Up @@ -142,7 +142,7 @@ async fn test_can_return_nested_query_response_with_implicit_foreign_keys_postgr
let resp = client
.post("http://127.0.0.1:29987/api/graph/fuel_indexer_test/index1")
.header(CONTENT_TYPE, "application/graphql".to_owned())
.body(r#"{ "query": "query { tx { block { id height } id timestamp } }" }"#)
.body(r#"{ "query": "query { txentity { block { id height } id timestamp } }" }"#)
.send()
.await
.unwrap();
Expand Down
Loading

0 comments on commit 7942ab6

Please sign in to comment.