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
894cc1eb
Commit
894cc1eb
authored
Jul 10, 2019
by
liuyuhang
Committed by
33cn
Aug 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test
parent
62469022
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
268 additions
and
593 deletions
+268
-593
board_test.go
plugin/dapp/autonomy/executor/board_test.go
+0
-277
boardaction.go
plugin/dapp/autonomy/executor/boardaction.go
+6
-6
boardaction_test.go
plugin/dapp/autonomy/executor/boardaction_test.go
+235
-259
plugin.go
plugin/dapp/autonomy/plugin.go
+2
-2
jrpc_channel_test.go
plugin/dapp/autonomy/rpc/jrpc_channel_test.go
+22
-46
const.go
plugin/dapp/autonomy/types/const.go
+0
-2
types.go
plugin/dapp/autonomy/types/types.go
+2
-1
init.go
plugin/dapp/init/init.go
+1
-0
No files found.
plugin/dapp/autonomy/executor/board_test.go
View file @
894cc1eb
...
@@ -3,280 +3,3 @@
...
@@ -3,280 +3,3 @@
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
executor
package
executor
//import (
// "testing"
//
// "github.com/stretchr/testify/assert"
//
// "encoding/hex"
//
// "github.com/33cn/chain33/account"
// "github.com/33cn/chain33/common"
// "github.com/33cn/chain33/common/address"
// "github.com/33cn/chain33/common/crypto"
// dbm "github.com/33cn/chain33/common/db"
// "github.com/33cn/chain33/types"
// "github.com/33cn/chain33/util"
// pty "github.com/33cn/plugin/plugin/dapp/unfreeze/types"
//)
//
//type execEnv struct {
// blockTime int64
// blockHeight int64
// difficulty uint64
//}
//
//var (
// Symbol = "TEST"
// AssetExecToken = "token"
// AssetExecPara = "paracross"
//
// PrivKeyA = "0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" // 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
// PrivKeyB = "0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4" // 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
// PrivKeyC = "0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115" // 1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k
// PrivKeyD = "0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71" // 1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs
// Nodes = [][]byte{
// []byte("1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"),
// []byte("1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"),
// []byte("1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"),
// []byte("1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"),
// }
//)
//
//func TestUnfreeze(t *testing.T) {
// types.SetTitleOnlyForTest("chain33")
// total := int64(100000)
// accountA := types.Account{
// Balance: total,
// Frozen: 0,
// Addr: string(Nodes[0]),
// }
// accountB := types.Account{
// Balance: total,
// Frozen: 0,
// Addr: string(Nodes[1]),
// }
//
// execAddr := address.ExecAddress(pty.UnfreezeX)
// stateDB, _ := dbm.NewGoMemDB("1", "2", 100)
// _, ldb, kvdb := util.CreateTestDB()
//
// accA, _ := account.NewAccountDB(AssetExecPara, Symbol, stateDB)
// accA.SaveExecAccount(execAddr, &accountA)
//
// accB, _ := account.NewAccountDB(AssetExecPara, Symbol, stateDB)
// accB.SaveExecAccount(execAddr, &accountB)
//
// env := execEnv{
// 10,
// types.GetDappFork(pty.UnfreezeX, pty.ForkUnfreezeIDX),
// 1539918074,
// }
// ty := pty.UnfreezeType{}
//
// // 创建
// opt := &pty.FixAmount{Period: 10, Amount: 2}
// p1 := &pty.UnfreezeCreate{
// StartTime: 10,
// AssetExec: AssetExecPara,
// AssetSymbol: Symbol,
// TotalCount: 10000,
// Beneficiary: string(Nodes[1]),
// Means: "FixAmount",
// MeansOpt: &pty.UnfreezeCreate_FixAmount{FixAmount: opt},
// }
// createTx, err := ty.RPC_UnfreezeCreateTx(p1)
// if err != nil {
// t.Error("RPC_UnfreezeCreateTx", "err", err)
// }
// createTx, err = signTx(createTx, PrivKeyA)
// if err != nil {
// t.Error("RPC_UnfreezeCreateTx sign", "err", err)
// }
// exec := newUnfreeze()
// exec.SetStateDB(stateDB)
// exec.SetLocalDB(kvdb)
// exec.SetEnv(env.blockHeight, env.blockTime, env.difficulty)
// receipt, err := exec.Exec(createTx, int(1))
// assert.Nil(t, err)
// assert.NotNil(t, receipt)
// //t.Log(receipt)
// accTmp := accA.LoadExecAccount(accountA.Addr, execAddr)
// assert.Equal(t, total-p1.TotalCount, accTmp.Balance)
// assert.Equal(t, p1.TotalCount, accTmp.Frozen)
//
// receiptDate := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
// set, err := exec.ExecLocal(createTx, receiptDate, int(1))
// assert.Nil(t, err)
// assert.NotNil(t, set)
//
// req1 := &pty.ReqUnfreezes{
// Beneficiary: p1.Beneficiary,
// }
// reply, err := exec.Query("ListUnfreezeByBeneficiary", types.Encode(req1))
// assert.Nil(t, err)
// assert.NotNil(t, reply)
// resp, ok := reply.(*pty.ReplyUnfreezes)
// assert.True(t, ok)
// assert.Equal(t, 1, len(resp.Unfreeze))
// assert.Equal(t, string(unfreezeID(createTx.Hash())), resp.Unfreeze[0].UnfreezeID)
//
// // 提币
// p2 := &pty.UnfreezeWithdraw{
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
// }
// withdrawTx, err := ty.RPC_UnfreezeWithdrawTx(p2)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx", "err", err)
// }
// withdrawTx, err = signTx(withdrawTx, PrivKeyB)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
// }
// blockTime := int64(10)
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
// receipt, err = exec.Exec(withdrawTx, 1)
// assert.Nil(t, err)
// assert.NotNil(t, receipt)
// //t.Log(receipt)
// accATmp := accA.LoadExecAccount(accountA.Addr, execAddr)
// accBTmp := accB.LoadExecAccount(accountB.Addr, execAddr)
// assert.Equal(t, total-p1.TotalCount, accATmp.Balance)
//
// u := pty.Unfreeze{}
// e := types.Decode(receipt.KV[2].Value, &u)
// assert.Nil(t, e)
// assert.Equal(t, u.Remaining, accATmp.Frozen)
// assert.Equal(t, accountB.Balance+p1.TotalCount-u.Remaining, accBTmp.Balance)
//
// receiptDate2 := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
// set, err = exec.ExecLocal(withdrawTx, receiptDate2, int(1))
// assert.Nil(t, err)
// assert.NotNil(t, set)
//
// // 不是受益人提币
// {
// p2 := &pty.UnfreezeWithdraw{
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
// }
// withdrawTx, err := ty.RPC_UnfreezeWithdrawTx(p2)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx", "err", err)
// }
// withdrawTx, err = signTx(withdrawTx, PrivKeyC)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
// }
// blockTime := int64(10)
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
// receipt, err = exec.Exec(withdrawTx, 1)
// assert.Equal(t, pty.ErrNoPrivilege, err)
// assert.Nil(t, receipt)
// }
//
// // 不是创建者终止
// {
// p3 := &pty.UnfreezeTerminate{
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
// }
// terminateTx, err := ty.RPC_UnfreezeTerminateTx(p3)
// if err != nil {
// t.Error("RPC_UnfreezeTerminateTx", "err", err)
// }
// terminateTx, err = signTx(terminateTx, PrivKeyC)
// if err != nil {
// t.Error("RPC_UnfreezeTerminateTx sign", "err", err)
// }
// receipt, err = exec.Exec(terminateTx, 1)
// assert.Equal(t, pty.ErrNoPrivilege, err)
// assert.Nil(t, receipt)
// }
//
// // 终止
// p3 := &pty.UnfreezeTerminate{
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
// }
// terminateTx, err := ty.RPC_UnfreezeTerminateTx(p3)
// if err != nil {
// t.Error("RPC_UnfreezeTerminateTx", "err", err)
// }
// terminateTx, err = signTx(terminateTx, PrivKeyA)
// if err != nil {
// t.Error("RPC_UnfreezeTerminateTx sign", "err", err)
// }
// exec.SetEnv(env.blockHeight+2, env.blockTime+blockTime, env.difficulty)
// receipt, err = exec.Exec(terminateTx, 1)
// assert.Nil(t, err)
// assert.NotNil(t, receipt)
// //t.Log(receipt)
// accATmp = accA.LoadExecAccount(accountA.Addr, execAddr)
// assert.Equal(t, total+total, accATmp.Balance+accBTmp.Balance)
// assert.Equal(t, int64(0), accATmp.Frozen)
//
// receiptDate3 := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
// set, err = exec.ExecLocal(terminateTx, receiptDate3, int(1))
// assert.Nil(t, err)
// assert.NotNil(t, set)
//
// // 终止后不能继续提币
// {
// p2 := &pty.UnfreezeWithdraw{
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
// }
// withdrawTx, err := ty.RPC_UnfreezeWithdrawTx(p2)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx", "err", err)
// }
// withdrawTx, err = signTx(withdrawTx, PrivKeyB)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
// }
// blockTime := int64(10)
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime+blockTime, env.difficulty)
// receipt, err = exec.Exec(withdrawTx, 1)
// assert.Equal(t, pty.ErrUnfreezeEmptied, err)
// assert.Nil(t, receipt)
// }
//
// req := types.ReqString{Data: hex.EncodeToString(createTx.Hash())}
// _, err = exec.Query("GetUnfreeze", types.Encode(&req))
// assert.Nil(t, err)
//
// _, err = exec.Query("GetUnfreezeWithdraw", types.Encode(&req))
// assert.Nil(t, err)
//
// _, err = exec.ExecDelLocal(terminateTx, receiptDate3, int(1))
// assert.Nil(t, err)
//
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
// _, err = exec.ExecDelLocal(withdrawTx, receiptDate2, int(1))
// assert.Nil(t, err)
//
// exec.SetEnv(env.blockHeight, env.blockTime+blockTime, env.difficulty)
// _, err = exec.ExecDelLocal(createTx, receiptDate, int(1))
// assert.Nil(t, err)
//
// ldb.Close()
//}
//
//func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) {
// signType := types.SECP256K1
// c, err := crypto.New(types.GetSignName(pty.UnfreezeX, signType))
// if err != nil {
// return tx, err
// }
//
// bytes, err := common.FromHex(hexPrivKey[:])
// if err != nil {
// return tx, err
// }
//
// privKey, err := c.PrivKeyFromBytes(bytes)
// if err != nil {
// return tx, err
// }
//
// tx.Sign(int32(signType), privKey)
// return tx, nil
//}
plugin/dapp/autonomy/executor/boardaction.go
View file @
894cc1eb
...
@@ -77,7 +77,7 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
...
@@ -77,7 +77,7 @@ func (a *action) propBoard(prob *auty.ProposalBoard) (*types.Receipt, error) {
value
:=
types
.
Encode
(
cur
)
value
:=
types
.
Encode
(
cur
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
value
})
receiptLog
:=
a
.
G
etReceiptLog
(
nil
,
cur
,
auty
.
TyLogPropBoard
)
receiptLog
:=
g
etReceiptLog
(
nil
,
cur
,
auty
.
TyLogPropBoard
)
logs
=
append
(
logs
,
receiptLog
)
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
...
@@ -138,7 +138,7 @@ func (a *action) rvkPropBoard(rvkProb *auty.RevokeProposalBoard) (*types.Receipt
...
@@ -138,7 +138,7 @@ func (a *action) rvkPropBoard(rvkProb *auty.RevokeProposalBoard) (*types.Receipt
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
propBoardID
(
rvkProb
.
ProposalID
),
Value
:
types
.
Encode
(
&
cur
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
propBoardID
(
rvkProb
.
ProposalID
),
Value
:
types
.
Encode
(
&
cur
)})
a
.
G
etReceiptLog
(
pre
,
&
cur
,
auty
.
TyLogRvkPropBoard
)
g
etReceiptLog
(
pre
,
&
cur
,
auty
.
TyLogRvkPropBoard
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
...
@@ -253,7 +253,7 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
...
@@ -253,7 +253,7 @@ func (a *action) votePropBoard(voteProb *auty.VoteProposalBoard) (*types.Receipt
if
cur
.
Res
.
Pass
{
if
cur
.
Res
.
Pass
{
ty
=
auty
.
TyLogTmintPropBoard
ty
=
auty
.
TyLogTmintPropBoard
}
}
receiptLog
:=
a
.
G
etReceiptLog
(
pre
,
&
cur
,
int32
(
ty
))
receiptLog
:=
g
etReceiptLog
(
pre
,
&
cur
,
int32
(
ty
))
logs
=
append
(
logs
,
receiptLog
)
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
...
@@ -324,7 +324,7 @@ func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.
...
@@ -324,7 +324,7 @@ func (a *action) tmintPropBoard(tmintProb *auty.TerminateProposalBoard) (*types.
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
propBoardID
(
tmintProb
.
ProposalID
),
Value
:
types
.
Encode
(
&
cur
)})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
propBoardID
(
tmintProb
.
ProposalID
),
Value
:
types
.
Encode
(
&
cur
)})
a
.
G
etReceiptLog
(
pre
,
&
cur
,
auty
.
TyLogTmintPropBoard
)
g
etReceiptLog
(
pre
,
&
cur
,
auty
.
TyLogTmintPropBoard
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
}
...
@@ -353,9 +353,9 @@ func (a *action) getStartHeightVoteAccount(addr string, height int64) (*types.Ac
...
@@ -353,9 +353,9 @@ func (a *action) getStartHeightVoteAccount(addr string, height int64) (*types.Ac
return
account
[
0
],
nil
return
account
[
0
],
nil
}
}
//
G
etReceiptLog 根据提案信息获取log
//
g
etReceiptLog 根据提案信息获取log
// 状态变化:
// 状态变化:
func
(
a
*
action
)
G
etReceiptLog
(
pre
,
cur
*
auty
.
AutonomyProposalBoard
,
ty
int32
)
*
types
.
ReceiptLog
{
func
g
etReceiptLog
(
pre
,
cur
*
auty
.
AutonomyProposalBoard
,
ty
int32
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
ty
log
.
Ty
=
ty
r
:=
&
auty
.
ReceiptProposalBoard
{
Prev
:
pre
,
Current
:
cur
}
r
:=
&
auty
.
ReceiptProposalBoard
{
Prev
:
pre
,
Current
:
cur
}
...
...
plugin/dapp/autonomy/executor/boardaction_test.go
View file @
894cc1eb
...
@@ -9,267 +9,221 @@ import (
...
@@ -9,267 +9,221 @@ import (
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
"github.com/33cn/chain33/types"
apimock
"github.com/33cn/chain33/client/mocks"
dbmock
"github.com/33cn/chain33/common/db/mocks"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common"
commonlog
"github.com/33cn/chain33/common/log"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/account"
_
"github.com/33cn/chain33/system"
"github.com/stretchr/testify/mock"
"github.com/33cn/chain33/common/address"
)
)
//type execEnv struct {
type
execEnv
struct
{
// blockTime int64
blockTime
int64
// 1539918074
// blockHeight int64
blockHeight
int64
// difficulty uint64
index
int
//}
difficulty
uint64
//
txHash
string
//var (
}
// Symbol = "TEST"
// AssetExecToken = "token"
var
(
// AssetExecPara = "paracross"
Symbol
=
"BTY"
//
Asset
=
"coins"
// PrivKeyA = "0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" // 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
// PrivKeyB = "0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4" // 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
PrivKeyA
=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
// 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
// PrivKeyC = "0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115" // 1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k
PrivKeyB
=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
// 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
// PrivKeyD = "0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71" // 1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs
PrivKeyC
=
"0x7a80a1f75d7360c6123c32a78ecf978c1ac55636f87892df38d8b85a9aeff115"
// 1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k
// Nodes = [][]byte{
PrivKeyD
=
"0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71"
// 1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs
// []byte("1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"),
AddrA
=
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
// []byte("1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"),
AddrB
=
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
// []byte("1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"),
AddrC
=
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
// []byte("1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"),
AddrD
=
"1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
// }
//)
AddrBWeight
uint64
=
1
//
AddrCWeight
uint64
=
4
//func TestUnfreeze(t *testing.T) {
AddrDWeight
uint64
=
10
// types.SetTitleOnlyForTest("chain33")
NewWeight
uint64
=
2
// total := int64(100000)
Requiredweight
uint64
=
5
// accountA := types.Account{
NewRequiredweight
uint64
=
4
// Balance: total,
CoinsBtyDailylimit
uint64
=
100
// Frozen: 0,
NewCoinsBtyDailylimit
uint64
=
10
// Addr: string(Nodes[0]),
PrintFlag
=
false
// }
InAmount
int64
=
10
// accountB := types.Account{
OutAmount
int64
=
5
// Balance: total,
// Frozen: 0,
boards
=
[]
string
{
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
,
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
,
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
}
// Addr: string(Nodes[1]),
)
// }
//
func
init
()
{
// execAddr := address.ExecAddress(pty.UnfreezeX)
commonlog
.
SetLogLevel
(
"error"
)
// stateDB, _ := dbm.NewGoMemDB("1", "2", 100)
//types.AllowUserExec = append(types.AllowUserExec, []byte("coins"))
// _, ldb, kvdb := util.CreateTestDB()
}
//
// accA, _ := account.NewAccountDB(AssetExecPara, Symbol, stateDB)
func
TestProposalBoard
(
t
*
testing
.
T
)
{
// accA.SaveExecAccount(execAddr, &accountA)
total
:=
types
.
Coin
*
30000
//
accountA
:=
types
.
Account
{
// accB, _ := account.NewAccountDB(AssetExecPara, Symbol, stateDB)
Balance
:
total
,
// accB.SaveExecAccount(execAddr, &accountB)
Frozen
:
0
,
//
Addr
:
AddrA
,
// env := execEnv{
}
// 10,
// types.GetDappFork(pty.UnfreezeX, pty.ForkUnfreezeIDX),
accountB
:=
types
.
Account
{
// 1539918074,
Balance
:
total
,
// }
Frozen
:
0
,
// ty := pty.UnfreezeType{}
Addr
:
AddrB
,
//
}
// // 创建
// opt := &pty.FixAmount{Period: 10, Amount: 2}
accountC
:=
types
.
Account
{
// p1 := &pty.UnfreezeCreate{
Balance
:
total
,
// StartTime: 10,
Frozen
:
0
,
// AssetExec: AssetExecPara,
Addr
:
AddrC
,
// AssetSymbol: Symbol,
}
// TotalCount: 10000,
// Beneficiary: string(Nodes[1]),
accountD
:=
types
.
Account
{
// Means: "FixAmount",
Balance
:
total
,
// MeansOpt: &pty.UnfreezeCreate_FixAmount{FixAmount: opt},
Frozen
:
0
,
// }
Addr
:
AddrD
,
// createTx, err := ty.RPC_UnfreezeCreateTx(p1)
}
// if err != nil {
// t.Error("RPC_UnfreezeCreateTx", "err", err)
env
:=
execEnv
{
// }
1539918074
,
// createTx, err = signTx(createTx, PrivKeyA)
10
,
// if err != nil {
2
,
// t.Error("RPC_UnfreezeCreateTx sign", "err", err)
1539918074
,
// }
"hash"
,
// exec := newUnfreeze()
}
// exec.SetStateDB(stateDB)
// exec.SetLocalDB(kvdb)
stateDB
,
_
:=
dbm
.
NewGoMemDB
(
"state"
,
"state"
,
100
)
// exec.SetEnv(env.blockHeight, env.blockTime, env.difficulty)
localDB
:=
new
(
dbmock
.
KVDB
)
// receipt, err := exec.Exec(createTx, int(1))
api
:=
new
(
apimock
.
QueueProtocolAPI
)
// assert.Nil(t, err)
// assert.NotNil(t, receipt)
accCoin
:=
account
.
NewCoinsAccount
()
// //t.Log(receipt)
accCoin
.
SetDB
(
stateDB
)
// accTmp := accA.LoadExecAccount(accountA.Addr, execAddr)
accCoin
.
SaveAccount
(
&
accountA
)
// assert.Equal(t, total-p1.TotalCount, accTmp.Balance)
accCoin
.
SaveExecAccount
(
address
.
ExecAddress
(
auty
.
AutonomyX
),
&
accountA
)
// assert.Equal(t, p1.TotalCount, accTmp.Frozen)
accCoin
.
SaveAccount
(
&
accountB
)
//
accCoin
.
SaveAccount
(
&
accountC
)
// receiptDate := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
accCoin
.
SaveAccount
(
&
accountD
)
// set, err := exec.ExecLocal(createTx, receiptDate, int(1))
// assert.Nil(t, err)
driver
:=
newAutonomy
()
// assert.NotNil(t, set)
driver
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
//
driver
.
SetStateDB
(
stateDB
)
// req1 := &pty.ReqUnfreezes{
driver
.
SetLocalDB
(
localDB
)
// Beneficiary: p1.Beneficiary,
driver
.
SetAPI
(
api
)
// }
// reply, err := exec.Query("ListUnfreezeByBeneficiary", types.Encode(req1))
// PropBoardTx
// assert.Nil(t, err)
opt1
:=
&
auty
.
ProposalBoard
{
// assert.NotNil(t, reply)
Year
:
2019
,
// resp, ok := reply.(*pty.ReplyUnfreezes)
Month
:
7
,
// assert.True(t, ok)
Day
:
10
,
// assert.Equal(t, 1, len(resp.Unfreeze))
Boards
:
boards
,
// assert.Equal(t, string(unfreezeID(createTx.Hash())), resp.Unfreeze[0].UnfreezeID)
StartBlockHeight
:
env
.
blockHeight
+
5
,
//
EndBlockHeight
:
env
.
blockHeight
+
10
,
// // 提币
}
// p2 := &pty.UnfreezeWithdraw{
pbtx
,
err
:=
propBoardTx
(
opt1
)
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
require
.
NoError
(
t
,
err
)
// }
pbtx
,
err
=
signTx
(
pbtx
,
PrivKeyA
)
// withdrawTx, err := ty.RPC_UnfreezeWithdrawTx(p2)
require
.
NoError
(
t
,
err
)
// if err != nil {
exec
:=
newAutonomy
()
// t.Error("RPC_UnfreezeWithdrawTx", "err", err)
exec
.
SetStateDB
(
stateDB
)
// }
exec
.
SetLocalDB
(
localDB
)
// withdrawTx, err = signTx(withdrawTx, PrivKeyB)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
// if err != nil {
receipt
,
err
:=
exec
.
Exec
(
pbtx
,
int
(
1
))
// t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
require
.
NoError
(
t
,
err
)
// }
require
.
NotNil
(
t
,
receipt
)
// blockTime := int64(10)
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
}
// receipt, err = exec.Exec(withdrawTx, 1)
// assert.Nil(t, err)
func
propBoardTx
(
parm
*
auty
.
ProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
// assert.NotNil(t, receipt)
if
parm
==
nil
{
// //t.Log(receipt)
return
nil
,
types
.
ErrInvalidParam
// accATmp := accA.LoadExecAccount(accountA.Addr, execAddr)
}
// accBTmp := accB.LoadExecAccount(accountB.Addr, execAddr)
val
:=
&
auty
.
AutonomyAction
{
// assert.Equal(t, total-p1.TotalCount, accATmp.Balance)
Ty
:
auty
.
AutonomyActionPropBoard
,
//
Value
:
&
auty
.
AutonomyAction_PropBoard
{
PropBoard
:
parm
},
// u := pty.Unfreeze{}
}
// e := types.Decode(receipt.KV[2].Value, &u)
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
// assert.Nil(t, e)
}
// assert.Equal(t, u.Remaining, accATmp.Frozen)
// assert.Equal(t, accountB.Balance+p1.TotalCount-u.Remaining, accBTmp.Balance)
func
revokeProposalBoardTx
(
parm
*
auty
.
RevokeProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
//
if
parm
==
nil
{
// receiptDate2 := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
return
nil
,
types
.
ErrInvalidParam
// set, err = exec.ExecLocal(withdrawTx, receiptDate2, int(1))
}
// assert.Nil(t, err)
val
:=
&
auty
.
AutonomyAction
{
// assert.NotNil(t, set)
Ty
:
auty
.
AutonomyActionRvkPropBoard
,
//
Value
:
&
auty
.
AutonomyAction_RvkPropBoard
{
RvkPropBoard
:
parm
},
// // 不是受益人提币
}
// {
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
// p2 := &pty.UnfreezeWithdraw{
}
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
// }
func
voteProposalBoardTx
(
parm
*
auty
.
VoteProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
// withdrawTx, err := ty.RPC_UnfreezeWithdrawTx(p2)
if
parm
==
nil
{
// if err != nil {
return
nil
,
types
.
ErrInvalidParam
// t.Error("RPC_UnfreezeWithdrawTx", "err", err)
}
// }
val
:=
&
auty
.
AutonomyAction
{
// withdrawTx, err = signTx(withdrawTx, PrivKeyC)
Ty
:
auty
.
AutonomyActionVotePropBoard
,
// if err != nil {
Value
:
&
auty
.
AutonomyAction_VotePropBoard
{
VotePropBoard
:
parm
},
// t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
}
// }
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
// blockTime := int64(10)
}
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
// receipt, err = exec.Exec(withdrawTx, 1)
func
terminateProposalBoardTx
(
parm
*
auty
.
TerminateProposalBoard
)
(
*
types
.
Transaction
,
error
)
{
// assert.Equal(t, pty.ErrNoPrivilege, err)
if
parm
==
nil
{
// assert.Nil(t, receipt)
return
nil
,
types
.
ErrInvalidParam
// }
}
//
val
:=
&
auty
.
AutonomyAction
{
// // 不是创建者终止
Ty
:
auty
.
AutonomyActionTmintPropBoard
,
// {
Value
:
&
auty
.
AutonomyAction_TmintPropBoard
{
TmintPropBoard
:
parm
},
// p3 := &pty.UnfreezeTerminate{
}
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
return
types
.
CreateFormatTx
(
types
.
ExecName
(
auty
.
AutonomyX
),
types
.
Encode
(
val
))
// }
}
// terminateTx, err := ty.RPC_UnfreezeTerminateTx(p3)
// if err != nil {
func
TestGetStartHeightVoteAccount
(
t
*
testing
.
T
)
{
// t.Error("RPC_UnfreezeTerminateTx", "err", err)
at
:=
newAutonomy
()
.
(
*
Autonomy
)
// }
at
.
SetLocalDB
(
new
(
dbmock
.
KVDB
))
// terminateTx, err = signTx(terminateTx, PrivKeyC)
// if err != nil {
api
:=
new
(
apimock
.
QueueProtocolAPI
)
// t.Error("RPC_UnfreezeTerminateTx sign", "err", err)
at
.
SetAPI
(
api
)
// }
tx
:=
&
types
.
Transaction
{}
// receipt, err = exec.Exec(terminateTx, 1)
action
:=
newAction
(
at
,
tx
,
0
)
// assert.Equal(t, pty.ErrNoPrivilege, err)
// assert.Nil(t, receipt)
addr
:=
"1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP"
// }
api
.
On
(
"StoreList"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreListReply
{},
nil
)
//
api
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
types
.
Header
{
StateHash
:
[]
byte
(
"111111111111111111111"
)},
nil
)
// // 终止
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
&
types
.
StoreReplyValue
{
Values
:
make
([][]
byte
,
1
)},
nil
)
// p3 := &pty.UnfreezeTerminate{
hear
:=
&
types
.
Header
{
StateHash
:
[]
byte
(
"111111111111111111111"
)}
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
api
.
On
(
"GetHeaders"
,
mock
.
Anything
)
.
// }
Return
(
&
types
.
Headers
{
// terminateTx, err := ty.RPC_UnfreezeTerminateTx(p3)
Items
:
[]
*
types
.
Header
{
hear
}},
nil
)
// if err != nil {
_
,
err
:=
action
.
getStartHeightVoteAccount
(
addr
,
0
)
// t.Error("RPC_UnfreezeTerminateTx", "err", err)
require
.
NoError
(
t
,
err
)
// }
}
// terminateTx, err = signTx(terminateTx, PrivKeyA)
// if err != nil {
func
TestGetReceiptLog
(
t
*
testing
.
T
)
{
// t.Error("RPC_UnfreezeTerminateTx sign", "err", err)
pre
:=
&
auty
.
AutonomyProposalBoard
{
// }
PropBoard
:
&
auty
.
ProposalBoard
{
Year
:
1800
,
Month
:
1
},
// exec.SetEnv(env.blockHeight+2, env.blockTime+blockTime, env.difficulty)
Res
:
&
auty
.
VotesResult
{
TotalVotes
:
100
},
// receipt, err = exec.Exec(terminateTx, 1)
Status
:
1
,
// assert.Nil(t, err)
Address
:
"121"
,
// assert.NotNil(t, receipt)
}
// //t.Log(receipt)
cur
:=
&
auty
.
AutonomyProposalBoard
{
// accATmp = accA.LoadExecAccount(accountA.Addr, execAddr)
PropBoard
:
&
auty
.
ProposalBoard
{
Year
:
1900
,
Month
:
1
},
// assert.Equal(t, total+total, accATmp.Balance+accBTmp.Balance)
Res
:
&
auty
.
VotesResult
{
TotalVotes
:
100
},
// assert.Equal(t, int64(0), accATmp.Frozen)
Status
:
2
,
//
Address
:
"123"
,
// receiptDate3 := &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
}
// set, err = exec.ExecLocal(terminateTx, receiptDate3, int(1))
log
:=
getReceiptLog
(
pre
,
cur
,
2
)
// assert.Nil(t, err)
require
.
Equal
(
t
,
int32
(
2
),
log
.
Ty
)
// assert.NotNil(t, set)
recpt
:=
&
auty
.
ReceiptProposalBoard
{}
//
err
:=
types
.
Decode
(
log
.
Log
,
recpt
)
// // 终止后不能继续提币
require
.
NoError
(
t
,
err
)
// {
require
.
Equal
(
t
,
int32
(
1800
),
recpt
.
Prev
.
PropBoard
.
Year
)
// p2 := &pty.UnfreezeWithdraw{
require
.
Equal
(
t
,
int32
(
1900
),
recpt
.
Current
.
PropBoard
.
Year
)
// UnfreezeID: hex.EncodeToString(createTx.Hash()),
}
// }
// withdrawTx, err := ty.RPC_UnfreezeWithdrawTx(p2)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx", "err", err)
// }
// withdrawTx, err = signTx(withdrawTx, PrivKeyB)
// if err != nil {
// t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
// }
// blockTime := int64(10)
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime+blockTime, env.difficulty)
// receipt, err = exec.Exec(withdrawTx, 1)
// assert.Equal(t, pty.ErrUnfreezeEmptied, err)
// assert.Nil(t, receipt)
// }
//
// req := types.ReqString{Data: hex.EncodeToString(createTx.Hash())}
// _, err = exec.Query("GetUnfreeze", types.Encode(&req))
// assert.Nil(t, err)
//
// _, err = exec.Query("GetUnfreezeWithdraw", types.Encode(&req))
// assert.Nil(t, err)
//
// _, err = exec.ExecDelLocal(terminateTx, receiptDate3, int(1))
// assert.Nil(t, err)
//
// exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
// _, err = exec.ExecDelLocal(withdrawTx, receiptDate2, int(1))
// assert.Nil(t, err)
//
// exec.SetEnv(env.blockHeight, env.blockTime+blockTime, env.difficulty)
// _, err = exec.ExecDelLocal(createTx, receiptDate, int(1))
// assert.Nil(t, err)
//
// ldb.Close()
//}
//
//func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error) {
// signType := types.SECP256K1
// c, err := crypto.New(types.GetSignName(pty.UnfreezeX, signType))
// if err != nil {
// return tx, err
// }
//
// bytes, err := common.FromHex(hexPrivKey[:])
// if err != nil {
// return tx, err
// }
//
// privKey, err := c.PrivKeyFromBytes(bytes)
// if err != nil {
// return tx, err
// }
//
// tx.Sign(int32(signType), privKey)
// return tx, nil
//}
func
TestCopyAutonomyProposalBoard
(
t
*
testing
.
T
)
{
func
TestCopyAutonomyProposalBoard
(
t
*
testing
.
T
)
{
cur
:=
&
auty
.
AutonomyProposalBoard
{
cur
:=
&
auty
.
AutonomyProposalBoard
{
...
@@ -291,3 +245,24 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
...
@@ -291,3 +245,24 @@ func TestCopyAutonomyProposalBoard(t *testing.T) {
require
.
Equal
(
t
,
"123"
,
new
.
Address
)
require
.
Equal
(
t
,
"123"
,
new
.
Address
)
require
.
Equal
(
t
,
2
,
int
(
new
.
Status
))
require
.
Equal
(
t
,
2
,
int
(
new
.
Status
))
}
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
signType
:=
types
.
SECP256K1
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
auty
.
AutonomyX
,
signType
))
if
err
!=
nil
{
return
tx
,
err
}
bytes
,
err
:=
common
.
FromHex
(
hexPrivKey
[
:
])
if
err
!=
nil
{
return
tx
,
err
}
privKey
,
err
:=
c
.
PrivKeyFromBytes
(
bytes
)
if
err
!=
nil
{
return
tx
,
err
}
tx
.
Sign
(
int32
(
signType
),
privKey
)
return
tx
,
nil
}
\ No newline at end of file
plugin/dapp/autonomy/plugin.go
View file @
894cc1eb
...
@@ -9,12 +9,12 @@ import (
...
@@ -9,12 +9,12 @@ import (
"github.com/33cn/plugin/plugin/dapp/autonomy/commands"
"github.com/33cn/plugin/plugin/dapp/autonomy/commands"
"github.com/33cn/plugin/plugin/dapp/autonomy/executor"
"github.com/33cn/plugin/plugin/dapp/autonomy/executor"
"github.com/33cn/plugin/plugin/dapp/autonomy/rpc"
"github.com/33cn/plugin/plugin/dapp/autonomy/rpc"
ptypes
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
"github.com/33cn/plugin/plugin/dapp/autonomy/types"
)
)
func
init
()
{
func
init
()
{
pluginmgr
.
Register
(
&
pluginmgr
.
PluginBase
{
pluginmgr
.
Register
(
&
pluginmgr
.
PluginBase
{
Name
:
ptypes
.
PackageName
,
Name
:
types
.
AutonomyX
,
ExecName
:
executor
.
GetName
(),
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Exec
:
executor
.
Init
,
Cmd
:
commands
.
AutonomyCmd
,
Cmd
:
commands
.
AutonomyCmd
,
...
...
plugin/dapp/autonomy/rpc/jrpc_channel_test.go
View file @
894cc1eb
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
rpctypes
"github.com/33cn/chain33/rpc/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/chain33/util/testnode"
pty
"github.com/33cn/plugin/plugin/dapp/blackwhite
/types"
auty
"github.com/33cn/plugin/plugin/dapp/autonomy
/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
...
@@ -38,13 +38,11 @@ func TestJRPCChannel(t *testing.T) {
...
@@ -38,13 +38,11 @@ func TestJRPCChannel(t *testing.T) {
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
}{
{
fn
:
testCreateRawTxCmd
},
{
fn
:
testPropBoardTxCmd
},
{
fn
:
testPlayRawTxCmd
},
{
fn
:
testRevokeProposalBoardTxCmd
},
{
fn
:
testShowRawTxCmd
},
{
fn
:
testVoteProposalBoardTxCmd
},
{
fn
:
testTimeoutDoneTxCmd
},
{
fn
:
testTerminateProposalBoardTxCmd
},
{
fn
:
testRoundInfoCmd
},
{
fn
:
testGetProposalBoardCmd
},
{
fn
:
testRoundListCmd
},
{
fn
:
testLoopResultCmd
},
}
}
for
index
,
testCase
:=
range
testCases
{
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
...
@@ -58,58 +56,36 @@ func TestJRPCChannel(t *testing.T) {
...
@@ -58,58 +56,36 @@ func TestJRPCChannel(t *testing.T) {
}
}
}
}
func
test
CreateRaw
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
test
PropBoard
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
pty
.
BlackwhiteCreateTxReq
{}
params
:=
&
auty
.
ProposalBoard
{}
var
res
string
var
res
string
return
jrpc
.
Call
(
"
blackwhite.BlackwhiteCreate
Tx"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
autonomy.PropBoard
Tx"
,
params
,
&
res
)
}
}
func
test
PlayRaw
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
test
RevokeProposalBoard
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
pty
.
BlackwhitePlayTxReq
{}
params
:=
&
auty
.
RevokeProposalBoard
{}
var
res
string
var
res
string
return
jrpc
.
Call
(
"
blackwhite.BlackwhitePlay
Tx"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
autonomy.RevokeProposalBoard
Tx"
,
params
,
&
res
)
}
}
func
test
ShowRaw
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
test
VoteProposalBoard
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
pty
.
BlackwhiteShowTxReq
{}
params
:=
&
auty
.
VoteProposalBoard
{}
var
res
string
var
res
string
return
jrpc
.
Call
(
"
blackwhite.BlackwhiteShow
Tx"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
autonomy.VoteProposalBoard
Tx"
,
params
,
&
res
)
}
}
func
testT
imeoutDone
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
testT
erminateProposalBoard
TxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
pty
.
BlackwhiteTimeoutDoneTxReq
{}
params
:=
&
auty
.
TerminateProposalBoard
{}
var
res
string
var
res
string
return
jrpc
.
Call
(
"
blackwhite.BlackwhiteTimeoutDone
Tx"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
autonomy.TerminateProposalBoard
Tx"
,
params
,
&
res
)
}
}
func
test
RoundInfo
Cmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
test
GetProposalBoard
Cmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
ReqBlackwhiteRoundInfo
{}
req
:=
&
auty
.
ReqQueryProposalBoard
{}
params
.
FuncName
=
pty
.
GetBlackwhiteRoundInfo
params
.
FuncName
=
auty
.
GetProposalBoard
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
ReplyBlackwhiteRoundInfo
{}
rep
=
&
auty
.
ReplyQueryProposalBoard
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testRoundListCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
ReqBlackwhiteRoundList
{}
params
.
FuncName
=
pty
.
GetBlackwhiteByStatusAndAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
ReplyBlackwhiteRoundList
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testLoopResultCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
ReqLoopResult
{}
params
.
FuncName
=
pty
.
GetBlackwhiteloopResult
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
ReplyLoopResults
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
}
plugin/dapp/autonomy/types/const.go
View file @
894cc1eb
...
@@ -83,8 +83,6 @@ const (
...
@@ -83,8 +83,6 @@ const (
//建议用github的组织名称,或者用户名字开头, 再加上自己的插件的名字
//建议用github的组织名称,或者用户名字开头, 再加上自己的插件的名字
//如果发生重名,可以通过配置文件修改这些名字
//如果发生重名,可以通过配置文件修改这些名字
var
(
var
(
PackageName
=
"chain33.autonomy"
RPCName
=
"Chain33.Autonomy"
AutonomyX
=
"autonomy"
AutonomyX
=
"autonomy"
ExecerAutonomy
=
[]
byte
(
AutonomyX
)
ExecerAutonomy
=
[]
byte
(
AutonomyX
)
)
)
plugin/dapp/autonomy/types/types.go
View file @
894cc1eb
...
@@ -16,9 +16,10 @@ var tlog = log.New("module", name)
...
@@ -16,9 +16,10 @@ var tlog = log.New("module", name)
func
init
()
{
func
init
()
{
name
=
AutonomyX
name
=
AutonomyX
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
AutonomyX
))
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
name
))
// init executor type
// init executor type
types
.
RegistorExecutor
(
name
,
NewType
())
types
.
RegistorExecutor
(
name
,
NewType
())
types
.
RegisterDappFork
(
name
,
"Enable"
,
1
)
}
}
//getRealExecName
//getRealExecName
...
...
plugin/dapp/init/init.go
View file @
894cc1eb
package
init
package
init
import
(
import
(
_
"github.com/33cn/plugin/plugin/dapp/autonomy"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/blackwhite"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/blackwhite"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/cert"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/cert"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/echo"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/echo"
//auto gen
...
...
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