Skip to content

Commit

Permalink
test: revert to the last working version
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek committed Apr 10, 2024
1 parent a361612 commit e211812
Show file tree
Hide file tree
Showing 32 changed files with 261 additions and 359 deletions.
6 changes: 3 additions & 3 deletions backend/app/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ def __init__(self, used: int, expected: int):


class ExternalApiException(OctantException):
description = "Request to an external service failed."
description = "API call to {} failed. Error: {}"
code = 500

def __init__(self, e: RequestException, status_code: int = None):
def __init__(self, api_url: str, e: RequestException, status_code: int = None):
if status_code is not None:
self.code = status_code
else:
if hasattr(e, "response") and e.response is not None:
self.code = e.response.status_code
super().__init__(
self.description,
self.description.format(api_url, str(e)),
self.code,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_validators_by_address(validator_address: str) -> list[dict]:
return all_validators
except requests.exceptions.RequestException as e:
ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(api_url, e, 500)


def get_detailed_validators_by_indices(indices: str) -> list:
Expand All @@ -46,4 +46,4 @@ def get_detailed_validators_by_indices(indices: str) -> list:
return list(json_response["data"])
except requests.exceptions.RequestException as e:
ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(VALIDATOR_API_URL_BASE, e, 500)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests


import app as app_module
from app.constants import BITQUERY_API
from app.exceptions import ExternalApiException
Expand Down Expand Up @@ -35,6 +36,6 @@ def get_blocks_rewards(address: str, start_block: int, end_block: int) -> float:
json_response = response.json()
except requests.exceptions.RequestException as e:
app_module.ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(api_url, e, 500)

return json_response["data"]["ethereum"]["blocks"][0]["reward"]
9 changes: 3 additions & 6 deletions backend/app/infrastructure/external_api/etherscan/account.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import requests
from flask import current_app as app

import app as app_module
from app.constants import ETHERSCAN_API
from app.exceptions import ExternalApiException
from app.infrastructure.external_api.etherscan.helpers import raise_for_status
from app.infrastructure.external_api.etherscan.req_params import (
AccountAction,
)
from app.infrastructure.external_api.etherscan.req_params import AccountAction
from flask import current_app as app

MAX_RESPONSE_SIZE = 10000

Expand Down Expand Up @@ -35,7 +32,7 @@ def get_transactions(
return txs
except requests.exceptions.RequestException as e:
app_module.ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(api_url, e, 500)


def _get_api_url(address: str, tx_type: AccountAction) -> str:
Expand Down
7 changes: 3 additions & 4 deletions backend/app/infrastructure/external_api/etherscan/blocks.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import requests
from flask import current_app as app

import app as app_module
import requests
from app.constants import ETHERSCAN_API
from app.exceptions import ExternalApiException
from app.infrastructure.external_api.etherscan.helpers import raise_for_status
from app.infrastructure.external_api.etherscan.req_params import (
ClosestValue,
BlockAction,
)
from flask import current_app as app


def get_block_num_from_ts(timestamp: int) -> int:
Expand All @@ -21,7 +20,7 @@ def get_block_num_from_ts(timestamp: int) -> int:
result = int(json_response["result"])
except requests.exceptions.RequestException as e:
app_module.ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(api_url, e, 500)

return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_message_details(message_hash: str, is_mainnet: bool) -> dict:
json_response = response.json()
except requests.exceptions.RequestException as e:
app_module.ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(api_url, e, 500)

return json_response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_user_details(user_address: str, is_mainnet: bool) -> dict:
json_response = response.json()
except requests.exceptions.RequestException as e:
app_module.ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e, 500)
raise ExternalApiException(api_url, e, 500)

return json_response

Expand Down
15 changes: 0 additions & 15 deletions backend/tests/infrastracture/external_api/etherscan/conftest.py

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions client/cypress/e2e/_2makePandingSnapshot.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from 'axios';

import { mockCoinPricesServer, visitWithLoader } from 'cypress/utils/e2e';
import { mutateAsyncMakeSnapshot, loaderCheck } from 'cypress/utils/moveTime';
import { QUERY_KEYS } from 'src/api/queryKeys';
import { IS_ONBOARDING_ALWAYS_VISIBLE, IS_ONBOARDING_DONE } from 'src/constants/localStorageKeys';
import env from 'src/env';
Expand Down Expand Up @@ -39,8 +38,8 @@ describe('Make pending snapshot', () => {
}

cy.wrap(null).then(() => {
return mutateAsyncMakeSnapshot(win, 'pending').then(() => {
loaderCheck();
axios.post(`${env.serverEndpoint}snapshots/pending`).then(() => {
cy.get('[data-test=SyncView]', { timeout: 60000 }).should('not.exist');
});
});
});
Expand Down
39 changes: 23 additions & 16 deletions client/cypress/e2e/allocationAllocationWindowClosed.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
visitWithLoader,
mockCoinPricesServer,
navigateWithCheck,
moveEpoch,
} from 'cypress/utils/e2e';
import { moveEpoch } from 'cypress/utils/moveTime';
import viewports from 'cypress/utils/viewports';
import { QUERY_KEYS } from 'src/api/queryKeys';
import {
Expand All @@ -16,8 +16,8 @@ import { ROOT_ROUTES } from 'src/routes/RootRoutes/routes';

let wasTimeMoved = false;

describe('allocation (allocation window closed)', () => {
describe('move time to allocation window closed', () => {
[Object.values(viewports)[0]].forEach(({ device, viewportWidth, viewportHeight, isDesktop }) => {
describe('move time', { retries: 0 }, () => {
before(() => {
/**
* Global Metamask setup done by Synpress is not always done.
Expand Down Expand Up @@ -51,23 +51,30 @@ describe('allocation (allocation window closed)', () => {
// Move time only once, for the first device.
if (!wasTimeMoved) {
cy.log(`test 1_2 ${isDecisionWindowOpen}`);
moveEpoch(win, 'decisionWindowClosed').then(() => {
cy.get('[data-test=PlaygroundView]').should('be.visible');
const isDecisionWindowOpenAfter = win.clientReactQuery.getQueryData(
QUERY_KEYS.isDecisionWindowOpen,
);
wasTimeMoved = true;
cy.log(`test 1_2 ${isDecisionWindowOpenAfter}`);
expect(isDecisionWindowOpenAfter).to.be.false;
});
moveEpoch(win, 'decisionWindowClosed')
.then(() => {
cy.get('[data-test=PlaygroundView]').should('be.visible');
const isDecisionWindowOpenAfter = win.clientReactQuery.getQueryData(
QUERY_KEYS.isDecisionWindowOpen,
);
wasTimeMoved = true;
cy.log(`test 1_2 ${isDecisionWindowOpenAfter}`);
expect(isDecisionWindowOpenAfter).to.be.false;
});
} else {
expect(true).to.be.true;
}
});
});

it('playground', () => {
cy.wait(30000);
});
});
[Object.values(viewports)[0]].forEach(({ device, viewportWidth, viewportHeight, isDesktop }) => {
describe(`test cases: ${device}`, { viewportHeight, viewportWidth }, () => {
describe(
`allocation (allocation window closed): ${device}`,
{ viewportHeight, viewportWidth },
() => {
before(() => {
/**
* Global Metamask setup done by Synpress is not always done.
Expand Down Expand Up @@ -129,6 +136,6 @@ describe('allocation (allocation window closed)', () => {
.find('[data-test=AllocationItem__InputText__suffix]')
.contains('GWEI');
});
});
});
},
);
});
42 changes: 25 additions & 17 deletions client/cypress/e2e/allocationsAllocationWindowOpen.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
mockCoinPricesServer,
navigateWithCheck,
connectWallet,
moveEpoch,
} from 'cypress/utils/e2e';
import { moveEpoch } from 'cypress/utils/moveTime';
import viewports from 'cypress/utils/viewports';
import { QUERY_KEYS } from 'src/api/queryKeys';
import {
Expand All @@ -22,8 +22,8 @@ chai.use(chaiColors);
let wasTimeMoved = false;
const budget = '10000000000';

describe('allocation (allocation window open)', () => {
describe('move time to allocation window open', () => {
[Object.values(viewports)[0]].forEach(({ device, viewportWidth, viewportHeight }) => {
describe('move time', { retries: 0 }, () => {
before(() => {
/**
* Global Metamask setup done by Synpress is not always done.
Expand All @@ -39,6 +39,7 @@ describe('allocation (allocation window open)', () => {
localStorage.setItem(IS_ONBOARDING_ALWAYS_VISIBLE, 'false');
localStorage.setItem(IS_ONBOARDING_DONE, 'true');
localStorage.setItem(ALLOCATION_ITEMS_KEY, '[]');
visitWithLoader(ROOT_ROUTES.playground.absolute);
});

it('allocation window is open, when it is not, move time', () => {
Expand All @@ -53,21 +54,28 @@ describe('allocation (allocation window open)', () => {

// Move time only once, for the first device.
if (!wasTimeMoved) {
moveEpoch(win, 'decisionWindowOpen').then(() => {
const isDecisionWindowOpenAfter = win.clientReactQuery.getQueryData(
QUERY_KEYS.isDecisionWindowOpen,
);
wasTimeMoved = true;
expect(isDecisionWindowOpenAfter).to.be.true;
});
moveEpoch(win, 'decisionWindowOpen')
.then(() => {
const isDecisionWindowOpenAfter = win.clientReactQuery.getQueryData(
QUERY_KEYS.isDecisionWindowOpen,
);
wasTimeMoved = true;
expect(isDecisionWindowOpenAfter).to.be.true;
});
} else {
expect(true).to.be.true;
}
});
});
});
[Object.values(viewports)[0]].forEach(({ device, viewportWidth, viewportHeight }) => {
describe(`test cases: ${device}`, { viewportHeight, viewportWidth }, () => {

it('playground', () => {
cy.wait(30000);
});
})
describe(
`allocation (allocation window open): ${device}`,
{ viewportHeight, viewportWidth },
() => {
before(() => {
/**
* Global Metamask setup done by Synpress is not always done.
Expand Down Expand Up @@ -147,18 +155,18 @@ describe('allocation (allocation window open)', () => {
cy.get('[data-test=AllocationItem]')
.eq(0)
.find('[data-test=AllocationItem__InputText]')
.type('99999999999999999999');
.type('99999999999999999999999999999999999999999999999');
cy.get('[data-test=AllocationItem]')
.eq(0)
.find('[data-test=AllocationItem__InputText]')
.should('have.css', 'background-color')
.and('be.colored', '#ffefee');
.and('be.colored', '#ff6157');
cy.get('[data-test=AllocationItem]')
.eq(0)
.find('[data-test=AllocationItem__InputText]')
.invoke('dat', 'iserror')
.should('be.true');
});
});
});
},
);
});
2 changes: 1 addition & 1 deletion client/cypress/support/e2e.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ declare namespace Cypress {
interface ApplicationWindow {
// Importing QueryClient breaks <reference types="cypress" /> making these types not visible.
clientReactQuery: any;
mutateAsyncMakeSnapshot: (type: 'pending' | 'finalized') => Promise<void>;
mutateAsyncMoveToDecisionWindowClosed: () => Promise<void>;
mutateAsyncMoveToDecisionWindowOpen: () => Promise<void>;
mutateAsyncMakeSnapshot: (type: 'pending' | 'finalized') => Promise<void>;
}
}
Loading

0 comments on commit e211812

Please sign in to comment.