This is the monorepo for @chainsafe/cypress-polkadot-wallet
Cypress plugin. It includes the sources, and some examples.
- 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')
If you're using papi, make sure to set up a dappName
when calling connectInjectedExtension
(version 1.6.0
or above is required for that to work). This will guarantee higher compatibility with this plugin.
You can now easily use the following commands:
- 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
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'
)
Read the authentication request queue
Example
cy.getAuthRequests().then((authQueue) => {
cy.wrap(Object.values(authQueue).length).should('eq', 1)
})
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'])
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')
Read the wallet transaction request queue
Example
cy.getTxRequests().then((txQueue) => {
cy.wrap(Object.values(txQueue).length).should('eq', 1)
})
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)
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')
We have a very simple Dapp example, and a set of Cypress tests using @chainsafe/cypress-polkadot-wallet
- Take a look at the Example Dapp
- Take a look at the Cypress tests for:
This project is licensed under the terms of the Apache-2.0.