Skip to content

Commit

Permalink
Merge pull request #3048 from Emurgo/yushi/fix-e2e-fiat
Browse files Browse the repository at this point in the history
fix e2e test
  • Loading branch information
Nebyt authored Nov 3, 2022
2 parents effea36 + a209522 commit e12aaba
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/yoroi-extension/app/api/ada/lib/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CONFIG: ConfigType = {
addressRequestSize: 50,
txsBodiesRequestSize: 150,
coinPriceRefreshInterval: 60000,
coinPriceFreshnessThreshold: 120000,
coinPriceFreshnessThreshold: 900000,
pubKeyData: '',
pubKeyMaster: '',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { observer } from 'mobx-react';
import { BigNumber } from 'bignumber.js';
import { Component } from 'react';
import { getTokenName } from '../../stores/stateless/tokenHelpers';
Expand All @@ -20,6 +21,8 @@ type Props = {|
+unitOfAccountSetting: UnitOfAccountSettingType,
+getCurrentPrice: (from: string, to: string) => ?string,
|}

@observer
export default class AmountDisplay extends Component<Props> {
static defaultProps: {| showAmount: boolean, showFiat: boolean |} = {
showAmount: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/yoroi-extension/config/shelley-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"addressRequestSize": 50,
"txsBodiesRequestSize": 150,
"coinPriceRefreshInterval": 60000,
"coinPriceFreshnessThreshold": 120000,
"coinPriceFreshnessThreshold": 900000,
"pubKeyData": "0e011fe7149bff8e3802168261aec6da54febee37da6a41d6179fa545868421e",
"pubKeyMaster": "ab9e4f1c4d996a0e9cdda8546bf5ee1dd8397fd7ab287c331ff171c7e4e0e9e2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yoroi-extension/config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"addressRequestSize": 50,
"txsBodiesRequestSize": 150,
"coinPriceRefreshInterval": 60000,
"coinPriceFreshnessThreshold": 120000,
"coinPriceFreshnessThreshold": 900000,
"pubKeyData": "0e011fe7149bff8e3802168261aec6da54febee37da6a41d6179fa545868421e",
"pubKeyMaster": "ab9e4f1c4d996a0e9cdda8546bf5ee1dd8397fd7ab287c331ff171c7e4e0e9e2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
secondThemeSelected,
} from '../pages/settingsPage';
import type { LocatorObject } from '../support/webdriver';
import { adaToFiatPrices } from '../support/helpers/common-constants';
import { adaToFiatPricesMainUrl, oneSecond } from '../support/helpers/common-constants';
import { loadingSpinnerWindow } from '../pages/commonComponentsPage';

const axios = require('axios');
Expand Down Expand Up @@ -97,6 +97,8 @@ When(
await this.scrollIntoView(currencySelector);
await this.click(currencySelector);
await this.waitForElementNotPresent(loadingSpinnerWindow);

await this.driver.sleep(oneSecond);
}
);

Expand All @@ -105,15 +107,18 @@ Then(
async function (currency) {
const amountDisplayFiatValue = await this.getText(amountDisplayFiat);

const response = await axios(adaToFiatPrices);
const response = await axios(`${adaToFiatPricesMainUrl}ADA/current`);
const value = await response.data.ticker.prices[currency];

const adaAmount = await this.getText(amountDisplayADA);
const adaValue = parseFloat(
parseFloat(adaAmount.replace('\n', '').replace(' ADA', '')).toFixed(2)
);

const expectedValue = adaValue * value;
const expectedValueNotFixed = adaValue * value;
const expectedValue = expectedValueNotFixed < 1
? expectedValueNotFixed.toFixed(6)
: expectedValueNotFixed.toFixed(2);
expect(amountDisplayFiatValue).to.equal(`${expectedValue} ${currency}`);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {
transactionIdText,
} from '../pages/walletTransactionsHistoryPage';
import { summaryTab } from '../pages/walletPage';
import { displayInfo , txSuccessfulStatuses, adaToFiatPrices } from '../support/helpers/common-constants';
import {
displayInfo,
txSuccessfulStatuses,
adaToFiatPricesMainUrl,
oneSecond,
} from '../support/helpers/common-constants';
import { getMethod } from '../support/helpers/helpers';

const axios = require('axios');
Expand Down Expand Up @@ -229,19 +234,26 @@ Then(/^I wait for (\d+) minute\(s\) the last transaction is confirmed$/, async f
Then(
/^I validate the transaction amount to (USD|JPY|EUR|CNY|KRW|BTC|ETH|BRL) currency pairing$/,
async function (currency) {
const response = await axios(adaToFiatPrices);
const rate = await response.data.ticker.prices[currency];
const TIMESTAMP = '1555773413000'; // the timestamp of the first tx of this wallet
const response = await axios(`${adaToFiatPricesMainUrl}ADA/${TIMESTAMP}`);

const rate = response.data.tickers[0].prices[currency];

await this.driver.sleep(oneSecond);
const allTxsList = await this.findElements(transactionComponent);
for (const txListElement of allTxsList) {
const txAmount = await getTxAmount(txListElement);

expect(txAmount).to.contain(currency);

const amountList = txAmount.split('\n');
const fiatAmount = amountList[0].replace(currency, '');
const adaAmount = parseFloat(amountList[1].replace('ADA', ''));

const expectedValue = parseFloat((adaAmount * rate).toFixed(6));
const expectedValueNotFixed = adaAmount * rate;
const expectedValue = expectedValueNotFixed < 1
? expectedValueNotFixed.toFixed(6)
: expectedValueNotFixed.toFixed(2);
expect(fiatAmount).to.contain(`${expectedValue}`);
}
}
Expand Down

0 comments on commit e12aaba

Please sign in to comment.