2022-07-18 17:12:28 +02:00
const { strict : assert } = require ( 'assert' ) ;
2023-05-05 15:56:08 +02:00
const { convertToHexValue , withFixtures , openDapp } = require ( '../helpers' ) ;
2022-10-28 10:42:12 +02:00
const FixtureBuilder = require ( '../fixture-builder' ) ;
2023-01-23 17:19:55 +01:00
const { SMART _CONTRACTS } = require ( '../seeder/smart-contracts' ) ;
describe ( 'Create token, approve token and approve token without gas' , function ( ) {
const smartContract = SMART _CONTRACTS . HST ;
const ganacheOptions = {
accounts : [
{
secretKey :
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC' ,
balance : convertToHexValue ( 25000000000000000000 ) ,
} ,
] ,
} ;
it ( 'imports and renders the balance for the new token' , async function ( ) {
await withFixtures (
{
dapp : true ,
fixtures : new FixtureBuilder ( )
. withPermissionControllerConnectedToTestDapp ( )
. build ( ) ,
ganacheOptions ,
smartContract ,
title : this . test . title ,
} ,
async ( { driver , contractRegistry } ) => {
const contractAddress = await contractRegistry . getContractAddress (
smartContract ,
) ;
await driver . navigate ( ) ;
await driver . fill ( '#password' , 'correct horse battery staple' ) ;
await driver . press ( '#password' , driver . Key . ENTER ) ;
// create token
2023-05-05 15:56:08 +02:00
await openDapp ( driver , contractAddress ) ;
2023-01-23 17:19:55 +01:00
const windowHandles = await driver . getAllWindowHandles ( ) ;
const extension = windowHandles [ 0 ] ;
// imports custom token from extension
await driver . switchToWindow ( extension ) ;
await driver . clickElement ( ` [data-testid="home__asset-tab"] ` ) ;
2023-05-17 05:00:47 +02:00
await driver . clickElement ( { tag : 'button' , text : 'Tokens' } ) ;
2023-01-23 17:19:55 +01:00
2023-06-01 23:14:38 +02:00
await driver . clickElement ( { text : 'Import tokens' , tag : 'button' } ) ;
2023-01-23 17:19:55 +01:00
await driver . clickElement ( {
text : 'Custom token' ,
tag : 'button' ,
} ) ;
2023-08-14 18:08:59 +02:00
await driver . fill (
'[data-testid="import-tokens-modal-custom-address"]' ,
contractAddress ,
) ;
await driver . waitForSelector (
'[data-testid="import-tokens-modal-custom-decimals"]' ,
) ;
2023-01-23 17:19:55 +01:00
await driver . delay ( 2000 ) ;
await driver . clickElement ( {
2023-08-14 18:08:59 +02:00
text : 'Next' ,
2023-01-23 17:19:55 +01:00
tag : 'button' ,
} ) ;
await driver . delay ( 2000 ) ;
2023-08-14 18:08:59 +02:00
await driver . clickElement (
'[data-testid="import-tokens-modal-import-button"]' ,
) ;
2023-01-23 17:19:55 +01:00
// renders balance for newly created token
await driver . clickElement ( '.app-header__logo-container' ) ;
2023-05-17 05:00:47 +02:00
await driver . clickElement ( { tag : 'button' , text : 'Tokens' } ) ;
2023-06-01 23:14:38 +02:00
await driver . waitForSelector ( {
css : '[data-testid="multichain-token-list-item-value"]' ,
text : '10 TST' ,
2023-01-23 17:19:55 +01:00
} ) ;
} ,
) ;
2022-07-18 17:12:28 +02:00
} ) ;
2023-01-23 17:19:55 +01:00
it ( 'approves an already created token and displays the token approval data' , async function ( ) {
await withFixtures (
{
dapp : true ,
fixtures : new FixtureBuilder ( )
. withPermissionControllerConnectedToTestDapp ( )
. build ( ) ,
ganacheOptions ,
smartContract ,
title : this . test . title ,
} ,
async ( { driver , contractRegistry } ) => {
const contractAddress = await contractRegistry . getContractAddress (
smartContract ,
) ;
await driver . navigate ( ) ;
await driver . fill ( '#password' , 'correct horse battery staple' ) ;
await driver . press ( '#password' , driver . Key . ENTER ) ;
// create token
2023-05-05 15:56:08 +02:00
await openDapp ( driver , contractAddress ) ;
2023-01-23 17:19:55 +01:00
let windowHandles = await driver . getAllWindowHandles ( ) ;
const extension = windowHandles [ 0 ] ;
await driver . findClickableElement ( '#deployButton' ) ;
// approve token from dapp
await driver . clickElement ( { text : 'Approve Tokens' , tag : 'button' } ) ;
await driver . waitUntilXWindowHandles ( 3 ) ;
windowHandles = await driver . getAllWindowHandles ( ) ;
await driver . switchToWindowWithTitle (
'MetaMask Notification' ,
windowHandles ,
) ;
await driver . clickElement ( {
2023-04-11 05:19:42 +02:00
text : 'Verify third-party details' ,
2023-01-23 17:19:55 +01:00
css : '.token-allowance-container__verify-link' ,
} ) ;
const modalTitle = await driver . waitForSelector ( {
2023-04-11 05:19:42 +02:00
text : 'Third-party details' ,
2023-01-23 17:19:55 +01:00
tag : 'h5' ,
} ) ;
2023-04-11 05:19:42 +02:00
assert . equal ( await modalTitle . getText ( ) , 'Third-party details' ) ;
2023-01-23 17:19:55 +01:00
await driver . clickElement ( {
text : 'Got it' ,
tag : 'button' ,
} ) ;
await driver . clickElement ( {
text : 'View details' ,
css : '.token-allowance-container__view-details' ,
} ) ;
// checks elements on approve token popup
const functionType = await driver . findElement ( {
text : 'Function: Approve' ,
tag : 'h6' ,
} ) ;
assert . equal ( await functionType . getText ( ) , 'Function: Approve' ) ;
const confirmDataDiv = await driver . findElement (
'.approve-content-card-container__data__data-block' ,
) ;
const confirmDataText = await confirmDataDiv . getText ( ) ;
assert (
confirmDataText . match (
/0x095ea7b30000000000000000000000009bc5baf874d2da8d216ae9f137804184ee5afef4/u ,
) ,
) ;
await driver . clickElement ( { text : 'Next' , tag : 'button' } ) ;
await driver . findElement ( {
2023-07-11 16:57:59 +02:00
text : 'Spending cap request for your ' ,
css : '.box--flex-direction-row' ,
2023-01-23 17:19:55 +01:00
} ) ;
2023-07-11 16:57:59 +02:00
const defaultSpendingCap = await driver . findElement ( {
2023-01-23 17:19:55 +01:00
text : '7 TST' ,
2023-07-19 19:55:38 +02:00
css : '.mm-box > h6' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
2023-07-11 16:57:59 +02:00
await defaultSpendingCap . getText ( ) ,
2023-01-23 17:19:55 +01:00
'7 TST' ,
'Default value is not correctly set' ,
) ;
await driver . clickElement ( {
text : 'Approve' ,
tag : 'button' ,
} ) ;
await driver . switchToWindow ( extension ) ;
await driver . clickElement ( { tag : 'button' , text : 'Activity' } ) ;
// check list of pending transactions in extension
await driver . wait ( async ( ) => {
2023-07-17 19:48:15 +02:00
const pendingTxes = await driver . findElements ( '.activity-list-item' ) ;
2023-01-23 17:19:55 +01:00
return pendingTxes . length === 1 ;
} , 10000 ) ;
const approveTokenTask = await driver . waitForSelector ( {
// Selects only the very first transaction list item immediately following the 'Pending' header
2023-07-17 19:48:15 +02:00
css : '.transaction-list__completed-transactions .activity-list-item [data-testid="activity-list-item-action"]' ,
2023-02-24 20:21:55 +01:00
text : 'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
await approveTokenTask . getText ( ) ,
2023-02-24 20:21:55 +01:00
'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
) ;
} ,
) ;
} ) ;
2022-07-18 17:12:28 +02:00
2023-01-23 17:19:55 +01:00
it ( 'set custom spending cap, customizes gas, edit spending cap and checks transaction in transaction list' , async function ( ) {
await withFixtures (
{
dapp : true ,
fixtures : new FixtureBuilder ( )
. withPermissionControllerConnectedToTestDapp ( )
. build ( ) ,
ganacheOptions ,
smartContract ,
title : this . test . title ,
} ,
async ( { driver , contractRegistry } ) => {
const contractAddress = await contractRegistry . getContractAddress (
smartContract ,
) ;
await driver . navigate ( ) ;
await driver . fill ( '#password' , 'correct horse battery staple' ) ;
await driver . press ( '#password' , driver . Key . ENTER ) ;
// create token
2023-05-05 15:56:08 +02:00
await openDapp ( driver , contractAddress ) ;
2023-01-23 17:19:55 +01:00
let windowHandles = await driver . getAllWindowHandles ( ) ;
const extension = windowHandles [ 0 ] ;
await driver . findClickableElement ( '#deployButton' ) ;
// approve token from dapp
await driver . clickElement ( { text : 'Approve Tokens' , tag : 'button' } ) ;
await driver . waitUntilXWindowHandles ( 3 ) ;
windowHandles = await driver . getAllWindowHandles ( ) ;
await driver . switchToWindowWithTitle (
'MetaMask Notification' ,
windowHandles ,
) ;
// set custom spending cap
let setSpendingCap = await driver . findElement (
'[data-testid="custom-spending-cap-input"]' ,
) ;
await setSpendingCap . fill ( '5' ) ;
await driver . clickElement ( {
text : 'View details' ,
css : '.token-allowance-container__view-details' ,
} ) ;
await driver . clickElement ( {
text : 'Next' ,
tag : 'button' ,
} ) ;
2023-07-11 16:57:59 +02:00
let spendingCap = await driver . findElement ( {
2023-01-23 17:19:55 +01:00
text : '5 TST' ,
2023-07-19 19:55:38 +02:00
css : '.mm-box > h6' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
2023-07-11 16:57:59 +02:00
await spendingCap . getText ( ) ,
2023-01-23 17:19:55 +01:00
'5 TST' ,
'Default value is not correctly set' ,
) ;
// editing gas fee
const editBtn = await driver . findElements ( {
text : 'Edit' ,
class : 'btn-link > h6' ,
} ) ;
editBtn [ 1 ] . click ( ) ;
await driver . clickElement ( {
text : 'Edit suggested gas fee' ,
tag : 'button' ,
} ) ;
const [ gasLimitInput , gasPriceInput ] = await driver . findElements (
'input[type="number"]' ,
) ;
await gasPriceInput . clear ( ) ;
await gasPriceInput . fill ( '10' ) ;
await gasLimitInput . clear ( ) ;
await gasLimitInput . fill ( '60001' ) ;
await driver . clickElement ( { text : 'Save' , tag : 'button' } ) ;
2023-04-14 09:59:51 +02:00
await driver . waitForSelector (
{
css : '.box--flex-direction-row > h6' ,
text : '0.0006 ETH' ,
} ,
{ timeout : 15000 } ,
) ;
2023-01-23 17:19:55 +01:00
// editing spending cap
await driver . clickElement ( {
class : '.review-spending-cap__heading-detail__button' ,
text : 'Edit' ,
} ) ;
setSpendingCap = await driver . findElement (
'[data-testid="custom-spending-cap-input"]' ,
) ;
await setSpendingCap . fill ( '9' ) ;
await driver . clickElement ( {
text : 'Next' ,
tag : 'button' ,
} ) ;
2023-07-11 16:57:59 +02:00
spendingCap = await driver . findElement ( {
2023-01-23 17:19:55 +01:00
text : '9 TST' ,
2023-07-19 19:55:38 +02:00
css : '.mm-box > h6' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
2023-07-11 16:57:59 +02:00
await spendingCap . getText ( ) ,
2023-01-23 17:19:55 +01:00
'9 TST' ,
'Default value is not correctly set' ,
) ;
// submits the transaction
await driver . clickElement ( { text : 'Approve' , tag : 'button' } ) ;
// finds the transaction in transaction list
await driver . switchToWindow ( extension ) ;
await driver . clickElement ( { tag : 'button' , text : 'Activity' } ) ;
await driver . wait ( async ( ) => {
2023-07-17 19:48:15 +02:00
const pendingTxes = await driver . findElements ( '.activity-list-item' ) ;
2023-01-23 17:19:55 +01:00
return pendingTxes . length === 1 ;
} , 10000 ) ;
const approveTokenTask = await driver . waitForSelector ( {
// Select only the heading of the first entry in the transaction list.
2023-07-17 19:48:15 +02:00
css : '.transaction-list__completed-transactions .activity-list-item [data-testid="activity-list-item-action"]' ,
2023-02-24 20:21:55 +01:00
text : 'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
await approveTokenTask . getText ( ) ,
2023-02-24 20:21:55 +01:00
'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
) ;
} ,
) ;
} ) ;
2022-07-18 17:12:28 +02:00
2023-01-23 17:19:55 +01:00
it ( 'set maximum spending cap, submits the transaction and finds the transaction in the transactions list' , async function ( ) {
await withFixtures (
{
dapp : true ,
fixtures : new FixtureBuilder ( )
. withPermissionControllerConnectedToTestDapp ( )
. build ( ) ,
ganacheOptions ,
smartContract ,
title : this . test . title ,
} ,
async ( { driver , contractRegistry } ) => {
const contractAddress = await contractRegistry . getContractAddress (
smartContract ,
) ;
await driver . navigate ( ) ;
await driver . fill ( '#password' , 'correct horse battery staple' ) ;
await driver . press ( '#password' , driver . Key . ENTER ) ;
// create token
2023-05-05 15:56:08 +02:00
await openDapp ( driver , contractAddress ) ;
2023-01-23 17:19:55 +01:00
const windowHandles = await driver . getAllWindowHandles ( ) ;
const extension = windowHandles [ 0 ] ;
await driver . findClickableElement ( '#deployButton' ) ;
// approve token from dapp
await driver . clickElement ( { text : 'Approve Tokens' , tag : 'button' } ) ;
await driver . switchToWindow ( extension ) ;
await driver . clickElement ( { tag : 'button' , text : 'Activity' } ) ;
const pendingTxes = await driver . findElements (
2023-07-17 19:48:15 +02:00
'.transaction-list__pending-transactions .activity-list-item' ,
2023-01-23 17:19:55 +01:00
) ;
pendingTxes [ 0 ] . click ( ) ;
// set max spending cap
await driver . clickElement ( {
2023-08-04 00:30:41 +02:00
css : '[data-testid="custom-spending-cap-max-button"]' ,
2023-01-23 17:19:55 +01:00
text : 'Max' ,
} ) ;
await driver . clickElement ( {
tag : 'button' ,
text : 'Next' ,
} ) ;
// checks the balance
const balance = await driver . findElement ( {
css : '.box--display-flex > h6' ,
text : '10 TST' ,
} ) ;
const maxSpendingCap = await driver . findElement ( {
text : '10 TST' ,
2023-07-19 19:55:38 +02:00
css : '.mm-box > h6' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
await maxSpendingCap . getText ( ) ,
await balance . getText ( ) ,
'Max spending cap is not set corectly' ,
) ;
await driver . delay ( 500 ) ;
await driver . clickElement ( {
tag : 'button' ,
text : 'Approve' ,
} ) ;
const approveTokenTask = await driver . waitForSelector ( {
// Select only the heading of the first entry in the transaction list.
2023-07-17 19:48:15 +02:00
css : '.transaction-list__completed-transactions .activity-list-item [data-testid="activity-list-item-action"]' ,
2023-02-24 20:21:55 +01:00
text : 'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
await approveTokenTask . getText ( ) ,
2023-02-24 20:21:55 +01:00
'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
) ;
} ,
) ;
2022-07-18 17:12:28 +02:00
} ) ;
2023-07-11 16:57:59 +02:00
it ( 'approves token without gas, set site suggested spending cap, submits the transaction and finds the transaction in the transactions list' , async function ( ) {
2023-01-23 17:19:55 +01:00
await withFixtures (
{
dapp : true ,
fixtures : new FixtureBuilder ( )
. withPermissionControllerConnectedToTestDapp ( )
. build ( ) ,
ganacheOptions ,
smartContract ,
title : this . test . title ,
} ,
async ( { driver , contractRegistry } ) => {
const contractAddress = await contractRegistry . getContractAddress (
smartContract ,
) ;
await driver . navigate ( ) ;
await driver . fill ( '#password' , 'correct horse battery staple' ) ;
await driver . press ( '#password' , driver . Key . ENTER ) ;
2023-05-05 15:56:08 +02:00
await openDapp ( driver , contractAddress ) ;
2023-01-23 17:19:55 +01:00
const windowHandles = await driver . getAllWindowHandles ( ) ;
const extension = windowHandles [ 0 ] ;
await driver . findClickableElement ( '#deployButton' ) ;
// approve token without gas from dapp
await driver . clickElement ( {
text : 'Approve Tokens Without Gas' ,
tag : 'button' ,
} ) ;
// switch to extension
await driver . switchToWindow ( extension ) ;
await driver . clickElement ( { tag : 'button' , text : 'Activity' } ) ;
2023-07-17 19:48:15 +02:00
const pendingTxes = await driver . findElements ( '.activity-list-item' ) ;
2023-01-23 17:19:55 +01:00
pendingTxes [ 0 ] . click ( ) ;
2023-07-11 16:57:59 +02:00
// set custom spending cap
const spendingCap = await driver . findElement (
'[data-testid="custom-spending-cap-input"]' ,
) ;
await spendingCap . fill ( '5' ) ;
// set site suggested spending cap
2023-01-23 17:19:55 +01:00
await driver . clickElement ( {
2023-07-11 16:57:59 +02:00
text : 'Use site suggestion' ,
2023-01-23 17:19:55 +01:00
css : '.mm-button-link' ,
} ) ;
await driver . clickElement ( {
text : 'Next' ,
tag : 'button' ,
} ) ;
await driver . delay ( 500 ) ;
await driver . clickElement ( { text : 'Approve' , tag : 'button' } ) ;
// check transaction in Activity tab
const approveTokenTask = await driver . waitForSelector ( {
2023-07-17 19:48:15 +02:00
css : '.transaction-list__completed-transactions .activity-list-item [data-testid="activity-list-item-action"]' ,
2023-02-24 20:21:55 +01:00
text : 'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
} ) ;
assert . equal (
await approveTokenTask . getText ( ) ,
2023-02-24 20:21:55 +01:00
'Approve TST spending cap' ,
2023-01-23 17:19:55 +01:00
) ;
} ,
) ;
2022-07-18 17:12:28 +02:00
} ) ;
} ) ;