mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-01 17:27:53 +00:00
b6bc5d1e29
closes #16912 Sending the dapps events to mixpanel | Event Name | Properties | Possible Values | Notes | | --- | --- | --- | --- | | dapps-health | state | - wc_available - wc_unavailable - chains_down - network_down - pair_error - connection_error - sign_error | | | | error | | string description | | dapps-navigation | flow | - dapps_list_opened - connect_initiated - disconnect_initiated - pair_initiated | | | | connector | - wallet_connect - browser_connect | | | dapps-connection | flow | - proposal_received - proposal_accepted - proposal_rejected - connected - disconnected | | | | networks | networks[string] - array of networks | Array of proposed or connected networks | | | methods | methods[string] - array of methods | Array of proposed methods | | | dapp | dapp uri | | | | connector | - wallet_connect - browser_connect | | | | isSiwe | boolean | | | dapps-sign | flow | - sign_received - sign_accepted - sign_rejected | | | | connector | - wallet_connect - browser_connect | | | | method | - personal_sign - eth_sign - eth_signTypedData_v4 - eth_signTypedData - eth_signTransaction - eth_sendTransaction | | | | dapp | string - dapp uri | | | | chainId | int - chain id | |
254 lines
12 KiB
QML
254 lines
12 KiB
QML
import QtQuick 2.15
|
|
|
|
import QtTest 1.15
|
|
|
|
import AppLayouts.Wallet.services.dapps 1.0
|
|
import AppLayouts.Wallet.services.dapps.plugins 1.0
|
|
|
|
Item {
|
|
id: root
|
|
|
|
width: 600
|
|
height: 400
|
|
|
|
Component {
|
|
id: chainsSupervisorPluginComponent
|
|
ChainsSupervisorPlugin {
|
|
id: chainsSupervisorPlugin
|
|
networksModel: ListModel {
|
|
ListElement {
|
|
chainId: 1
|
|
isOnline: true
|
|
}
|
|
ListElement {
|
|
chainId: 2
|
|
isOnline: true
|
|
}
|
|
}
|
|
sdk: WalletConnectSDKBase {
|
|
property bool sdkReady: true
|
|
projectId: "projectId"
|
|
|
|
property var getActiveSessionsCallbacks: []
|
|
getActiveSessions: function(callback) {
|
|
getActiveSessionsCallbacks.push({callback})
|
|
}
|
|
|
|
property var emitSessionEventCalls: []
|
|
emitSessionEvent: function(topic, event, chainId) {
|
|
emitSessionEventCalls.push({topic, event, chainId})
|
|
}
|
|
|
|
pair: function() {
|
|
verify(false, "pair should not be called")
|
|
}
|
|
|
|
buildApprovedNamespaces: function(id, params, supportedNamespaces) {
|
|
verify(false, "buildApprovedNamespaces should not be called")
|
|
}
|
|
|
|
approveSession: function(sessionProposalJson, approvedNamespaces) {
|
|
verif(false, "approveSession should not be called")
|
|
}
|
|
|
|
acceptSessionRequest: function(topic, id, signature) {
|
|
verify(false, "acceptSessionRequest should not be called")
|
|
}
|
|
|
|
rejectSessionRequest: function(topic, id, error) {
|
|
verify(false, "rejectSessionRequest should not be called")
|
|
}
|
|
|
|
populateAuthPayload: function(id, authPayload, chains, methods) {
|
|
verify(false, "populateAuthPayload should not be called")
|
|
}
|
|
|
|
formatAuthMessage: function(id, request, iss) {
|
|
verify(false, "formatAuthMessage should not be called")
|
|
}
|
|
|
|
buildAuthObject: function(id, authPayload, signature, iss) {
|
|
verify(false, "buildAuthObject should not be called")
|
|
}
|
|
|
|
acceptSessionAuthenticate: function(id, auths) {
|
|
verify(false, "acceptSessionAuthenticate should not be called")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function getConfiguredSession(requiredEvents, requiredChains, requiredAccounts) {
|
|
return {
|
|
topic: "topic",
|
|
namespaces: {
|
|
eip155: {
|
|
events: requiredEvents,
|
|
chains: requiredChains,
|
|
accounts: requiredAccounts
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TestCase {
|
|
id: chainsSupervisorPluginTest
|
|
name: "ChainsSupervisorPlugin"
|
|
|
|
property ChainsSupervisorPlugin componentUnderTest: null
|
|
|
|
function init() {
|
|
componentUnderTest = chainsSupervisorPluginComponent.createObject(root)
|
|
tryVerify(() => componentUnderTest.isOnline)
|
|
tryVerify(() => !componentUnderTest.allChainsOffline)
|
|
tryVerify(() => !componentUnderTest.networkOffline)
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks = []
|
|
componentUnderTest.sdk.emitSessionEventCalls = []
|
|
}
|
|
|
|
function test_allChainsDisabled() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
tryVerify(() => componentUnderTest.allChainsOffline)
|
|
}
|
|
|
|
function test_disconnectEventAllValid() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// 2 chains negociated. 2 accounts
|
|
// Expected two disconnect events
|
|
const validSession = getConfiguredSession(["disconnect"], ["eip155:1", "eip155:2"], ["eip155:1:0x1234", "eip155:2:0x1234"])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 2)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].topic, validSession.topic)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].event.name, "disconnect")
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].chainId, "eip155:1")
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[1].topic, validSession.topic)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[1].event.name, "disconnect")
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[1].chainId, "eip155:2")
|
|
}
|
|
|
|
function test_disconnectEventSingleChainAccount() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// 2 chains negociated. Account on a single chain
|
|
// Expected a single disconnect event
|
|
const validSession = getConfiguredSession(["disconnect"], ["eip155:1", "eip155:2"], ["eip155:1:0x1234"])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 1)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].topic, validSession.topic)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].event.name, "disconnect")
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].chainId, "eip155:1")
|
|
}
|
|
|
|
function test_disconnectEventNoAccount() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// 2 chains negociated. No account
|
|
// Expected no disconnect event
|
|
const validSession = getConfiguredSession(["disconnect"], ["eip155:1", "eip155:2"], [])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 0)
|
|
}
|
|
|
|
function test_disconnectEventOneChainTwoAccounts() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// 1 chain negociated. 2 accounts on a single chain
|
|
// Expected a single disconnect event
|
|
const validSession = getConfiguredSession(["disconnect"], ["eip155:1"], ["eip155:1:0x1234", "eip155:1:0x5678"])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 1)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].topic, validSession.topic)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].event.name, "disconnect")
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].chainId, "eip155:1")
|
|
}
|
|
|
|
function test_disconnectEventNoChains() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// No chain negociated. 2 accounts
|
|
// Expected no disconnect event
|
|
const validSession = getConfiguredSession(["disconnect"], [], ["eip155:1:0x1234", "eip155:2:0x1234"])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 0)
|
|
}
|
|
|
|
function test_disconnectEventNoChainNoAccount() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// No chain negociated. No account
|
|
// Expected no disconnect event
|
|
const validSession = getConfiguredSession(["disconnect"], [], [])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 0)
|
|
}
|
|
|
|
function test_disconnectEventNoEventNegociated() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
// 2 chains negociated. 2 accounts
|
|
// Missing `disconnect` - Expected no disconnect event
|
|
const validSession = getConfiguredSession([], ["eip155:1", "eip155:2"], ["eip155:1:0x1234", "eip155:2:0x1234"])
|
|
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 0)
|
|
}
|
|
|
|
function test_chainBackOnline() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks = []
|
|
|
|
const validSession = getConfiguredSession(["connect"], ["eip155:1"], ["eip155:1:0x1234"])
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", true)
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls.length, 1)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].topic, validSession.topic)
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].event.name, "connect")
|
|
compare(componentUnderTest.sdk.emitSessionEventCalls[0].chainId, "eip155:1")
|
|
}
|
|
|
|
function test_spammingOnlineState() {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", false)
|
|
const validSession = getConfiguredSession(["connect"], ["eip155:1", "eip155:2"], ["eip155:1:0x1234", "eip155:2:0x1234"])
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks[0].callback([validSession])
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks = []
|
|
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", false)
|
|
componentUnderTest.networksModel.setProperty(1, "isOnline", true)
|
|
componentUnderTest.sdk.getActiveSessionsCallbacks = []
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
componentUnderTest.networksModel.setProperty(0, "isOnline", i % 2 === 0)
|
|
}
|
|
|
|
compare(componentUnderTest.sdk.getActiveSessionsCallbacks.length, 1)
|
|
}
|
|
}
|
|
} |