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 {
// Query_CreateNewAccount 通知para共识模块钱包创建了一个新的账户
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共识交易的账户
client.commitMsgClient.onWalletAccount(acc)
return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil
......@@ -825,7 +828,10 @@ func (client *client) Query_CreateNewAccount(acc *types.Account) (types.Message,
// Query_WalletStatus 通知para共识模块钱包锁状态有变化
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锁的状态开启/关闭发送共识交易
client.commitMsgClient.onWalletStatus(walletStatus)
return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil
......
......@@ -205,7 +205,7 @@ out:
continue
}
//开启挖矿
if client.privateKey != nil && readTick == nil {
if readTick == nil {
ticker = time.NewTicker(time.Second * time.Duration(minerInterval))
readTick = ticker.C
plog.Info("para consensus start mining")
......@@ -593,6 +593,11 @@ func (client *commitMsgClient) onWalletStatus(status *types.WalletStatus) {
plog.Info("para commit fetchPriKey")
}
if client.privateKey == nil {
plog.Info("para commit wallet status prikey null", "status", status.IsWalletLock)
return
}
select {
case client.minerSwitch <- !status.IsWalletLock:
case <-client.quit:
......
......@@ -50,42 +50,40 @@ func TestParaNode(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, detail.Receipt.Ty, int32(types.ExecOk))
testParaQuery(para)
for i := 0; i < 3; i++ {
tx = util.CreateTxWithExecer(para.Para.GetGenesisKey(), "user.p.guodun.none")
para.Para.SendTxRPC(tx)
para.Para.WaitHeight(int64(i) + 1)
}
testParaQuery(para)
}
func testParaQuery(para *node.ParaNode) {
var param types.ReqWalletImportPrivkey
param.Label = "Importprivkey"
param.Privkey = "CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
var acc types.Account
acc.Addr = "1EbDHAXpoiewjPLX9uqoz38HsKqMXayZrF"
para.Para.GetAPI().Notify(
"consensus", types.EventConsensusQuery, &types.ChainExecutor{
Driver: "para",
FuncName: "CreateNewAccount",
Param: types.Encode(&param),
Param: types.Encode(&acc),
})
var param1 types.ReqNewAccount
param1.Label = "NewAccount"
var walletsatus types.WalletStatus
walletsatus.IsWalletLock = true
para.Para.GetAPI().Notify(
"consensus", types.EventConsensusQuery, &types.ChainExecutor{
Driver: "para",
FuncName: "CreateNewAccount",
Param: types.Encode(&param1),
FuncName: "WalletStatus",
Param: types.Encode(&walletsatus),
})
var walletsatus types.WalletStatus
walletsatus.IsWalletLock = true
walletsatus.IsWalletLock = false
para.Para.GetAPI().Notify(
"consensus", types.EventConsensusQuery, &types.ChainExecutor{
Driver: "para",
FuncName: "WalletStatus",
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