Skip to content

Conversation

@andreitrand
Copy link
Contributor

@andreitrand andreitrand commented Nov 4, 2025

Add additional tests which verify PreImage behavior:

    1. A manager account requests a preimage hash once then unrequests it multiple times (added additional checks)
    1. Check the noting and unnoting of empty images
    1. Check the noting and unnoting of oversized images
    1. Check the repeated noting and unnoting of the same preimage
    1. Check preimage behavior when requesting, noting, unrequesting and unnoting occur in different orders
    1. Check the "ensure_updated" extrinsic applies fees depending on the update ratio

Several utility functions have been moved to the helpers file as they are shared with other test files.

This is a continuation of the PR: #470.
Also address outstanding comments from the original PR.

Closes #453.

@andreitrand andreitrand marked this pull request as draft November 4, 2025 13:34
@andreitrand andreitrand force-pushed the andreitrand-pet-tests-preimage-additional branch 4 times, most recently from 9246af8 to f9f62b5 Compare November 11, 2025 12:40
@andreitrand andreitrand marked this pull request as ready for review November 11, 2025 12:41
@andreitrand andreitrand force-pushed the andreitrand-pet-tests-preimage-additional branch 2 times, most recently from f0478e4 to 68b834c Compare November 11, 2025 16:33
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

The code changes introduce several new tests for preimage functionality. However, two of the new tests (preimageOversizedTest and preimageEnsureUpdatedTest) are incomplete as they contain commented-out assertions and TODOs. Additionally, some new test functions have very similar names which could lead to confusion. The refactoring in other files looks good.


Suggestions that couldn't be attached to a specific line

packages/shared/src/preimage.ts:262, 431

The function preimageRequestAndNoteTest was renamed to preimageNoteAndRequestTest (line 262), and a new test also named preimageRequestAndNoteTest was added (line 431). These names are very similar and can be easily confused. For better clarity, consider renaming them to more explicitly describe the order of operations, such as preimageNoteThenRequestTest and preimageRequestThenNoteTest.

@andreitrand andreitrand force-pushed the andreitrand-pet-tests-preimage-additional branch from 68b834c to a023900 Compare November 12, 2025 14:19
@andreitrand
Copy link
Contributor Author

The code changes introduce several new tests for preimage functionality. However, two of the new tests (preimageOversizedTest and preimageEnsureUpdatedTest) are incomplete as they contain commented-out assertions and TODOs. Additionally, some new test functions have very similar names which could lead to confusion. The refactoring in other files looks good.

Suggestions that couldn't be attached to a specific line

packages/shared/src/preimage.ts:262, 431

The function preimageRequestAndNoteTest was renamed to preimageNoteAndRequestTest (line 262), and a new test also named preimageRequestAndNoteTest was added (line 431). These names are very similar and can be easily confused. For better clarity, consider renaming them to more explicitly describe the order of operations, such as preimageNoteThenRequestTest and preimageRequestThenNoteTest.

Fixed.

@rockbmb
Copy link
Collaborator

rockbmb commented Nov 13, 2025

Will close #453 .

@rockbmb rockbmb added the e2e tests Related to end-to-end tests label Nov 13, 2025
@andreitrand andreitrand force-pushed the andreitrand-pet-tests-preimage-additional branch 2 times, most recently from 1348d53 to 4b7d54e Compare November 19, 2025 18:43
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Found a logic issue in the new helper function scheduleCallListWithOrigin which incorrectly schedules multiple calls for the same block, causing only the last one to be executed. This also affects the preimageSingleRequestMultipleUnrequestTest which currently passes but verifies incorrect behavior. Additionally, there are commented-out assertions in the new tests that should be addressed.

Comment on lines 147 to 155
const agenda = calls.map(({ call, origin }) => [
[scheduledBlock],
[
{
call,
origin: origin,
},
],
])
Copy link
Contributor

Choose a reason for hiding this comment

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

The agenda construction creates multiple entries with the same key ([scheduledBlock]) when calls has more than one element. setStorage will likely overwrite previous entries with the same key, resulting in only the last call being scheduled. You should aggregate all calls into a single entry for the scheduledBlock.

Suggested fix:

  const agenda = [
    [
      [scheduledBlock],
      calls.map(({ call, origin }) => ({
        call,
        origin,
      })),
    ],
  ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


// A "Dispatched" event does appear from the scheduler.
events = await getEventsWithType(client, 'scheduler')
expect(events.length).toBe(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

The test expects exactly 1 Dispatched event, which confirms that only one of the three unrequest calls is being executed due to the bug in scheduleCallListWithOrigin. Once the helper is fixed to schedule all 3 calls, this expectation should be updated to expect 3 Dispatched events (one for each call, even if they are no-ops).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +721 to +727
// expect((await getEventsWithType(client, 'preimage')).length).toBe(0)
// expect((await getEventsWithType(client, 'system')).length).toBeGreaterThan(0)
// expectFailedExtrinsicWithType(client, client.api.errors.preimage.PreimageTooLarge)
Copy link
Contributor

Choose a reason for hiding this comment

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

These assertions are commented out. If the test is intended to verify that the extrinsic fails and no preimage events are emitted, these should be uncommented. If there is a reason they are disabled (e.g., pending functionality), the TODO should be more descriptive or the code removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reorganized the TODO messages.

// 6. If the ratio of new to total preimages is less than 90%, check that fees have been paid.
if (expectFees) {
// TODO: The "ensure_updated" fee should be strictly positive in this case!
// expect(ensureUpdatedFee).toBeGreaterThan(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

The assertion expect(ensureUpdatedFee).toBeGreaterThan(0) is commented out with a TODO. If the fee calculation is expected to be positive, this should be fixed or explained.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added details for TODO.

@rockbmb
Copy link
Collaborator

rockbmb commented Nov 20, 2025

Found a logic issue in the new helper function scheduleCallListWithOrigin which incorrectly schedules multiple calls for the same block, causing only the last one to be executed. This also affects the preimageSingleRequestMultipleUnrequestTest which currently passes but verifies incorrect behavior. Additionally, there are commented-out assertions in the new tests that should be addressed.

It's right! 😮

Code as-is:
image

With the fix:
image

Tested with yarn test preimage -t "preimage single request and multiple unrequest test", with a pause right before scheduleInlineCallListWithSameOrigin.

@andreitrand
Copy link
Contributor Author

Found a logic issue in the new helper function scheduleCallListWithOrigin which incorrectly schedules multiple calls for the same block, causing only the last one to be executed. This also affects the preimageSingleRequestMultipleUnrequestTest which currently passes but verifies incorrect behavior. Additionally, there are commented-out assertions in the new tests that should be addressed.

It's right! 😮

Code as-is: image

With the fix: image

Tested with yarn test preimage -t "preimage single request and multiple unrequest test", with a pause right before scheduleInlineCallListWithSameOrigin.

Fixed with the suggested solution.

Add additional tests which verify PreImage behavior:
- 1) A manager account requests a preimage hash once then unrequests it multiple times (added additional checks)
- 2) Check the noting and unnoting of empty images
- 3) Check the noting and unnoting of oversized images
- 4) Check the repeated noting and unnoting of the same preimage
- 5) Check preimage behavior when requesting, noting, unrequesting and unnoting occur in different orders
- 6) Check the "ensure_updated" extrinsic applies fees depending on the update ratio

Several utility functions have been moved to the helpers file as they are shared with other test files.

This is a continuation of the PR: open-web3-stack#470.
Also address outstanding comments from the original PR.
@andreitrand andreitrand force-pushed the andreitrand-pet-tests-preimage-additional branch from 22e6522 to a19cb6b Compare November 20, 2025 15:07
@rockbmb rockbmb merged commit 20f9bf5 into open-web3-stack:master Nov 20, 2025
216 of 222 checks passed
@rockbmb
Copy link
Collaborator

rockbmb commented Nov 20, 2025

Merged, thanks @andreitrand !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e tests Related to end-to-end tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve preimage functionality test coverage

2 participants