diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 96f9f87e5..a787c6cf9 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1424,7 +1424,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) { diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 59abcacf8..9e60b710b 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -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 diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index c6b4b6c69..db72ea611 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -16,6 +16,7 @@ import ( // DebugInfo represents smart-contract debug information. type DebugInfo struct { + Hash util.Uint160 `json:"hash"` EntryPoint string `json:"entrypoint"` Documents []string `json:"documents"` Methods []MethodDebugInfo `json:"methods"` @@ -131,8 +132,9 @@ func (c *codegen) saveSequencePoint(n ast.Node) { }) } -func (c *codegen) emitDebugInfo() *DebugInfo { +func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo { d := &DebugInfo{ + Hash: hash.Hash160(contract), EntryPoint: mainIdent, Events: []EventDebugInfo{}, } @@ -313,7 +315,7 @@ 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 { @@ -333,7 +335,7 @@ 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, diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 7059e1384..a277d451d 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -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,6 +178,7 @@ func TestSequencePoints(t *testing.T) { func TestDebugInfo_MarshalJSON(t *testing.T) { d := &DebugInfo{ + Hash: util.Uint160{10, 11, 12, 13}, EntryPoint: "main", Documents: []string{"/path/to/file"}, Methods: []MethodDebugInfo{