Package Exports
- @chainsafe/cypress-polkadot-wallet
- @chainsafe/cypress-polkadot-wallet/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@chainsafe/cypress-polkadot-wallet) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@chainsafe/cypress-polkadot-wallet monorepo
Test your Dapp with Cypress as if you had a Polkadot wallet connected in the browser.
⚙️ 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, origin)
Initialize the Polkadot wallet. If an origin is passed there is no need to authorize the first connection for Dapps of this origin
- getAuthRequests()
Read the authentication request queue
- approveAuth(id, accountAddresses)
Authorize a specific request
- rejectAuth(id, reason)
Reject a specific authentication request
- getTxRequests()
Read the tx request queue
- approveTx(id)
Authorize a specific transaction
- rejectTx(id, reason)
Reject a specific transaction
initWallet(accounts, origin)
Initialize the Polkadot wallet. If an origin is passed there is no need to authorize the first connection for Dapps of this origin
Kind: global function
Param | Type | Description |
---|---|---|
accounts | Array.<InjectedAccount> |
Accounts to load into the wallet. |
origin | string | undefined |
Dapp name to automatically share accounts with without needing to authorize |
Example
cy.initWallet(
[{ address: '7NPoMQbiA6trJKkjB35uk96MeJD4PGWkLQLH7k7hXEkZpiba', name: 'Alice', type: 'sr25519' }],
'Multix'
)
getAuthRequests()
Read the authentication request queue
Kind: global function
Example
cy.getAuthRequests().then((authQueue) => {
cy.wrap(Object.values(authQueue).length).should('eq', 1)
})
approveAuth(id, accountAddresses)
Authorize a specific request
Kind: global function
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
Kind: global function
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 tx request queue
Kind: global function
Example
cy.getTxRequests().then((txQueue) => {
cy.wrap(Object.values(txQueue).length).should('eq', 1)
})
approveTx(id)
Authorize a specific transaction
Kind: global function
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
Kind: global function
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
- Take a look at the Example Dapp
- Take a look at the Cypress tests
📄 License
This project is licensed under the terms of the Apache-2.0.