diff --git a/.changelog/2081.internal.md b/.changelog/2081.internal.md new file mode 100644 index 0000000000..13cad5e01d --- /dev/null +++ b/.changelog/2081.internal.md @@ -0,0 +1 @@ +Test hardcoded Paratime withdraw gas limit diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts new file mode 100644 index 0000000000..c81303f025 --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts @@ -0,0 +1,65 @@ +import { test, expect } from '@playwright/test' +import { paraTimesConfig } from '../../src/config' + +for (const net of ['mainnet', 'testnet']) { + for (const paratime of ['sapphire', 'emerald', 'cipher']) { + test(`Check if hardcoded Paratime withdraw gas limit needs to be updated: ${net} ${paratime}`, async ({ + page, + }) => { + await page.goto('/e2e') + + const estimatedGas = await page.evaluate( + async ([net, paratime, paraTimesConfig]) => { + const oasis: typeof import('@oasisprotocol/client') = (window as any).oasis + const oasisRT: typeof import('@oasisprotocol/client-rt') = (window as any).oasisRT + + const nic = + net === 'mainnet' + ? new oasis.client.NodeInternal('https://grpc.oasis.io') + : new oasis.client.NodeInternal('https://testnet.grpc.oasis.io') + + const txWrapper = new oasisRT.consensusAccounts.Wrapper( + oasis.misc.fromHex(paraTimesConfig[paratime][net].runtimeId!), + ) + .callDeposit() + .setBody({ + amount: [ + oasis.quantity.fromBigInt(10n ** 18n * 1000000000n), + oasisRT.token.NATIVE_DENOMINATION, + ], + to: oasis.staking.addressFromBech32( + // await getEvmBech32Address('0x0000000000000000000000000000000000000000') + 'oasis1qq2v39p9fqk997vk6742axrzqyu9v2ncyuqt8uek', + ), + }) + .setFeeAmount([oasis.quantity.fromBigInt(10n ** 18n), oasisRT.token.NATIVE_DENOMINATION]) + .setFeeGas(10n ** 18n) + .setFeeConsensusMessages(1) + .setSignerInfo([ + { + address_spec: { + signature: { + ed25519: oasis.signature.NaclSigner.fromRandom('this key is not important').public(), + }, + }, + nonce: 10000n, + }, + ]) + + const estimatedGas = await new oasisRT.core.Wrapper( + oasis.misc.fromHex(paraTimesConfig[paratime][net].runtimeId!), + ) + .queryEstimateGas() + .setArgs({ tx: txWrapper.transaction }) + .query(nic) + + return estimatedGas + }, + [net, paratime, paraTimesConfig] as const, + ) + + expect(estimatedGas.toString()).toMatchSnapshot() + expect(estimatedGas).toBeLessThan(paraTimesConfig[paratime].feeGas) + }) + } +} diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-cipher-1-main-linux.txt b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-cipher-1-main-linux.txt new file mode 100644 index 0000000000..f46dba18d2 --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-cipher-1-main-linux.txt @@ -0,0 +1 @@ +4106320 \ No newline at end of file diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-emerald-1-main-linux.txt b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-emerald-1-main-linux.txt new file mode 100644 index 0000000000..0a2fd0af9e --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-emerald-1-main-linux.txt @@ -0,0 +1 @@ +61316 \ No newline at end of file diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-sapphire-1-main-linux.txt b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-sapphire-1-main-linux.txt new file mode 100644 index 0000000000..0a2fd0af9e --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-mainnet-sapphire-1-main-linux.txt @@ -0,0 +1 @@ +61316 \ No newline at end of file diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-cipher-1-main-linux.txt b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-cipher-1-main-linux.txt new file mode 100644 index 0000000000..f46dba18d2 --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-cipher-1-main-linux.txt @@ -0,0 +1 @@ +4106320 \ No newline at end of file diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-emerald-1-main-linux.txt b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-emerald-1-main-linux.txt new file mode 100644 index 0000000000..0a2fd0af9e --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-emerald-1-main-linux.txt @@ -0,0 +1 @@ +61316 \ No newline at end of file diff --git a/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-sapphire-1-main-linux.txt b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-sapphire-1-main-linux.txt new file mode 100644 index 0000000000..0a2fd0af9e --- /dev/null +++ b/playwright/tests/monitor-paratime-withdraw-gas.spec.ts-snapshots/Check-if-hardcoded-Paratime-withdraw-gas-limit-needs-to-be-updated-testnet-sapphire-1-main-linux.txt @@ -0,0 +1 @@ +61316 \ No newline at end of file diff --git a/src/app/pages/E2EPage/index.tsx b/src/app/pages/E2EPage/index.tsx index 058f072f56..951e91f295 100644 --- a/src/app/pages/E2EPage/index.tsx +++ b/src/app/pages/E2EPage/index.tsx @@ -9,6 +9,7 @@ import { useNavigate } from 'react-router-dom' import * as monitor from 'vendors/monitor' import * as oasisscan from 'vendors/oasisscan' import * as oasis from '@oasisprotocol/client' +import * as oasisRT from '@oasisprotocol/client-rt' import { useDispatch, useStore } from 'react-redux' import { walletActions } from '../../state/wallet' import { AlertBox, AlertBoxStatus } from '../../components/AlertBox' @@ -33,6 +34,7 @@ interface e2eWindow extends Window { monitor: any oasisscan: any oasis: any + oasisRT: any store: any } declare const window: e2eWindow @@ -43,6 +45,7 @@ function ExposeInternals() { window.monitor = monitor window.oasisscan = oasisscan window.oasis = oasis + window.oasisRT = oasisRT window.store = store return () => { // Keep globals even after redirecting away diff --git a/src/config.ts b/src/config.ts index 32fce17c9a..d36d2d8e83 100644 --- a/src/config.ts +++ b/src/config.ts @@ -177,7 +177,7 @@ export const paraTimesConfig: ParaTimesConfig = { } // https://github.com/mozilla/webextension-polyfill/blob/6e3e26c/src/browser-polyfill.js#L9 -export const runtimeIs = (window as any).chrome?.runtime?.id ? 'extension' : 'webapp' +export const runtimeIs = (globalThis as any).chrome?.runtime?.id ? 'extension' : 'webapp' export const deploys = { production: 'https://wallet.oasis.io',