Merge remote-tracking branch 'origin/master' into update_web3js_4

pull/4108/head
yann300 1 year ago
commit c37f24fcc6
  1. 5
      libs/remix-debug/src/solidity-decoder/internalCallTree.ts
  2. 5
      libs/remix-debug/test/decoder/localsTests/int.ts
  3. 3
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.css
  4. 2
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx
  5. 8
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/dropdown-panel.tsx
  6. 23
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/function-panel.tsx
  7. 10
      libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger-head.tsx
  8. 4
      libs/remix-ui/debugger-ui/src/types/index.ts

@ -165,7 +165,6 @@ export class InternalCallTree {
const scope = this.findScope(vmtraceIndex) const scope = this.findScope(vmtraceIndex)
if (!scope) return [] if (!scope) return []
let scopeId = this.scopeStarts[scope.firstStep] let scopeId = this.scopeStarts[scope.firstStep]
const scopeDetail = this.scopes[scopeId]
const functions = [] const functions = []
if (!scopeId) return functions if (!scopeId) return functions
let i = 0 let i = 0
@ -174,6 +173,7 @@ export class InternalCallTree {
i += 1 i += 1
if (i > 1000) throw new Error('retrieFunctionStack: recursion too deep') if (i > 1000) throw new Error('retrieFunctionStack: recursion too deep')
const functionDefinition = this.functionDefinitionsByScope[scopeId] const functionDefinition = this.functionDefinitionsByScope[scopeId]
const scopeDetail = this.scopes[scopeId]
if (functionDefinition !== undefined) { if (functionDefinition !== undefined) {
functions.push({ ...functionDefinition, ...scopeDetail }) functions.push({ ...functionDefinition, ...scopeDetail })
} }
@ -280,7 +280,10 @@ async function buildTree (tree, step, scopeId, isCreation, functionDefinition?,
const stepDetail: StepDetail = tree.traceManager.trace[step] const stepDetail: StepDetail = tree.traceManager.trace[step]
const nextStepDetail: StepDetail = tree.traceManager.trace[step + 1] const nextStepDetail: StepDetail = tree.traceManager.trace[step + 1]
if (stepDetail && nextStepDetail) { if (stepDetail && nextStepDetail) {
// for complicated opcodes which don't have a static gas cost:
stepDetail.gasCost = parseInt(stepDetail.gas as string) - parseInt(nextStepDetail.gas as string) stepDetail.gasCost = parseInt(stepDetail.gas as string) - parseInt(nextStepDetail.gas as string)
} else {
stepDetail.gasCost = parseInt(stepDetail.gasCost as unknown as string)
} }
// gas per line // gas per line

@ -61,6 +61,11 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult,
st.equals(functions3.length, 1) st.equals(functions3.length, 1)
st.equal(functions1[0].gasCost, 54) st.equal(functions1[0].gasCost, 54)
st.equal(functions1[1].gasCost, 436)
st.equal(functions2[0].gasCost, 23)
st.equal(functions2[1].gasCost, 54)
st.equal(functions2[2].gasCost, 436)
st.equals(Object.keys(functions1[0])[0], 'functionDefinition') st.equals(Object.keys(functions1[0])[0], 'functionDefinition')
st.equals(Object.keys(functions1[0])[1], 'inputs') st.equals(Object.keys(functions1[0])[1], 'inputs')

@ -21,3 +21,6 @@
overflow-y: auto; overflow-y: auto;
height: fit-content; height: fit-content;
} }
.jumpToFunctionClick span {
cursor: pointer;
}

@ -461,7 +461,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
{state.debugging && <StepManager stepManager={stepManager} />} {state.debugging && <StepManager stepManager={stepManager} />}
</div> </div>
<div className="debuggerPanels" ref={panelsRef}> <div className="debuggerPanels" ref={panelsRef}>
{state.debugging && <VmDebuggerHead debugging={state.debugging} vmDebugger={vmDebugger} />} {state.debugging && <VmDebuggerHead debugging={state.debugging} vmDebugger={vmDebugger} stepManager={stepManager} />}
{state.debugging && ( {state.debugging && (
<VmDebugger <VmDebugger
debugging={state.debugging} debugging={state.debugging}

@ -20,6 +20,8 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
extractFunc, extractFunc,
formatSelfFunc, formatSelfFunc,
registerEvent, registerEvent,
handleExpandFunc,
formatClassNamesFunc,
triggerEvent, triggerEvent,
loadMoreEvent, loadMoreEvent,
loadMoreCompletedEvent, loadMoreCompletedEvent,
@ -135,9 +137,9 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
toggleDropdown: !prevState.toggleDropdown toggleDropdown: !prevState.toggleDropdown
} }
}) })
} };
const handleExpand = (keyPath) => { const handleExpand = handleExpandFunc || function (keyPath) {
if (!state.expandPath.includes(keyPath)) { if (!state.expandPath.includes(keyPath)) {
state.expandPath.push(keyPath) state.expandPath.push(keyPath)
} else { } else {
@ -221,6 +223,7 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
label={formatSelfFunc ? formatSelfFunc(key, data) : formatSelfDefault(key, data)} label={formatSelfFunc ? formatSelfFunc(key, data) : formatSelfDefault(key, data)}
onClick={() => handleExpand(keyPath)} onClick={() => handleExpand(keyPath)}
expand={state.expandPath.includes(keyPath)} expand={state.expandPath.includes(keyPath)}
labelClass={formatClassNamesFunc && formatClassNamesFunc(key, data)}
> >
<TreeView id={`treeView${key}`} key={keyPath}> <TreeView id={`treeView${key}`} key={keyPath}>
{children} {children}
@ -246,6 +249,7 @@ export const DropdownPanel = (props: DropdownPanelProps) => {
label={formatSelfFunc ? formatSelfFunc(key, data) : formatSelfDefault(key, data)} label={formatSelfFunc ? formatSelfFunc(key, data) : formatSelfDefault(key, data)}
onClick={() => handleExpand(keyPath)} onClick={() => handleExpand(keyPath)}
expand={state.expandPath.includes(keyPath)} expand={state.expandPath.includes(keyPath)}
labelClass={formatClassNamesFunc && formatClassNamesFunc(key, data)}
/> />
) )
} }

@ -2,16 +2,31 @@ import React, {useState, useEffect} from 'react' // eslint-disable-line
import DropdownPanel from './dropdown-panel' // eslint-disable-line import DropdownPanel from './dropdown-panel' // eslint-disable-line
import {default as deepequal} from 'deep-equal' // eslint-disable-line import {default as deepequal} from 'deep-equal' // eslint-disable-line
export const FunctionPanel = ({data, className}) => { export const FunctionPanel = ({data, className, stepManager}) => {
const [calldata, setCalldata] = useState(null) const [functionData, setFunctionData] = useState(null)
useEffect(() => { useEffect(() => {
if (!deepequal(calldata, data)) setCalldata(data) if (!deepequal(functionData, data)) {
setFunctionData(data.map(el => el.label))
}
}, [data]) }, [data])
const formatSelfFunc = (key, data) => {
return data.self
}
const handleExpandFunc = (keyPath) => {
stepManager.jumpTo(data[parseInt(keyPath)].function.firstStep)
}
const formatClassNamesFunc = (keyPath, data) => {
return 'jumpToFunctionClick'
}
return ( return (
<div id="FunctionPanel" className={className} data-id="functionPanel"> <div id="FunctionPanel" className={className} data-id="functionPanel">
<DropdownPanel dropdownName="Function Stack" calldata={calldata || {}} /> <DropdownPanel dropdownName="Function Stack" calldata={functionData || {}} formatSelfFunc={formatSelfFunc} formatClassNamesFunc={formatClassNamesFunc} handleExpandFunc={handleExpandFunc} />
</div> </div>
) )
} }

@ -5,7 +5,7 @@ import StepDetail from './step-detail' // eslint-disable-line
import SolidityState from './solidity-state' // eslint-disable-line import SolidityState from './solidity-state' // eslint-disable-line
import SolidityLocals from './solidity-locals' // eslint-disable-line import SolidityLocals from './solidity-locals' // eslint-disable-line
export const VmDebuggerHead = ({vmDebugger: {registerEvent, triggerEvent}, debugging}) => { export const VmDebuggerHead = ({vmDebugger: {registerEvent, triggerEvent}, debugging, stepManager}) => {
const [functionPanel, setFunctionPanel] = useState(null) const [functionPanel, setFunctionPanel] = useState(null)
const [stepDetail, setStepDetail] = useState({ const [stepDetail, setStepDetail] = useState({
'vm trace step': '-', 'vm trace step': '-',
@ -32,7 +32,11 @@ export const VmDebuggerHead = ({vmDebugger: {registerEvent, triggerEvent}, debug
const functions = [] const functions = []
for (const func of stack) { for (const func of stack) {
functions.push((func.functionDefinition.name || func.functionDefinition.kind) + '(' + func.inputs.join(', ') + ')' + ' - ' + func.gasCost + ' gas') const label = (func.functionDefinition.name || func.functionDefinition.kind) + '(' + func.inputs.join(', ') + ')' + ' - ' + func.gasCost + ' gas'
functions.push({
label,
function: func
})
} }
setFunctionPanel(() => functions) setFunctionPanel(() => functions)
}) })
@ -127,7 +131,7 @@ export const VmDebuggerHead = ({vmDebugger: {registerEvent, triggerEvent}, debug
return ( return (
<div id="vmheadView" className="mt-1 px-2 d-flex"> <div id="vmheadView" className="mt-1 px-2 d-flex">
<div className="d-flex flex-column pr-2" style={{flex: 1}}> <div className="d-flex flex-column pr-2" style={{flex: 1}}>
<FunctionPanel className="pb-1" data={functionPanel} /> <FunctionPanel className="pb-1" data={functionPanel} stepManager={stepManager} />
<SolidityLocals className="pb-1" data={solidityLocals.calldata} message={solidityLocals.message} registerEvent={registerEvent} triggerEvent={triggerEvent} /> <SolidityLocals className="pb-1" data={solidityLocals.calldata} message={solidityLocals.message} registerEvent={registerEvent} triggerEvent={triggerEvent} />
<CodeListView className="pb-2 flex-grow-1" registerEvent={registerEvent} /> <CodeListView className="pb-2 flex-grow-1" registerEvent={registerEvent} />
</div> </div>

@ -18,6 +18,8 @@ export type ExtractFunc = (json: any, parent?: any) => ExtractData
export type FormatSelfFunc = (key: string | number, data: ExtractData) => JSX.Element export type FormatSelfFunc = (key: string | number, data: ExtractData) => JSX.Element
export type RegisterEventType = (type: string, listener: any) => void // listener is a function export type RegisterEventType = (type: string, listener: any) => void // listener is a function
export type TriggerEventType = (type: string, payload: Array<any>) => void export type TriggerEventType = (type: string, payload: Array<any>) => void
export type HandleExpandFunc = (keyPath: string) => void
export type FormatClassNamesFunc = (key: string | number, data: ExtractData) => string
export interface DropdownPanelProps { export interface DropdownPanelProps {
dropdownName: string, dropdownName: string,
className?: string, className?: string,
@ -30,6 +32,8 @@ export interface DropdownPanelProps {
extractFunc?: ExtractFunc, extractFunc?: ExtractFunc,
formatSelfFunc?: FormatSelfFunc, formatSelfFunc?: FormatSelfFunc,
registerEvent?: RegisterEventType, registerEvent?: RegisterEventType,
handleExpandFunc?: HandleExpandFunc,
formatClassNamesFunc?: FormatClassNamesFunc
triggerEvent?: TriggerEventType, triggerEvent?: TriggerEventType,
loadMoreEvent?: string, loadMoreEvent?: string,
loadMoreCompletedEvent?: string, loadMoreCompletedEvent?: string,

Loading…
Cancel
Save