Skip to content
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

fix: make e2e tests for passkey more rigorous in their success checks #2246

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

JoeCap08055
Copy link
Collaborator

@JoeCap08055 JoeCap08055 commented Dec 30, 2024

Goal

The goal of this PR is to make the e2e tests for the passkey pallet a bit more discerning, and more clear to read.
Previously, the tests were determining a successful token transfer by the absence of an exception and an increased nonce. While this is technically correct, according to the logic by which the extrinsic call would complete with no exceptions, it is a bit opaque.

This PR enhances the test conditions to check that:

  • The appropriate events are generated in the block, and the event contents are correct
  • The correct reciever's balance is incremented by the transfer amount
  • The correct sender's balance is decremented by the transfer amount + fee
  • Failure tests are enhance to check the specific error that caused the failure

Test conditions for the success cases are also enhanced so that successful tests are more verbose, as each check is encapsulated in a separate test block.

Also, the function Extrinsic.sendUnsigned() was fixed to properly parse and return the event stream from the blockchain, in the same manner that Extrinsic.signAndSend() does.

Checklist

  • Updated Pallet Readme?
  • Updated js/api-augment for Custom RPC APIs?
  • Design doc(s) updated?
  • Unit Tests added?
  • e2e Tests added?
  • Benchmarks added?
  • Spec version incremented?

Comment on lines -49 to -52
await assert.doesNotReject(passkeyProxy.fundAndSendUnsigned(fundingSource));
await ExtrinsicHelper.waitForFinalization((await getBlockNumber()) + 2);
// adding some delay before fetching the nonce to ensure it is updated
await new Promise((resolve) => setTimeout(resolve, 1000));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't need to await finalization now that sendUnsigned has been fixed to not resolve until the extrinsic is included in a finalized block.

@@ -264,6 +264,10 @@ export class Extrinsic<N = unknown, T extends ISubmittableResult = ISubmittableR
public async fundAndSendUnsigned(source: KeyringPair) {
await this.fundOperation(source);
log('Fund and Send', `Fund Source: ${getUnifiedAddress(source)}`);
return this.sendUnsigned();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deleted code block; now that sendUnsigned is doing what this block used to do.

const accountPKey = getUnifiedPublicKey(fundedSr25519Keys);
const nonce = await getNonce(fundedSr25519Keys);
const transferAmount = 55_000_000n;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have constants for these like DOLLARS and CENTS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure, but the amount isn't important anyway; we just want to be sure to check that whatever amount is transferred, the balance changes by that amount.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But that does remind me, it would be good to also check that the correct sender's balance decreases by the appropriate amount.

Copy link
Collaborator

@enddynayn enddynayn left a comment

Choose a reason for hiding this comment

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

👍 great!

Copy link
Collaborator

@saraswatpuneet saraswatpuneet left a comment

Choose a reason for hiding this comment

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

Lgtm

@JoeCap08055 JoeCap08055 enabled auto-merge (squash) January 2, 2025 20:06
@JoeCap08055 JoeCap08055 merged commit c5151d5 into main Jan 2, 2025
28 checks passed
@JoeCap08055 JoeCap08055 deleted the fix/tighten-passkey-e2e-tests branch January 2, 2025 20:31
JoeCap08055 added a commit that referenced this pull request Jan 2, 2025
…#2246)

# Goal
The goal of this PR is to make the e2e tests for the passkey pallet a
bit more discerning, and more clear to read.
Previously, the tests were determining a successful token transfer by
the absence of an exception and an increased nonce. While this is
technically correct, according to the logic by which the extrinsic call
would complete with no exceptions, it is a bit opaque.

This PR enhances the test conditions to check that:
* The appropriate events are generated in the block, and the event
contents are correct
* The correct reciever's balance is incremented by the transfer amount
* The correct sender's balance is decremented by the transfer amount +
fee
* Failure tests are enhance to check the specific error that caused the
failure

Test conditions for the success cases are also enhanced so that
successful tests are more verbose, as each check is encapsulated in a
separate test block.

Also, the function `Extrinsic.sendUnsigned()` was fixed to properly
parse and return the event stream from the blockchain, in the same
manner that `Extrinsic.signAndSend()` does.

# Checklist
- [ ] Updated Pallet Readme?
- [ ] Updated js/api-augment for Custom RPC APIs?
- [ ] Design doc(s) updated?
- [ ] Unit Tests added?
- [ ] e2e Tests added?
- [ ] Benchmarks added?
- [ ] Spec version incremented?
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.

4 participants