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

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Dec 11, 2023
1 parent 65755a7 commit 68222b2
Show file tree
Hide file tree
Showing 19 changed files with 1,009 additions and 1,004 deletions.
1,807 changes: 916 additions & 891 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fuel-indexer-postgres = { version = "0.24.1", path = "./packages/fuel-indexer-da
fuel-indexer-schema = { version = "0.24.1", path = "./packages/fuel-indexer-schema", default-features = false }
fuel-indexer-types = { version = "0.24.1", path = "./packages/fuel-indexer-types" }
fuel-indexer-utils = { version = "0.24.1", path = "./packages/fuel-indexer-utils" }
fuel-crypto = { version = "0.43", default-features = false}
fuel-tx = { version = "0.43", default-features = false }
fuel-types = { version = "0.43", default-features = false, features = ["serde"] }
fuel-vm = { version = "0.43", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ enum PanicReason {
InvalidMetadataIdentifier
MalformedCallStructure
ReservedRegisterNotWritable
ErrorFlag
InvalidImmediateValue
ExpectedCoinInput
MaxMemoryAccess
MemoryWriteOverlap
ContractNotInInputs
InternalBalanceOverflow
Expand All @@ -58,7 +56,6 @@ enum PanicReason {
TransferAmountCannotBeZero
ExpectedOutputVariable
ExpectedParentInternalContext
IllegalJump
ContractIdAlreadyDeployed
Unknown
}
Expand Down Expand Up @@ -463,7 +460,6 @@ union Output =
type CreateTransaction @entity {
id: ID!
gas_price: U64!
gas_limit: U64!
maturity: U32!
bytecode_length: U64!
bytecode_witness_index: U8!
Expand All @@ -482,7 +478,6 @@ type CreateTransaction @entity {
type ScriptTransaction @entity {
id: ID!
gas_price: U64!
gas_limit: U64!
maturity: U32!
script: Bytes!
script_data: Bytes!
Expand All @@ -500,7 +495,6 @@ type ScriptTransaction @entity {
type MintTransaction @entity {
id: ID!
tx_pointer: TxPointer!
outputs: [Output!]
metadata: Json
is_mint: Boolean!
receipts: [Receipt!]
Expand Down
14 changes: 0 additions & 14 deletions examples/fuel-explorer/fuel-explorer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ impl From<fuel::ClientPanicReason> for PanicReason {
fuel::ClientPanicReason::ReservedRegisterNotWritable => {
PanicReason::ReservedRegisterNotWritable
}
fuel::ClientPanicReason::ErrorFlag => PanicReason::ErrorFlag,
fuel::ClientPanicReason::InvalidImmediateValue => {
PanicReason::InvalidImmediateValue
}
fuel::ClientPanicReason::ExpectedCoinInput => PanicReason::ExpectedCoinInput,
fuel::ClientPanicReason::MaxMemoryAccess => PanicReason::MaxMemoryAccess,
fuel::ClientPanicReason::MemoryWriteOverlap => {
PanicReason::MemoryWriteOverlap
}
Expand All @@ -88,7 +86,6 @@ impl From<fuel::ClientPanicReason> for PanicReason {
fuel::ClientPanicReason::ExpectedParentInternalContext => {
PanicReason::ExpectedParentInternalContext
}
fuel::ClientPanicReason::IllegalJump => PanicReason::IllegalJump,
fuel::ClientPanicReason::ContractIdAlreadyDeployed => {
PanicReason::ContractIdAlreadyDeployed
}
Expand Down Expand Up @@ -728,7 +725,6 @@ impl From<fuel::TransactionData> for Transaction {
let tx_status = TransactionStatus::from(transaction.status.clone());
match transaction.transaction {
fuel::Transaction::Script(fuel::Script {
gas_limit,
gas_price,
maturity,
script,
Expand Down Expand Up @@ -762,7 +758,6 @@ impl From<fuel::TransactionData> for Transaction {
.collect::<Vec<_>>();

let script_tx = ScriptTransaction::new(
gas_limit,
gas_price,
*maturity,
script.to_owned().into(),
Expand All @@ -781,7 +776,6 @@ impl From<fuel::TransactionData> for Transaction {
Self::from(script_tx).get_or_create()
}
fuel::Transaction::Create(fuel::Create {
gas_limit,
gas_price,
maturity,
bytecode_length,
Expand Down Expand Up @@ -821,7 +815,6 @@ impl From<fuel::TransactionData> for Transaction {
.collect::<Vec<_>>();

let create_tx = CreateTransaction::new(
gas_limit,
gas_price,
*maturity,
bytecode_length,
Expand All @@ -842,15 +835,9 @@ impl From<fuel::TransactionData> for Transaction {
}
fuel::Transaction::Mint(fuel::Mint {
tx_pointer,
outputs,
metadata,
}) => {
let tx_pointer = TxPointer::from(tx_pointer.to_owned());
let outputs = outputs
.iter()
.map(|o| Output::from(o.to_owned()))
.map(|o| o.id)
.collect::<Vec<UID>>();
let receipts = transaction
.receipts
.iter()
Expand All @@ -859,7 +846,6 @@ impl From<fuel::TransactionData> for Transaction {

let mint_tx = MintTransaction::new(
tx_pointer.id,
Some(outputs),
metadata.to_owned().map(|m| m.into()),
true,
Some(receipts),
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async-graphql-axum = "5.0.7"
async-std = "1"
axum = { version = "0.6", features = ["multipart", "macros"] }
clap = { features = ["cargo", "derive", "env"], workspace = true }
fuel-crypto = { version = "=0.35.4", features = ["std"] }
fuel-crypto = { workspace = true, features = ["std"] }
fuel-indexer-database = { workspace = true }
fuel-indexer-graphql = { workspace = true }
fuel-indexer-lib = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ chrono = { version = "0.4", features = ["serde"] }
clap = { workspace = true }
criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
duct = "0.13"
fuel-core-client = "0.20"
fuel-core-client = "0.21"
fuel-indexer = { workspace = true }
fuel-indexer-database = { workspace = true }
fuel-indexer-graphql = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-plugin/src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl ToSQLValue for UID {

impl ToSQLValue for BlockHeight {
fn to_sql_value(self) -> sql::Value {
sqlparser::test_utils::number(&self.as_usize().to_string())
sqlparser::test_utils::number(&self.to_string())
}
}

Expand Down
104 changes: 50 additions & 54 deletions packages/fuel-indexer-tests/src/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{assets, defaults, TestError, WORKSPACE_ROOT};
use crate::{
assets, defaults, utils::update_test_manifest_asset_paths, TestError, WORKSPACE_ROOT,
};
use actix_service::Service;
use actix_web::test;
use axum::routing::Router;
Expand All @@ -7,7 +9,7 @@ use fuel_indexer_api_server::api::WebApi;
use fuel_indexer_database::IndexerConnectionPool;
use fuel_indexer_lib::{
config::{DatabaseConfig, IndexerConfig, WebApiConfig},
defaults::SERVICE_REQUEST_CHANNEL_SIZE,
defaults::{MAX_DB_CONNECTIONS, SERVICE_REQUEST_CHANNEL_SIZE},
manifest::Manifest,
utils::{derive_socket_addr, ServiceRequest},
};
Expand Down Expand Up @@ -38,8 +40,8 @@ use tokio::{
use tracing_subscriber::filter::EnvFilter;

abigen!(Contract(
name = "FuelIndexer",
abi = "packages/fuel-indexer-tests/sway/test-contract1/out/debug/test-contract1-abi.json"
name = "FuelIndexerTest",
abi = "packages/fuel-indexer-tests/contracts/fuel-indexer-test/out/debug/fuel-indexer-test-abi.json"
));

pub struct TestPostgresDb {
Expand Down Expand Up @@ -91,7 +93,8 @@ pub async fn setup_indexing_test_components(
let db = TestPostgresDb::new().await.unwrap();
let mut service = indexer_service_postgres(Some(&db.url), config).await;

let manifest = assets::test_indexer_updated_manifest();
let mut manifest = Manifest::try_from(assets::FUEL_INDEXER_TEST_MANIFEST).unwrap();
update_test_manifest_asset_paths(&mut manifest);

service
.register_indexer_from_manifest(
Expand All @@ -116,7 +119,8 @@ pub async fn setup_web_test_components(
let db = TestPostgresDb::new().await.unwrap();
let mut service = indexer_service_postgres(Some(&db.url), config.clone()).await;

let manifest = assets::test_indexer_updated_manifest();
let mut manifest = Manifest::try_from(assets::FUEL_INDEXER_TEST_MANIFEST).unwrap();
update_test_manifest_asset_paths(&mut manifest);

service
.register_indexer_from_manifest(
Expand Down Expand Up @@ -189,20 +193,22 @@ impl TestPostgresDb {
.await?;

// Instantiate a pool so that it can be stored in the struct for use in the tests
let pool =
match IndexerConnectionPool::connect(&test_db_config.clone().to_string())
.await
{
Ok(pool) => match pool {
IndexerConnectionPool::Postgres(p) => {
let mut conn = p.acquire().await?;

fuel_indexer_postgres::run_migration(&mut conn).await?;
p
}
},
Err(e) => return Err(TestError::PoolCreationError(e)),
};
let pool = match IndexerConnectionPool::connect(
&test_db_config.clone().to_string(),
MAX_DB_CONNECTIONS,
)
.await
{
Ok(pool) => match pool {
IndexerConnectionPool::Postgres(p) => {
let mut conn = p.acquire().await?;

fuel_indexer_postgres::run_migration(&mut conn).await?;
p
}
},
Err(e) => return Err(TestError::PoolCreationError(e)),
};

Ok(Self {
db_name,
Expand Down Expand Up @@ -342,22 +348,22 @@ pub async fn setup_example_test_fuel_node() -> Result<(), ()> {
let wallet_path = Path::new(WORKSPACE_ROOT).join("test-chain-config.json");

let contract_bin_path = Path::new(WORKSPACE_ROOT)
.join("sway")
.join("test-contract1")
.join("contracts")
.join("fuel-indexer-test")
.join("out")
.join("debug")
.join("test-contract1.bin");
.join("fuel-indexer-test.bin");

setup_test_fuel_node(wallet_path, Some(contract_bin_path), None).await
}

pub fn get_test_contract_id() -> Bech32ContractId {
let contract_bin_path = Path::new(WORKSPACE_ROOT)
.join("sway")
.join("test-contract1")
.join("contracts")
.join("fuel-indexer-test")
.join("out")
.join("debug")
.join("test-contract1.bin");
.join("fuel-indexer-test.bin");

let loaded_contract = Contract::load_from(
contract_bin_path.as_os_str().to_str().unwrap(),
Expand All @@ -378,9 +384,12 @@ pub async fn api_server_app_postgres(
config.database = DatabaseConfig::from_str(url).unwrap();
}

let pool = IndexerConnectionPool::connect(&config.database.to_string())
.await
.unwrap();
let pool = IndexerConnectionPool::connect(
&config.database.to_string(),
config.max_db_connections,
)
.await
.unwrap();

let (tx, rx) = channel::<ServiceRequest>(SERVICE_REQUEST_CHANNEL_SIZE);

Expand All @@ -401,15 +410,18 @@ pub async fn indexer_service_postgres(

let (_tx, rx) = channel::<ServiceRequest>(SERVICE_REQUEST_CHANNEL_SIZE);

let pool = IndexerConnectionPool::connect(&config.database.to_string())
.await
.unwrap();
let pool = IndexerConnectionPool::connect(
&config.database.to_string(),
config.max_db_connections,
)
.await
.unwrap();

IndexerService::new(config, pool, rx).await.unwrap()
}

pub async fn connect_to_deployed_contract(
) -> Result<FuelIndexer<WalletUnlocked>, Box<dyn std::error::Error>> {
) -> Result<FuelIndexerTest<WalletUnlocked>, Box<dyn std::error::Error>> {
let wallet_path = Path::new(WORKSPACE_ROOT).join("test-chain-config.json");
let wallet_path_str = wallet_path.as_os_str().to_str().unwrap();
let mut wallet =
Expand All @@ -429,7 +441,7 @@ pub async fn connect_to_deployed_contract(
let contract_id: Bech32ContractId =
Bech32ContractId::from(fuels::types::ContractId::from(get_test_contract_id()));

let contract = FuelIndexer::new(contract_id.clone(), wallet);
let contract = FuelIndexerTest::new(contract_id.clone(), wallet);

println!("Using contract at {contract_id}");

Expand All @@ -450,7 +462,7 @@ pub mod test_web {
use fuels::types::bech32::Bech32ContractId;
use std::path::Path;

use super::{tx_params, FuelIndexer};
use super::{tx_params, FuelIndexerTest};

async fn fuel_indexer_test_blocks(state: web::Data<Arc<AppState>>) -> impl Responder {
let _ = state
Expand Down Expand Up @@ -835,28 +847,12 @@ pub mod test_web {
HttpResponse::Ok()
}

async fn trigger_predicate_witness_data(
state: web::Data<Arc<AppState>>,
) -> impl Responder {
let data = vec![1u8];
let _ = state
.contract
.methods()
.trigger_find()
.tx_params(tx_params())
.call()
.await
.unwrap();

HttpResponse::Ok()
}

pub struct AppState {
pub contract: FuelIndexer<WalletUnlocked>,
pub contract: FuelIndexerTest<WalletUnlocked>,
}

pub fn app(
contract: FuelIndexer<WalletUnlocked>,
contract: FuelIndexerTest<WalletUnlocked>,
) -> App<
impl ServiceFactory<
ServiceRequest,
Expand Down Expand Up @@ -956,7 +952,7 @@ pub mod test_web {
println!("Starting server at {}", defaults::WEB_API_ADDR);

let _ = HttpServer::new(move || {
app(FuelIndexer::new(contract_id.clone(), wallet.clone()))
app(FuelIndexerTest::new(contract_id.clone(), wallet.clone()))
})
.bind(defaults::WEB_API_ADDR)
.unwrap()
Expand Down
8 changes: 1 addition & 7 deletions packages/fuel-indexer-tests/tests/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{collections::HashSet, str::FromStr};

const REVERT_VM_CODE: u64 = 0x0004;
const EXPECTED_CONTRACT_ID: &str =
"60ddf75280b60e644e90fca5febaffb024882f0203b04ed8c7e9df8aa961060e";
"5805ad6fc1543e317cc86d4da1185b8e122c183861bf9e151a3819ac3e26103d";
const TRANSFER_BASE_ASSET_ID: &str =
"0000000000000000000000000000000000000000000000000000000000000000";

Expand Down Expand Up @@ -773,9 +773,3 @@ async fn test_find() {
.get::<&str, usize>(2)
.contains("called `Option::unwrap()` on a `None` value"));
}


#[actix_web::test]
async fn test_signal_predicate_witness_data() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ database:
port: "5432"
database: postgres
verbose: "false"
max_db_connections: 100
metrics: true
stop_idle_indexers: false
run_migrations: true
Expand Down
Loading

0 comments on commit 68222b2

Please sign in to comment.