Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
c2cd9285
Commit
c2cd9285
authored
Jan 12, 2019
by
vipwzw
Committed by
33cn
Jan 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix test
parent
4be69878
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
139 additions
and
65 deletions
+139
-65
evm_test.go
plugin/dapp/evm/executor/tests/evm_test.go
+1
-2
util_test.go
plugin/dapp/evm/executor/tests/util_test.go
+1
-1
const.go
plugin/dapp/js/executor/const.go
+8
-3
const_test.go
plugin/dapp/js/executor/const_test.go
+1
-0
js.go
plugin/dapp/js/executor/js.go
+23
-0
jsvm_test.go
plugin/dapp/js/executor/jsvm_test.go
+6
-1
rpc_test.go
plugin/dapp/js/executor/rpc_test.go
+3
-1
runtime.js
plugin/dapp/js/executor/runtime.js
+7
-3
test.js
plugin/dapp/js/executor/test.js
+1
-0
assettransfer_test.go
plugin/dapp/paracross/executor/assettransfer_test.go
+1
-1
assetwithdraw_test.go
plugin/dapp/paracross/executor/assetwithdraw_test.go
+1
-1
paracross_test.go
plugin/dapp/paracross/executor/paracross_test.go
+1
-1
relay_test.go
plugin/dapp/relay/executor/relay_test.go
+7
-7
relaydb_test.go
plugin/dapp/relay/executor/relaydb_test.go
+29
-29
ticketnum.go
plugin/dapp/ticket/executor/ticketnum.go
+14
-6
exec_test.go
plugin/dapp/unfreeze/executor/exec_test.go
+4
-4
proc.go
vendor/github.com/33cn/chain33/blockchain/proc.go
+1
-1
api.go
vendor/github.com/33cn/chain33/client/api/api.go
+1
-0
config.go
vendor/github.com/33cn/chain33/types/config.go
+14
-1
cfg.go
vendor/github.com/33cn/chain33/util/testnode/cfg.go
+0
-1
testnode.go
vendor/github.com/33cn/chain33/util/testnode/testnode.go
+10
-1
util.go
vendor/github.com/33cn/chain33/util/util.go
+5
-1
No files found.
plugin/dapp/evm/executor/tests/evm_test.go
View file @
c2cd9285
...
@@ -12,7 +12,6 @@ import (
...
@@ -12,7 +12,6 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"testing"
"testing"
"time"
"time"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
...
@@ -110,7 +109,7 @@ func runCase(tt *testing.T, c VMCase, file string) {
...
@@ -110,7 +109,7 @@ func runCase(tt *testing.T, c VMCase, file string) {
// 1 构建预置环境 pre
// 1 构建预置环境 pre
inst
:=
evm
.
NewEVMExecutor
()
inst
:=
evm
.
NewEVMExecutor
()
inst
.
SetEnv
(
c
.
env
.
currentNumber
,
c
.
env
.
currentTimestamp
,
uint64
(
c
.
env
.
currentDifficulty
))
inst
.
SetEnv
(
c
.
env
.
currentNumber
,
c
.
env
.
currentTimestamp
,
uint64
(
c
.
env
.
currentDifficulty
)
,
nil
,
nil
)
inst
.
CheckInit
()
inst
.
CheckInit
()
statedb
:=
inst
.
GetMStateDB
()
statedb
:=
inst
.
GetMStateDB
()
mdb
:=
createStateDB
(
statedb
,
c
)
mdb
:=
createStateDB
(
statedb
,
c
)
...
...
plugin/dapp/evm/executor/tests/util_test.go
View file @
c2cd9285
...
@@ -252,7 +252,7 @@ func createContract(mdb *db.GoMemDB, tx types.Transaction, maxCodeSize int) (ret
...
@@ -252,7 +252,7 @@ func createContract(mdb *db.GoMemDB, tx types.Transaction, maxCodeSize int) (ret
inst
.
CheckInit
()
inst
.
CheckInit
()
msg
,
_
:=
inst
.
GetMessage
(
&
tx
)
msg
,
_
:=
inst
.
GetMessage
(
&
tx
)
inst
.
SetEnv
(
10
,
0
,
uint64
(
10
))
inst
.
SetEnv
(
10
,
0
,
uint64
(
10
)
,
nil
,
nil
)
statedb
=
inst
.
GetMStateDB
()
statedb
=
inst
.
GetMStateDB
()
statedb
.
StateDB
=
mdb
statedb
.
StateDB
=
mdb
...
...
plugin/dapp/js/executor/const.go
View file @
c2cd9285
...
@@ -413,12 +413,16 @@ kvcreator.prototype.receipt = function() {
...
@@ -413,12 +413,16 @@ kvcreator.prototype.receipt = function() {
function GetExecName() {
function GetExecName() {
var exec = execname()
var exec = execname()
if (exec.err) {
throwerr(exec.err)
return ""
}
return exec.value
return exec.value
}
}
function GetRandnum() {
var n = randnum()
throwerr(n.err)
return n.value
}
function ExecAddress(name) {
function ExecAddress(name) {
var addr = execaddress(name)
var addr = execaddress(name)
if (addr.err) {
if (addr.err) {
...
@@ -521,6 +525,7 @@ function Init(context) {
...
@@ -521,6 +525,7 @@ function Init(context) {
this.context = context
this.context = context
this.kvc.add("action", "init")
this.kvc.add("action", "init")
this.kvc.add("context", this.context)
this.kvc.add("context", this.context)
this.kvc.add("randnum", GetRandnum())
return this.kvc.receipt()
return this.kvc.receipt()
}
}
...
...
plugin/dapp/js/executor/const_test.go
View file @
c2cd9285
...
@@ -7,6 +7,7 @@ function Init(context) {
...
@@ -7,6 +7,7 @@ function Init(context) {
this.context = context
this.context = context
this.kvc.add("action", "init")
this.kvc.add("action", "init")
this.kvc.add("context", this.context)
this.kvc.add("context", this.context)
this.kvc.add("randnum", GetRandnum())
return this.kvc.receipt()
return this.kvc.receipt()
}
}
...
...
plugin/dapp/js/executor/js.go
View file @
c2cd9285
...
@@ -3,9 +3,11 @@ package executor
...
@@ -3,9 +3,11 @@ package executor
import
(
import
(
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"fmt"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
drivers
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
...
@@ -114,6 +116,9 @@ func (u *js) callVM(prefix string, payload *jsproto.Call, tx *types.Transaction,
...
@@ -114,6 +116,9 @@ func (u *js) callVM(prefix string, payload *jsproto.Call, tx *types.Transaction,
vm
.
Set
(
"args"
,
payload
.
Args
)
vm
.
Set
(
"args"
,
payload
.
Args
)
callfunc
:=
"callcode(context, f, args, loglist)"
callfunc
:=
"callcode(context, f, args, loglist)"
jsvalue
,
err
:=
vm
.
Run
(
callfunc
)
jsvalue
,
err
:=
vm
.
Run
(
callfunc
)
if
u
.
GetExecutorAPI
()
.
IsErr
()
{
return
nil
,
api
.
ErrAPIEnv
}
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -229,6 +234,23 @@ func (u *js) execnameFunc(vm *otto.Otto, name string) {
...
@@ -229,6 +234,23 @@ func (u *js) execnameFunc(vm *otto.Otto, name string) {
})
})
}
}
func
(
u
*
js
)
randnumFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
vm
.
Set
(
"randnum"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
hash
:=
u
.
GetLastHash
()
fmt
.
Println
(
"-----randnum"
,
common
.
ToHex
(
hash
))
param
:=
&
types
.
ReqRandHash
{
ExecName
:
"ticket"
,
BlockNum
:
5
,
Hash
:
hash
,
}
randhash
,
err
:=
u
.
GetExecutorAPI
()
.
GetRandNum
(
param
)
if
err
!=
nil
{
return
errReturn
(
vm
,
err
)
}
return
okReturn
(
vm
,
common
.
ToHex
(
randhash
))
})
}
func
(
u
*
js
)
listdbFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
func
(
u
*
js
)
listdbFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
//List(prefix, key []byte, count, direction int32) ([][]byte, error)
//List(prefix, key []byte, count, direction int32) ([][]byte, error)
_
,
plocal
:=
calcAllPrefix
(
name
)
_
,
plocal
:=
calcAllPrefix
(
name
)
...
@@ -281,6 +303,7 @@ func (u *js) createVM(name string, tx *types.Transaction, index int) (*otto.Otto
...
@@ -281,6 +303,7 @@ func (u *js) createVM(name string, tx *types.Transaction, index int) (*otto.Otto
u
.
localdbFunc
(
vm
,
name
)
u
.
localdbFunc
(
vm
,
name
)
u
.
listdbFunc
(
vm
,
name
)
u
.
listdbFunc
(
vm
,
name
)
u
.
execnameFunc
(
vm
,
name
)
u
.
execnameFunc
(
vm
,
name
)
u
.
randnumFunc
(
vm
,
name
)
u
.
registerAccountFunc
(
vm
)
u
.
registerAccountFunc
(
vm
)
u
.
registerTableFunc
(
vm
,
name
)
u
.
registerTableFunc
(
vm
,
name
)
return
vm
,
nil
return
vm
,
nil
...
...
plugin/dapp/js/executor/jsvm_test.go
View file @
c2cd9285
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util"
...
@@ -16,6 +17,7 @@ import (
...
@@ -16,6 +17,7 @@ import (
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
"github.com/robertkrimen/otto"
"github.com/robertkrimen/otto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
)
func
init
()
{
func
init
()
{
...
@@ -24,7 +26,10 @@ func init() {
...
@@ -24,7 +26,10 @@ func init() {
func
initExec
(
ldb
db
.
DB
,
kvdb
db
.
KVDB
,
code
string
,
t
assert
.
TestingT
)
*
js
{
func
initExec
(
ldb
db
.
DB
,
kvdb
db
.
KVDB
,
code
string
,
t
assert
.
TestingT
)
*
js
{
e
:=
newjs
()
.
(
*
js
)
e
:=
newjs
()
.
(
*
js
)
e
.
SetEnv
(
1
,
time
.
Now
()
.
Unix
(),
1
)
e
.
SetEnv
(
1
,
time
.
Now
()
.
Unix
(),
1
,
nil
,
nil
)
mockapi
:=
&
mocks
.
QueueProtocolAPI
{}
mockapi
.
On
(
"Query"
,
"ticket"
,
"RandNumHash"
,
mock
.
Anything
)
.
Return
(
&
types
.
ReplyHash
{
Hash
:
[]
byte
(
"hello"
)},
nil
)
e
.
SetAPI
(
mockapi
)
e
.
SetLocalDB
(
kvdb
)
e
.
SetLocalDB
(
kvdb
)
e
.
SetStateDB
(
kvdb
)
e
.
SetStateDB
(
kvdb
)
c
,
tx
:=
createCodeTx
(
"test"
,
code
)
c
,
tx
:=
createCodeTx
(
"test"
,
code
)
...
...
plugin/dapp/js/executor/rpc_test.go
View file @
c2cd9285
...
@@ -25,7 +25,9 @@ func init() {
...
@@ -25,7 +25,9 @@ func init() {
}
}
func
TestJsVM
(
t
*
testing
.
T
)
{
func
TestJsVM
(
t
*
testing
.
T
)
{
mocker
:=
testnode
.
New
(
"--free--"
,
nil
)
cfg
,
sub
:=
testnode
.
GetDefaultConfig
()
cfg
.
Consensus
.
Name
=
"ticket"
mocker
:=
testnode
.
NewWithConfig
(
cfg
,
sub
,
nil
)
defer
mocker
.
Close
()
defer
mocker
.
Close
()
mocker
.
Listen
()
mocker
.
Listen
()
//开始部署合约, 测试阶段任何人都可以部署合约
//开始部署合约, 测试阶段任何人都可以部署合约
...
...
plugin/dapp/js/executor/runtime.js
View file @
c2cd9285
...
@@ -410,12 +410,16 @@ kvcreator.prototype.receipt = function() {
...
@@ -410,12 +410,16 @@ kvcreator.prototype.receipt = function() {
function
GetExecName
()
{
function
GetExecName
()
{
var
exec
=
execname
()
var
exec
=
execname
()
if
(
exec
.
err
)
{
throwerr
(
exec
.
err
)
return
""
}
return
exec
.
value
return
exec
.
value
}
}
function
GetRandnum
()
{
var
n
=
randnum
()
throwerr
(
n
.
err
)
return
n
.
value
}
function
ExecAddress
(
name
)
{
function
ExecAddress
(
name
)
{
var
addr
=
execaddress
(
name
)
var
addr
=
execaddress
(
name
)
if
(
addr
.
err
)
{
if
(
addr
.
err
)
{
...
...
plugin/dapp/js/executor/test.js
View file @
c2cd9285
...
@@ -4,6 +4,7 @@ function Init(context) {
...
@@ -4,6 +4,7 @@ function Init(context) {
this
.
context
=
context
this
.
context
=
context
this
.
kvc
.
add
(
"action"
,
"init"
)
this
.
kvc
.
add
(
"action"
,
"init"
)
this
.
kvc
.
add
(
"context"
,
this
.
context
)
this
.
kvc
.
add
(
"context"
,
this
.
context
)
this
.
kvc
.
add
(
"randnum"
,
GetRandnum
())
return
this
.
kvc
.
receipt
()
return
this
.
kvc
.
receipt
()
}
}
...
...
plugin/dapp/paracross/executor/assettransfer_test.go
View file @
c2cd9285
...
@@ -54,7 +54,7 @@ func (suite *AssetTransferTestSuite) SetupTest() {
...
@@ -54,7 +54,7 @@ func (suite *AssetTransferTestSuite) SetupTest() {
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
,
nil
,
nil
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
true
enableParacrossTransfer
=
true
...
...
plugin/dapp/paracross/executor/assetwithdraw_test.go
View file @
c2cd9285
...
@@ -49,7 +49,7 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
...
@@ -49,7 +49,7 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
,
nil
,
nil
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
true
enableParacrossTransfer
=
true
...
...
plugin/dapp/paracross/executor/paracross_test.go
View file @
c2cd9285
...
@@ -102,7 +102,7 @@ func (suite *CommitTestSuite) SetupSuite() {
...
@@ -102,7 +102,7 @@ func (suite *CommitTestSuite) SetupSuite() {
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
,
nil
,
nil
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
false
enableParacrossTransfer
=
false
...
...
plugin/dapp/relay/executor/relay_test.go
View file @
c2cd9285
...
@@ -72,7 +72,7 @@ func (s *suiteRelay) SetupSuite() {
...
@@ -72,7 +72,7 @@ func (s *suiteRelay) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
accDb
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -139,7 +139,7 @@ func (s *suiteRelay) TestExec_1() {
...
@@ -139,7 +139,7 @@ func (s *suiteRelay) TestExec_1() {
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -180,7 +180,7 @@ func (s *suiteRelay) TestExec_2() {
...
@@ -180,7 +180,7 @@ func (s *suiteRelay) TestExec_2() {
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
,
nil
,
nil
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
...
@@ -216,7 +216,7 @@ func (s *suiteRelay) TestExec_3() {
...
@@ -216,7 +216,7 @@ func (s *suiteRelay) TestExec_3() {
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
,
nil
,
nil
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
receipt
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
...
@@ -287,7 +287,7 @@ func (s *suiteRelay) TestExec_4() {
...
@@ -287,7 +287,7 @@ func (s *suiteRelay) TestExec_4() {
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
,
nil
,
nil
)
_
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
_
,
err
:=
s
.
relay
.
Exec
(
tx
,
0
)
s
.
Nil
(
err
)
s
.
Nil
(
err
)
...
@@ -404,7 +404,7 @@ func (s *suiteBtcHeader) SetupSuite() {
...
@@ -404,7 +404,7 @@ func (s *suiteBtcHeader) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
s
.
db
)
relay
.
SetStateDB
(
s
.
db
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -515,7 +515,7 @@ func (s *suiteBtcHeader) TestSaveBtcHead_1() {
...
@@ -515,7 +515,7 @@ func (s *suiteBtcHeader) TestSaveBtcHead_1() {
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Payload
=
types
.
Encode
(
sell
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
db
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
nil
,
types
.
ErrNotFound
)
.
Once
()
s
.
db
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
nil
,
types
.
ErrNotFound
)
.
Once
()
s
.
db
.
On
(
"Set"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
nil
)
.
Once
()
s
.
db
.
On
(
"Set"
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
nil
)
.
Once
()
...
...
plugin/dapp/relay/executor/relaydb_test.go
View file @
c2cd9285
...
@@ -152,7 +152,7 @@ func (s *suiteRelayDB) SetupSuite() {
...
@@ -152,7 +152,7 @@ func (s *suiteRelayDB) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
accDb
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -175,7 +175,7 @@ func (s *suiteRelayDB) TestRelayCreate_1() {
...
@@ -175,7 +175,7 @@ func (s *suiteRelayDB) TestRelayCreate_1() {
tx
.
Nonce
=
1
//for different order id
tx
.
Nonce
=
1
//for different order id
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -207,7 +207,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1aUnlock() {
...
@@ -207,7 +207,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1aUnlock() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -228,7 +228,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1bCancel() {
...
@@ -228,7 +228,7 @@ func (s *suiteRelayDB) TestRevokeCreate_1bCancel() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -308,7 +308,7 @@ func (s *suiteAccept) setupRelayCreate() {
...
@@ -308,7 +308,7 @@ func (s *suiteAccept) setupRelayCreate() {
tx
.
Nonce
=
2
//for different order id
tx
.
Nonce
=
2
//for different order id
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -335,7 +335,7 @@ func (s *suiteAccept) SetupSuite() {
...
@@ -335,7 +335,7 @@ func (s *suiteAccept) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
accDb
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -356,7 +356,7 @@ func (s *suiteAccept) TestRelayAccept() {
...
@@ -356,7 +356,7 @@ func (s *suiteAccept) TestRelayAccept() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -387,7 +387,7 @@ func (s *suiteAccept) TestRevokeAccept_1() {
...
@@ -387,7 +387,7 @@ func (s *suiteAccept) TestRevokeAccept_1() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
22
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
22
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -408,7 +408,7 @@ func (s *suiteAccept) TestRevokeAccept_2() {
...
@@ -408,7 +408,7 @@ func (s *suiteAccept) TestRevokeAccept_2() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -429,7 +429,7 @@ func (s *suiteAccept) TestRevokeAccept_3() {
...
@@ -429,7 +429,7 @@ func (s *suiteAccept) TestRevokeAccept_3() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
)
s
.
relay
.
SetEnv
(
11
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
+
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -506,7 +506,7 @@ func (s *suiteConfirm) setupRelayCreate() {
...
@@ -506,7 +506,7 @@ func (s *suiteConfirm) setupRelayCreate() {
tx
.
Nonce
=
3
//for different order id
tx
.
Nonce
=
3
//for different order id
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -533,7 +533,7 @@ func (s *suiteConfirm) SetupSuite() {
...
@@ -533,7 +533,7 @@ func (s *suiteConfirm) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
accDb
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -555,7 +555,7 @@ func (s *suiteConfirm) setupAccept() {
...
@@ -555,7 +555,7 @@ func (s *suiteConfirm) setupAccept() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -586,7 +586,7 @@ func (s *suiteConfirm) TestConfirm_1() {
...
@@ -586,7 +586,7 @@ func (s *suiteConfirm) TestConfirm_1() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
_
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
_
,
err
:=
s
.
relayDb
.
confirmTx
(
order
)
s
.
Equal
(
ty
.
ErrRelayReturnAddr
,
err
)
s
.
Equal
(
ty
.
ErrRelayReturnAddr
,
err
)
...
@@ -604,7 +604,7 @@ func (s *suiteConfirm) TestConfirm_2() {
...
@@ -604,7 +604,7 @@ func (s *suiteConfirm) TestConfirm_2() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -635,7 +635,7 @@ func (s *suiteConfirm) TestRevokeConfirm_1() {
...
@@ -635,7 +635,7 @@ func (s *suiteConfirm) TestRevokeConfirm_1() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -656,7 +656,7 @@ func (s *suiteConfirm) TestRevokeConfirm_2() {
...
@@ -656,7 +656,7 @@ func (s *suiteConfirm) TestRevokeConfirm_2() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
4
*
lockBtcHeight
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
+
4
*
lockBtcHeight
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -733,7 +733,7 @@ func (s *suiteVerify) setupRelayCreate() {
...
@@ -733,7 +733,7 @@ func (s *suiteVerify) setupRelayCreate() {
tx
.
Nonce
=
4
//for different order id
tx
.
Nonce
=
4
//for different order id
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -764,7 +764,7 @@ func (s *suiteVerify) setupAccept() {
...
@@ -764,7 +764,7 @@ func (s *suiteVerify) setupAccept() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -795,7 +795,7 @@ func (s *suiteVerify) setupConfirm() {
...
@@ -795,7 +795,7 @@ func (s *suiteVerify) setupConfirm() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -822,7 +822,7 @@ func (s *suiteVerify) SetupSuite() {
...
@@ -822,7 +822,7 @@ func (s *suiteVerify) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
accDb
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -880,7 +880,7 @@ func (s *suiteVerify) TestVerify() {
...
@@ -880,7 +880,7 @@ func (s *suiteVerify) TestVerify() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
receipt
,
err
:=
s
.
relayDb
.
verifyTx
(
order
)
receipt
,
err
:=
s
.
relayDb
.
verifyTx
(
order
)
...
@@ -964,7 +964,7 @@ func (s *suiteVerifyCli) setupRelayCreate() {
...
@@ -964,7 +964,7 @@ func (s *suiteVerifyCli) setupRelayCreate() {
tx
.
Nonce
=
5
//for different order id
tx
.
Nonce
=
5
//for different order id
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
)
s
.
relay
.
SetEnv
(
10
,
1000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
10
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -995,7 +995,7 @@ func (s *suiteVerifyCli) setupAccept() {
...
@@ -995,7 +995,7 @@ func (s *suiteVerifyCli) setupAccept() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
)
s
.
relay
.
SetEnv
(
20
,
2000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
20
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -1026,7 +1026,7 @@ func (s *suiteVerifyCli) setupConfirm() {
...
@@ -1026,7 +1026,7 @@ func (s *suiteVerifyCli) setupConfirm() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
)
s
.
relay
.
SetEnv
(
30
,
3000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
heightBytes
:=
types
.
Encode
(
&
types
.
Int64
{
Data
:
int64
(
30
)})
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
s
.
kvdb
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
heightBytes
,
nil
)
.
Once
()
...
@@ -1053,7 +1053,7 @@ func (s *suiteVerifyCli) SetupSuite() {
...
@@ -1053,7 +1053,7 @@ func (s *suiteVerifyCli) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
accDb
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -1085,7 +1085,7 @@ func (s *suiteVerifyCli) TestVerify() {
...
@@ -1085,7 +1085,7 @@ func (s *suiteVerifyCli) TestVerify() {
tx
.
To
=
s
.
addrRelay
tx
.
To
=
s
.
addrRelay
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
tx
.
Sign
(
types
.
SECP256K1
,
privTo
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
receipt
,
err
:=
s
.
relayDb
.
verifyCmdTx
(
order
)
receipt
,
err
:=
s
.
relayDb
.
verifyCmdTx
(
order
)
...
@@ -1128,7 +1128,7 @@ func (s *suiteSaveBtcHeader) SetupSuite() {
...
@@ -1128,7 +1128,7 @@ func (s *suiteSaveBtcHeader) SetupSuite() {
relay
:=
&
relay
{}
relay
:=
&
relay
{}
relay
.
SetStateDB
(
s
.
db
)
relay
.
SetStateDB
(
s
.
db
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetEnv
(
10
,
100
,
1
,
nil
,
nil
)
relay
.
SetIsFree
(
false
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetChild
(
relay
)
...
@@ -1138,7 +1138,7 @@ func (s *suiteSaveBtcHeader) SetupSuite() {
...
@@ -1138,7 +1138,7 @@ func (s *suiteSaveBtcHeader) SetupSuite() {
tx
.
To
=
"addr"
tx
.
To
=
"addr"
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
tx
.
Sign
(
types
.
SECP256K1
,
privFrom
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
)
s
.
relay
.
SetEnv
(
40
,
4000
,
1
,
nil
,
nil
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
s
.
relayDb
=
newRelayDB
(
s
.
relay
,
tx
)
}
}
...
...
plugin/dapp/ticket/executor/ticketnum.go
View file @
c2cd9285
...
@@ -19,7 +19,7 @@ const (
...
@@ -19,7 +19,7 @@ const (
// GetRandNum for ticket executor
// GetRandNum for ticket executor
func
(
ticket
*
Ticket
)
GetRandNum
(
blockHash
[]
byte
,
blockNum
int64
)
(
types
.
Message
,
error
)
{
func
(
ticket
*
Ticket
)
GetRandNum
(
blockHash
[]
byte
,
blockNum
int64
)
(
types
.
Message
,
error
)
{
tlog
.
Debug
(
"GetRandNum"
,
"blockHash"
,
blockHash
,
"blockNum"
,
blockNum
)
tlog
.
Debug
(
"GetRandNum"
,
"blockHash"
,
common
.
ToHex
(
blockHash
)
,
"blockNum"
,
blockNum
)
if
blockNum
<
minBlockNum
{
if
blockNum
<
minBlockNum
{
blockNum
=
minBlockNum
blockNum
=
minBlockNum
...
@@ -35,6 +35,11 @@ func (ticket *Ticket) GetRandNum(blockHash []byte, blockNum int64) (types.Messag
...
@@ -35,6 +35,11 @@ func (ticket *Ticket) GetRandNum(blockHash []byte, blockNum int64) (types.Messag
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
//如果是genesis block 那么直接返回一个固定值,防止测试的时候出错
if
txActions
==
nil
&&
err
==
nil
{
modify
:=
common
.
Sha256
([]
byte
(
"hello"
))
return
&
types
.
ReplyHash
{
Hash
:
modify
},
nil
}
var
modifies
[]
byte
var
modifies
[]
byte
var
bits
uint32
var
bits
uint32
var
ticketIds
string
var
ticketIds
string
...
@@ -59,7 +64,7 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
...
@@ -59,7 +64,7 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
var
txActions
[]
*
tickettypes
.
TicketAction
var
txActions
[]
*
tickettypes
.
TicketAction
var
reqHashes
types
.
ReqHashes
var
reqHashes
types
.
ReqHashes
currHash
:=
blockHash
currHash
:=
blockHash
tlog
.
Debug
(
"getTxActions"
,
"blockHash"
,
blockHash
,
"blockNum"
,
blockNum
)
tlog
.
Debug
(
"getTxActions"
,
"blockHash"
,
common
.
ToHex
(
blockHash
)
,
"blockNum"
,
blockNum
)
//根据blockHash,查询block,循环blockNum
//根据blockHash,查询block,循环blockNum
for
blockNum
>
0
{
for
blockNum
>
0
{
...
@@ -69,22 +74,26 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
...
@@ -69,22 +74,26 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
if
err
!=
nil
{
if
err
!=
nil
{
return
txActions
,
err
return
txActions
,
err
}
}
if
tempBlock
.
Head
.
Height
<=
0
{
return
nil
,
nil
}
reqHashes
.
Hashes
=
append
(
reqHashes
.
Hashes
,
currHash
)
reqHashes
.
Hashes
=
append
(
reqHashes
.
Hashes
,
currHash
)
currHash
=
tempBlock
.
Head
.
ParentHash
currHash
=
tempBlock
.
Head
.
ParentHash
if
tempBlock
.
Head
.
Height
<
0
&&
blockNum
>
1
{
if
tempBlock
.
Head
.
Height
<
0
&&
blockNum
>
1
{
return
txActions
,
types
.
ErrBlockNotFound
return
txActions
,
types
.
ErrBlockNotFound
}
}
if
tempBlock
.
Head
.
Height
<=
1
{
break
}
blockNum
--
blockNum
--
}
}
blockDetails
,
err
:=
ticket
.
GetAPI
()
.
GetBlockByHashes
(
&
reqHashes
)
blockDetails
,
err
:=
ticket
.
GetAPI
()
.
GetBlockByHashes
(
&
reqHashes
)
if
err
!=
nil
{
if
err
!=
nil
{
tlog
.
Error
(
"getTxActions"
,
"blockHash"
,
blockHash
,
"blockNum"
,
blockNum
,
"err"
,
err
)
tlog
.
Error
(
"getTxActions"
,
"blockHash"
,
blockHash
,
"blockNum"
,
blockNum
,
"err"
,
err
)
return
txActions
,
err
return
txActions
,
err
}
}
for
_
,
block
:=
range
blockDetails
.
Items
{
for
_
,
block
:=
range
blockDetails
.
Items
{
tlog
.
Debug
(
"getTxActions"
,
"blockHeight"
,
block
.
Block
.
Height
,
"blockhash"
,
block
.
Block
.
Hash
(
))
tlog
.
Debug
(
"getTxActions"
,
"blockHeight"
,
block
.
Block
.
Height
,
"blockhash"
,
common
.
ToHex
(
block
.
Block
.
Hash
()
))
ticketAction
,
err
:=
ticket
.
getMinerTx
(
block
.
Block
)
ticketAction
,
err
:=
ticket
.
getMinerTx
(
block
.
Block
)
if
err
!=
nil
{
if
err
!=
nil
{
return
txActions
,
err
return
txActions
,
err
...
@@ -92,7 +101,6 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
...
@@ -92,7 +101,6 @@ func (ticket *Ticket) getTxActions(blockHash []byte, blockNum int64) ([]*tickett
txActions
=
append
(
txActions
,
ticketAction
)
txActions
=
append
(
txActions
,
ticketAction
)
}
}
return
txActions
,
nil
return
txActions
,
nil
}
}
func
(
ticket
*
Ticket
)
getMinerTx
(
current
*
types
.
Block
)
(
*
tickettypes
.
TicketAction
,
error
)
{
func
(
ticket
*
Ticket
)
getMinerTx
(
current
*
types
.
Block
)
(
*
tickettypes
.
TicketAction
,
error
)
{
...
...
plugin/dapp/unfreeze/executor/exec_test.go
View file @
c2cd9285
...
@@ -90,7 +90,7 @@ func TestUnfreeze(t *testing.T) {
...
@@ -90,7 +90,7 @@ func TestUnfreeze(t *testing.T) {
}
}
exec
:=
newUnfreeze
()
exec
:=
newUnfreeze
()
exec
.
SetStateDB
(
stateDB
)
exec
.
SetStateDB
(
stateDB
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
,
nil
,
nil
)
receipt
,
err
:=
exec
.
Exec
(
createTx
,
int
(
1
))
receipt
,
err
:=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
assert
.
NotNil
(
t
,
receipt
)
...
@@ -117,7 +117,7 @@ func TestUnfreeze(t *testing.T) {
...
@@ -117,7 +117,7 @@ func TestUnfreeze(t *testing.T) {
t
.
Error
(
"RPC_UnfreezeWithdrawTx sign"
,
"err"
,
err
)
t
.
Error
(
"RPC_UnfreezeWithdrawTx sign"
,
"err"
,
err
)
}
}
blockTime
:=
int64
(
10
)
blockTime
:=
int64
(
10
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
blockTime
,
env
.
difficulty
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
blockTime
,
env
.
difficulty
,
nil
,
nil
)
receipt
,
err
=
exec
.
Exec
(
withdrawTx
,
1
)
receipt
,
err
=
exec
.
Exec
(
withdrawTx
,
1
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
assert
.
NotNil
(
t
,
receipt
)
...
@@ -151,7 +151,7 @@ func TestUnfreeze(t *testing.T) {
...
@@ -151,7 +151,7 @@ func TestUnfreeze(t *testing.T) {
t
.
Error
(
"RPC_UnfreezeWithdrawTx sign"
,
"err"
,
err
)
t
.
Error
(
"RPC_UnfreezeWithdrawTx sign"
,
"err"
,
err
)
}
}
blockTime
:=
int64
(
10
)
blockTime
:=
int64
(
10
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
blockTime
,
env
.
difficulty
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
blockTime
,
env
.
difficulty
,
nil
,
nil
)
receipt
,
err
=
exec
.
Exec
(
withdrawTx
,
1
)
receipt
,
err
=
exec
.
Exec
(
withdrawTx
,
1
)
assert
.
Equal
(
t
,
pty
.
ErrNoPrivilege
,
err
)
assert
.
Equal
(
t
,
pty
.
ErrNoPrivilege
,
err
)
assert
.
Nil
(
t
,
receipt
)
assert
.
Nil
(
t
,
receipt
)
...
@@ -214,7 +214,7 @@ func TestUnfreeze(t *testing.T) {
...
@@ -214,7 +214,7 @@ func TestUnfreeze(t *testing.T) {
t
.
Error
(
"RPC_UnfreezeWithdrawTx sign"
,
"err"
,
err
)
t
.
Error
(
"RPC_UnfreezeWithdrawTx sign"
,
"err"
,
err
)
}
}
blockTime
:=
int64
(
10
)
blockTime
:=
int64
(
10
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
blockTime
+
blockTime
,
env
.
difficulty
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
blockTime
+
blockTime
,
env
.
difficulty
,
nil
,
nil
)
receipt
,
err
=
exec
.
Exec
(
withdrawTx
,
1
)
receipt
,
err
=
exec
.
Exec
(
withdrawTx
,
1
)
assert
.
Equal
(
t
,
pty
.
ErrUnfreezeEmptied
,
err
)
assert
.
Equal
(
t
,
pty
.
ErrUnfreezeEmptied
,
err
)
assert
.
Nil
(
t
,
receipt
)
assert
.
Nil
(
t
,
receipt
)
...
...
vendor/github.com/33cn/chain33/blockchain/proc.go
View file @
c2cd9285
...
@@ -230,7 +230,7 @@ func (chain *BlockChain) getLastHeader(msg queue.Message) {
...
@@ -230,7 +230,7 @@ func (chain *BlockChain) getLastHeader(msg queue.Message) {
func
(
chain
*
BlockChain
)
addBlockDetail
(
msg
queue
.
Message
)
{
func
(
chain
*
BlockChain
)
addBlockDetail
(
msg
queue
.
Message
)
{
blockDetail
:=
msg
.
Data
.
(
*
types
.
BlockDetail
)
blockDetail
:=
msg
.
Data
.
(
*
types
.
BlockDetail
)
Height
:=
blockDetail
.
Block
.
Height
Height
:=
blockDetail
.
Block
.
Height
chainlog
.
Info
(
"EventAddBlockDetail"
,
"height"
,
blockDetail
.
Block
.
Height
,
"
hash"
,
common
.
HashHex
(
blockDetail
.
Block
.
Hash
()
))
chainlog
.
Info
(
"EventAddBlockDetail"
,
"height"
,
blockDetail
.
Block
.
Height
,
"
parent"
,
common
.
ToHex
(
blockDetail
.
Block
.
ParentHash
))
//首先判断共识过来的block的parenthash是否是当前bestchain链的tip区块,如果不是就直接返回错误给共识模块
//首先判断共识过来的block的parenthash是否是当前bestchain链的tip区块,如果不是就直接返回错误给共识模块
blockDetail
,
err
:=
chain
.
ProcAddBlockMsg
(
true
,
blockDetail
,
"self"
)
blockDetail
,
err
:=
chain
.
ProcAddBlockMsg
(
true
,
blockDetail
,
"self"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
vendor/github.com/33cn/chain33/client/api/api.go
View file @
c2cd9285
...
@@ -87,6 +87,7 @@ func newParaChainAPI(api client.QueueProtocolAPI, grpcaddr string) ExecutorAPI {
...
@@ -87,6 +87,7 @@ func newParaChainAPI(api client.QueueProtocolAPI, grpcaddr string) ExecutorAPI {
if
paraRemoteGrpcClient
==
""
{
if
paraRemoteGrpcClient
==
""
{
paraRemoteGrpcClient
=
"127.0.0.1:8002"
paraRemoteGrpcClient
=
"127.0.0.1:8002"
}
}
println
(
"------"
,
paraRemoteGrpcClient
)
conn
,
err
:=
grpc
.
Dial
(
paraRemoteGrpcClient
,
grpc
.
WithInsecure
())
conn
,
err
:=
grpc
.
Dial
(
paraRemoteGrpcClient
,
grpc
.
WithInsecure
())
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
vendor/github.com/33cn/chain33/types/config.go
View file @
c2cd9285
...
@@ -217,8 +217,10 @@ func S(key string, value interface{}) {
...
@@ -217,8 +217,10 @@ func S(key string, value interface{}) {
mu
.
Lock
()
mu
.
Lock
()
defer
mu
.
Unlock
()
defer
mu
.
Unlock
()
if
strings
.
HasPrefix
(
key
,
"config."
)
{
if
strings
.
HasPrefix
(
key
,
"config."
)
{
if
isLocal
()
{
if
!
isLocal
()
{
//only local can modify for test
panic
(
"prefix config. is readonly"
)
panic
(
"prefix config. is readonly"
)
}
else
{
tlog
.
Error
(
"modify "
+
key
+
" is only for test"
)
}
}
return
return
}
}
...
@@ -559,6 +561,17 @@ func parseSubModule(cfg *subModule) (*ConfigSubModule, error) {
...
@@ -559,6 +561,17 @@ func parseSubModule(cfg *subModule) (*ConfigSubModule, error) {
return
&
subcfg
,
nil
return
&
subcfg
,
nil
}
}
//ModifySubConfig json data modify
func
ModifySubConfig
(
sub
[]
byte
,
key
string
,
value
interface
{})
([]
byte
,
error
)
{
var
data
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
(
sub
,
&
data
)
if
err
!=
nil
{
return
nil
,
err
}
data
[
key
]
=
value
return
json
.
Marshal
(
data
)
}
func
parseItem
(
data
map
[
string
]
interface
{})
map
[
string
][]
byte
{
func
parseItem
(
data
map
[
string
]
interface
{})
map
[
string
][]
byte
{
subconfig
:=
make
(
map
[
string
][]
byte
)
subconfig
:=
make
(
map
[
string
][]
byte
)
if
len
(
data
)
==
0
{
if
len
(
data
)
==
0
{
...
...
vendor/github.com/33cn/chain33/util/testnode/cfg.go
View file @
c2cd9285
...
@@ -9,7 +9,6 @@ Title="local"
...
@@ -9,7 +9,6 @@ Title="local"
TestNet=true
TestNet=true
FixTime=false
FixTime=false
[log]
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
loglevel = "debug"
loglevel = "debug"
...
...
vendor/github.com/33cn/chain33/util/testnode/testnode.go
View file @
c2cd9285
...
@@ -66,6 +66,7 @@ type Chain33Mock struct {
...
@@ -66,6 +66,7 @@ type Chain33Mock struct {
store
queue
.
Module
store
queue
.
Module
rpc
*
rpc
.
RPC
rpc
*
rpc
.
RPC
cfg
*
types
.
Config
cfg
*
types
.
Config
sub
*
types
.
ConfigSubModule
datadir
string
datadir
string
lastsend
[]
byte
lastsend
[]
byte
}
}
...
@@ -86,7 +87,7 @@ func newWithConfig(cfg *types.Config, sub *types.ConfigSubModule, mockapi client
...
@@ -86,7 +87,7 @@ func newWithConfig(cfg *types.Config, sub *types.ConfigSubModule, mockapi client
q
:=
queue
.
New
(
"channel"
)
q
:=
queue
.
New
(
"channel"
)
types
.
Debug
=
false
types
.
Debug
=
false
datadir
:=
util
.
ResetDatadir
(
cfg
,
"$TEMP/"
)
datadir
:=
util
.
ResetDatadir
(
cfg
,
"$TEMP/"
)
mock
:=
&
Chain33Mock
{
cfg
:
cfg
,
q
:
q
,
datadir
:
datadir
}
mock
:=
&
Chain33Mock
{
cfg
:
cfg
,
sub
:
sub
,
q
:
q
,
datadir
:
datadir
}
mock
.
random
=
rand
.
New
(
rand
.
NewSource
(
types
.
Now
()
.
UnixNano
()))
mock
.
random
=
rand
.
New
(
rand
.
NewSource
(
types
.
Now
()
.
UnixNano
()))
mock
.
exec
=
executor
.
New
(
cfg
.
Exec
,
sub
.
Exec
)
mock
.
exec
=
executor
.
New
(
cfg
.
Exec
,
sub
.
Exec
)
...
@@ -163,6 +164,14 @@ func (mock *Chain33Mock) Listen() {
...
@@ -163,6 +164,14 @@ func (mock *Chain33Mock) Listen() {
l
:=
len
(
mock
.
cfg
.
RPC
.
GrpcBindAddr
)
l
:=
len
(
mock
.
cfg
.
RPC
.
GrpcBindAddr
)
mock
.
cfg
.
RPC
.
GrpcBindAddr
=
mock
.
cfg
.
RPC
.
GrpcBindAddr
[
0
:
l
-
2
]
+
":"
+
fmt
.
Sprint
(
portgrpc
)
mock
.
cfg
.
RPC
.
GrpcBindAddr
=
mock
.
cfg
.
RPC
.
GrpcBindAddr
[
0
:
l
-
2
]
+
":"
+
fmt
.
Sprint
(
portgrpc
)
}
}
if
mock
.
sub
.
Consensus
[
"para"
]
!=
nil
{
data
,
err
:=
types
.
ModifySubConfig
(
mock
.
sub
.
Consensus
[
"para"
],
"ParaRemoteGrpcClient"
,
mock
.
cfg
.
RPC
.
GrpcBindAddr
)
if
err
!=
nil
{
panic
(
err
)
}
mock
.
sub
.
Consensus
[
"para"
]
=
data
types
.
S
(
"config.consensus.sub.para.ParaRemoteGrpcClient"
,
mock
.
cfg
.
RPC
.
GrpcBindAddr
)
}
}
}
//GetBlockChain :
//GetBlockChain :
...
...
vendor/github.com/33cn/chain33/util/util.go
View file @
c2cd9285
...
@@ -130,7 +130,11 @@ func JSONPrint(t *testing.T, input interface{}) {
...
@@ -130,7 +130,11 @@ func JSONPrint(t *testing.T, input interface{}) {
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
}
}
t
.
Log
(
string
(
data
))
if
t
==
nil
{
fmt
.
Println
(
string
(
data
))
}
else
{
t
.
Log
(
string
(
data
))
}
}
}
// CreateManageTx : Create Manage Tx
// CreateManageTx : Create Manage Tx
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment