Skip to content

Instantly share code, notes, and snippets.

@maxhoheiser
Created March 30, 2022 09:36
Show Gist options
  • Save maxhoheiser/1141ccc4297059a142974fc0401523ac to your computer and use it in GitHub Desktop.
Save maxhoheiser/1141ccc4297059a142974fc0401523ac to your computer and use it in GitHub Desktop.
Custom cypress login command
const publicKeys = {
// admin
[1]: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
// user
[2]: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
[3]: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
};
Cypress.Commands.add(
"switchToAccount",
/**
* @param {1|2|3} accountNumber
*/
(accountNumber) => {
const publicKey = publicKeys[accountNumber];
cy.getMetamaskWalletAddress().then((address) => {
if (address !== publicKey) {
cy.switchMetamaskAccount(accountNumber).should("be.true");
cy.confirmMetamaskSignatureRequest().should("be.true");
cy.getMetamaskWalletAddress().should("eq", publicKey);
}
});
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment