-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> This PR reintroduces the happy path send flow tests for BTC ## **Related issues** Fixes: MetaMask/accounts-planning#668 ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
- Loading branch information
1 parent
8368b89
commit caf6b24
Showing
4 changed files
with
347 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { strict as assert } from 'assert'; | ||
import { Suite } from 'mocha'; | ||
import { Driver } from '../../webdriver/driver'; | ||
import { DEFAULT_BTC_ACCOUNT, DEFAULT_BTC_BALANCE } from '../../constants'; | ||
import { | ||
getTransactionRequest, | ||
SendFlowPlaceHolders, | ||
withBtcAccountSnap, | ||
} from './common-btc'; | ||
|
||
export async function startSendFlow(driver: Driver, recipient?: string) { | ||
// Wait a bit so the MultichainRatesController is able to fetch BTC -> USD rates. | ||
await driver.delay(1000); | ||
|
||
// Start the send flow. | ||
const sendButton = await driver.waitForSelector({ | ||
text: 'Send', | ||
tag: 'button', | ||
css: '[data-testid="coin-overview-send"]', | ||
}); | ||
// FIXME: Firefox test is flaky without this delay. The send flow doesn't start properly. | ||
if (driver.browser === 'firefox') { | ||
await driver.delay(1000); | ||
} | ||
await sendButton.click(); | ||
|
||
// See the review button is disabled by default. | ||
await driver.waitForSelector({ | ||
text: 'Review', | ||
tag: 'button', | ||
css: '[disabled]', | ||
}); | ||
|
||
if (recipient) { | ||
// Set the recipient address (if any). | ||
await driver.pasteIntoField( | ||
`input[placeholder="${SendFlowPlaceHolders.RECIPIENT}"]`, | ||
recipient, | ||
); | ||
} | ||
} | ||
|
||
describe('BTC Account - Send', function (this: Suite) { | ||
it('can send complete the send flow', async function () { | ||
await withBtcAccountSnap( | ||
{ title: this.test?.fullTitle() }, | ||
async (driver, mockServer) => { | ||
await startSendFlow(driver, DEFAULT_BTC_ACCOUNT); | ||
|
||
// TODO: Remove delay here. There is a race condition if the amount and address are set too fast. | ||
await driver.delay(1000); | ||
|
||
// Set the amount to send. | ||
const mockAmountToSend = '0.5'; | ||
await driver.pasteIntoField( | ||
`input[placeholder="${SendFlowPlaceHolders.AMOUNT}"]`, | ||
mockAmountToSend, | ||
); | ||
|
||
// From here, the "summary panel" should have some information about the fees and total. | ||
await driver.waitForSelector({ | ||
text: 'Total', | ||
tag: 'p', | ||
}); | ||
|
||
// The review button will become available. | ||
const snapReviewButton = await driver.findClickableElement({ | ||
text: 'Review', | ||
tag: 'button', | ||
css: '.snap-ui-renderer__footer-button', | ||
}); | ||
assert.equal(await snapReviewButton.isEnabled(), true); | ||
await snapReviewButton.click(); | ||
|
||
// TODO: There isn't any check for the fees and total amount. This requires calculating the vbytes used in a transaction dynamically. | ||
// We already have unit tests for these calculations on the Snap. | ||
|
||
// ------------------------------------------------------------------------------ | ||
// From here, we have moved to the confirmation screen (second part of the flow). | ||
|
||
// We should be able to send the transaction right away. | ||
const snapSendButton = await driver.waitForSelector({ | ||
text: 'Send', | ||
tag: 'button', | ||
css: '.snap-ui-renderer__footer-button', | ||
}); | ||
assert.equal(await snapSendButton.isEnabled(), true); | ||
await snapSendButton.click(); | ||
|
||
// Check that we are selecting the "Activity tab" right after the send. | ||
await driver.waitForSelector({ | ||
tag: 'div', | ||
text: 'Bitcoin activity is not supported', | ||
}); | ||
|
||
const transaction = await getTransactionRequest(mockServer); | ||
assert(transaction !== undefined); | ||
}, | ||
); | ||
}); | ||
|
||
it('can send the max amount', async function () { | ||
await withBtcAccountSnap( | ||
{ title: this.test?.fullTitle() }, | ||
async (driver, mockServer) => { | ||
await startSendFlow(driver, DEFAULT_BTC_ACCOUNT); | ||
|
||
// TODO: Remove delay here. There is a race condition if the amount and address are set too fast. | ||
await driver.delay(1000); | ||
|
||
// Use the max spendable amount of that account. | ||
await driver.clickElement({ | ||
text: 'Max', | ||
tag: 'button', | ||
}); | ||
|
||
// From here, the "summary panel" should have some information about the fees and total. | ||
await driver.waitForSelector({ | ||
text: 'Total', | ||
tag: 'p', | ||
}); | ||
|
||
await driver.waitForSelector({ | ||
text: `${DEFAULT_BTC_BALANCE} BTC`, | ||
tag: 'p', | ||
}); | ||
|
||
// The review button will become available. | ||
const snapReviewButton = await driver.findClickableElement({ | ||
text: 'Review', | ||
tag: 'button', | ||
css: '.snap-ui-renderer__footer-button', | ||
}); | ||
assert.equal(await snapReviewButton.isEnabled(), true); | ||
await snapReviewButton.click(); | ||
|
||
// TODO: There isn't any check for the fees and total amount. This requires calculating the vbytes used in a transaction dynamically. | ||
// We already have unit tests for these calculations on the snap. | ||
|
||
// ------------------------------------------------------------------------------ | ||
// From here, we have moved to the confirmation screen (second part of the flow). | ||
|
||
// We should be able to send the transaction right away. | ||
const snapSendButton = await driver.waitForSelector({ | ||
text: 'Send', | ||
tag: 'button', | ||
css: '.snap-ui-renderer__footer-button', | ||
}); | ||
assert.equal(await snapSendButton.isEnabled(), true); | ||
await snapSendButton.click(); | ||
|
||
// Check that we are selecting the "Activity tab" right after the send. | ||
await driver.waitForSelector({ | ||
tag: 'div', | ||
text: 'Bitcoin activity is not supported', | ||
}); | ||
|
||
const transaction = await getTransactionRequest(mockServer); | ||
assert(transaction !== undefined); | ||
}, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.