manifest: add Offset in method descriptor

This commit is contained in:
Evgenii Stratonikov 2020-07-23 16:12:41 +03:00
parent e52c39ae7e
commit a892e3ffa8
3 changed files with 13 additions and 3 deletions

View file

@ -270,6 +270,7 @@ func (m *MethodDebugInfo) ToManifestMethod() (manifest.Method, error) {
return result, err
}
result.Name = strings.ToLower(string(m.Name.Name[0])) + m.Name.Name[1:]
result.Offset = int(m.Range.Start)
result.Parameters = parameters
result.ReturnType = returnType
return result, nil

View file

@ -129,19 +129,22 @@ func unexportedMethod() int { return 1 }
t.Run("convert to Manifest", func(t *testing.T) {
actual, err := d.convertToManifest(smartcontract.HasStorage)
require.NoError(t, err)
// note: offsets are hard to predict, so we just take them from the output
expected := &manifest.Manifest{
ABI: manifest.ABI{
Hash: hash.Hash160(buf),
Methods: []manifest.Method{
{
Name: "main",
Name: "main",
Offset: 0,
Parameters: []manifest.Parameter{
manifest.NewParameter("op", smartcontract.StringType),
},
ReturnType: smartcontract.BoolType,
},
{
Name: "methodInt",
Name: "methodInt",
Offset: 66,
Parameters: []manifest.Parameter{
{
Name: "a",
@ -152,26 +155,31 @@ func unexportedMethod() int { return 1 }
},
{
Name: "methodString",
Offset: 97,
Parameters: []manifest.Parameter{},
ReturnType: smartcontract.StringType,
},
{
Name: "methodByteArray",
Offset: 103,
Parameters: []manifest.Parameter{},
ReturnType: smartcontract.ByteArrayType,
},
{
Name: "methodArray",
Offset: 108,
Parameters: []manifest.Parameter{},
ReturnType: smartcontract.ArrayType,
},
{
Name: "methodStruct",
Offset: 113,
Parameters: []manifest.Parameter{},
ReturnType: smartcontract.ArrayType,
},
{
Name: "methodConcat",
Name: "methodConcat",
Offset: 88,
Parameters: []manifest.Parameter{
{
Name: "a",

View file

@ -38,6 +38,7 @@ type groupAux struct {
// Method represents method's metadata.
type Method struct {
Name string `json:"name"`
Offset int `json:"offset"`
Parameters []Parameter `json:"parameters"`
ReturnType smartcontract.ParamType `json:"returntype"`
}