Skip to content

Commit

Permalink
Test hardcoded Paratime withdraw gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Oct 31, 2024
1 parent 0851d1a commit 3f6719a
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/2081.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test hardcoded Paratime withdraw gas limit
65 changes: 65 additions & 0 deletions playwright/tests/monitor-paratime-withdraw-gas.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4106320
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
61316
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
61316
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4106320
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
61316
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
61316
3 changes: 3 additions & 0 deletions src/app/pages/E2EPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,6 +34,7 @@ interface e2eWindow extends Window {
monitor: any
oasisscan: any
oasis: any
oasisRT: any
store: any
}
declare const window: e2eWindow
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3f6719a

Please sign in to comment.