mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-09 13:56:10 +00:00
106988d534
This PR is refactoring the dapps service to avoid code duplication between SDKs and also to avoid overlapping requests/responses. It brings Browser Connect inline with Wallet Connect in terms of session management and sign transactions. New architecture: WalletConnectService becomes DAppsService. Its responsibility is to provide dapp access to the app. This is the component currently used by the UI What does it do: 1. Provide dapp APIs line connect, disconnect, session requests etc 2. Spawn app notifications on dapp events 3. Timeout requests if the dapp does not respons DAppsRequestHandler becomes DAppsModule. This component is consumed by the DAppService. Its responsibility is to aggregate all the building blocks for the dapps, but does not control any of the dapp features or consume the SDKs requests. What does it do: 1. Aggregate all the building blocks for dapps (currently known as plugins) DAppConnectionsPlugin - This component provides the session management features line connect, disconnect and provide a model with the connected dapps. SignRequestPlugin - This component provides the sign request management. It receives the sign request from the dapp, translates it to what Status understands and manages the lifecycle of the request.
150 lines
6.0 KiB
QML
150 lines
6.0 KiB
QML
import QtQuick 2.15
|
|
|
|
import QtTest 1.15
|
|
|
|
import AppLayouts.Wallet.services.dapps.types 1.0
|
|
|
|
import shared.stores 1.0
|
|
|
|
Item {
|
|
id: root
|
|
|
|
width: 600
|
|
height: 400
|
|
|
|
Component {
|
|
id: sessionRequestComponent
|
|
|
|
SessionRequestWithAuth {
|
|
id: sessionRequest
|
|
readonly property SignalSpy executeSpy: SignalSpy { target: sessionRequest; signalName: "execute" }
|
|
readonly property SignalSpy rejectedSpy: SignalSpy { target: sessionRequest; signalName: "rejected" }
|
|
readonly property SignalSpy authFailedSpy: SignalSpy { target: sessionRequest; signalName: "authFailed" }
|
|
|
|
// SessionRequestResolved required properties
|
|
// Not of interest for this test
|
|
event: "event"
|
|
topic: "topic"
|
|
requestId: "id"
|
|
method: "method"
|
|
accountAddress: "address"
|
|
chainId: "chainID"
|
|
sourceId: 0
|
|
data: "data"
|
|
preparedData: "preparedData"
|
|
dappUrl: "dappUrl"
|
|
dappIcon: "dappIcon"
|
|
dappName: "dappName"
|
|
store: DAppsStore {
|
|
signal userAuthenticated(string topic, string id, string password, string pin)
|
|
signal userAuthenticationFailed(string topic, string id)
|
|
|
|
property var authenticateUserCalls: []
|
|
function authenticateUser(topic, id, address) {
|
|
authenticateUserCalls.push({topic, id, address})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TestCase {
|
|
id: sessionRequestTest
|
|
name: "SessionRequestWithAuth"
|
|
// Ensure mocked GroupedAccountsAssetsModel is properly initialized
|
|
when: windowShown
|
|
|
|
property SessionRequestWithAuth componentUnderTest: null
|
|
|
|
function init() {
|
|
componentUnderTest = createTemporaryObject(sessionRequestComponent, root)
|
|
}
|
|
|
|
function test_acceptAndAuthenticated() {
|
|
componentUnderTest.accept()
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 0)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
|
|
componentUnderTest.store.userAuthenticated("topic", "id", "password", "pin")
|
|
|
|
compare(componentUnderTest.executeSpy.count, 1)
|
|
compare(componentUnderTest.rejectedSpy.count, 0)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
}
|
|
|
|
function test_AcceptAndAuthFails() {
|
|
componentUnderTest.accept()
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 0)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
|
|
componentUnderTest.store.userAuthenticationFailed("topic", "id")
|
|
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.authFailedSpy.count, 1)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
}
|
|
|
|
function test_AcceptRequestExpired() {
|
|
ignoreWarning("Error: request expired")
|
|
componentUnderTest.expirationTimestamp = Date.now() / 1000 - 1
|
|
componentUnderTest.accept()
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 1)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 0)
|
|
}
|
|
|
|
function test_AcceptAndReject() {
|
|
componentUnderTest.accept()
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 0)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
|
|
componentUnderTest.reject(false)
|
|
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 1)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
}
|
|
|
|
function test_AcceptAndExpiresAfterAuth() {
|
|
ignoreWarning("Error: request expired")
|
|
componentUnderTest.accept()
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 0)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
|
|
componentUnderTest.expirationTimestamp = Date.now() / 1000 - 1
|
|
componentUnderTest.store.userAuthenticated("topic", "id", "password", "pin")
|
|
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 1)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 1)
|
|
}
|
|
|
|
function test_Reject() {
|
|
componentUnderTest.reject(false)
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 1)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 0)
|
|
}
|
|
|
|
function test_RejectExpiredRequest() {
|
|
componentUnderTest.expirationTimestamp = Date.now() / 1000 - 1
|
|
componentUnderTest.reject(false)
|
|
compare(componentUnderTest.executeSpy.count, 0)
|
|
compare(componentUnderTest.rejectedSpy.count, 1)
|
|
compare(componentUnderTest.authFailedSpy.count, 0)
|
|
compare(componentUnderTest.store.authenticateUserCalls.length, 0)
|
|
}
|
|
}
|
|
} |