Skip to content

Commit

Permalink
Merge branch 'new-dawn' into feat/import-wallet-using-cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler authored Sep 17, 2024
2 parents b8e992d + 675f983 commit 4917134
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 27 deletions.
5 changes: 4 additions & 1 deletion wallets/metamask/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ export default defineConfig({
async setupNodeEvents(on, config) {
return configureSynpress(on, config)
}
}
},

defaultCommandTimeout: 12_000,
taskTimeout: 15_000
})
23 changes: 23 additions & 0 deletions wallets/metamask/src/cypress/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ export default class MetaMask {
}

async confirmTransactionAndWaitForMining() {
await waitFor(
() =>
this.metamaskExtensionPage.locator(TransactionPage.nftApproveAllConfirmationPopup.approveButton).isVisible(),
5_000,
false
)

return this.metamaskPlaywright
.confirmTransactionAndWaitForMining()
.then(() => {
Expand Down Expand Up @@ -336,6 +343,22 @@ export default class MetaMask {
await this.metamaskPlaywright.goBackToHomePage()

await expect(this.metamaskExtensionPage.locator(HomePageSelectors.copyAccountAddressButton)).toBeVisible()
}

// Lock/Unlock

async lock() {
await this.metamaskPlaywright.lock()
await expect(
this.metamaskExtensionPage.locator(this.metamaskPlaywright.lockPage.selectors.submitButton)
).toBeVisible()

return true
}

async unlock() {
await this.metamaskPlaywright.unlock()
await expect(this.metamaskExtensionPage.locator(this.metamaskPlaywright.homePage.selectors.logo)).toBeVisible()

return true
}
Expand Down
4 changes: 4 additions & 0 deletions wallets/metamask/src/cypress/configureSynpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export default function configureSynpress(
openTransactionDetails: (txIndex: number) => metamask?.openTransactionDetails(txIndex),
closeTransactionDetails: () => metamask?.closeTransactionDetails(),

// Lock/Unlock
lock: () => metamask?.lock(),
unlock: () => metamask?.unlock()

// Others

goBackToHomePage: () => metamask?.goBackToHomePage()

Check notice

Code scanning / CodeQL

Syntax error Note

Error: ',' expected.
Expand Down
12 changes: 12 additions & 0 deletions wallets/metamask/src/cypress/support/synpressCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ declare global {
openTransactionDetails(txIndex: number): Chainable<void>
closeTransactionDetails(): Chainable<void>

lock(): Chainable<void>
unlock(): Chainable<void>

goBackToHomePage(): Chainable<void>
}
}
Expand Down Expand Up @@ -168,6 +171,15 @@ export default function synpressCommands() {
Cypress.Commands.add('rejectTokenPermission', () => {
return cy.task('rejectTokenPermission')
})

// Lock/Unlock

Cypress.Commands.add('lock', () => {
return cy.task('lock')
})
Cypress.Commands.add('unlock', () => {
return cy.task('unlock')
})

// Others

Expand Down
2 changes: 2 additions & 0 deletions wallets/metamask/test/cypress/batchTransfer.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
before(() => {
cy.switchNetwork('Anvil')

cy.get('#deployERC1155Button').click()

cy.confirmTransaction().then(() => {
Expand Down
4 changes: 0 additions & 4 deletions wallets/metamask/test/cypress/confirmSignature.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
before(() => {
cy.switchNetwork('Anvil')
})

it('should confirm `personal_sign`', () => {
cy.get('#personalSign').click()

Expand Down
8 changes: 0 additions & 8 deletions wallets/metamask/test/cypress/confirmTransaction.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ const connectDeployAndMintNft = () => {
})
}

before(() => {
cy.connectToAnvil().then(() => {
cy.get('#connectButton').click()

cy.connectToDapp()
})
})

describe('with default gas setting', () => {
it('should confirm contract deployment', () => {
cy.get('#tokenAddresses').should('be.empty')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
it('should confirm contract deployment and wait for mining', () => {
cy.get('#tokenAddresses').should('be.empty')
cy.get('#createToken').click()

cy.confirmTransactionAndWaitForMining().then(() => {
cy.get('#tokenAddresses').should('include', /^0x/)
})
})

it('should confirm legacy transaction and wait for mining', () => {
cy.get('#sendButton').click()

cy.confirmTransactionAndWaitForMining()
})

it('should confirm EIP-1559 transaction and wait for mining', () => {
cy.get('#sendEIP1559Button').click()

cy.confirmTransactionAndWaitForMining().then(() => {
cy.get('#tokenAddresses').should('include', /^0x/)
})
})

it('should work correctly when calling sequentially', () => {
cy.get('#sendEIP1559Button').click()
cy.confirmTransactionAndWaitForMining().then(() => {
cy.get('#sendEIP1559Button').click()
cy.confirmTransactionAndWaitForMining().then(() => {
cy.get('#tokenAddresses').should('include', /^0x/)
})
})
})
2 changes: 1 addition & 1 deletion wallets/metamask/test/cypress/connectToDapp.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ it('should connect account to the app', () => {
cy.get('#connectButton').click()
cy.connectToDapp()

cy.get('#accounts').should('contain', '0x')
cy.get('#accounts').should('include', /^0x/)
})
5 changes: 5 additions & 0 deletions wallets/metamask/test/cypress/lock.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it('should lock & unlock the wallet without any error', () => {
cy.lock().then(() => {
cy.unlock()
})
})
17 changes: 4 additions & 13 deletions wallets/metamask/test/cypress/rejectAddNetwork.cy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
it('should reject new network request', () => {
cy.createAnvilNode({
chainId: 1338,
port: 8546
}).then(() => {
cy.get('#addEthereumChain').click()
cy.get('#addEthereumChain').click()

cy.rejectNewNetwork().then(() => {
cy.get('#chainId').should('have.text', '0x1')
cy.rejectNewNetwork().then(() => {
cy.get('#chainId').should('have.text', '0x7a69')

cy.emptyAnvilNode()
})
cy.emptyAnvilNode()
})
})

after(() => {
cy.switchNetwork('Ethereum Mainnet')
})

0 comments on commit 4917134

Please sign in to comment.