Compare commits
No commits in common. "master" and "dnw-add" have entirely different histories.
3 changed files with 33 additions and 128 deletions
|
@ -18,7 +18,12 @@ func GetNumber(key []byte) int {
|
||||||
if len(key) != keySize {
|
if len(key) != keySize {
|
||||||
panic("Invalid key size")
|
panic("Invalid key size")
|
||||||
}
|
}
|
||||||
|
// var num int
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
// it := storage.Find(ctx, 123, storage.ValuesOnly)
|
||||||
|
// for iterator.Next(it) {
|
||||||
|
// num = iterator.Value(it).(int)
|
||||||
|
// }
|
||||||
num := storage.Get(ctx, append([]byte{prefixNumber}, key...))
|
num := storage.Get(ctx, append([]byte{prefixNumber}, key...))
|
||||||
if num == nil {
|
if num == nil {
|
||||||
panic("Cannot get number")
|
panic("Cannot get number")
|
||||||
|
|
|
@ -4,11 +4,9 @@ go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/nspcc-dev/neo-go v0.101.3
|
github.com/nspcc-dev/neo-go v0.101.3
|
||||||
//github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace github.com/nspcc-dev/neo-go => /Users/ekaterina.lebedeva/neo-go-0.101.3/
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/benbjohnson/clock v1.1.0 // indirect
|
github.com/benbjohnson/clock v1.1.0 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
|
|
@ -4,17 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
_ "github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ctrPath = "../contract"
|
const ctrPath = "../contract"
|
||||||
|
@ -38,121 +36,14 @@ func TestContract_GetNumber(t *testing.T) {
|
||||||
inv.InvokeFail(t, "Cannot get number", "getNumber", validKey)
|
inv.InvokeFail(t, "Cannot get number", "getNumber", validKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Coverage struct {
|
|
||||||
Document string
|
|
||||||
MethodID string
|
|
||||||
StartLine int
|
|
||||||
StartCol int
|
|
||||||
EndLine int
|
|
||||||
EndCol int
|
|
||||||
Counter int
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestContract_PutNumber(t *testing.T) {
|
func TestContract_PutNumber(t *testing.T) {
|
||||||
e := newExecutor(t)
|
e := newExecutor(t)
|
||||||
ctrPutGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
ctrPutGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
||||||
e.DeployContract(t, ctrPutGetNum, nil)
|
e.DeployContract(t, ctrPutGetNum, nil)
|
||||||
di := ctrPutGetNum.DebugInfo
|
inv := e.CommitteeInvoker(ctrPutGetNum.Hash)
|
||||||
|
inv.Invoke(t, stackitem.Null{}, "putNumber", validKey, 42)
|
||||||
|
|
||||||
// Find contract.go doc
|
inv.Invoke(t, 42, "getNumber", validKey)
|
||||||
iDoc := len(di.Documents)
|
|
||||||
for i, cDoc := range di.Documents {
|
|
||||||
if strings.Contains(cDoc, "contract.go") {
|
|
||||||
iDoc = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if iDoc == len(di.Documents) {
|
|
||||||
fmt.Fprintf(os.Stderr, "No such file\n")
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get sequence points for current method
|
|
||||||
iPutMethod := len(di.Methods)
|
|
||||||
for i := 0; i < len(di.Methods); i++ {
|
|
||||||
if di.Methods[i].ID == "PutNumber" {
|
|
||||||
iPutMethod = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if iPutMethod == len(di.Methods) {
|
|
||||||
fmt.Fprintf(os.Stderr, "No \"PutNumber\" method in %s contract\n", ctrPutGetNum.Manifest.Name)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
//seqPoints := make([]compiler.DebugSeqPoint, len(di.Methods[iPutMethod].SeqPoints))
|
|
||||||
//copy(seqPoints, di.Methods[iPutMethod].SeqPoints)
|
|
||||||
var seqPoints []compiler.DebugSeqPoint
|
|
||||||
for _, curPoint := range di.Methods[iPutMethod].SeqPoints {
|
|
||||||
if curPoint.Document == iDoc {
|
|
||||||
seqPoints = append(seqPoints, curPoint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
spew.Dump(seqPoints)
|
|
||||||
|
|
||||||
ic, err := e.Chain.GetTestVM(trigger.Application, nil, nil)
|
|
||||||
require.NoError(t, err)
|
|
||||||
fmt.Println(ic.VM.SyscallHandler == nil)
|
|
||||||
|
|
||||||
ic.VM.LoadNEFMethod(ctrPutGetNum.NEF, ctrPutGetNum.Hash, ctrPutGetNum.Hash, callflag.All, false, 101, -1, nil)
|
|
||||||
ic.VM.Context().Estack().PushVal(2)
|
|
||||||
ic.VM.Context().Estack().PushVal(validKey)
|
|
||||||
|
|
||||||
fmt.Println("\nPrinting debug info for PutNumber:")
|
|
||||||
for !ic.VM.HasStopped() {
|
|
||||||
_, curInstr := ic.VM.Context().NextInstr()
|
|
||||||
for i := 0; i < len(seqPoints); i++ {
|
|
||||||
if int(curInstr) == seqPoints[i].Opcode {
|
|
||||||
fmt.Printf("%s: %d.%d, %d.%d hooray!!\n", di.Documents[iDoc], seqPoints[i].StartLine, seqPoints[i].StartCol, seqPoints[i].EndLine, seqPoints[i].EndCol)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//fmt.Println(nStr, " ", curInstr)
|
|
||||||
ic.VM.Step()
|
|
||||||
}
|
|
||||||
if ic.VM.HasFailed() {
|
|
||||||
//govm.SyscallHandler()
|
|
||||||
fmt.Fprintln(os.Stderr, "Something went wrong")
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
fmt.Println("\n Done printing!")
|
|
||||||
|
|
||||||
// e.DeployContract(t, ctrPutGetNum, nil)
|
|
||||||
// // inv := e.CommitteeInvoker(ctrPutGetNum.Hash)
|
|
||||||
// // inv.Invoke(t, stackitem.Null{}, "putNumber", validKey, 42)
|
|
||||||
// // inv.Invoke(t, 42, "getNumber", validKey)
|
|
||||||
|
|
||||||
// fmt.Println("\n I'm printing debug info for compiled file!")
|
|
||||||
// spew.Dump(ctrPutGetNum.DebugInfo)
|
|
||||||
// fmt.Println()
|
|
||||||
// //fmt.Println(json.MarshalIndent(ctrPutGetNum.Manifest, "", " "))
|
|
||||||
|
|
||||||
// govm := vm.New()
|
|
||||||
// govm.LoadNEFMethod(ctrPutGetNum.NEF, ctrPutGetNum.Hash, ctrPutGetNum.Hash, callflag.All, false, 101, -1, nil)
|
|
||||||
// fmt.Println("PrintOps:")
|
|
||||||
// govm.PrintOps(os.Stdout)
|
|
||||||
// govm.Context().Estack().PushVal(2)
|
|
||||||
// govm.Context().Estack().PushVal(validKey)
|
|
||||||
|
|
||||||
// fmt.Println("\nPrinting opcodes for PutNumber:")
|
|
||||||
// for !govm.HasStopped() {
|
|
||||||
// nStr, curInstr := govm.Context().NextInstr()
|
|
||||||
// fmt.Println(nStr, " ", curInstr)
|
|
||||||
// govm.Step()
|
|
||||||
// }
|
|
||||||
// if govm.HasFailed() {
|
|
||||||
// //govm.SyscallHandler()
|
|
||||||
// fmt.Fprintln(os.Stderr, "Something went wrong")
|
|
||||||
// t.FailNow()
|
|
||||||
// }
|
|
||||||
// govm.LoadNEFMethod(ctrPutGetNum.NEF, ctrPutGetNum.Hash, ctrPutGetNum.Hash, callflag.All, true, 0, -1, nil)
|
|
||||||
// govm.Context().Estack().PushVal(validKey)
|
|
||||||
// fmt.Println("\nPrinting opcodes for GetNumber:")
|
|
||||||
// for !govm.HasStopped() {
|
|
||||||
// nStr, curInstr := govm.Context().NextInstr()
|
|
||||||
// fmt.Println(nStr, " ", curInstr)
|
|
||||||
// govm.Step()
|
|
||||||
// }
|
|
||||||
// res := govm.Estack().Pop().Value()
|
|
||||||
// fmt.Println("\nresult = ", res)
|
|
||||||
// fmt.Println("\n Done printing!")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContract_InvalidKey(t *testing.T) {
|
func TestContract_InvalidKey(t *testing.T) {
|
||||||
|
@ -168,23 +59,31 @@ func TestContract_Add(t *testing.T) {
|
||||||
e := newExecutor(t)
|
e := newExecutor(t)
|
||||||
ctrAdd := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
ctrAdd := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
||||||
e.DeployContract(t, ctrAdd, nil)
|
e.DeployContract(t, ctrAdd, nil)
|
||||||
inv := e.CommitteeInvoker(ctrAdd.Hash)
|
spew.Dump(ctrAdd.Manifest)
|
||||||
inv.Invoke(t, 3, "add", 1, 2)
|
|
||||||
|
|
||||||
govm := vm.New()
|
govm := vm.New()
|
||||||
govm.LoadNEFMethod(ctrAdd.NEF, ctrAdd.Hash, ctrAdd.Hash, callflag.All, true, 170, -1, nil)
|
govm.LoadNEFMethod(ctrAdd.NEF, ctrAdd.Hash, ctrAdd.Hash, callflag.All, true, 170, -1, nil)
|
||||||
govm.Context().Estack().PushVal(1)
|
govm.Context().Estack().PushVal(1)
|
||||||
govm.Context().Estack().PushVal(2)
|
govm.Context().Estack().PushVal(3)
|
||||||
|
//fmt.Println(govm.Context().CurrInstr())
|
||||||
fmt.Println("\nPrinting opcodes:")
|
_, curInstr := govm.Context().CurrInstr()
|
||||||
for !govm.HasStopped() {
|
//while curInstr != RET do
|
||||||
nStr, curInstr := govm.Context().NextInstr()
|
for curInstr != 0x40 {
|
||||||
fmt.Println(nStr, " ", curInstr)
|
fmt.Println(curInstr)
|
||||||
govm.Step()
|
govm.Step()
|
||||||
|
_, curInstr = govm.Context().CurrInstr()
|
||||||
}
|
}
|
||||||
|
fmt.Println(govm.Context().CurrInstr())
|
||||||
|
|
||||||
res := govm.Estack().Pop().Value()
|
//govm.DumpEStack()
|
||||||
fmt.Println("\nresult = ", res)
|
//govm.Run()
|
||||||
|
res := govm.Context().Estack().Pop().Value()
|
||||||
|
fmt.Println(res)
|
||||||
|
|
||||||
|
// manif, _ := json.MarshalIndent(ctrAdd.Manifest, "", " ")
|
||||||
|
// fmt.Println(string(manif))
|
||||||
|
inv := e.CommitteeInvoker(ctrAdd.Hash)
|
||||||
|
inv.Invoke(t, 3, "add", 1, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
|
@ -195,10 +94,13 @@ func Test(t *testing.T) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
govm.PrintOps(os.Stdout)
|
govm.PrintOps(os.Stdout)
|
||||||
|
//step in a loop for debug
|
||||||
|
//
|
||||||
govm.Context().Jump(170)
|
govm.Context().Jump(170)
|
||||||
govm.Context().Estack().PushVal(1)
|
govm.Context().Estack().PushVal(1)
|
||||||
govm.Context().Estack().PushVal(2)
|
govm.Context().Estack().PushVal(2)
|
||||||
|
|
||||||
govm.Run()
|
govm.Run()
|
||||||
res := govm.Estack().Pop().Value()
|
res := govm.Context().Estack().Pop().Value()
|
||||||
fmt.Println(res)
|
fmt.Println(res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue