-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_test.go
More file actions
127 lines (107 loc) · 2.67 KB
/
basic_test.go
File metadata and controls
127 lines (107 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package chaintester
import (
"context"
"fmt"
"testing"
)
var ctx = context.Background()
func TestChainTester(t *testing.T) {
tester := NewChainTester()
info, _ := tester.GetInfo()
t.Logf("+++++++++info: %v", info.ToString())
key, err := tester.CreateKey()
if err != nil {
panic(err)
}
t.Logf("+++++++++key: %v", key.ToString())
privKey, _ := key.GetString("private")
t.Logf("+++++++++private key: %v", privKey)
pubKey, _ := key.GetString("public")
t.Logf("+++++++++public key: %v", pubKey)
_, err = tester.CreateAccount("hello", "helloworld33", pubKey, pubKey, 10*1024*1024, 10*10000, 10*10000)
if err != nil {
panic(err)
}
ret, _ := tester.GetAccount("helloworld33")
t.Logf("+++++++++account info: %v", ret.ToString())
tester.SetNativeApply("hello", nil)
err = tester.DeployContract("hello", "test/test.wasm", "test/test.abi")
if err != nil {
panic(err)
}
tester.ProduceBlock()
permissions := `
{
"hello": "active"
}
`
args := `
{
"name": "go"
}
`
ret, err = tester.PushAction("hello", "inc", args, permissions)
if err != nil {
panic(err)
}
tester.ProduceBlock()
sender := NewActionSender(tester)
sender.AddActionWithSigner("hello", "inc", args, "hello")
ret, err = sender.Send()
if err != nil {
panic(err)
}
// t.Logf("%v", ret.ToString())
ret, err = tester.GetTableRows(true, "hello", "", "counter", "", "", 10)
if err != nil {
panic(fmt.Errorf("++++++++error:%v", err))
}
t.Logf("%v", ret.ToString())
ret, err = tester.GetTableRows(true, "eosio.token", "hello", "accounts", "EOS", "", 1)
if err != nil {
panic(fmt.Errorf("++++++++error:%v", err))
}
balance, err := ret.GetString("rows", 0)
if err != nil {
panic(err)
}
t.Logf("++++++++++= balance: %s", balance)
ret, err = tester.PushAction("hello", "test", "", permissions)
if err != nil {
panic(err)
}
tester.ProduceBlock(10)
ret, err = tester.PushAction("hello", "test", "", permissions)
if err != nil {
panic(err)
}
tester.ProduceBlock()
t.Logf("+++++++balance of hello: %d", tester.GetBalance("hello"))
tester.SetNativeApply("hello", native_apply)
ret, err = tester.PushAction("hello", "test", "", permissions)
if err != nil {
panic(err)
}
tester.ProduceBlock()
}
func TestApplyCtx(t *testing.T) {
tester := NewChainTester()
defer tester.FreeChain()
tester.SetNativeApply("hello", native_apply)
tester.GetInfo()
{
defer func() {
err := recover()
if err == nil {
panic(fmt.Errorf("err should not be nil"))
}
t.Logf("++++%v", err)
}()
GetVMAPI().Prints(ctx, "hello, world!\n")
}
}
func native_apply(receiver uint64, firstReceiver uint64, action uint64) {
for i := 0; i < 10; i++ {
GetVMAPI().Prints(ctx, "hello, world!\n")
}
}