compiler: add ability to generate .abi.json file
A part of integration with NEO Blockchain Toolkit (see #902). To be able to deploy smart-contract compiled with neo-go compiler via NEO Express, we have to generate additional .abi.json file. This file contains the following information: - hash of the compiled contract - smart-contract metadata (title, description, version, author, email, has-storage, has-dynamic-invoke, is-payable) - smart-contract entry point - functions - events However, this .abi.json file is slightly different from the one, described in manifest.go, so we have to add auxilaury stractures for json marshalling. The .abi.json format used by NEO-Express is described [here](https://github.com/neo-project/neo-devpack-dotnet/blob/master/src/Neo.Compiler.MSIL/FuncExport.cs#L66).
This commit is contained in:
parent
ab7f2cb4fb
commit
2ec1d76320
4 changed files with 186 additions and 11 deletions
|
@ -3,7 +3,9 @@ package compiler
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"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/vm/opcode"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -113,6 +115,56 @@ func methodStruct() struct{} { return struct{}{} }
|
|||
require.True(t, int(index) < len(buf))
|
||||
require.EqualValues(t, opcode.RET, buf[index])
|
||||
}
|
||||
|
||||
t.Run("convert to ABI", func(t *testing.T) {
|
||||
author := "Joe"
|
||||
email := "Joe@ex.com"
|
||||
version := "1.0"
|
||||
title := "MyProj"
|
||||
description := "Description"
|
||||
actual := d.convertToABI(buf, &smartcontract.ContractDetails{
|
||||
Author: author,
|
||||
Email: email,
|
||||
Version: version,
|
||||
ProjectName: title,
|
||||
Description: description,
|
||||
HasStorage: true,
|
||||
HasDynamicInvocation: false,
|
||||
IsPayable: false,
|
||||
ReturnType: smartcontract.BoolType,
|
||||
Parameters: []smartcontract.ParamType{
|
||||
smartcontract.StringType,
|
||||
},
|
||||
})
|
||||
expected := ABI{
|
||||
Hash: hash.Hash160(buf),
|
||||
Metadata: Metadata{
|
||||
Author: author,
|
||||
Email: email,
|
||||
Version: version,
|
||||
Title: title,
|
||||
Description: description,
|
||||
HasStorage: true,
|
||||
HasDynamicInvocation: false,
|
||||
IsPayable: false,
|
||||
},
|
||||
EntryPoint: mainIdent,
|
||||
Functions: []Method{
|
||||
{
|
||||
Name: mainIdent,
|
||||
Parameters: []DebugParam{
|
||||
{
|
||||
Name: "op",
|
||||
Type: "String",
|
||||
},
|
||||
},
|
||||
ReturnType: "Boolean",
|
||||
},
|
||||
},
|
||||
Events: []Event{},
|
||||
}
|
||||
assert.Equal(t, expected, actual)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSequencePoints(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue