Skip to content

Commit

Permalink
Switch backend to v2 for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Oct 25, 2024
1 parent 683b697 commit b63ee41
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REACT_APP_E2E_TEST=1

REACT_APP_META_CSP=
EXTENSION_CSP=
REACT_APP_BACKEND=oasisscan
REACT_APP_BACKEND=oasisscanV2
REACT_APP_TRANSAK_URL=https://global-stg.transak.com
# Our staging API key from transak dashboard
REACT_APP_TRANSAK_PARTNER_ID=3566e9e3-d3b7-493c-a33e-91d33c5c32cb
2 changes: 1 addition & 1 deletion .github/dump_validators.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

curl -s https://api.oasisscan.com/mainnet/validator/list?pageSize=500 |
curl -s https://api.oasisscan.com/v2/mainnet/validator/list?pageSize=500 |
jq '{
dump_timestamp: (now * 1000 | floor),
dump_timestamp_iso: (now | strftime("%Y-%m-%dT%H:%M:%SZ")),
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/api-transaction-methods.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('check all transaction methods from API are mapped in transactionMethod
ignoreTimeoutError() // Ignore if API is not responding

cy.request({
url: 'https://api.oasisscan.com/mainnet/chain/methods', // does not include consensus methods
url: 'https://api.oasisscan.com/v2/mainnet/chain/methods', // does not include consensus methods
retryOnNetworkFailure: false,
failOnStatusCode: false,
timeout: 5000,
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/refreshing-balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('Accounts page should continuously refresh balance', async ({ page }) => {
await expect(page.getByTestId('account-balance-summary')).toContainText('123.0')
await expect(page.getByTestId('account-choice')).toContainText('123.0')
await mockApi(page, 456)
await page.waitForRequest('**/chain/account/info/*', { timeout: 60_000 })
await page.waitForRequest('**/account/info/*', { timeout: 60_000 })
await page.waitForRequest('**/chain/transactions*', { timeout: 60_000 })
await expect(page.getByTestId('account-balance-summary')).toContainText('456.0')
await expect(page.getByTestId('account-choice')).toContainText('456.0')
Expand Down
7 changes: 3 additions & 4 deletions playwright/tests/syncTabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../src/utils/__fixtures__/test-inputs'
import { addPersistedStorageV1, clearPersistedStorage } from '../utils/storage'
import { fillPrivateKeyWithoutPassword, fillPrivateKeyAndPassword } from '../utils/fillPrivateKey'
import type { AccountsRow } from '../../src/vendors/oasisscan/index'
import type { AccountInfoResponse } from '../../src/vendors/oasisscan-v2/index'

test.beforeEach(async ({ context, page }) => {
await warnSlowApi(context)
Expand Down Expand Up @@ -312,7 +312,7 @@ test.describe('syncTabs', () => {

// Delay getAccountBalanceWithFallback so addWallet is called after wallet is locked.
let apiBalance: Route
await context.route('**/chain/account/info/*', route => (apiBalance = route))
await context.route('**/account/info/*', route => (apiBalance = route))

await page.getByPlaceholder('Enter your private key here').fill(privateKey2)
await page.keyboard.press('Enter')
Expand All @@ -321,15 +321,14 @@ test.describe('syncTabs', () => {
body: JSON.stringify({
code: 0,
data: {
rank: 0,
address: '',
available: '0',
escrow: '0',
debonding: '0',
total: '0',
nonce: 1,
allowances: [],
} satisfies AccountsRow,
} satisfies AccountInfoResponse,
}),
})
await page.waitForTimeout(100)
Expand Down
110 changes: 39 additions & 71 deletions playwright/utils/mockApi.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { BrowserContext, Page } from '@playwright/test'
import type { OperationsRowMethodEnum } from '../../src/vendors/oasisscan/index'
import type {
AccountsRow,
DelegationRow,
OperationsRow,
OperationsRowMethodEnum,
RuntimeTransactionInfoRow,
ValidatorRow,
} from '../../src/vendors/oasisscan/index'
AccountInfoResponse,
AccountDelegationsInfo,
ChainTransactionInfoResponse,
ValidatorInfo,
} from '../../src/vendors/oasisscan-v2/index'

export async function mockApi(context: BrowserContext | Page, balance: number) {
await context.route('**/chain/account/info/*', route => {
await context.route('**/account/info/*', route => {
route.fulfill({
body: JSON.stringify({
code: 0,
data: {
rank: 0,
address: route.request().url().split('/chain/account/info/')[1],
address: route.request().url().split('/account/info/')[1],
available: balance.toString(),
escrow: '0',
debonding: '0',
total: balance.toString(),
nonce: 1,
allowances: [],
} satisfies AccountsRow,
} satisfies AccountInfoResponse,
}),
})
})
await context.route('**/chain/account/delegations?*', route => {
await context.route('**/account/delegations?*', route => {
route.fulfill({
body: JSON.stringify({ code: 0, data: { list: [], page: 1, size: 500, maxPage: 0, totalSize: 0 } }),
})
})
await context.route('**/chain/account/debonding?*', route => {
await context.route('**/account/debonding?*', route => {
route.fulfill({
body: JSON.stringify({ code: 0, data: { list: [], page: 1, size: 500, maxPage: 0, totalSize: 0 } }),
})
Expand Down Expand Up @@ -111,39 +109,37 @@ export async function mockApi(context: BrowserContext | Page, balance: number) {
export async function mockApiMoreData(context: BrowserContext | Page) {
await mockApi(context, 0)

await context.route('**/chain/account/info/*', route => {
await context.route('**/account/info/*', route => {
route.fulfill({
body: JSON.stringify({
code: 0,
data: {
rank: 0,
address: route.request().url().split('/chain/account/info/')[1],
address: route.request().url().split('/account/info/')[1],
available: '23.239060788',
escrow: '100.996756163',
debonding: '0',
total: '124.235816951',
nonce: 70,
allowances: [],
} satisfies AccountsRow,
} satisfies AccountInfoResponse,
}),
})
})
await context.route('**/chain/account/delegations?*', route => {
await context.route('**/account/delegations?*', route => {
route.fulfill({
body: JSON.stringify({
code: 0,
data: {
list: [
{
validatorAddress: 'oasis1qpn83e8hm3gdhvpfv66xj3qsetkj3ulmkugmmxn3',
entityAddress: 'oasis1qpn83e8hm3gdhvpfv66xj3qsetkj3ulmkugmmxn3',
validatorName: 'Chorus One',
icon: 'https://s3.amazonaws.com/keybase_processed_uploads/3a844f583b686ec5285403694b738a05_360_360.jpg',
entityAddress: null,
shares: '71.939343766',
amount: '100.996756163',
active: true,
},
] as DelegationRow[],
] as AccountDelegationsInfo[],
page: 1,
size: 500,
maxPage: 0,
Expand All @@ -152,7 +148,7 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
}),
})
})
await context.route('**/chain/account/debonding?*', route => {
await context.route('**/account/debonding?*', route => {
route.fulfill({
body: JSON.stringify({ code: 0, data: { list: [], page: 1, size: 500, maxPage: 0, totalSize: 0 } }),
})
Expand All @@ -169,29 +165,31 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
method: 'staking.AddEscrow' as OperationsRowMethodEnum,
fee: '0',
amount: '100.00',
shares: '0.00',
add: true,
timestamp: 1642862677,
time: 81860045,
status: true,
from: new URL(route.request().url()).searchParams.get('address')!,
to: 'oasis1qq3xrq0urs8qcffhvmhfhz4p0mu7ewc8rscnlwxe',
nonce: 2,
raw: '',
errorMessage: '',
},
{
txHash: '9d5a9eb4e82633e7847989d3e84bce6a51b18434dea83e7f038091dbbb5c8bd5',
height: 6919536,
method: 'staking.Transfer' as OperationsRowMethodEnum,
fee: '0',
amount: '119.90',
shares: null,
add: true,
timestamp: 1642862287,
time: 81860435,
status: true,
from: 'oasis1qprje45lh2qqrsy4rcvgx4zpnpzkhkqcm58emr3l',
to: new URL(route.request().url()).searchParams.get('address')!,
nonce: 2,
raw: '',
errorMessage: '',
},
] satisfies (OperationsRow | RuntimeTransactionInfoRow)[],
] satisfies ChainTransactionInfoResponse[],
page: 1,
size: 20,
maxPage: 1,
Expand All @@ -215,10 +213,10 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
name: 'Mars Staking | Long term fee 1%',
icon: 'https://s3.amazonaws.com/keybase_processed_uploads/f30f9b2207b7d83ef05219ca483b6f05_360_360.jpg',
website: 'https://linktr.ee/marssuper',
twitter: null,
twitter: 'marssuper',
keybase: 'marssuper',
email: '[email protected]',
description: null,
description: '',
escrow: '134193743.56',
escrowChange24: '-1097851.50',
escrowPercent: 0.0326,
Expand All @@ -229,15 +227,9 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
nonce: 0,
score: 20912186,
delegators: 23446,
nodes: null,
uptime: '100%',
active: true,
commission: 0.01,
bound: null,
rates: null,
bounds: null,
escrowSharesStatus: null,
escrowAmountStatus: null,
status: true,
},
{
Expand All @@ -252,7 +244,7 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
twitter: 'stakefish',
keybase: 'bflabs',
email: '[email protected]',
description: null,
description: '',
escrow: '185814524.64',
escrowChange24: '-206667.72',
escrowPercent: 0.0452,
Expand All @@ -263,15 +255,9 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
nonce: 0,
score: 21933228,
delegators: 8756,
nodes: null,
uptime: '100%',
active: true,
commission: 0.05,
bound: null,
rates: null,
bounds: null,
escrowSharesStatus: null,
escrowAmountStatus: null,
status: true,
},
{
Expand All @@ -281,12 +267,12 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
nodeId: '6wbL5/OxvFGxi55o7AxcwKmfjXbXGC1hw4lfnEZxBXA=',
nodeAddress: 'oasis1qqp0h2h92eev7nsxgqctvuegt8ge3vyg0qyluc4k',
name: 'BinanceStaking',
icon: null,
icon: 'https://s3.amazonaws.com/keybase_processed_uploads/e1378cd4d5203ded716906687ad53905_360_360.jpg',
website: 'https://www.binance.com',
twitter: null,
keybase: null,
email: null,
description: null,
twitter: 'binance',
keybase: 'binance',
email: 'binance',
description: '',
escrow: '131080178.79',
escrowChange24: '-7133.04',
escrowPercent: 0.0319,
Expand All @@ -297,15 +283,9 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
nonce: 0,
score: 20933210,
delegators: 7988,
nodes: null,
uptime: '100%',
active: true,
commission: 0.1,
bound: null,
rates: null,
bounds: null,
escrowSharesStatus: null,
escrowAmountStatus: null,
status: true,
},
{
Expand All @@ -319,8 +299,8 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
website: 'https://www.stake5labs.com',
twitter: 'stake5labs',
keybase: 'stake5labs',
email: null,
description: null,
email: 'stake5labs',
description: '',
escrow: '40029484.50',
escrowChange24: '2718.71',
escrowPercent: 0.0097,
Expand All @@ -331,15 +311,9 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
nonce: 0,
score: 20640813,
delegators: 5120,
nodes: null,
uptime: '100%',
active: true,
commission: 0.2,
bound: null,
rates: null,
bounds: null,
escrowSharesStatus: null,
escrowAmountStatus: null,
status: true,
},
{
Expand All @@ -352,9 +326,9 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
icon: 'https://s3.amazonaws.com/keybase_processed_uploads/3a844f583b686ec5285403694b738a05_360_360.jpg',
website: 'https://chorus.one',
twitter: 'ChorusOne',
keybase: null,
email: null,
description: null,
keybase: 'ChorusOne',
email: 'ChorusOne',
description: '',
escrow: '135556888.36',
escrowChange24: '3137.73',
escrowPercent: 0.033,
Expand All @@ -365,18 +339,12 @@ export async function mockApiMoreData(context: BrowserContext | Page) {
nonce: 0,
score: 21753374,
delegators: 2360,
nodes: null,
uptime: '100%',
active: true,
commission: 0.05,
bound: null,
rates: null,
bounds: null,
escrowSharesStatus: null,
escrowAmountStatus: null,
status: true,
},
] satisfies ValidatorRow[],
] satisfies ValidatorInfo[],
active: 120,
delegators: 49619,
inactive: 82,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exports[`<Footer /> should render mobile version of footer 1`] = `
</span>
<br />
<span>
Oasis Scan API & Oasis gRPC
Oasis Scan API v2 & Oasis gRPC
</span>
</span>
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/AccountPage/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('<AccountPage />', () => {
}),
)
const page = renderPage(store, ['/account/oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk'])
expect(page.container).toHaveTextContent('Oasis Scan API appears to be down')
expect(page.container).toHaveTextContent('Oasis Scan API v2 appears to be down')
const balance = await screen.findByTestId('account-balance-total')
expect(balance).toHaveTextContent('-')
const balanceSummary = await screen.findByTestId('account-balance-summary')
Expand Down
Loading

0 comments on commit b63ee41

Please sign in to comment.