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

Adds more unit tests for WCPairing #437

Merged
merged 3 commits into from
Aug 19, 2022

Conversation

MaisaMilena
Copy link
Contributor

  • Rename some tests to specify if is testing init from uri or topic
  • Add scenarios that throw error

While working on this I noticed that the activate function sets the status to true even if updateExpiry throws an error. Is that the expected behavior? Maybe activate should only change the active var?

@MaisaMilena
Copy link
Contributor Author

Btw, while on development running the tests, CacaoSignerTest and SignerTest failed

Copy link

@sekimondre sekimondre left a comment

Choose a reason for hiding this comment

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

Test needs a fix (update less than expiry)

func testUpdateExpiry_WhenNewExpiryDateIsLessThanExpiryDate_ShouldThrowInvalidUpdateExpiryValue() {
let expiryDate = referenceDate.advanced(by: 10 * .minute)
var pairing = WCPairing(topic: "", relay: .stub(), peerMetadata: .stub(), expiryDate: expiryDate)
XCTAssertThrowsError(try pairing.updateExpiry(40 * .day)) { error in

Choose a reason for hiding this comment

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

The expire date you set is 10 minutes into the future, the update value should be less than this, like the test says, but you're testing with a 40-day date (greater than max, like the test above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ops! 😅

Comment on lines 89 to 90
pairing.activate()
XCTAssertThrowsError(try pairing.updateExpiry(10 * .minute)) { error in

Choose a reason for hiding this comment

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

activate() makes a call to updateExpiry() internally (which sets a 30-day expiry).

Is there a reason to call activate before a throwing update? Does it make a difference for this test to invert the order?

Copy link
Contributor Author

@MaisaMilena MaisaMilena Aug 16, 2022

Choose a reason for hiding this comment

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

I was trying to check the error inside the activate() function, but if I understood it right, the error dies inside activate(). I changed the test, now checking for the expiryDate update. If an error occurs, it shouldn't be updated.

@flypaper0
Copy link
Contributor

lgtm, more tests is always better 👍
fix testcase naming pls "testUpdateExpiry_WhenValueIsGreaterThanMax_ShouldThrowInvalidUpdateExpiryValue"
Little less text and without "_"

@MaisaMilena
Copy link
Contributor Author

@flypaper0 updated! Do these new names fit better?

@sekimondre sekimondre merged commit a82c6ac into WalletConnect:develop Aug 19, 2022
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.

3 participants