Skip to content

Commit de185eb

Browse files
authored
Merge pull request #2165 from oasisprotocol/lw/test-consensus-fee
Test hardcoded Consensus transaction fee
2 parents 6a21514 + d4f5885 commit de185eb

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.changelog/2165.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test hardcoded Consensus transaction fee
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { test, expect } from '@playwright/test'
2+
import { E2EWindow } from '../../src/app/pages/E2EPage/E2EWindow'
3+
4+
for (const net of ['mainnet', 'testnet']) {
5+
test(`Check if hardcoded consensus fee needs to be updated (setFeeAmount(oasis.quantity.fromBigInt(0n))) : ${net}`, async ({
6+
page,
7+
}) => {
8+
await page.goto('/e2e')
9+
10+
const estimatedGas = await page.evaluate(
11+
async ([net]) => {
12+
const { oasis, grpcWeb } = window as E2EWindow
13+
14+
const nic =
15+
net === 'mainnet'
16+
? new oasis.client.NodeInternal('https://grpc.oasis.io')
17+
: new oasis.client.NodeInternal('https://testnet.grpc.oasis.io')
18+
19+
function toCBOR(v) {
20+
// gRPC cannot handle nil arguments unmarshalled from CBOR, so we use a special case to
21+
// marshal `nil` to an empty byte string.
22+
if (v == null) return new Uint8Array()
23+
return oasis.misc.toCBOR(v)
24+
}
25+
function createMethodDescriptorUnary(serviceName, methodName) {
26+
const MethodType = grpcWeb.MethodType
27+
return new grpcWeb.MethodDescriptor(
28+
`/oasis-core.${serviceName}/${methodName}`,
29+
MethodType.UNARY,
30+
null as any,
31+
null as any,
32+
toCBOR,
33+
oasis.misc.fromCBOR,
34+
)
35+
}
36+
const methodDescriptorConsensusMinGasPrice = createMethodDescriptorUnary('Consensus', 'MinGasPrice')
37+
38+
// `const minPrice = await nic.consensusMinGasPrice()` in next version
39+
const minPrice = await nic['callUnary']<undefined, Uint8Array>(
40+
methodDescriptorConsensusMinGasPrice,
41+
undefined,
42+
)
43+
return oasis.quantity.toBigInt(minPrice).toString()
44+
},
45+
[net] as const,
46+
)
47+
48+
expect(estimatedGas).toBe('0')
49+
})
50+
}

src/app/pages/E2EPage/E2EWindow.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as nexus from 'vendors/nexus'
44
import * as oasis from '@oasisprotocol/client'
55
import * as oasisRT from '@oasisprotocol/client-rt'
66
import * as encryption from '../../state/persist/encryption'
7+
import * as grpcWeb from 'grpc-web'
78
import { Store } from '@reduxjs/toolkit'
89
import { RootState } from '../../../types'
910

@@ -15,6 +16,7 @@ interface _E2EWindow extends Window {
1516
oasisRT: typeof oasisRT
1617
encryption: typeof encryption
1718
store: Store<RootState>
19+
grpcWeb: typeof grpcWeb
1820
}
1921

2022
export type E2EWindow = _E2EWindow & typeof globalThis

src/app/pages/E2EPage/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as nexus from 'vendors/nexus'
1212
import * as oasis from '@oasisprotocol/client'
1313
import * as oasisRT from '@oasisprotocol/client-rt'
1414
import * as encryption from 'app/state/persist/encryption'
15+
import * as grpcWeb from 'grpc-web'
1516
import { useDispatch, useStore } from 'react-redux'
1617
import { walletActions } from '../../state/wallet'
1718
import { AlertBox, AlertBoxStatus } from '../../components/AlertBox'
@@ -45,6 +46,7 @@ function ExposeInternals() {
4546
window.oasis = oasis
4647
window.oasisRT = oasisRT
4748
window.encryption = encryption
49+
window.grpcWeb = grpcWeb
4850
window.store = store
4951
return () => {
5052
// Keep globals even after redirecting away

0 commit comments

Comments
 (0)