Skip to content

Commit

Permalink
native: support callflags-based native method after HFEchidna
Browse files Browse the repository at this point in the history
Close #3702

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Dec 19, 2024
1 parent 397aad0 commit f6b3dc0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/compiler/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,7 @@ func codeGen(info *buildInfo) (*nef.File, *DebugInfo, error) {
if c.callTokens != nil {
f.Tokens = c.callTokens
}
fmt.Println(f.Tokens)
f.Checksum = f.CalculateChecksum()
return f, di, vm.IsScriptCorrect(buf, methods)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/compiler/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
"github.com/nspcc-dev/neo-go/pkg/vm"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
Expand Down Expand Up @@ -277,7 +278,7 @@ func runNativeTestCases(t *testing.T, ctr interop.ContractMD, name string, nativ
for i, tc := range nativeTestCases {
addNativeTestCase(t, srcBuilder, ctr, i, name, tc.method, tc.params...)
}

fmt.Printf("srcBuilder: %v\n", srcBuilder)
ne, di, err := compiler.CompileWithOptions("file.go", strings.NewReader(srcBuilder.String()), nil)
require.NoError(t, err)

Expand Down Expand Up @@ -342,7 +343,8 @@ func runNativeTestCase(t *testing.T, b *nef.File, di *compiler.DebugInfo, ctr in
md := getMethod(t, ctr, method, params)
result := getTestStackItem(md.MD.ReturnType)
isVoid := md.MD.ReturnType == smartcontract.VoidType

b2 := md.RequiredFlags == callflag.States|callflag.AllowNotify
fmt.Printf("b2: %v\n", b2)
v := vm.New()
v.LoadToken = func(id int32) error {
t := b.Tokens[id]
Expand All @@ -359,6 +361,7 @@ func runNativeTestCase(t *testing.T, b *nef.File, di *compiler.DebugInfo, ctr in
return fmt.Errorf("wrong hasReturn %v", t.HasReturn)
}
if t.CallFlag != md.RequiredFlags {
fmt.Printf("t.CallFlag: %v\n", t.CallFlag)
return fmt.Errorf("wrong flags %v", t.CallFlag)
}
for range t.ParamCount {
Expand Down
15 changes: 12 additions & 3 deletions pkg/core/native/native_neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,27 @@ func newNEO(cfg config.ProtocolConfiguration) *NEO {

desc = newDescriptor("registerCandidate", smartcontract.BoolType,
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
md = newMethodAndPrice(n.registerCandidate, 0, callflag.States)
md = newMethodAndPrice(n.registerCandidate, 0, callflag.States, config.HFDefault, config.HFEchidna)
n.AddMethod(md, desc)

md = newMethodAndPrice(n.registerCandidate, 0, callflag.States|callflag.AllowNotify, config.HFEchidna)
n.AddMethod(md, desc)

desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States)
md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States, config.HFDefault, config.HFEchidna)
n.AddMethod(md, desc)

md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States|callflag.AllowNotify, config.HFEchidna)
n.AddMethod(md, desc)

desc = newDescriptor("vote", smartcontract.BoolType,
manifest.NewParameter("account", smartcontract.Hash160Type),
manifest.NewParameter("voteTo", smartcontract.PublicKeyType))
md = newMethodAndPrice(n.vote, 1<<16, callflag.States)
md = newMethodAndPrice(n.vote, 1<<16, callflag.States, config.HFDefault, config.HFEchidna)
n.AddMethod(md, desc)

md = newMethodAndPrice(n.vote, 1<<16, callflag.States|callflag.AllowNotify, config.HFEchidna)
n.AddMethod(md, desc)

desc = newDescriptor("getCandidates", smartcontract.ArrayType)
Expand Down

0 comments on commit f6b3dc0

Please sign in to comment.