compiler: specify safe methods in config

This commit is contained in:
Evgenii Stratonikov 2020-12-10 17:55:52 +03:00
parent d7194e4da5
commit 2341ae0c53
5 changed files with 16 additions and 1 deletions

View file

@ -363,6 +363,7 @@ func initSmartContract(ctx *cli.Context) error {
m := ProjectConfig{
Name: contractName,
SupportedStandards: []string{},
SafeMethods: []string{},
Events: []manifest.Event{
{
Name: "Hello world!",
@ -423,6 +424,7 @@ func contractCompile(ctx *cli.Context) error {
o.Name = conf.Name
o.ContractEvents = conf.Events
o.ContractSupportedStandards = conf.SupportedStandards
o.SafeMethods = conf.SafeMethods
}
result, err := compiler.CompileAndSave(src, o)
@ -646,6 +648,7 @@ func testInvokeScript(ctx *cli.Context) error {
// ProjectConfig contains project metadata.
type ProjectConfig struct {
Name string
SafeMethods []string
SupportedStandards []string
Events []manifest.Event
}

View file

@ -59,6 +59,7 @@ func RuntimeNotify(args []interface{}) {
require.NoError(t, err)
require.Equal(t,
`name: testContract
safemethods: []
supportedstandards: []
events:
- name: Hello world!

View file

@ -51,6 +51,9 @@ type Options struct {
// The list of standards supported by the contract.
ContractSupportedStandards []string
// SafeMethods contains list of methods which will be marked as safe in manifest.
SafeMethods []string
}
type buildInfo struct {

View file

@ -433,6 +433,12 @@ func (di *DebugInfo) ConvertToManifest(o *Options) (*manifest.Manifest, error) {
if err != nil {
return nil, err
}
for i := range o.SafeMethods {
if mMethod.Name == o.SafeMethods[i] {
mMethod.Safe = true
break
}
}
methods = append(methods, mMethod)
}
}

View file

@ -150,7 +150,7 @@ func _deploy(isUpdate bool) {}
}
t.Run("convert to Manifest", func(t *testing.T) {
actual, err := d.ConvertToManifest(&Options{Name: "MyCTR"})
actual, err := d.ConvertToManifest(&Options{Name: "MyCTR", SafeMethods: []string{"methodInt", "methodString"}})
require.NoError(t, err)
// note: offsets are hard to predict, so we just take them from the output
expected := &manifest.Manifest{
@ -183,12 +183,14 @@ func _deploy(isUpdate bool) {}
},
},
ReturnType: smartcontract.IntegerType,
Safe: true,
},
{
Name: "methodString",
Offset: 101,
Parameters: []manifest.Parameter{},
ReturnType: smartcontract.StringType,
Safe: true,
},
{
Name: "methodByteArray",