Skip to content

ChainSafe/cypress-polkadot-wallet

Repository files navigation

@chainsafe/cypress-polkadot-wallet monorepo

This is the monorepo for @chainsafe/cypress-polkadot-wallet Cypress plugin. It includes the sources, and some examples.

⚙️ Install

  • npm:
npm install @chainsafe/cypress-polkadot-wallet
  • yarn:
yarn add @chainsafe/cypress-polkadot-wallet
  • pnpm:
pnpm add @chainsafe/cypress-polkadot-wallet

Then import the plugin into your cypress/support/e2e.js file:

import '@chainsafe/cypress-polkadot-wallet'
// or
require('@chainsafe/cypress-polkadot-wallet')

🧪 Usage

You can now easily use the following commands:

Functions

initWallet(accounts, authorizedDappName, walletName)

Initialize the Polkadot wallet. If an authorizedDappName is passed there is no need to authorize the first connection for Dapps using this name.

getAuthRequests()

Read the authentication request queue

approveAuth(id, accountAddresses)

Approve a specific authentication request for the Dapp to get access the wallet accounts

rejectAuth(id, reason)

Reject a specific authentication request. The Dapp will receive 0 connected wallet as a result.

getTxRequests()

Read the wallet transaction request queue

approveTx(id)

Approve a specific transaction

rejectTx(id, reason)

Reject a specific transaction

initWallet(accounts, authorizedDappName, walletName)

Initialize the Polkadot wallet. If an authorizedDappName is passed there is no need to authorize the first connection for Dapps using this name.

Param Type Description
accounts Array.<InjectedAccount> Accounts to load into the wallet.
authorizedDappName string | undefined Dapp name to automatically share accounts with, without needing to authorize
walletName string | undefined Sets the name of the injected wallet (default 'polkadot-js')

Example

cy.initWallet(
  [{ address: '7NPoMQbiA6trJKkjB35uk96MeJD4PGWkLQLH7k7hXEkZpiba', name: 'Alice', type: 'sr25519' }],
  'My-Dapp',
  'My-wallet-extension'
)

getAuthRequests()

Read the authentication request queue

Example

cy.getAuthRequests().then((authQueue) => {
  cy.wrap(Object.values(authQueue).length).should('eq', 1)
})

approveAuth(id, accountAddresses)

Approve a specific authentication request for the Dapp to get access the wallet accounts

Param Type Description
id number the id of the request to authorize. This id is part of the getAuthRequests object response.
accountAddresses Array.<string> the account addresses to share with the applications. These addresses must be part of the ones shared in the initWallet

Example

cy.approveAuth(1694443839903, ['7NPoMQbiA6trJKkjB35uk96MeJD4PGWkLQLH7k7hXEkZpiba'])

rejectAuth(id, reason)

Reject a specific authentication request. The Dapp will receive 0 connected wallet as a result

Param Type Description
id number the id of the request to reject. This id is part of the getAuthRequests object response
reason reason the reason for the rejection

Example

cy.rejectAuth(1694443839903, 'Cancelled')

getTxRequests()

Read the wallet transaction request queue

Example

cy.getTxRequests().then((txQueue) => {
  cy.wrap(Object.values(txQueue).length).should('eq', 1)
})

approveTx(id)

Approve a specific transaction

Param Type Description
id number the id of the request to approve. This id is part of the getTxRequests object response

Example

cy.approveTx(1694443839903)

rejectTx(id, reason)

Reject a specific transaction

Param Type Description
id number the id of the tx request to reject. This id is part of the getTxRequests object response.
reason reason the reason for the rejection

Example

cy.rejectTx(1694443839903, 'Cancelled')

📐 Example

We have a very simple Dapp example, and a set of Cypress tests using @chainsafe/cypress-polkadot-wallet

📄 License

This project is licensed under the terms of the Apache-2.0.