Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions solidity/ts/testsuite/simulator/MockWindowEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { EthereumBytes32, EthereumData, EthereumQuantity, EthereumSignedTransact
import { ErrorWithDataAndCode, JsonRpcResponseError, printError } from './utils/errors.js'
import * as funtypes from 'funtypes'
import { getConfig } from './utils/config.js'
import { dataStringWith0xStart } from './utils/bigint.js'

async function singleCallWithFromOverride(ethereumClientService: EthereumClientService, simulationState: SimulationState | undefined, request: EthCallParams, from: bigint) {
const callParams = request.params[0]
Expand Down Expand Up @@ -146,7 +145,7 @@ export const getMockedEthSimulateWindowEthereum = (): MockWindowEthereum => {
if (lastTx === undefined) throw new Error('Failed To append transaction')
if (lastTx.ethSimulateV1CallResult.status === 'failure') {
console.error(transaction.error)
throw new ErrorWithDataAndCode(lastTx.ethSimulateV1CallResult.error.code, lastTx.ethSimulateV1CallResult.error.message, dataStringWith0xStart(lastTx.ethSimulateV1CallResult.error.data))
throw new ErrorWithDataAndCode(lastTx.ethSimulateV1CallResult.error.code, lastTx.ethSimulateV1CallResult.error.message, lastTx.ethSimulateV1CallResult.error.data)
}
afterTransactionSendCallBack(args, lastTx)
return EthereumBytes32.serialize(signed.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const simulateEstimateGas = async (ethereumClientService: EthereumClientS
if (lastBlock === undefined) return { error: { code: ERROR_INTERCEPTOR_GAS_ESTIMATION_FAILED, message: 'ETH Simulate Failed to estimate gas', data: '0x' } }
const lastResult = lastBlock.simulatedTransactions[lastBlock.simulatedTransactions.length - 1]?.ethSimulateV1CallResult
if (lastResult === undefined) return { error: { code: ERROR_INTERCEPTOR_GAS_ESTIMATION_FAILED, message: 'ETH Simulate Failed to estimate gas', data: '0x' } }
if (lastResult.status === 'failure') return { error: { ...lastResult.error, data: dataStringWith0xStart(lastResult.error.data) } }
if (lastResult.status === 'failure') return { error: { ...lastResult.error, data: lastResult.error?.data === undefined ? '0x' : lastResult.error.data } }
const gasSpent = lastResult.gasUsed * 135n * 64n / (100n * 63n) // add 35% * 64 / 63 extra to account for gas savings <https://eips.ethereum.org/EIPS/eip-3529>
return { gas: gasSpent < maxGas ? gasSpent : maxGas }
} catch (error: unknown) {
Expand Down
13 changes: 5 additions & 8 deletions solidity/ts/testsuite/simulator/types/ethSimulateTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CodeMessageError } from './rpc.js'
import { EthereumAccessList, EthereumAddress, EthereumBlockTag, EthereumBytes32, EthereumData, EthereumInput, EthereumQuantity, EthereumQuantitySmall, EthereumTimestamp, LiteralConverterParserFactory } from './wire-types.js'
import * as funtypes from 'funtypes'

Expand Down Expand Up @@ -104,14 +105,10 @@ const CallResultLogs = funtypes.ReadonlyArray(CallResultLog)

type EthSimulateCallResultFailure = funtypes.Static<typeof EthSimulateCallResultFailure>
const EthSimulateCallResultFailure = funtypes.ReadonlyObject({
status: funtypes.Literal('0x0').withParser(LiteralConverterParserFactory('0x0', 'failure' as const)),
returnData: EthereumData,
gasUsed: EthereumQuantitySmall,
error: funtypes.ReadonlyObject({
code: funtypes.Number,
message: funtypes.String,
data: EthereumData
})
status: funtypes.Literal('0x0').withParser(LiteralConverterParserFactory('0x0', 'failure' as const)),
returnData: EthereumData,
gasUsed: EthereumQuantitySmall,
error: CodeMessageError
})

type EthSimulateCallResultSuccess = funtypes.Static<typeof EthSimulateCallResultSuccess>
Expand Down
14 changes: 9 additions & 5 deletions solidity/ts/testsuite/simulator/types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export const RpcEntry = funtypes.ReadonlyObject({
httpsRpc: funtypes.String,
})

export type CodeMessageError = funtypes.Static<typeof CodeMessageError>
export const CodeMessageError = funtypes.ReadonlyObject({
code: funtypes.Number,
message: funtypes.String,
})
export const CodeMessageError = funtypes.Intersect(
funtypes.ReadonlyObject({
code: funtypes.Number,
message: funtypes.String,
}),
funtypes.ReadonlyPartial({
data: funtypes.String
})
)
7 changes: 2 additions & 5 deletions solidity/ts/testsuite/simulator/types/visualizerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as funtypes from 'funtypes'
import { EthereumAddress, EthereumQuantity, EthereumSendableSignedTransaction, EthereumTimestamp } from './wire-types.js'
import { SignMessageParams } from './jsonRpcSigningTypes.js'
import { EthSimulateV1CallResult, StateOverrides } from './ethSimulateTypes.js'
import { CodeMessageError } from './rpc.js'

export type SimulatedTransaction = funtypes.Static<typeof SimulatedTransaction>
export const SimulatedTransaction = funtypes.ReadonlyObject({
Expand All @@ -13,11 +14,7 @@ export const SimulatedTransaction = funtypes.ReadonlyObject({

export type EstimateGasError = funtypes.Static<typeof EstimateGasError>
export const EstimateGasError = funtypes.ReadonlyObject({
error: funtypes.ReadonlyObject({
code: funtypes.Number,
message: funtypes.String,
data: funtypes.String
})
error: CodeMessageError
})

export type SignedMessageTransaction = funtypes.Static<typeof SignedMessageTransaction>
Expand Down