-
Notifications
You must be signed in to change notification settings - Fork 15
Add tests for PreImage (continued) #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for PreImage (continued) #471
Conversation
9246af8 to
f9f62b5
Compare
f0478e4 to
68b834c
Compare
There was a problem hiding this 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.
68b834c to
a023900
Compare
Fixed. |
|
Will close #453 . |
packages/polkadot/src/__snapshots__/polkadot.preimage.e2e.test.ts.snap
Outdated
Show resolved
Hide resolved
1348d53 to
4b7d54e
Compare
There was a problem hiding this 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.
packages/shared/src/helpers/index.ts
Outdated
| const agenda = calls.map(({ call, origin }) => [ | ||
| [scheduledBlock], | ||
| [ | ||
| { | ||
| call, | ||
| origin: origin, | ||
| }, | ||
| ], | ||
| ]) |
There was a problem hiding this comment.
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,
})),
],
]There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
packages/shared/src/preimage.ts
Outdated
|
|
||
| // A "Dispatched" event does appear from the scheduler. | ||
| events = await getEventsWithType(client, 'scheduler') | ||
| expect(events.length).toBe(1) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| // expect((await getEventsWithType(client, 'preimage')).length).toBe(0) | ||
| // expect((await getEventsWithType(client, 'system')).length).toBeGreaterThan(0) | ||
| // expectFailedExtrinsicWithType(client, client.api.errors.preimage.PreimageTooLarge) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added details for TODO.
It's right! 😮 Tested with |
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.
22e6522 to
a19cb6b
Compare
|
Merged, thanks @andreitrand ! |




Add additional tests which verify PreImage behavior:
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.