MCPcopy Create free account
hub / github.com/DNAProject/DNA / TestMap

Function TestMap

smartcontract/test/map_test.go:33–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestMap(t *testing.T) {
34 byteCode := []byte{
35 byte(neovm.NEWMAP),
36 byte(neovm.DUP), // dup map
37 byte(neovm.PUSH0), // key (index)
38 byte(neovm.PUSH0), // key (index)
39 byte(neovm.SETITEM),
40
41 byte(neovm.DUP), // dup map
42 byte(neovm.PUSH0), // key (index)
43 byte(neovm.PUSH1), // value (newItem)
44 byte(neovm.SETITEM),
45 }
46
47 // pick a value out
48 byteCode = append(byteCode,
49 []byte{ // extract element
50 byte(neovm.DUP), // dup map (items)
51 byte(neovm.PUSH0), // key (index)
52
53 byte(neovm.PICKITEM),
54 byte(neovm.JMPIF), // dup map (items)
55 0x04, 0x00, // skip a drop?
56 byte(neovm.DROP),
57 }...)
58
59 // count faults vs successful executions
60 N := 1024
61 faults := 0
62
63 //dbFile := "/tmp/test"
64 //os.RemoveAll(dbFile)
65 //testLevelDB, err := leveldbstore.NewLevelDBStore(dbFile)
66 //if err != nil {
67 // panic(err)
68 //}
69
70 for n := 0; n < N; n++ {
71 // Setup Execution Environment
72 //store := statestore.NewMemDatabase()
73 //testBatch := statestore.NewStateStoreBatch(store, testLevelDB)
74 config := &smartcontract.Config{
75 Time: 10,
76 Height: 10,
77 Tx: &types.Transaction{},
78 }
79 sc := smartcontract.SmartContract{
80 Config: config,
81 Gas: 100,
82 CacheDB: nil,
83 }
84 engine, err := sc.NewExecuteEngine(byteCode, types.InvokeNeo)
85
86 _, err = engine.Invoke()
87 if err != nil {
88 fmt.Println("err:", err)
89 faults += 1
90 }

Callers

nothing calls this directly

Calls 2

NewExecuteEngineMethod · 0.95
InvokeMethod · 0.65

Tested by

no test coverage detected