Merge pull request #1100 from nspcc-dev/neo3/compiler/dbgjson
compiler: update debug.json format
This commit is contained in:
commit
53f2e130c0
4 changed files with 24 additions and 18 deletions
|
@ -1442,7 +1442,7 @@ func CodeGen(info *buildInfo) ([]byte, *DebugInfo, error) {
|
|||
if err := c.writeJumps(buf); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return buf, c.emitDebugInfo(), nil
|
||||
return buf, c.emitDebugInfo(buf), nil
|
||||
}
|
||||
|
||||
func (c *codegen) resolveFuncDecls(f *ast.File, pkg *types.Package) {
|
||||
|
|
|
@ -118,7 +118,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
if o.ABIInfo == "" {
|
||||
return b, err
|
||||
}
|
||||
abi := di.convertToABI(b, o.ContractFeatures)
|
||||
abi := di.convertToABI(o.ContractFeatures)
|
||||
abiData, err := json.Marshal(abi)
|
||||
if err != nil {
|
||||
return b, err
|
||||
|
|
|
@ -16,10 +16,10 @@ import (
|
|||
|
||||
// DebugInfo represents smart-contract debug information.
|
||||
type DebugInfo struct {
|
||||
EntryPoint string `json:"entrypoint"`
|
||||
Documents []string `json:"documents"`
|
||||
Methods []MethodDebugInfo `json:"methods"`
|
||||
Events []EventDebugInfo `json:"events"`
|
||||
Hash util.Uint160 `json:"hash"`
|
||||
Documents []string `json:"documents"`
|
||||
Methods []MethodDebugInfo `json:"methods"`
|
||||
Events []EventDebugInfo `json:"events"`
|
||||
}
|
||||
|
||||
// MethodDebugInfo represents smart-contract's method debug information.
|
||||
|
@ -131,10 +131,10 @@ func (c *codegen) saveSequencePoint(n ast.Node) {
|
|||
})
|
||||
}
|
||||
|
||||
func (c *codegen) emitDebugInfo() *DebugInfo {
|
||||
func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
|
||||
d := &DebugInfo{
|
||||
EntryPoint: mainIdent,
|
||||
Events: []EventDebugInfo{},
|
||||
Hash: hash.Hash160(contract),
|
||||
Events: []EventDebugInfo{},
|
||||
}
|
||||
for name, scope := range c.funcs {
|
||||
m := c.methodInfoFromScope(name, scope)
|
||||
|
@ -313,10 +313,10 @@ func parsePairJSON(data []byte, sep string) (string, string, error) {
|
|||
|
||||
// convertToABI converts contract to the ABI struct for debugger.
|
||||
// Note: manifest is taken from the external source, however it can be generated ad-hoc. See #1038.
|
||||
func (di *DebugInfo) convertToABI(contract []byte, fs smartcontract.PropertyState) ABI {
|
||||
func (di *DebugInfo) convertToABI(fs smartcontract.PropertyState) ABI {
|
||||
methods := make([]Method, 0)
|
||||
for _, method := range di.Methods {
|
||||
if method.Name.Name == di.EntryPoint {
|
||||
if method.Name.Name == mainIdent {
|
||||
methods = append(methods, Method{
|
||||
Name: method.Name.Name,
|
||||
Parameters: method.Parameters,
|
||||
|
@ -333,12 +333,12 @@ func (di *DebugInfo) convertToABI(contract []byte, fs smartcontract.PropertyStat
|
|||
}
|
||||
}
|
||||
return ABI{
|
||||
Hash: hash.Hash160(contract),
|
||||
Hash: di.Hash,
|
||||
Metadata: Metadata{
|
||||
HasStorage: fs&smartcontract.HasStorage != 0,
|
||||
IsPayable: fs&smartcontract.IsPayable != 0,
|
||||
},
|
||||
EntryPoint: di.EntryPoint,
|
||||
EntryPoint: mainIdent,
|
||||
Functions: methods,
|
||||
Events: events,
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -47,9 +48,13 @@ func methodStruct() struct{} { return struct{}{} }
|
|||
require.NoError(t, c.compile(info, pkg))
|
||||
|
||||
buf := c.prog.Bytes()
|
||||
d := c.emitDebugInfo()
|
||||
d := c.emitDebugInfo(buf)
|
||||
require.NotNil(t, d)
|
||||
|
||||
t.Run("hash", func(t *testing.T) {
|
||||
require.True(t, hash.Hash160(buf).Equals(d.Hash))
|
||||
})
|
||||
|
||||
t.Run("return types", func(t *testing.T) {
|
||||
returnTypes := map[string]string{
|
||||
"methodInt": "Integer",
|
||||
|
@ -117,7 +122,7 @@ func methodStruct() struct{} { return struct{}{} }
|
|||
}
|
||||
|
||||
t.Run("convert to ABI", func(t *testing.T) {
|
||||
actual := d.convertToABI(buf, smartcontract.HasStorage)
|
||||
actual := d.convertToABI(smartcontract.HasStorage)
|
||||
expected := ABI{
|
||||
Hash: hash.Hash160(buf),
|
||||
Metadata: Metadata{
|
||||
|
@ -160,7 +165,8 @@ func TestSequencePoints(t *testing.T) {
|
|||
c := newCodegen(info, pkg)
|
||||
require.NoError(t, c.compile(info, pkg))
|
||||
|
||||
d := c.emitDebugInfo()
|
||||
buf := c.prog.Bytes()
|
||||
d := c.emitDebugInfo(buf)
|
||||
require.NotNil(t, d)
|
||||
|
||||
// Main func has 2 return on 4-th and 6-th lines.
|
||||
|
@ -172,8 +178,8 @@ func TestSequencePoints(t *testing.T) {
|
|||
|
||||
func TestDebugInfo_MarshalJSON(t *testing.T) {
|
||||
d := &DebugInfo{
|
||||
EntryPoint: "main",
|
||||
Documents: []string{"/path/to/file"},
|
||||
Hash: util.Uint160{10, 11, 12, 13},
|
||||
Documents: []string{"/path/to/file"},
|
||||
Methods: []MethodDebugInfo{
|
||||
{
|
||||
ID: "id1",
|
||||
|
|
Loading…
Reference in a new issue