Commit 822f9e5f authored by Moody Salem's avatar Moody Salem Committed by GitHub

Connect integration tests (#757)

* Connect a testing wallet

* Replace with a funded address

* Fix the balance checking and adding logging
parent 6781fce5
{ {
"baseUrl": "http://localhost:3000" "baseUrl": "http://localhost:3000",
"pluginsFile": false,
"fixturesFolder": false,
"supportFile": "cypress/support/index.js",
"video": false
} }
import { TEST_ADDRESS_NEVER_USE } from '../support/commands'
describe('Landing Page', () => { describe('Landing Page', () => {
beforeEach(() => cy.visit('/')) beforeEach(() => cy.visit('/'))
it('loads exchange page', () => { it('loads exchange page', () => {
cy.get('#exchangePage') cy.get('#exchangePage')
}) })
...@@ -18,4 +19,9 @@ describe('Landing Page', () => { ...@@ -18,4 +19,9 @@ describe('Landing Page', () => {
cy.get('#pool-navLink').click() cy.get('#pool-navLink').click()
cy.url().should('include', '/pool') cy.url().should('include', '/pool')
}) })
it('is connected', () => {
cy.get('#web3-status-connected').click()
cy.get('#web3-account-identifier-row').contains(TEST_ADDRESS_NEVER_USE)
})
}) })
...@@ -4,7 +4,15 @@ describe('Swap', () => { ...@@ -4,7 +4,15 @@ describe('Swap', () => {
cy.get('#swapInputField').type('0.001') cy.get('#swapInputField').type('0.001')
}) })
it('zero swap amount', () => {
cy.get('#swapInputField').type('0.0')
})
it('can enter an amount into output', () => { it('can enter an amount into output', () => {
cy.get('#swapOutputField').type('0.001') cy.get('#swapOutputField').type('0.001')
}) })
it('zero output amount', () => {
cy.get('#swapOutputField').type('0.0')
})
}) })
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.tsx can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = () => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
export const TEST_ADDRESS_NEVER_USE: string
// declare namespace Cypress {
// // eslint-disable-next-line @typescript-eslint/class-name-casing
// interface cy {
// additionalCommands(): void
// }
// }
// ***********************************************
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
import { JsonRpcProvider } from '@ethersproject/providers'
import { Wallet } from '@ethersproject/wallet'
import { _Eip1193Bridge } from '@ethersproject/experimental/lib/eip1193-bridge'
// never send real ether to this, obviously
const PRIVATE_KEY_TEST_NEVER_USE = '0xad20c82497421e9784f18460ad2fe84f73569068e98e270b3e63743268af5763'
// address of the above key
export const TEST_ADDRESS_NEVER_USE = '0x0fF2D1eFd7A57B7562b2bf27F3f37899dB27F4a5'
class CustomizedBridge extends _Eip1193Bridge {
async sendAsync(...args) {
console.debug('sendAsync called', ...args)
return this.send(...args)
}
async send(...args) {
console.debug('send called', ...args)
const isCallbackForm = typeof args[0] === 'object' && typeof args[1] === 'function'
let callback
let method
let params
if (isCallbackForm) {
callback = args[1]
method = args[0].method
params = args[0].params
} else {
method = args[0]
params = args[1]
}
if (method === 'eth_requestAccounts' || method === 'eth_accounts') {
if (isCallbackForm) {
callback({ result: [TEST_ADDRESS_NEVER_USE] })
} else {
return Promise.resolve([TEST_ADDRESS_NEVER_USE])
}
}
if (method === 'eth_chainId') {
if (isCallbackForm) {
callback(null, { result: '0x4' })
} else {
return Promise.resolve('0x4')
}
}
try {
const result = await super.send(method, params)
console.debug('result received', method, params, result)
if (isCallbackForm) {
callback(null, { result })
} else {
return result
}
} catch (error) {
if (isCallbackForm) {
callback(error, null)
} else {
throw error
}
}
}
}
// sets up the injected provider to be a mock ethereum provider with the given mnemonic/index
Cypress.Commands.overwrite('visit', (original, url, options) => {
return original(url, {
...options,
onBeforeLoad(win) {
options && options.onBeforeLoad && options.onBeforeLoad(win)
const provider = new JsonRpcProvider('https://rinkeby.infura.io/v3/b8800ce81b8c451698081d269b86692b', 4)
const signer = new Wallet(PRIVATE_KEY_TEST_NEVER_USE, provider)
const bridge = new CustomizedBridge(signer, provider)
win.ethereum = bridge
}
})
})
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
// TODO(moodysalem): commands for connecting a mock ethereum provider.
// *********************************************************** // ***********************************************************
// This example support/index.ts is processed and // This file is processed and loaded automatically before your test files.
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
// //
// You can read more here: // You can read more here:
// https://on.cypress.io/configuration // https://on.cypress.io/configuration
...@@ -15,6 +7,3 @@ ...@@ -15,6 +7,3 @@
// Import commands.ts using ES2015 syntax: // Import commands.ts using ES2015 syntax:
import './commands' import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
...@@ -325,7 +325,7 @@ export default function AccountDetails({ ...@@ -325,7 +325,7 @@ export default function AccountDetails({
</CircleWrapper> </CircleWrapper>
</div> </div>
</AccountGroupingRow> </AccountGroupingRow>
<AccountGroupingRow> <AccountGroupingRow id="web3-account-identifier-row">
{ENSName ? ( {ENSName ? (
<> <>
<AccountControl hasENS={!!ENSName} isENS={true}> <AccountControl hasENS={!!ENSName} isENS={true}>
......
...@@ -96,10 +96,22 @@ export default function Option({ ...@@ -96,10 +96,22 @@ export default function Option({
header, header,
subheader = null, subheader = null,
icon, icon,
active = false active = false,
id
}: {
link?: string | null
clickable?: boolean
size?: number | null
onClick?: null | (() => void)
color: string
header: React.ReactNode
subheader: React.ReactNode | null
icon: string
active?: boolean
id: string
}) { }) {
const content = ( const content = (
<OptionCardClickable onClick={onClick} clickable={clickable && !active} active={active}> <OptionCardClickable id={id} onClick={onClick} clickable={clickable && !active} active={active}>
<OptionCardLeft> <OptionCardLeft>
<HeaderText color={color}> <HeaderText color={color}>
{' '} {' '}
......
...@@ -126,6 +126,7 @@ export default function PendingView({ ...@@ -126,6 +126,7 @@ export default function PendingView({
} }
return ( return (
<Option <Option
id={`connect-${key}`}
key={key} key={key}
clickable={false} clickable={false}
color={option.color} color={option.color}
......
...@@ -223,6 +223,7 @@ export default function WalletModal({ ...@@ -223,6 +223,7 @@ export default function WalletModal({
onClick={() => { onClick={() => {
option.connector !== connector && !option.href && tryActivation(option.connector) option.connector !== connector && !option.href && tryActivation(option.connector)
}} }}
id={`connect-${key}`}
key={key} key={key}
active={option.connector && option.connector === connector} active={option.connector && option.connector === connector}
color={option.color} color={option.color}
...@@ -243,6 +244,7 @@ export default function WalletModal({ ...@@ -243,6 +244,7 @@ export default function WalletModal({
if (option.name === 'MetaMask') { if (option.name === 'MetaMask') {
return ( return (
<Option <Option
id={`connect-${key}`}
key={key} key={key}
color={'#E8831D'} color={'#E8831D'}
header={'Install Metamask'} header={'Install Metamask'}
...@@ -270,6 +272,7 @@ export default function WalletModal({ ...@@ -270,6 +272,7 @@ export default function WalletModal({
!isMobile && !isMobile &&
!option.mobileOnly && ( !option.mobileOnly && (
<Option <Option
id={`connect-${key}`}
onClick={() => { onClick={() => {
option.connector === connector option.connector === connector
? setWalletView(WALLET_VIEWS.ACCOUNT) ? setWalletView(WALLET_VIEWS.ACCOUNT)
......
...@@ -170,7 +170,7 @@ export default function Web3Status() { ...@@ -170,7 +170,7 @@ export default function Web3Status() {
function getWeb3Status() { function getWeb3Status() {
if (account) { if (account) {
return ( return (
<Web3StatusConnected onClick={toggleWalletModal} pending={hasPendingTransactions}> <Web3StatusConnected id="web3-status-connected" onClick={toggleWalletModal} pending={hasPendingTransactions}>
{hasPendingTransactions ? ( {hasPendingTransactions ? (
<RowBetween> <RowBetween>
<Text>{pending?.length} Pending</Text> <SpinnerWrapper src={LightCircle} alt="loader" /> <Text>{pending?.length} Pending</Text> <SpinnerWrapper src={LightCircle} alt="loader" />
...@@ -190,7 +190,7 @@ export default function Web3Status() { ...@@ -190,7 +190,7 @@ export default function Web3Status() {
) )
} else { } else {
return ( return (
<Web3StatusConnect onClick={toggleWalletModal} faded={!account}> <Web3StatusConnect id="connect-wallet" onClick={toggleWalletModal} faded={!account}>
<Text>{t('Connect to a Wallet')}</Text> <Text>{t('Connect to a Wallet')}</Text>
</Web3StatusConnect> </Web3StatusConnect>
) )
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment