Skip to content

Commit

Permalink
Merge branch 'main' into tbaut-arrow-squid
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Oct 17, 2023
2 parents 5e0e96a + 2db0e8a commit e3b0972
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
24 changes: 23 additions & 1 deletion packages/ui/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { AuthRequests, Extension, TxRequests } from './Extension'
import { MultisigInfo, rejectCurrentMultisigTxs } from '../utils/rejectCurrentMultisigTxs'
import { InjectedAccountWitMnemonic } from '../fixtures/injectedAccounts'
import { injectedAccounts, InjectedAccountWitMnemonic } from '../fixtures/injectedAccounts'
import { topMenuItems } from './page-objects/topMenuItems'
import 'cypress-wait-until'

// ***********************************************
Expand Down Expand Up @@ -43,6 +44,7 @@ import 'cypress-wait-until'
// }

const extension = new Extension()
const Account1 = Object.values(injectedAccounts)[0].address

Cypress.Commands.add('initExtension', (accounts: InjectedAccountWitMnemonic[]) => {
cy.log('Initializing extension')
Expand All @@ -59,6 +61,20 @@ Cypress.Commands.add('getAuthRequests', () => {
return cy.wrap(extension.getAuthRequests())
})

Cypress.Commands.add('connectAccounts', (accountAddresses = [Account1] as string[]) => {
cy.getAuthRequests().then((authRequests) => {
const requests = Object.values(authRequests)
// we should have 1 connection request to the extension
cy.wrap(requests.length).should('eq', 1)
// this request should be from the application Multix
cy.wrap(requests[0].origin).should('eq', 'Multix')
// let's allow Accounts to connect
cy.enableAuth(requests[0].id, accountAddresses)
// the ui should then move on to connecting to the rpcs
topMenuItems.multiproxySelector().should('be.visible')
})
})

Cypress.Commands.add('enableAuth', (id: number, accountAddresses: string[]) => {
return extension.enableAuth(id, accountAddresses)
})
Expand Down Expand Up @@ -97,6 +113,12 @@ declare global {
*/
getAuthRequests: () => Chainable<AuthRequests>

/**
* Connect an accounts to the dApp
* @param accountAddresses
*/
connectAccounts: (accountAddresses?: string[]) => void

/**
* Authorize a specific request
* @param {number} id - the id of the request to authorize. This id is part of the getAuthRequests object response.
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/cypress/support/page-objects/newMultisigPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const newMultisigPage = {
addressSelector: () => cy.get('[data-cy="input-account-address"]')
}
2 changes: 1 addition & 1 deletion packages/ui/cypress/support/page-objects/topMenuItems.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const topMenuItems = {
homeButton: () => cy.get('[data-cy=button-navigate-home]'),
newMultisigButton: () => cy.get('[data-cy=button-new-multisig]'),
newMultisigButton: () => cy.get('[data-cy=button-navigate-new-multisig]'),
settingsButton: () => cy.get('[data-cy=button-navigate-settings]'),
overviewButton: () => cy.get('[data-cy=button-navigate-overview]'),
aboutButton: () => cy.get('[data-cy=button-navigate-about]'),
Expand Down
34 changes: 21 additions & 13 deletions packages/ui/cypress/tests/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { landingPageUrl } from '../fixtures/landingData'
import { landingPage } from '../support/page-objects/landingPage'
import { topMenuItems } from '../support/page-objects/topMenuItems'
import { clickOnConnect } from '../utils/clickOnConnect'
import { newMultisigPage } from '../support/page-objects/newMultisigPage'
import { accountDisplay } from '../support/page-objects/components/accountDisplay'

describe('Connect Account', () => {
beforeEach(() => {
Expand All @@ -21,22 +23,28 @@ describe('Connect Account', () => {
// let's allow it for Alice
cy.rejectAuth(requests[0].id, 'Cancelled')
// the ui should then move on to connecting to the rpcs
landingPage.noAccountFoundError().should('be.visible')
landingPage
.noAccountFoundError()
.should(
'contain.text',
'No account found. Please connect at least one in a wallet extension.'
)
})
})

it('Connects with Alice', () => {
const AliceAddress = Object.values(injectedAccounts)[0].address
cy.getAuthRequests().then((authRequests) => {
const requests = Object.values(authRequests)
// we should have 1 connection request to the extension
cy.wrap(requests.length).should('eq', 1)
// this request should be from the application Multix
cy.wrap(requests[0].origin).should('eq', 'Multix')
// let's allow it for Alice
cy.enableAuth(requests[0].id, [AliceAddress])
// the ui should then move on to connecting to the rpcs
topMenuItems.multiproxySelector().should('be.visible')
it('Connect Accounts', () => {
const { address: address1 } = Object.values(injectedAccounts)[0]
const { address: address2 } = Object.values(injectedAccounts)[1]

cy.connectAccounts([address1, address2])

topMenuItems.newMultisigButton().click()
// Click on the account address selector to show the list of accounts
newMultisigPage.addressSelector().click()

accountDisplay.nameLabel().each((el, index) => {
const expectedName = Object.values(injectedAccounts)[index].name
cy.wrap(el).should('have.text', expectedName)
})
})
})
12 changes: 1 addition & 11 deletions packages/ui/cypress/tests/transactions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ describe('Perform transactions', () => {
cy.visit(landingPageUrl)
cy.initExtension(injectedAccounts)
clickOnConnect()
cy.getAuthRequests().then((authRequests) => {
const requests = Object.values(authRequests)
// we should have 1 connection request to the extension
cy.wrap(requests.length).should('eq', 1)
// this request should be from the application Multix
cy.wrap(requests[0].origin).should('eq', 'Multix')
// let's allow it for Alice
cy.enableAuth(requests[0].id, [AliceAddress])
// the ui should then move on to connecting to the rpcs
topMenuItems.multiproxySelector().should('be.visible')
})
cy.connectAccounts([AliceAddress])
})

it('Abort a tx with Alice', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/cypress/tests/watched-accounts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Watched Accounts', () => {
settingsPage.accountContainer().should('have.length', 0)
})

it('can see error when attemping to add same address more than once', () => {
it('can see error when attempting to add same address more than once', () => {
// add an account first
cy.visit(settingsPageWatchAccountUrl)
addWatchAccount(addresses.Alice, 'Alice')
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/CallInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const handleBalanceDisplay = ({

const getTypeName = (index: number, name: string, api: ApiPromise) => {
const [pallet, method] = name.split('.')
const metaArgs = !!pallet && !!method && api.tx[pallet][method].meta.args
const metaArgs = !!pallet && !!method && api.tx[pallet][method]?.meta?.args

return (
(!!metaArgs && metaArgs[index] && (metaArgs[index].toHuman().typeName as string)) || undefined
Expand All @@ -125,7 +125,7 @@ const createUlTree = ({ name, args, decimals, unit, api, typeName }: CreateTreeP
}

if (_typeName === 'RuntimeCall') {
return handleCallDisplay({ call: value, decimals, unit, api, key: `${key}` })
return handleCallDisplay({ call: value, decimals, unit, api, key: `${key}-call` })
}

// generically show nice value for Balance type
Expand Down

0 comments on commit e3b0972

Please sign in to comment.