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
74f124c0
Commit
74f124c0
authored
Jul 22, 2019
by
liuyuhang
Committed by
33cn
Aug 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add query by txhash
parent
ec2de227
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
174 additions
and
214 deletions
+174
-214
test-rpc.sh
plugin/dapp/autonomy/cmd/build/test-rpc.sh
+3
-121
testcase.sh
plugin/dapp/autonomy/cmd/build/testcase.sh
+0
-67
proposal_board.go
plugin/dapp/autonomy/commands/proposal_board.go
+11
-3
proposal_project.go
plugin/dapp/autonomy/commands/proposal_project.go
+11
-2
proposal_rule.go
plugin/dapp/autonomy/commands/proposal_rule.go
+11
-3
board.go
plugin/dapp/autonomy/executor/board.go
+19
-1
board_test.go
plugin/dapp/autonomy/executor/board_test.go
+18
-4
project.go
plugin/dapp/autonomy/executor/project.go
+19
-1
project_test.go
plugin/dapp/autonomy/executor/project_test.go
+18
-4
query.go
plugin/dapp/autonomy/executor/query.go
+21
-3
rule.go
plugin/dapp/autonomy/executor/rule.go
+19
-1
rule_test.go
plugin/dapp/autonomy/executor/rule_test.go
+18
-4
const.go
plugin/dapp/autonomy/types/const.go
+6
-0
No files found.
plugin/dapp/autonomy/cmd/build/test-rpc.sh
View file @
74f124c0
...
...
@@ -7,126 +7,8 @@ source ../dapp-test-common.sh
MAIN_HTTP
=
""
txhash
=
""
function
query_unfreezeID
()
{
chain33_BlockWait 1
"
$MAIN_HTTP
"
# echo "req=$req"
local times
=
10
while
true
;
do
req
=
'{"method":"Chain33.QueryTransaction","params":[{"hash":"'
"
$txhash
"
'"}]}'
ret
=
$(
curl
-ksd
"
$req
"
${
MAIN_HTTP
})
tx
=
$(
jq
-r
".result.tx.hash"
<<<
"
$ret
"
)
echo
"====query tx=
${
txhash
}
, return=
$ret
"
if
[
"
${
tx
}
"
!=
"
${
txhash
}
"
]
;
then
block_wait 1
times
=
$((
times
-
1
))
if
[
$times
-le
0
]
;
then
echo
"====query tx=
$txhash
failed"
echo
"req=
$req
"
curl
-ksd
"
$req
"
${
MAIN_HTTP
}
exit
1
fi
else
unfreeze_id
=
$(
jq
'(.result.receipt.logs['
"
$uid_index
"
'].log.current.unfreezeID)'
<<<
"
$ret
"
)
#echo "${unfreeze_id}"
unfreeze_id2
=
${
unfreeze_id
#\
"mavl-unfreeze-}
uid=
${
unfreeze_id2
%\
"}
echo "
====query tx=
$txhash
success
"
break
fi
done
}
function init() {
ispara=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo "
ipara
=
$ispara
"
exec_name="
unfreeze
"
uid_index=2
if [ "
$ispara
" == true ]; then
exec_name="
user
.p.para.
"
${
exec_name
}
uid_index=1
fi
exec_addr=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"'
${
exec_name
}
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
echo "
exec_addr
=
${
exec_addr
}
"
beneficiary=12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
beneficiary_key=0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01
owner=14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
owner_key=CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
#unfreeze_exec_addr=15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H
Chain33_SendToAddress "
$owner
" "
$exec_addr
" 500000000 "
${
MAIN_HTTP
}
"
Chain33_SendToAddress "
$beneficiary
" "
$exec_addr
" 500000000 "
${
MAIN_HTTP
}
"
block_wait 1
}
function CreateRawUnfreezeCreate() {
req='{"
jsonrpc
": "
2
.0
", "
method
" : "
unfreeze
.CreateRawUnfreezeCreate
" , "
params
":[{"
startTime
":10000,"
assetExec
":"
coins
","
assetSymbol
":"
bty
","
totalCount
":400000000,"
beneficiary
":"
'$beneficiary'
","
means
":"
FixAmount
","
fixAmount
": {"
period
":10,"
amount
":1000000}}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
chain33_SignRawTx "
$rawtx
" "
$owner_key
" "
${
MAIN_HTTP
}
"
query_unfreezeID
}
function CreateRawUnfreezeWithdraw() {
sleep 10
req='{"
method
":"
unfreeze
.CreateRawUnfreezeWithdraw
","
params
":[{"
unfreezeID
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
chain33_SignRawTx "
$rawtx
" "
${
beneficiary_key
}
" "
${
MAIN_HTTP
}
"
}
function CreateRawUnfreezeTerminate() {
req='{"
method
":"
unfreeze
.CreateRawUnfreezeTerminate
","
params
":[{"
unfreezeID
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
rawtx=
$(
jq
-r
".result"
<<<
"
$resp
"
)
chain33_SignRawTx "
$rawtx
" "
$owner_key
" "
${
MAIN_HTTP
}
"
block_wait 2
}
function GetUnfreeze() {
req='{"
method
":"
unfreeze
.GetUnfreeze
","
params
":[{"
data
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
}
function GetUnfreezeWithdraw() {
req='{"
method
":"
unfreeze
.GetUnfreezeWithdraw
","
params
":[{"
data
":"
'${uid}'
"}]}'
# echo "
#request
:
$req
"
resp=
$(
curl
-ksd
"
$req
"
"
${
MAIN_HTTP
}
"
)
# echo "
#resp
:
$resp
"
ok=
$(
jq
'(.error|not) and (.result != "")'
<<<
"
$resp
"
)
[ "
$ok
" == true ]
echo_rst "
$FUNCNAME
" "
$?
"
}
function
run_testcases
()
{
CreateRawUnfreezeCreate
CreateRawUnfreezeWithdraw
GetUnfreeze
GetUnfreezeWithdraw
CreateRawUnfreezeTerminate
echo
"run_testcases"
}
function
debug_function
()
{
...
...
@@ -143,10 +25,10 @@ function rpc_test() {
run_testcases
if
[
-n
"
$CASE_ERR
"
]
;
then
echo "
=======
unfreeze
rpc test error ===========
"
echo
"=======
autonomy
rpc test error ==========="
exit
1
else
echo "
======
unfreeze
rpc test pass ===========
"
echo
"======
autonomy
rpc test pass ==========="
fi
}
...
...
plugin/dapp/autonomy/cmd/build/testcase.sh
View file @
74f124c0
#!/usr/bin/env bash
CLI
=
"docker exec
${
NODE3
}
/root/chain33-cli"
beneficiary
=
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
beneficiary_key
=
0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01
#owner=14KEKbYtKKQm4wMthSK9J4La4nAiidGozt
owner_key
=
CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944
unfreeze_exec_addr
=
15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H
function
unfreeze_test
()
{
echo
"=========== # unfreeze test ============="
echo
"=== 1 check exec addr"
result
=
$(
$CLI
exec
addr
-e
unfreeze
)
if
[
"
${
result
}
"
!=
"
${
unfreeze_exec_addr
}
"
]
;
then
echo
"unfreeze exec addr is not right, expect
${
unfreeze_exec_addr
}
result
${
result
}
"
exit
1
fi
block_wait
"
${
CLI
}
"
2
echo
"=== 2 prepare: transfer bty to unfreeze "
result
=
$(
$CLI
send coins transfer
-a
5
-n
test
-t
${
unfreeze_exec_addr
}
-k
${
owner_key
})
echo
"
${
result
}
"
block_wait
"
${
CLI
}
"
2
echo
"=== 3 create unfreeze tx"
tx_hash
=
$(${
CLI
}
send unfreeze create fix_amount
-a
0.01
-e
coins
-s
bty
-b
${
beneficiary
}
-p
20
-t
2
-k
${
owner_key
})
block_wait
"
${
CLI
}
"
2
unfreeze_id
=
$(${
CLI
}
tx query
-s
"
${
tx_hash
}
"
| jq
".receipt.logs[2].log.current.unfreezeID"
)
echo
"
${
unfreeze_id
}
"
unfreeze_id2
=
${
unfreeze_id
#\
"mavl-unfreeze-}
uid=
${
unfreeze_id2
%\
"}
echo "
==== 4 check some message
"
sleep 20
withdraw=
$(${
CLI
}
unfreeze show_withdraw
--id
"
${
uid
}
"
| jq
".availableAmount"
)
if [ "
${
withdraw
}
" = "
0
" ]; then
echo "
create
unfreeze failed, expect withdraw shoult >0
"
exit 1
fi
echo "
==== 5 withdraw
"
${
CLI
}
send unfreeze withdraw --id "
${
uid
}
" -k "
${
beneficiary_key
}
"
block_wait "
${
CLI
}
" 2
remaining=
$(${
CLI
}
unfreeze show
--id
"
${
uid
}
"
| jq
".remaining"
)
if [ "
${
remaining
}
" = '"
200000000
"' ]; then
echo "
withdraw
failed, expect remaining < 200000000, result
${
remaining
}
"
exit 1
fi
echo "
==== 6 termenate
"
${
CLI
}
send unfreeze terminate --id "
${
uid
}
" -k "
${
owner_key
}
"
block_wait "
${
CLI
}
" 2
remaining=
$(${
CLI
}
unfreeze show
--id
"
${
uid
}
"
| jq
".remaining"
)
remainingNum=
$(
echo
"
$remaining
"
|
awk
'{print int($0)}'
)
if [ "
100000000
" -lt "
${
remainingNum
}
" ]; then
echo "
terminate
failed, expect remaining < 100000000, result
${
remaining
}
"
exit 1
fi
echo "
==================== unfreeze test end
"
}
function unfreeze() {
if [ "
${
2
}
" == "
init
" ]; then
return
elif [ "
${
2
}
" == "
config
" ]; then
return
elif [ "
${
2
}
" == "
test
" ]; then
unfreeze_test "
${
1
}
"
fi
}
plugin/dapp/autonomy/commands/proposal_board.go
View file @
74f124c0
...
...
@@ -203,9 +203,10 @@ func ShowProposalBoardCmd() *cobra.Command {
}
func
addShowProposalBoardflags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"t"
,
0
,
"type"
)
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"t"
,
0
,
"type
(0:query by hash; 1:list)
"
)
cmd
.
MarkFlagRequired
(
"type"
)
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
Flags
()
.
Uint32P
(
"status"
,
"s"
,
0
,
"status"
)
cmd
.
Flags
()
.
Int32P
(
"count"
,
"c"
,
0
,
"count"
)
cmd
.
Flags
()
.
Int32P
(
"direction"
,
"d"
,
0
,
"direction"
)
...
...
@@ -215,6 +216,7 @@ func addShowProposalBoardflags(cmd *cobra.Command) {
func
showProposalBoard
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
typ
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"type"
)
propID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
status
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"status"
)
count
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"count"
)
direction
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"direction"
)
...
...
@@ -224,16 +226,22 @@ func showProposalBoard(cmd *cobra.Command, args []string) {
var
rep
interface
{}
params
.
Execer
=
auty
.
AutonomyX
if
0
==
typ
{
req
:=
types
.
ReqString
{
Data
:
propID
,
}
params
.
FuncName
=
auty
.
GetProposalBoard
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
}
else
if
1
==
typ
{
req
:=
auty
.
ReqQueryProposalBoard
{
Status
:
int32
(
status
),
Count
:
count
,
Direction
:
direction
,
Index
:
index
,
}
params
.
FuncName
=
auty
.
Ge
tProposalBoard
params
.
FuncName
=
auty
.
Lis
tProposalBoard
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
rep
=
&
auty
.
ReplyQueryProposalBoard
{}
}
rep
=
&
auty
.
ReplyQueryProposalBoard
{}
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
rep
)
ctx
.
Run
()
...
...
plugin/dapp/autonomy/commands/proposal_project.go
View file @
74f124c0
...
...
@@ -222,9 +222,10 @@ func ShowProposalProjectCmd() *cobra.Command {
}
func
addShowProposalProjectflags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"t"
,
0
,
"type"
)
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"t"
,
0
,
"type
(0:query by hash; 1:list)
"
)
cmd
.
MarkFlagRequired
(
"type"
)
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
Flags
()
.
Uint32P
(
"status"
,
"s"
,
0
,
"status"
)
cmd
.
Flags
()
.
Int32P
(
"count"
,
"c"
,
0
,
"count"
)
cmd
.
Flags
()
.
Int32P
(
"direction"
,
"d"
,
0
,
"direction"
)
...
...
@@ -234,6 +235,7 @@ func addShowProposalProjectflags(cmd *cobra.Command) {
func
showProposalProject
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
typ
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"type"
)
propID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
status
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"status"
)
count
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"count"
)
direction
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"direction"
)
...
...
@@ -243,13 +245,20 @@ func showProposalProject(cmd *cobra.Command, args []string) {
var
rep
interface
{}
params
.
Execer
=
auty
.
AutonomyX
if
0
==
typ
{
req
:=
types
.
ReqString
{
Data
:
propID
,
}
params
.
FuncName
=
auty
.
GetProposalProject
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
rep
=
&
auty
.
ReplyQueryProposalProject
{}
}
else
if
1
==
typ
{
req
:=
auty
.
ReqQueryProposalProject
{
Status
:
int32
(
status
),
Count
:
count
,
Direction
:
direction
,
Index
:
index
,
}
params
.
FuncName
=
auty
.
Ge
tProposalProject
params
.
FuncName
=
auty
.
Lis
tProposalProject
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
rep
=
&
auty
.
ReplyQueryProposalProject
{}
}
...
...
plugin/dapp/autonomy/commands/proposal_rule.go
View file @
74f124c0
...
...
@@ -175,9 +175,10 @@ func ShowProposalRuleCmd() *cobra.Command {
}
func
addShowProposalRuleflags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"t"
,
0
,
"type"
)
cmd
.
Flags
()
.
Uint32P
(
"type"
,
"t"
,
0
,
"type
(0:query by hash; 1:list)
"
)
cmd
.
MarkFlagRequired
(
"type"
)
cmd
.
Flags
()
.
StringP
(
"proposalID"
,
"p"
,
""
,
"proposal ID"
)
cmd
.
Flags
()
.
Uint32P
(
"status"
,
"s"
,
0
,
"status"
)
cmd
.
Flags
()
.
Int32P
(
"count"
,
"c"
,
0
,
"count"
)
cmd
.
Flags
()
.
Int32P
(
"direction"
,
"d"
,
0
,
"direction"
)
...
...
@@ -187,6 +188,7 @@ func addShowProposalRuleflags(cmd *cobra.Command) {
func
showProposalRule
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
typ
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"type"
)
propID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"proposalID"
)
status
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"status"
)
count
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"count"
)
direction
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"direction"
)
...
...
@@ -196,16 +198,22 @@ func showProposalRule(cmd *cobra.Command, args []string) {
var
rep
interface
{}
params
.
Execer
=
auty
.
AutonomyX
if
0
==
typ
{
req
:=
types
.
ReqString
{
Data
:
propID
,
}
params
.
FuncName
=
auty
.
GetProposalRule
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
}
else
if
1
==
typ
{
req
:=
auty
.
ReqQueryProposalRule
{
Status
:
int32
(
status
),
Count
:
count
,
Direction
:
direction
,
Index
:
index
,
}
params
.
FuncName
=
auty
.
Ge
tProposalRule
params
.
FuncName
=
auty
.
Lis
tProposalRule
params
.
Payload
=
types
.
MustPBToJSON
(
&
req
)
rep
=
&
auty
.
ReplyQueryProposalRule
{}
}
rep
=
&
auty
.
ReplyQueryProposalRule
{}
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
rep
)
ctx
.
Run
()
...
...
plugin/dapp/autonomy/executor/board.go
View file @
74f124c0
...
...
@@ -94,7 +94,25 @@ func delBoardHeightIndex(res *auty.ReceiptProposalBoard) (kvs []*types.KeyValue)
return
kvs
}
func
(
a
*
Autonomy
)
getProposalBoard
(
req
*
auty
.
ReqQueryProposalBoard
)
(
types
.
Message
,
error
)
{
func
(
a
*
Autonomy
)
getProposalBoard
(
req
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
value
,
err
:=
a
.
GetStateDB
()
.
Get
(
propBoardID
(
req
.
Data
))
if
err
!=
nil
{
return
nil
,
err
}
prop
:=
&
auty
.
AutonomyProposalBoard
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
}
rep
:=
&
auty
.
ReplyQueryProposalBoard
{}
rep
.
PropBoards
=
append
(
rep
.
PropBoards
,
prop
)
return
rep
,
nil
}
func
(
a
*
Autonomy
)
listProposalBoard
(
req
*
auty
.
ReqQueryProposalBoard
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
plugin/dapp/autonomy/executor/board_test.go
View file @
74f124c0
...
...
@@ -144,6 +144,20 @@ func TestGetProposalBoard(t *testing.T) {
au
:=
&
Autonomy
{
dapp
.
DriverBase
{},
}
_
,
storedb
,
_
:=
util
.
CreateTestDB
()
au
.
SetStateDB
(
storedb
)
tx
:=
"1111111111111111111"
storedb
.
Set
(
propBoardID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalBoard
{}))
rsp
,
err
:=
au
.
getProposalBoard
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
1
)
}
func
TestListProposalBoard
(
t
*
testing
.
T
)
{
au
:=
&
Autonomy
{
dapp
.
DriverBase
{},
}
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
au
.
SetLocalDB
(
kvdb
)
...
...
@@ -192,7 +206,7 @@ func TestGetProposalBoard(t *testing.T) {
Direction
:
0
,
Index
:
-
1
,
}
rsp
,
err
:=
au
.
ge
tProposalBoard
(
req
)
rsp
,
err
:=
au
.
lis
tProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
len
(
testcase2
))
k
:=
2
...
...
@@ -209,7 +223,7 @@ func TestGetProposalBoard(t *testing.T) {
Direction
:
1
,
Index
:
-
1
,
}
rsp
,
err
=
au
.
ge
tProposalBoard
(
req
)
rsp
,
err
=
au
.
lis
tProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
...
...
@@ -224,7 +238,7 @@ func TestGetProposalBoard(t *testing.T) {
Direction
:
0
,
Index
:
-
1
,
}
rsp
,
err
=
au
.
ge
tProposalBoard
(
req
)
rsp
,
err
=
au
.
lis
tProposalBoard
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Height
...
...
@@ -239,7 +253,7 @@ func TestGetProposalBoard(t *testing.T) {
Direction
:
0
,
Index
:
Index
,
}
rsp
,
err
=
au
.
ge
tProposalBoard
(
req
)
rsp
,
err
=
au
.
lis
tProposalBoard
(
req
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalBoard
)
.
PropBoards
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
...
...
plugin/dapp/autonomy/executor/project.go
View file @
74f124c0
...
...
@@ -95,7 +95,25 @@ func delProjectHeightIndex(res *auty.ReceiptProposalProject) (kvs []*types.KeyVa
return
kvs
}
func
(
a
*
Autonomy
)
getProposalProject
(
req
*
auty
.
ReqQueryProposalProject
)
(
types
.
Message
,
error
)
{
func
(
a
*
Autonomy
)
getProposalProject
(
req
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
value
,
err
:=
a
.
GetStateDB
()
.
Get
(
propProjectID
(
req
.
Data
))
if
err
!=
nil
{
return
nil
,
err
}
prop
:=
&
auty
.
AutonomyProposalProject
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
}
rep
:=
&
auty
.
ReplyQueryProposalProject
{}
rep
.
PropProjects
=
append
(
rep
.
PropProjects
,
prop
)
return
rep
,
nil
}
func
(
a
*
Autonomy
)
listProposalProject
(
req
*
auty
.
ReqQueryProposalProject
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
plugin/dapp/autonomy/executor/project_test.go
View file @
74f124c0
...
...
@@ -148,6 +148,20 @@ func TestGetProposalProject(t *testing.T) {
au
:=
&
Autonomy
{
dapp
.
DriverBase
{},
}
_
,
storedb
,
_
:=
util
.
CreateTestDB
()
au
.
SetStateDB
(
storedb
)
tx
:=
"1111111111111111111"
storedb
.
Set
(
propProjectID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalProject
{}))
rsp
,
err
:=
au
.
getProposalProject
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
1
)
}
func
TestListProposalProject
(
t
*
testing
.
T
)
{
au
:=
&
Autonomy
{
dapp
.
DriverBase
{},
}
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
au
.
SetLocalDB
(
kvdb
)
...
...
@@ -198,7 +212,7 @@ func TestGetProposalProject(t *testing.T) {
Direction
:
0
,
Index
:
-
1
,
}
rsp
,
err
:=
au
.
ge
tProposalProject
(
req
)
rsp
,
err
:=
au
.
lis
tProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
len
(
testcase2
))
k
:=
2
...
...
@@ -215,7 +229,7 @@ func TestGetProposalProject(t *testing.T) {
Direction
:
1
,
Index
:
-
1
,
}
rsp
,
err
=
au
.
ge
tProposalProject
(
req
)
rsp
,
err
=
au
.
lis
tProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
...
...
@@ -230,7 +244,7 @@ func TestGetProposalProject(t *testing.T) {
Direction
:
0
,
Index
:
-
1
,
}
rsp
,
err
=
au
.
ge
tProposalProject
(
req
)
rsp
,
err
=
au
.
lis
tProposalProject
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Height
...
...
@@ -245,7 +259,7 @@ func TestGetProposalProject(t *testing.T) {
Direction
:
0
,
Index
:
Index
,
}
rsp
,
err
=
au
.
ge
tProposalProject
(
req
)
rsp
,
err
=
au
.
lis
tProposalProject
(
req
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalProject
)
.
PropProjects
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
...
...
plugin/dapp/autonomy/executor/query.go
View file @
74f124c0
...
...
@@ -10,16 +10,33 @@ import (
)
// Query_GetProposalBoard 查询提案董事会
func
(
a
*
Autonomy
)
Query_GetProposalBoard
(
in
*
auty
.
ReqQueryProposalBoard
)
(
types
.
Message
,
error
)
{
func
(
a
*
Autonomy
)
Query_GetProposalBoard
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
return
a
.
getProposalBoard
(
in
)
}
// Query_ListProposalBoard 批量查询
func
(
a
*
Autonomy
)
Query_ListProposalBoard
(
in
*
auty
.
ReqQueryProposalBoard
)
(
types
.
Message
,
error
)
{
return
a
.
listProposalBoard
(
in
)
}
// Query_GetProposalProject 查询提案项目
func
(
a
*
Autonomy
)
Query_GetProposalProject
(
in
*
auty
.
ReqQueryProposalProject
)
(
types
.
Message
,
error
)
{
func
(
a
*
Autonomy
)
Query_GetProposalProject
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
return
a
.
getProposalProject
(
in
)
}
// Query_ListProposalProject 批量查询
func
(
a
*
Autonomy
)
Query_ListProposalProject
(
in
*
auty
.
ReqQueryProposalProject
)
(
types
.
Message
,
error
)
{
return
a
.
listProposalProject
(
in
)
}
// Query_GetProposalRule 查询提案规则
func
(
a
*
Autonomy
)
Query_GetProposalRule
(
in
*
auty
.
ReqQueryProposalRule
)
(
types
.
Message
,
error
)
{
func
(
a
*
Autonomy
)
Query_GetProposalRule
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
return
a
.
getProposalRule
(
in
)
}
// Query_ListProposalRule 批量查询
func
(
a
*
Autonomy
)
Query_ListProposalRule
(
in
*
auty
.
ReqQueryProposalRule
)
(
types
.
Message
,
error
)
{
return
a
.
listProposalRule
(
in
)
}
\ No newline at end of file
plugin/dapp/autonomy/executor/rule.go
View file @
74f124c0
...
...
@@ -93,7 +93,25 @@ func delRuleHeightIndex(res *auty.ReceiptProposalRule) (kvs []*types.KeyValue) {
return
kvs
}
func
(
a
*
Autonomy
)
getProposalRule
(
req
*
auty
.
ReqQueryProposalRule
)
(
types
.
Message
,
error
)
{
func
(
a
*
Autonomy
)
getProposalRule
(
req
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
value
,
err
:=
a
.
GetStateDB
()
.
Get
(
propRuleID
(
req
.
Data
))
if
err
!=
nil
{
return
nil
,
err
}
prop
:=
&
auty
.
AutonomyProposalRule
{}
err
=
types
.
Decode
(
value
,
prop
)
if
err
!=
nil
{
return
nil
,
err
}
rep
:=
&
auty
.
ReplyQueryProposalRule
{}
rep
.
PropRules
=
append
(
rep
.
PropRules
,
prop
)
return
rep
,
nil
}
func
(
a
*
Autonomy
)
listProposalRule
(
req
*
auty
.
ReqQueryProposalRule
)
(
types
.
Message
,
error
)
{
if
req
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
plugin/dapp/autonomy/executor/rule_test.go
View file @
74f124c0
...
...
@@ -144,6 +144,20 @@ func TestGetProposalRule(t *testing.T) {
au
:=
&
Autonomy
{
dapp
.
DriverBase
{},
}
_
,
storedb
,
_
:=
util
.
CreateTestDB
()
au
.
SetStateDB
(
storedb
)
tx
:=
"1111111111111111111"
storedb
.
Set
(
propRuleID
(
tx
),
types
.
Encode
(
&
auty
.
AutonomyProposalRule
{}))
rsp
,
err
:=
au
.
getProposalRule
(
&
types
.
ReqString
{
Data
:
tx
})
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
rsp
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
1
)
}
func
TestListProposalRule
(
t
*
testing
.
T
)
{
au
:=
&
Autonomy
{
dapp
.
DriverBase
{},
}
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
au
.
SetLocalDB
(
kvdb
)
...
...
@@ -192,7 +206,7 @@ func TestGetProposalRule(t *testing.T) {
Direction
:
0
,
Index
:
-
1
,
}
rsp
,
err
:=
au
.
ge
tProposalRule
(
req
)
rsp
,
err
:=
au
.
lis
tProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
len
(
testcase2
))
k
:=
2
...
...
@@ -209,7 +223,7 @@ func TestGetProposalRule(t *testing.T) {
Direction
:
1
,
Index
:
-
1
,
}
rsp
,
err
=
au
.
ge
tProposalRule
(
req
)
rsp
,
err
=
au
.
lis
tProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
len
(
testcase2
))
for
i
,
tcase
:=
range
testcase2
{
...
...
@@ -224,7 +238,7 @@ func TestGetProposalRule(t *testing.T) {
Direction
:
0
,
Index
:
-
1
,
}
rsp
,
err
=
au
.
ge
tProposalRule
(
req
)
rsp
,
err
=
au
.
lis
tProposalRule
(
req
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
1
)
height
:=
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Height
...
...
@@ -239,7 +253,7 @@ func TestGetProposalRule(t *testing.T) {
Direction
:
0
,
Index
:
Index
,
}
rsp
,
err
=
au
.
ge
tProposalRule
(
req
)
rsp
,
err
=
au
.
lis
tProposalRule
(
req
)
require
.
Equal
(
t
,
len
(
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
),
2
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Height
,
testcase2
[
1
]
.
height
)
require
.
Equal
(
t
,
rsp
.
(
*
auty
.
ReplyQueryProposalRule
)
.
PropRules
[
0
]
.
Index
,
int32
(
testcase2
[
1
]
.
index
))
...
...
plugin/dapp/autonomy/types/const.go
View file @
74f124c0
...
...
@@ -66,10 +66,16 @@ const (
const
(
// GetProposalBoard 用于在cmd里面的区分不同的查询
GetProposalBoard
=
"GetProposalBoard"
// ListProposalBoard
ListProposalBoard
=
"ListProposalBoard"
// GetProposalProject 用于在cmd里面的区分不同的查询
GetProposalProject
=
"GetProposalProject"
// ListProposalProject
ListProposalProject
=
"ListProposalProject"
// GetProposalRule 用于在cmd里面的区分不同的查询
GetProposalRule
=
"GetProposalRule"
// ListProposalRule
ListProposalRule
=
"ListProposalRule"
)
...
...
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