Skip to content

Commit

Permalink
smartcontract: remove contract features
Browse files Browse the repository at this point in the history
We're featureless now, all contracts have access to storage and payable status
is to be determined via new NEP. Follow neo-project/neo#2060.
  • Loading branch information
roman-khimov committed Nov 13, 2020
1 parent 112fa5b commit 286d918
Show file tree
Hide file tree
Showing 32 changed files with 36 additions and 187 deletions.
15 changes: 0 additions & 15 deletions cli/smartcontract/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ func contractCompile(ctx *cli.Context) error {
if err != nil {
return err
}
o.ContractFeatures = conf.GetFeatures()
o.ContractEvents = conf.Events
o.ContractSupportedStandards = conf.SupportedStandards
}
Expand Down Expand Up @@ -632,24 +631,10 @@ func testInvokeScript(ctx *cli.Context) error {

// ProjectConfig contains project metadata.
type ProjectConfig struct {
HasStorage bool
IsPayable bool
SupportedStandards []string
Events []manifest.Event
}

// GetFeatures returns smartcontract features from the config.
func (p *ProjectConfig) GetFeatures() smartcontract.PropertyState {
var fs smartcontract.PropertyState
if p.IsPayable {
fs |= smartcontract.IsPayable
}
if p.HasStorage {
fs |= smartcontract.HasStorage
}
return fs
}

func inspect(ctx *cli.Context) error {
in := ctx.String("in")
compile := ctx.Bool("compile")
Expand Down
13 changes: 1 addition & 12 deletions cli/smartcontract/smart_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ func RuntimeNotify(args []interface{}) {
manifest, err := ioutil.ReadFile(contractName + "/" + files[1].Name())
require.NoError(t, err)
require.Equal(t,
`hasstorage: false
ispayable: false
supportedstandards: []
`supportedstandards: []
events:
- name: Hello world!
parameters:
Expand All @@ -69,15 +67,6 @@ events:
`, string(manifest))
}

func TestGetFeatures(t *testing.T) {
cfg := ProjectConfig{
IsPayable: true,
HasStorage: true,
}
f := cfg.GetFeatures()
require.Equal(t, smartcontract.IsPayable|smartcontract.HasStorage, f)
}

func TestParseCosigner(t *testing.T) {
acc := util.Uint160{1, 3, 5, 7}
testCases := map[string]transaction.Signer{
Expand Down
1 change: 0 additions & 1 deletion cli/testdata/deploy/neo-go.yml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
hasstorage: true
2 changes: 1 addition & 1 deletion cli/testdata/verify.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"abi":{"hash":"0x8dff9f223e4622961f410c015dd37052a59892bb","methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean"}],"events":[]},"groups":[],"features":{"payable":true,"storage":false},"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"safemethods":[],"extra":null}
{"abi":{"hash":"0x8dff9f223e4622961f410c015dd37052a59892bb","methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean"}],"events":[]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"safemethods":[],"extra":null}
2 changes: 0 additions & 2 deletions docs/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ project:
version: 1.0
name: 'Smart contract'
description: 'Even smarter than Jack himself'
hasstorage: true
hasdynamicinvocation: false
ispayable: false
returntype: ByteArray
parameters: ['String', 'Array']
```
Expand Down
2 changes: 0 additions & 2 deletions examples/engine/engine.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
hasstorage: false
ispayable: false
supportedstandards: []
events:
- name: Tx
Expand Down
2 changes: 0 additions & 2 deletions examples/iterator/iterator.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
hasstorage: true
ispayable: false
supportedstandards: []
events:
- name: found storage values
Expand Down
2 changes: 0 additions & 2 deletions examples/runtime/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
hasstorage: false
ispayable: false
supportedstandards: []
events:
- name: Event
Expand Down
2 changes: 0 additions & 2 deletions examples/storage/storage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
hasstorage: true
ispayable: false
supportedstandards: []
events: []
2 changes: 0 additions & 2 deletions examples/timer/timer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
hasstorage: true
ispayable: false
supportedstandards: []
events: []
2 changes: 0 additions & 2 deletions examples/token-sale/token_sale.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
hasstorage: true
ispayable: false
supportedstandards: ["NEP-5"]
events: []
2 changes: 0 additions & 2 deletions examples/token/token.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
hasstorage: true
ispayable: false
supportedstandards: ["NEP-5"]
events:
- name: transfer
Expand Down
6 changes: 1 addition & 5 deletions pkg/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path"
"strings"

"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
"golang.org/x/tools/go/loader"
Expand All @@ -35,9 +34,6 @@ type Options struct {
// The name of the output for contract manifest file.
ManifestFile string

// Contract features.
ContractFeatures smartcontract.PropertyState

// Runtime notifications.
ContractEvents []manifest.Event

Expand Down Expand Up @@ -211,7 +207,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
}

if o.ManifestFile != "" {
m, err := di.ConvertToManifest(o.ContractFeatures, o.ContractEvents, o.ContractSupportedStandards...)
m, err := di.ConvertToManifest(o.ContractEvents, o.ContractSupportedStandards...)
if err != nil {
return b, fmt.Errorf("failed to convert debug info to manifest: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/compiler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func parsePairJSON(data []byte, sep string) (string, string, error) {

// ConvertToManifest converts contract to the manifest.Manifest struct for debugger.
// Note: manifest is taken from the external source, however it can be generated ad-hoc. See #1038.
func (di *DebugInfo) ConvertToManifest(fs smartcontract.PropertyState, events []manifest.Event, supportedStandards ...string) (*manifest.Manifest, error) {
func (di *DebugInfo) ConvertToManifest(events []manifest.Event, supportedStandards ...string) (*manifest.Manifest, error) {
if di.MainPkg == "" {
return nil, errors.New("no Main method was found")
}
Expand All @@ -425,7 +425,6 @@ func (di *DebugInfo) ConvertToManifest(fs smartcontract.PropertyState, events []
}

result := manifest.NewManifest(di.Hash)
result.Features = fs
if supportedStandards != nil {
result.SupportedStandards = supportedStandards
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/compiler/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func _deploy(isUpdate bool) {}
}

t.Run("convert to Manifest", func(t *testing.T) {
actual, err := d.ConvertToManifest(smartcontract.HasStorage, nil)
actual, err := d.ConvertToManifest(nil)
require.NoError(t, err)
// note: offsets are hard to predict, so we just take them from the output
expected := &manifest.Manifest{
Expand Down Expand Up @@ -244,8 +244,7 @@ func _deploy(isUpdate bool) {}
},
Events: []manifest.Event{},
},
Groups: []manifest.Group{},
Features: smartcontract.HasStorage,
Groups: []manifest.Group{},
Permissions: []manifest.Permission{
{
Contract: manifest.PermissionDesc{
Expand All @@ -266,7 +265,6 @@ func _deploy(isUpdate bool) {}
require.ElementsMatch(t, expected.ABI.Methods, actual.ABI.Methods)
require.Equal(t, expected.ABI.Events, actual.ABI.Events)
require.Equal(t, expected.Groups, actual.Groups)
require.Equal(t, expected.Features, actual.Features)
require.Equal(t, expected.Permissions, actual.Permissions)
require.Equal(t, expected.Trusts, actual.Trusts)
require.Equal(t, expected.SafeMethods, actual.SafeMethods)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestAppCall(t *testing.T) {

inner, di, err := compiler.CompileWithDebugInfo("foo.go", strings.NewReader(srcInner))
require.NoError(t, err)
m, err := di.ConvertToManifest(smartcontract.NoProperties, nil)
m, err := di.ConvertToManifest(nil)
require.NoError(t, err)

ih := hash.Hash160(inner)
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func newDeployTx(t *testing.T, name string) (*transaction.Transaction, []byte) {
t.Logf("contractScript: %x", avm)

script := io.NewBufBinWriter()
m, err := di.ConvertToManifest(smartcontract.HasStorage, nil)
m, err := di.ConvertToManifest(nil)
require.NoError(t, err)
bs, err := m.MarshalJSON()
require.NoError(t, err)
Expand Down
9 changes: 0 additions & 9 deletions pkg/core/interop_neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ func contractUpdate(ic *interop.Context) error {
if !contract.Manifest.IsValid(contract.ScriptHash()) {
return errors.New("failed to check contract script hash against new manifest")
}
if !contract.HasStorage() {
siMap, err := ic.DAO.GetStorageItems(contract.ID)
if err != nil {
return fmt.Errorf("failed to update manifest: %w", err)
}
if len(siMap) != 0 {
return errors.New("old contract shouldn't have storage")
}
}
if err := ic.DAO.PutContractState(contract); err != nil {
return fmt.Errorf("failed to update manifest: %w", err)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/core/interop_neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
Expand Down Expand Up @@ -295,7 +294,6 @@ func createVMAndPushTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interop
func createVMAndContractState(t *testing.T) (*vm.VM, *state.Contract, *interop.Context, *Blockchain) {
script := []byte("testscript")
m := manifest.NewManifest(hash.Hash160(script))
m.Features = smartcontract.HasStorage
contractState := &state.Contract{
Script: script,
Manifest: *m,
Expand Down
19 changes: 6 additions & 13 deletions pkg/core/interop_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ func contractToStackItem(cs *state.Contract) (stackitem.Item, error) {
return stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(cs.Script),
stackitem.NewByteArray(manifest),
stackitem.NewBool(cs.HasStorage()),
stackitem.NewBool(cs.IsPayable()),
}), nil
}

Expand Down Expand Up @@ -365,9 +363,6 @@ func storageGetContextInternal(ic *interop.Context, isReadOnly bool) error {
if err != nil {
return err
}
if !contract.HasStorage() {
return errors.New("contract is not allowed to use storage")
}
sc := &StorageContext{
ID: contract.ID,
ReadOnly: isReadOnly,
Expand Down Expand Up @@ -464,14 +459,12 @@ func contractDestroy(ic *interop.Context) error {
if err != nil {
return err
}
if cs.HasStorage() {
siMap, err := ic.DAO.GetStorageItems(cs.ID)
if err != nil {
return err
}
for k := range siMap {
_ = ic.DAO.DeleteStorageItem(cs.ID, []byte(k))
}
siMap, err := ic.DAO.GetStorageItems(cs.ID)
if err != nil {
return err
}
for k := range siMap {
_ = ic.DAO.DeleteStorageItem(cs.ID, []byte(k))
}
return nil
}
Expand Down
32 changes: 1 addition & 31 deletions pkg/core/interop_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ func getTestContractState() (*state.Contract, *state.Contract) {
script := w.Bytes()
h := hash.Hash160(script)
m := manifest.NewManifest(h)
m.Features = smartcontract.HasStorage
m.ABI.Methods = []manifest.Method{
{
Name: "add",
Expand Down Expand Up @@ -675,15 +674,9 @@ func compareContractStates(t *testing.T, expected *state.Contract, actual stacki
expectedManifest, err := expected.Manifest.MarshalJSON()
require.NoError(t, err)

require.Equal(t, 4, len(act))
require.Equal(t, 2, len(act))
require.Equal(t, expected.Script, act[0].Value().([]byte))
require.Equal(t, expectedManifest, act[1].Value().([]byte))
hasstorage, err := act[2].TryBool()
require.NoError(t, err)
ispayable, err := act[3].TryBool()
require.NoError(t, err)
require.Equal(t, expected.HasStorage(), hasstorage)
require.Equal(t, expected.IsPayable(), ispayable)
}

func TestContractUpdate(t *testing.T) {
Expand Down Expand Up @@ -813,34 +806,12 @@ func TestContractUpdate(t *testing.T) {
require.Error(t, contractUpdate(ic))
})

t.Run("update manifest, old contract shouldn't have storage", func(t *testing.T) {
cs.Manifest.Features |= smartcontract.HasStorage
require.NoError(t, ic.DAO.PutContractState(cs))
require.NoError(t, ic.DAO.PutStorageItem(cs.ID, []byte("my_item"), &state.StorageItem{
Value: []byte{1, 2, 3},
IsConst: false,
}))
v.LoadScriptWithHash([]byte{byte(opcode.RET)}, cs.ScriptHash(), smartcontract.All)
manifest := &manifest.Manifest{
ABI: manifest.ABI{
Hash: cs.ScriptHash(),
},
}
manifestBytes, err := manifest.MarshalJSON()
require.NoError(t, err)
putArgsOnStack(stackitem.Null{}, manifestBytes)

require.Error(t, contractUpdate(ic))
})

t.Run("update manifest, positive", func(t *testing.T) {
cs.Manifest.Features = smartcontract.NoProperties
require.NoError(t, ic.DAO.PutContractState(cs))
manifest := &manifest.Manifest{
ABI: manifest.ABI{
Hash: cs.ScriptHash(),
},
Features: smartcontract.HasStorage,
}
manifestBytes, err := manifest.MarshalJSON()
require.NoError(t, err)
Expand Down Expand Up @@ -875,7 +846,6 @@ func TestContractUpdate(t *testing.T) {
ABI: manifest.ABI{
Hash: hash.Hash160(newScript),
},
Features: smartcontract.HasStorage,
}
newManifestBytes, err := newManifest.MarshalJSON()
require.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion pkg/core/native/designate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func isValidRole(r Role) bool {
func newDesignate() *Designate {
s := &Designate{ContractMD: *interop.NewContractMD(designateName)}
s.ContractID = designateContractID
s.Manifest.Features = smartcontract.HasStorage

desc := newDescriptor("getDesignatedByRole", smartcontract.ArrayType,
manifest.NewParameter("role", smartcontract.IntegerType),
Expand Down
1 change: 0 additions & 1 deletion pkg/core/native/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func GetOracleResponseScript() []byte {
func newOracle() *Oracle {
o := &Oracle{ContractMD: *interop.NewContractMD(oracleName)}
o.ContractID = oracleContractID
o.Manifest.Features = smartcontract.HasStorage

desc := newDescriptor("request", smartcontract.VoidType,
manifest.NewParameter("url", smartcontract.StringType),
Expand Down
1 change: 0 additions & 1 deletion pkg/core/native/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func newPolicy() *Policy {
p := &Policy{ContractMD: *interop.NewContractMD(policyName)}

p.ContractID = policyContractID
p.Manifest.Features |= smartcontract.HasStorage

desc := newDescriptor("getMaxTransactionsPerBlock", smartcontract.IntegerType)
md := newMethodAndPrice(p.getMaxTransactionsPerBlock, 1000000, smartcontract.AllowStates)
Expand Down
1 change: 0 additions & 1 deletion pkg/core/native_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func getOracleContractState(h util.Uint160) *state.Contract {
emit.Opcodes(w.BinWriter, opcode.RET)

m := manifest.NewManifest(h)
m.Features = smartcontract.HasStorage
m.ABI.Methods = []manifest.Method{
{
Name: "requestURL",
Expand Down
Loading

0 comments on commit 286d918

Please sign in to comment.