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

add a test for find after save #1519

Closed
wants to merge 1 commit into from
Closed

Conversation

lostman
Copy link
Contributor

@lostman lostman commented Dec 15, 2023

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.

@lostman lostman self-assigned this Dec 15, 2023
@deekerno deekerno closed this Feb 6, 2024
@lostman lostman removed their assignment Mar 16, 2024
@lostman lostman deleted the maciej/1518-find-after-save branch March 16, 2024 05:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants