Merge pull request #1100 from nspcc-dev/neo3/compiler/dbgjson

compiler: update debug.json format
This commit is contained in:
Roman Khimov 2020-06-24 18:35:08 +03:00 committed by GitHub
commit 53f2e130c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 18 deletions

View file

@ -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) {

View file

@ -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

View file

@ -16,7 +16,7 @@ import (
// DebugInfo represents smart-contract debug information.
type DebugInfo struct {
EntryPoint string `json:"entrypoint"`
Hash util.Uint160 `json:"hash"`
Documents []string `json:"documents"`
Methods []MethodDebugInfo `json:"methods"`
Events []EventDebugInfo `json:"events"`
@ -131,9 +131,9 @@ func (c *codegen) saveSequencePoint(n ast.Node) {
})
}
func (c *codegen) emitDebugInfo() *DebugInfo {
func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
d := &DebugInfo{
EntryPoint: mainIdent,
Hash: hash.Hash160(contract),
Events: []EventDebugInfo{},
}
for name, scope := range c.funcs {
@ -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,
}

View file

@ -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,7 +178,7 @@ func TestSequencePoints(t *testing.T) {
func TestDebugInfo_MarshalJSON(t *testing.T) {
d := &DebugInfo{
EntryPoint: "main",
Hash: util.Uint160{10, 11, 12, 13},
Documents: []string{"/path/to/file"},
Methods: []MethodDebugInfo{
{