-
Notifications
You must be signed in to change notification settings - Fork 180
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
[Push] Add wc_pushPropose method #872
Changes from 20 commits
c27cb3f
ad284c5
7da99cf
8dc58d5
94a5ae1
62611e1
a6f8f73
60b0c8b
cfe36b7
4d7f70e
49137f7
4081ca1
67c1cb0
15e5cee
6a42ae3
3e7aea3
d23fcfc
b0f7a4f
9e9cc13
c96ce48
cd04595
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 |
---|---|---|
|
@@ -62,7 +62,7 @@ final class PushTests: XCTestCase { | |
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix) | ||
let pushLogger = ConsoleLogger(suffix: prefix + " [Push]", loggingLevel: .debug) | ||
dappPairingClient = pairingClient | ||
dappPushClient = DappPushClientFactory.create(metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), | ||
dappPushClient = DappPushClientFactory.create(metadata: AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: []), | ||
logger: pushLogger, | ||
keyValueStorage: keyValueStorage, | ||
keychainStorage: keychain, | ||
|
@@ -91,55 +91,40 @@ final class PushTests: XCTestCase { | |
makeWalletClients() | ||
} | ||
|
||
func testRequestPush() async { | ||
let expectation = expectation(description: "expects to receive push request") | ||
|
||
let uri = try! await dappPairingClient.create() | ||
try! await walletPairingClient.pair(uri: uri) | ||
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic) | ||
|
||
walletPushClient.requestPublisher.sink { (_, _, _) in | ||
expectation.fulfill() | ||
} | ||
.store(in: &publishers) | ||
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
} | ||
|
||
func testWalletApprovesPushRequest() async { | ||
let expectation = expectation(description: "expects dapp to receive successful response") | ||
func testPushPropose() async { | ||
let expectation = expectation(description: "expects dapp to receive error response") | ||
|
||
let uri = try! await dappPairingClient.create() | ||
try! await walletPairingClient.pair(uri: uri) | ||
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic) | ||
try! await dappPushClient.propose(account: Account.stub(), topic: uri.topic) | ||
|
||
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in | ||
Task(priority: .high) { try! await walletPushClient.approve(id: id, onSign: sign) } | ||
}.store(in: &publishers) | ||
|
||
dappPushClient.responsePublisher.sink { (_, result) in | ||
dappPushClient.proposalResponsePublisher.sink { (result) in | ||
guard case .success = result else { | ||
XCTFail() | ||
return | ||
} | ||
expectation.fulfill() | ||
}.store(in: &publishers) | ||
|
||
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
|
||
} | ||
|
||
func testWalletRejectsPushRequest() async { | ||
func testWalletRejectsPushPropose() async { | ||
let expectation = expectation(description: "expects dapp to receive error response") | ||
|
||
let uri = try! await dappPairingClient.create() | ||
try! await walletPairingClient.pair(uri: uri) | ||
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic) | ||
try! await dappPushClient.propose(account: Account.stub(), topic: uri.topic) | ||
|
||
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in | ||
|
||
Task(priority: .high) { try! await walletPushClient.reject(id: id) } | ||
}.store(in: &publishers) | ||
|
||
dappPushClient.responsePublisher.sink { (_, result) in | ||
dappPushClient.proposalResponsePublisher.sink { (result) in | ||
guard case .failure = result else { | ||
XCTFail() | ||
return | ||
|
@@ -150,108 +135,48 @@ final class PushTests: XCTestCase { | |
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
} | ||
|
||
func testDappSendsPushMessage() async { | ||
let expectation = expectation(description: "expects wallet to receive push message") | ||
let pushMessage = PushMessage.stub() | ||
var pushSubscription: PushSubscription! | ||
let uri = try! await dappPairingClient.create() | ||
try! await walletPairingClient.pair(uri: uri) | ||
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic) | ||
|
||
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in | ||
Task(priority: .high) { try! await walletPushClient.approve(id: id, onSign: sign) } | ||
}.store(in: &publishers) | ||
|
||
dappPushClient.responsePublisher.sink { [unowned self] (_, result) in | ||
guard case .success(let result) = result else { | ||
XCTFail() | ||
return | ||
} | ||
pushSubscription = result.pushSubscription | ||
Task(priority: .userInitiated) { try! await dappPushClient.notify(topic: result.pushSubscription.topic, message: pushMessage) } | ||
}.store(in: &publishers) | ||
|
||
walletPushClient.pushMessagePublisher.sink { [unowned self] receivedPushMessageRecord in | ||
let messageHistory = walletPushClient.getMessageHistory(topic: pushSubscription.topic) | ||
XCTAssertEqual(pushMessage, receivedPushMessageRecord.message) | ||
XCTAssertTrue(messageHistory.contains(receivedPushMessageRecord)) | ||
expectation.fulfill() | ||
}.store(in: &publishers) | ||
|
||
|
||
func testWalletCreatesSubscription() async { | ||
let expectation = expectation(description: "expects to create push subscription") | ||
let metadata = AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: []) | ||
try! await walletPushClient.subscribe(metadata: metadata, account: Account.stub(), onSign: sign) | ||
walletPushClient.subscriptionsPublisher | ||
.first() | ||
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. why 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. because after calling deleteSubscription, subscriptionsPublisher will publish again with an empty array |
||
.sink { [unowned self] subscriptions in | ||
XCTAssertNotNil(subscriptions.first) | ||
Task { try! await walletPushClient.deleteSubscription(topic: subscriptions.first!.topic) } | ||
expectation.fulfill() | ||
}.store(in: &publishers) | ||
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
|
||
} | ||
|
||
func testWalletDeletePushSubscription() async { | ||
let expectation = expectation(description: "expects to delete push subscription") | ||
let uri = try! await dappPairingClient.create() | ||
try! await walletPairingClient.pair(uri: uri) | ||
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic) | ||
var subscriptionTopic: String! | ||
|
||
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in | ||
Task(priority: .high) { try! await walletPushClient.approve(id: id, onSign: sign) } | ||
}.store(in: &publishers) | ||
|
||
dappPushClient.responsePublisher.sink { [unowned self] (_, result) in | ||
guard case .success(let result) = result else { | ||
XCTFail() | ||
return | ||
} | ||
subscriptionTopic = result.pushSubscription.topic | ||
Task(priority: .userInitiated) { try! await walletPushClient.deleteSubscription(topic: result.pushSubscription.topic)} | ||
}.store(in: &publishers) | ||
|
||
dappPushClient.deleteSubscriptionPublisher.sink { topic in | ||
XCTAssertEqual(subscriptionTopic, topic) | ||
expectation.fulfill() | ||
}.store(in: &publishers) | ||
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
} | ||
|
||
func testDappDeletePushSubscription() async { | ||
func testDeletePushSubscription() async { | ||
let expectation = expectation(description: "expects to delete push subscription") | ||
let uri = try! await dappPairingClient.create() | ||
try! await walletPairingClient.pair(uri: uri) | ||
try! await dappPushClient.request(account: Account.stub(), topic: uri.topic) | ||
try! await dappPushClient.propose(account: Account.stub(), topic: uri.topic) | ||
var subscriptionTopic: String! | ||
|
||
walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in | ||
Task(priority: .high) { try! await walletPushClient.approve(id: id, onSign: sign) } | ||
}.store(in: &publishers) | ||
|
||
dappPushClient.responsePublisher.sink { [unowned self] (_, result) in | ||
guard case .success(let result) = result else { | ||
dappPushClient.proposalResponsePublisher.sink { [unowned self] (result) in | ||
guard case .success(let pushSubscription) = result else { | ||
XCTFail() | ||
return | ||
} | ||
subscriptionTopic = result.pushSubscription.topic | ||
Task(priority: .userInitiated) { try! await dappPushClient.delete(topic: result.pushSubscription.topic)} | ||
subscriptionTopic = pushSubscription.topic | ||
Task(priority: .userInitiated) { try! await walletPushClient.deleteSubscription(topic: pushSubscription.topic)} | ||
}.store(in: &publishers) | ||
|
||
walletPushClient.deleteSubscriptionPublisher.sink { topic in | ||
dappPushClient.deleteSubscriptionPublisher.sink { topic in | ||
XCTAssertEqual(subscriptionTopic, topic) | ||
expectation.fulfill() | ||
}.store(in: &publishers) | ||
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
} | ||
|
||
// Push Subscribe | ||
func testWalletCreatesSubscription() async { | ||
let expectation = expectation(description: "expects to create push subscription") | ||
let metadata = AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: []) | ||
try! await walletPushClient.subscribe(metadata: metadata, account: Account.stub(), onSign: sign) | ||
walletPushClient.subscriptionsPublisher | ||
.first() | ||
.sink { [unowned self] subscriptions in | ||
XCTAssertNotNil(subscriptions.first) | ||
Task { try! await walletPushClient.deleteSubscription(topic: subscriptions.first!.topic) } | ||
expectation.fulfill() | ||
}.store(in: &publishers) | ||
wait(for: [expectation], timeout: InputConfig.defaultTimeout) | ||
} | ||
|
||
func testWalletCreatesAndUpdatesSubscription() async { | ||
let expectation = expectation(description: "expects to create and update push subscription") | ||
let metadata = AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: []) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ final class MainRouter { | |
} | ||
|
||
func present(pushRequest: PushRequest) { | ||
PushRequestModule.create(app: app, pushRequest: pushRequest) | ||
.presentFullScreen(from: viewController, transparentBackground: true) | ||
// PushRequestModule.create(app: app, pushRequest: pushRequest) | ||
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. method unused now? 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 just want to showcase w3i capabilities and limitations for dogfooding. This presents a native screen. |
||
// .presentFullScreen(from: viewController, transparentBackground: true) | ||
} | ||
|
||
init(app: Application) { | ||
|
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.
push request step removed from protocol right?
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.
exactly, the method is deprecated