Skip to content

[7] Add rollback tests - #342

Merged
JonoPrest merged 40 commits into
mainfrom
jp/add-rollback-tests
Nov 19, 2024
Merged

[7] Add rollback tests#342
JonoPrest merged 40 commits into
mainfrom
jp/add-rollback-tests

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator
  • Adds tests for entity history db functions
  • Fixes an error in the prune stale history function

@JonoPrest
JonoPrest requested a review from DZakh November 18, 2024 15:21
FROM
public.${sql(tableName)}
WHERE
serial >= (SELECT serial FROM first_change)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug, caught by the test 🐛

Comment on lines +98 to +100
| DELETE =>
let {id} = v["entityData"]->(Utils.magic: Js.Dict.t<unknown> => entityIdOnly)
Delete({id: id})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just stripping the null fields instead of casting. Helps making the tests pass.

Comment on lines -6 to -17
type testEntity = {
id: string,
fieldA: int,
fieldB: option<string>,
}

let testEntitySchema: S.t<testEntity> = S.schema(s => {
id: s.matches(S.string),
fieldA: s.matches(S.int),
fieldB: s.matches(S.option(S.string)),
})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved these into an entity module to help with tests.

fieldB: option<string>,
}

let name = "TestEntity"->(Utils.magic: string => Enums.EntityType.t)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dangerous if it were to match on the entity type but right now the code doesn't do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future I'd actually want to:

  1. Remove the enum for entity type
  2. Change entityMod to simply be a record type

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 💪🏼, I have some ideas as well. Eg. I'm keen to derive the table from the rescript schema. And do some runtime validations there to start making it more pluggable as a library without needing a gql schema file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly how I visioned it myself 👍

sql,
~isUnorderedMultichainMode,
~eventIdentifier: Types.eventIdentifier,
~allEntities=Entities.allEntities,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added injection params for these functions to make it testable.

fieldB: option<string>,
}

let name = "TestEntity"->(Utils.magic: string => Enums.EntityType.t)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future I'd actually want to:

  1. Remove the enum for entity type
  2. Change entityMod to simply be a record type

Base automatically changed from jp/handle-dyn-contract-rollback to main November 18, 2024 17:19
@JonoPrest
JonoPrest merged commit ede2d57 into main Nov 19, 2024
@JonoPrest
JonoPrest deleted the jp/add-rollback-tests branch November 19, 2024 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants