Commit 5728f60e authored by mdj33's avatar mdj33 Committed by vipwzw

add ut

parent 703449dc
...@@ -817,7 +817,10 @@ func checkMinerTx(current *types.BlockDetail) error { ...@@ -817,7 +817,10 @@ func checkMinerTx(current *types.BlockDetail) error {
// Query_CreateNewAccount 通知para共识模块钱包创建了一个新的账户 // Query_CreateNewAccount 通知para共识模块钱包创建了一个新的账户
func (client *client) Query_CreateNewAccount(acc *types.Account) (types.Message, error) { func (client *client) Query_CreateNewAccount(acc *types.Account) (types.Message, error) {
plog.Info("Query_CreateNewAccount", "acc", acc) if acc == nil {
return nil, types.ErrInvalidParam
}
plog.Info("Query_CreateNewAccount", "acc", acc.Addr)
// 需要para共识这边处理新创建的账户是否是超级节点发送commit共识交易的账户 // 需要para共识这边处理新创建的账户是否是超级节点发送commit共识交易的账户
client.commitMsgClient.onWalletAccount(acc) client.commitMsgClient.onWalletAccount(acc)
return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil
...@@ -825,7 +828,10 @@ func (client *client) Query_CreateNewAccount(acc *types.Account) (types.Message, ...@@ -825,7 +828,10 @@ func (client *client) Query_CreateNewAccount(acc *types.Account) (types.Message,
// Query_WalletStatus 通知para共识模块钱包锁状态有变化 // Query_WalletStatus 通知para共识模块钱包锁状态有变化
func (client *client) Query_WalletStatus(walletStatus *types.WalletStatus) (types.Message, error) { func (client *client) Query_WalletStatus(walletStatus *types.WalletStatus) (types.Message, error) {
plog.Info("Query_WalletStatus", "walletStatus", walletStatus) if walletStatus == nil {
return nil, types.ErrInvalidParam
}
plog.Info("Query_WalletStatus", "walletStatus", walletStatus.IsWalletLock)
// 需要para共识这边根据walletStatus.IsWalletLock锁的状态开启/关闭发送共识交易 // 需要para共识这边根据walletStatus.IsWalletLock锁的状态开启/关闭发送共识交易
client.commitMsgClient.onWalletStatus(walletStatus) client.commitMsgClient.onWalletStatus(walletStatus)
return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil
......
...@@ -205,7 +205,7 @@ out: ...@@ -205,7 +205,7 @@ out:
continue continue
} }
//开启挖矿 //开启挖矿
if client.privateKey != nil && readTick == nil { if readTick == nil {
ticker = time.NewTicker(time.Second * time.Duration(minerInterval)) ticker = time.NewTicker(time.Second * time.Duration(minerInterval))
readTick = ticker.C readTick = ticker.C
plog.Info("para consensus start mining") plog.Info("para consensus start mining")
...@@ -593,6 +593,11 @@ func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) { ...@@ -593,6 +593,11 @@ func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) {
plog.Info("para commit fetchPriKey") plog.Info("para commit fetchPriKey")
} }
if client.privateKey == nil {
plog.Info("para commit wallet status prikey null", "status", status.IsWalletLock)
return
}
select { select {
case client.minerSwitch <- !status.IsWalletLock: case client.minerSwitch <- !status.IsWalletLock:
case <-client.quit: case <-client.quit:
......
...@@ -50,42 +50,40 @@ func TestParaNode(t *testing.T) { ...@@ -50,42 +50,40 @@ func TestParaNode(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, detail.Receipt.Ty, int32(types.ExecOk)) assert.Equal(t, detail.Receipt.Ty, int32(types.ExecOk))
testParaQuery(para)
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
tx = util.CreateTxWithExecer(para.Para.GetGenesisKey(), "user.p.guodun.none") tx = util.CreateTxWithExecer(para.Para.GetGenesisKey(), "user.p.guodun.none")
para.Para.SendTxRPC(tx) para.Para.SendTxRPC(tx)
para.Para.WaitHeight(int64(i) + 1) para.Para.WaitHeight(int64(i) + 1)
} }
testParaQuery(para)
} }
func testParaQuery(para *node.ParaNode) { func testParaQuery(para *node.ParaNode) {
var acc types.Account
var param types.ReqWalletImportPrivkey acc.Addr = "1EbDHAXpoiewjPLX9uqoz38HsKqMXayZrF"
param.Label = "Importprivkey"
param.Privkey = "CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
para.Para.GetAPI().Notify( para.Para.GetAPI().Notify(
"consensus", types.EventConsensusQuery, &types.ChainExecutor{ "consensus", types.EventConsensusQuery, &types.ChainExecutor{
Driver: "para", Driver: "para",
FuncName: "CreateNewAccount", FuncName: "CreateNewAccount",
Param: types.Encode(&param), Param: types.Encode(&acc),
}) })
var param1 types.ReqNewAccount var walletsatus types.WalletStatus
param1.Label = "NewAccount" walletsatus.IsWalletLock = true
para.Para.GetAPI().Notify( para.Para.GetAPI().Notify(
"consensus", types.EventConsensusQuery, &types.ChainExecutor{ "consensus", types.EventConsensusQuery, &types.ChainExecutor{
Driver: "para", Driver: "para",
FuncName: "CreateNewAccount", FuncName: "WalletStatus",
Param: types.Encode(&param1), Param: types.Encode(&walletsatus),
}) })
var walletsatus types.WalletStatus walletsatus.IsWalletLock = false
walletsatus.IsWalletLock = true
para.Para.GetAPI().Notify( para.Para.GetAPI().Notify(
"consensus", types.EventConsensusQuery, &types.ChainExecutor{ "consensus", types.EventConsensusQuery, &types.ChainExecutor{
Driver: "para", Driver: "para",
FuncName: "WalletStatus", FuncName: "WalletStatus",
Param: types.Encode(&walletsatus), Param: types.Encode(&walletsatus),
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment