-
Notifications
You must be signed in to change notification settings - Fork 191
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import XCTest | ||
import WalletConnectPairing | ||
@testable import WalletConnectPairing | ||
@testable import WalletConnectSign | ||
|
||
final class WCPairingTests: XCTestCase { | ||
|
@@ -35,18 +35,61 @@ final class WCPairingTests: XCTestCase { | |
XCTAssertEqual(pairing.expiryDate, inactiveExpiry) | ||
} | ||
|
||
func testUpdateExpiry() { | ||
func testUpdateExpiryForTopic() { | ||
var pairing = WCPairing(topic: "") | ||
let activeExpiry = referenceDate.advanced(by: WCPairing.timeToLiveActive) | ||
try? pairing.updateExpiry() | ||
XCTAssertEqual(pairing.expiryDate, activeExpiry) | ||
} | ||
|
||
func testUpdateExpiryForUri() { | ||
var pairing = WCPairing(uri: WalletConnectURI.stub()) | ||
let activeExpiry = referenceDate.advanced(by: WCPairing.timeToLiveActive) | ||
try? pairing.updateExpiry() | ||
XCTAssertEqual(pairing.expiryDate, activeExpiry) | ||
} | ||
|
||
func testActivate() { | ||
func testActivateTopic() { | ||
var pairing = WCPairing(topic: "") | ||
let activeExpiry = referenceDate.advanced(by: WCPairing.timeToLiveActive) | ||
XCTAssertFalse(pairing.active) | ||
pairing.activate() | ||
XCTAssertTrue(pairing.active) | ||
XCTAssertEqual(pairing.expiryDate, activeExpiry) | ||
} | ||
|
||
func testActivateURI() { | ||
var pairing = WCPairing(uri: WalletConnectURI.stub()) | ||
let activeExpiry = referenceDate.advanced(by: WCPairing.timeToLiveActive) | ||
XCTAssertFalse(pairing.active) | ||
pairing.activate() | ||
XCTAssertTrue(pairing.active) | ||
XCTAssertEqual(pairing.expiryDate, activeExpiry) | ||
} | ||
|
||
func testUpdateExpiry_WhenValueIsGreaterThanMax_ShouldThrowInvalidUpdateExpiryValue() { | ||
var pairing = WCPairing(topic: "", relay: .stub(), peerMetadata: .stub(), expiryDate: referenceDate) | ||
XCTAssertThrowsError(try pairing.updateExpiry(40 * .day)) { error in | ||
XCTAssertEqual(error as! WCPairing.Errors, WCPairing.Errors.invalidUpdateExpiryValue) | ||
} | ||
} | ||
|
||
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 | ||
XCTAssertEqual(error as! WCPairing.Errors, WCPairing.Errors.invalidUpdateExpiryValue) | ||
} | ||
} | ||
|
||
func testActivate_WhenUpdateExpiryFails_ShouldActivateAndThrowError() { | ||
let expiryDate = referenceDate.advanced(by: 10 * .minute) | ||
var pairing = WCPairing(topic: "", relay: .stub(), peerMetadata: .stub(), expiryDate: expiryDate) | ||
XCTAssertFalse(pairing.active) | ||
pairing.activate() | ||
XCTAssertThrowsError(try pairing.updateExpiry(10 * .minute)) { error in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a reason to call activate before a throwing update? Does it make a difference for this test to invert the order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to check the error inside the |
||
XCTAssertEqual(error as! WCPairing.Errors, WCPairing.Errors.invalidUpdateExpiryValue) | ||
} | ||
XCTAssertTrue(pairing.active) | ||
} | ||
} |
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 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).
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.
ops! 😅