-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathswapMod.test.ts
More file actions
106 lines (95 loc) · 4.1 KB
/
swapMod.test.ts
File metadata and controls
106 lines (95 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { SMALL_TIMEOUT } from '../config'
import { TEST_ADDRESS_NEVER_USE } from '../support/ethereum'
import { mockNativeBalanceHttp } from '../support/mocks/mockRpcCall'
const COW = '0x0625aFB445C3B6B7B929342a04A22599fd5dBB59'
const ETH = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
describe('Swap (mod)', () => {
it('starts with empty token selected', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
cy.get('#input-currency-input .token-amount-input').should('not.have.value')
cy.get('#input-currency-input .token-symbol-container').should('contain.text', 'Select a token')
cy.get('#output-currency-input .token-amount-input').should('not.have.value')
cy.get('#output-currency-input .token-symbol-container').should('contain.text', 'Select a token')
})
it('can enter an amount into input', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
cy.get('#input-currency-input .token-amount-input').should('have.value', '1')
cy.get('#input-currency-input .token-amount-input')
.type('{selectAll}{del}')
.type('0.001')
.should('have.value', '0.001')
})
it('zero swap amount', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
// Wait for the default sell amount to be auto-filled before clearing
cy.get('#input-currency-input .token-amount-input').should('have.value', '1')
cy.get('#input-currency-input .token-amount-input').type('{selectAll}{del}').type('0.0').should('have.value', '0.0')
})
it('invalid swap amount', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
// Wait for the default sell amount to be auto-filled before clearing
cy.get('#input-currency-input .token-amount-input').should('have.value', '1')
cy.get('#input-currency-input .token-amount-input').type('{selectAll}{del}').type('\@\@').should('have.value', '')
})
it('can enter an amount into output', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
// first clear/reset the INPUT currency input field
// as it is auto prefilled with "1"
cy.get('#input-currency-input .token-amount-input')
.clear()
// then we select and clear the OUTPUT field
.get('#output-currency-input .token-amount-input')
.clear()
// and type in an amount
.type('0.001', { delay: 400, force: true })
.should('have.value', '0.001')
})
it('zero output amount', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
// first clear/reset the INPUT currency input field
// as it is auto prefilled with "1"
cy.get('#input-currency-input .token-amount-input')
.clear()
// then we select and clear the OUTPUT field
.get('#output-currency-input .token-amount-input')
.clear()
// and type in an amount
.type('0.0')
.should('have.value', '0.0')
})
it('can find COW and swap Native for COW', () => {
// Mock ETH balance at the HTTP transport level. wagmi/viem reads balances via
// Multicall3.aggregate3 over HTTP (not window.ethereum), so we intercept the
// RPC response and patch the getEthBalance result for our test address.
mockNativeBalanceHttp(TEST_ADDRESS_NEVER_USE, 50n * 10n ** 18n)
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
cy.swapEnterInputAmount(ETH, '0.5', true)
cy.swapSelectOutput(COW)
cy.get('#output-currency-input .token-amount-input').should('not.equal', '')
cy.get('#do-trade-button').should('contain.text', 'Swap').click({ timeout: SMALL_TIMEOUT })
cy.get('#trade-confirmation > button').should('contain', 'Confirm Swap')
})
it('add a recipient does not exist unless in expert mode', () => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
cy.get('#add-recipient-button').should('not.exist')
})
describe('recipient', () => {
beforeEach(() => {
cy.visit('/#/11155111/swap')
cy.unlockCrossChainSwap()
cy.get('#open-settings-dialog-button').click()
cy.get('#toggle-recipient-mode-button').click()
})
it('Recipient is visible', () => {
cy.get('#recipient').should('exist')
})
})
})