FuelLabs / fuel-indexer

🗃 The Fuel indexer is a standalone service that can be used to index various components of the Fuel blockchain.
https://docs.fuel.network/docs/indexer/
140 stars 66 forks source link

add a test for find after save #1519

Closed lostman closed 5 months ago

lostman commented 7 months ago

Description

Work in progress PR to deal with #1518 issue.

An example indexer to see the problem in isolation.

type Block @entity {
    id: ID!
    height: U64!
    hash: Bytes32! @unique
    memo: String!
}
extern crate alloc;
use fuel_indexer_utils::prelude::*;

#[indexer(manifest = "find_after_save.manifest.yaml")]
pub mod find_after_save_index_mod {

    fn find_after_save_handler(block_data: BlockData) {
        if block_data.header.height == 1 {
            info!("Processing Block#{}. (>'.')>", block_data.header.height);

            let mut block = Block::new(
                block_data.header.height.into(),
                block_data.id,
                "one".to_string(),
            );
            block.save();
            info!("Saved: {block:#?}");

            let b = Block::find(Block::height().eq(block.height)).unwrap();
            info!("Found: {b:#?}");

            block.memo = "two".to_string();
            block.save();

            let b = Block::find(Block::height().eq(block.height)).unwrap();
            info!("Found (expecting modified): {b:#?}");

            assert_eq!(&b.memo, "two");
        }
    }
}

Testing steps

Please provide the exact testing steps for the reviewer(s) if this PR requires testing.

Changelog

Please add neat Changelog info here, according to our Contributor's Guide.