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 a76af87 commit f7cf6a6
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 749 deletions.
1,194 changes: 536 additions & 658 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.3", path = "./packages/fuel-indexer-da
fuel-indexer-schema = { version = "0.24.3", path = "./packages/fuel-indexer-schema", default-features = false }
fuel-indexer-types = { version = "0.24.3", path = "./packages/fuel-indexer-types" }
fuel-indexer-utils = { version = "0.24.3", 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
54 changes: 21 additions & 33 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 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 @@ -344,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 Down Expand Up @@ -417,7 +421,7 @@ pub async fn indexer_service_postgres(
}

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 @@ -437,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 @@ -458,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 @@ -843,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 @@ -964,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() {

}
1 change: 1 addition & 0 deletions packages/fuel-indexer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ description = "Fuel Indexer Types"

[dependencies]
bytes = { version = "1.4", features = ["serde"] }
fuel-crypto = { workspace = true }
fuel-tx = { workspace = true, features = ["serde"] }
fuel-types = { workspace = true }
fuels = { workspace = true }
Expand Down
19 changes: 6 additions & 13 deletions packages/fuel-indexer-types/src/fuel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};

pub mod field {
pub use fuel_tx::field::{
BytecodeLength, BytecodeWitnessIndex, GasLimit, GasPrice, Inputs, Maturity,
BytecodeLength, BytecodeWitnessIndex, GasPrice, Inputs, Maturity,
Outputs, ReceiptsRoot, Salt as TxFieldSalt, Script as TxFieldScript, ScriptData,
StorageSlots, TxPointer as FieldTxPointer, Witnesses,
};
Expand Down Expand Up @@ -43,7 +43,6 @@ impl Default for Transaction {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Create {
pub gas_price: Word,
pub gas_limit: Word,
pub maturity: BlockHeight,
pub bytecode_length: Word,
pub bytecode_witness_index: u8,
Expand Down Expand Up @@ -86,7 +85,6 @@ impl From<Json> for CommonMetadata {
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct Script {
pub gas_price: Word,
pub gas_limit: Word,
pub maturity: BlockHeight,
pub script: Vec<u8>,
pub script_data: Vec<u8>,
Expand Down Expand Up @@ -122,7 +120,6 @@ impl From<Json> for ScriptMetadata {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Mint {
pub tx_pointer: TxPointer,
pub outputs: Vec<Output>,
pub metadata: Option<MintMetadata>,
}

Expand Down Expand Up @@ -176,7 +173,7 @@ pub struct BlockData {
pub height: u32,
pub id: Bytes32,
pub header: Header,
pub producer: Option<Bytes32>,
pub producer: Option<fuel_crypto::fuel_types::Bytes32>,
pub time: i64,
pub consensus: Consensus,
pub transactions: Vec<TransactionData>,
Expand Down Expand Up @@ -393,18 +390,14 @@ impl From<ClientOutput> for Output {
.expect("Could not convert asset ID to bytes"),
),
}),
ClientOutput::Contract {
input_index,
balance_root,
state_root,
} => Output::ContractOutput(ContractOutput {
input_index: input_index.into(),
ClientOutput::Contract(contract) => Output::ContractOutput(ContractOutput {
input_index: contract.input_index.into(),
balance_root: Bytes32::from(
<[u8; 32]>::try_from(balance_root)
<[u8; 32]>::try_from(contract.balance_root)
.expect("Could not convert balance root to bytes"),
),
state_root: Bytes32::from(
<[u8; 32]>::try_from(state_root)
<[u8; 32]>::try_from(contract.state_root)
.expect("Could not convert state root to bytes"),
),
}),
Expand Down
Loading

0 comments on commit f7cf6a6

Please sign in to comment.