forked from TrueCloudLab/neoneo-go
parent
9d675f6e56
commit
4d07d72677
4 changed files with 17 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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,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,
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in a new issue