Commit 556c6d21 authored by vipwzw's avatar vipwzw Committed by 33cn

fix test

parent 9fad87f0
......@@ -26,7 +26,7 @@ func init() {
func initExec(ldb db.DB, kvdb db.KVDB, code string, t assert.TestingT) *js {
e := newjs().(*js)
e.SetEnv(1, time.Now().Unix(), 1, nil, nil)
e.SetEnv(1, time.Now().Unix(), 1)
mockapi := &mocks.QueueProtocolAPI{}
mockapi.On("Query", "ticket", "RandNumHash", mock.Anything).Return(&types.ReplyHash{Hash: []byte("hello")}, nil)
e.SetAPI(mockapi)
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"github.com/33cn/chain33/types"
)
const retryNum = 10
// GetMainHeightByTxHash get Block height
func (action *Action) GetMainHeightByTxHash(txHash []byte) (int64, error) {
param := &types.ReqHash{Hash: txHash}
txDetail, err := action.lottery.GetExecutorAPI().QueryTx(param)
if err != nil {
return -1, err
}
return txDetail.GetHeight(), nil
}
......@@ -261,12 +261,7 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
lott.BuyAmount = 0
llog.Debug("LotteryCreate", "OpRewardRatio", lott.OpRewardRatio, "DevRewardRatio", lott.DevRewardRatio)
if types.IsPara() {
mainHeight, err := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("LotteryCreate", "mainHeight", mainHeight)
return nil, err
}
lott.CreateOnMain = mainHeight
lott.CreateOnMain = action.lottery.GetMainHeight()
}
llog.Debug("LotteryCreate created", "lotteryID", lotteryID)
......@@ -316,22 +311,13 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
lott.Status = pty.LotteryPurchase
lott.Round++
if types.IsPara() {
mainHeight, err := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("LotteryBuy", "mainHeight", mainHeight)
return nil, err
}
lott.LastTransToPurStateOnMain = mainHeight
lott.LastTransToPurStateOnMain = action.lottery.GetMainHeight()
}
}
if lott.Status == pty.LotteryPurchase {
if types.IsPara() {
mainHeight, err := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("LotteryBuy", "mainHeight", mainHeight)
return nil, err
}
mainHeight := action.lottery.GetMainHeight()
if mainHeight-lott.LastTransToPurStateOnMain > lott.GetPurBlockNum() {
llog.Error("LotteryBuy", "action.height", action.height, "mainHeight", mainHeight, "LastTransToPurStateOnMain", lott.LastTransToPurStateOnMain)
return nil, pty.ErrLotteryStatus
......@@ -437,11 +423,7 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
}
if types.IsPara() {
mainHeight, err := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("LotteryBuy", "mainHeight", mainHeight)
return nil, err
}
mainHeight := action.lottery.GetMainHeight()
if mainHeight-lott.GetLastTransToPurStateOnMain() < lott.GetDrawBlockNum() {
llog.Error("LotteryDraw", "action.height", action.height, "mainHeight", mainHeight, "GetLastTransToPurStateOnMain", lott.GetLastTransToPurState())
return nil, pty.ErrLotteryStatus
......@@ -711,12 +693,7 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
action.recordMissing(lott)
if types.IsPara() {
mainHeight, err := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("LotteryDraw", "mainHeight", mainHeight)
return nil, nil, nil, err
}
lott.LastTransToDrawStateOnMain = mainHeight
lott.LastTransToDrawStateOnMain = action.lottery.GetHeight()
}
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, &updateInfo, &gainInfos, nil
}
......
......@@ -90,7 +90,7 @@ func TestUnfreeze(t *testing.T) {
}
exec := newUnfreeze()
exec.SetStateDB(stateDB)
exec.SetEnv(env.blockHeight, env.blockTime, env.difficulty, nil, nil)
exec.SetEnv(env.blockHeight, env.blockTime, env.difficulty)
receipt, err := exec.Exec(createTx, int(1))
assert.Nil(t, err)
assert.NotNil(t, receipt)
......@@ -117,7 +117,7 @@ func TestUnfreeze(t *testing.T) {
t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
}
blockTime := int64(10)
exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty, nil, nil)
exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty)
receipt, err = exec.Exec(withdrawTx, 1)
assert.Nil(t, err)
assert.NotNil(t, receipt)
......@@ -151,7 +151,7 @@ func TestUnfreeze(t *testing.T) {
t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
}
blockTime := int64(10)
exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime, env.difficulty, nil, nil)
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)
......@@ -214,7 +214,7 @@ func TestUnfreeze(t *testing.T) {
t.Error("RPC_UnfreezeWithdrawTx sign", "err", err)
}
blockTime := int64(10)
exec.SetEnv(env.blockHeight+1, env.blockTime+blockTime+blockTime, env.difficulty, nil, nil)
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)
......
......@@ -398,6 +398,11 @@ func (d *DriverBase) GetHeight() int64 {
return d.height
}
// GetMainHeight return height
func (d *DriverBase) GetMainHeight() int64 {
return d.mainHeight
}
// GetBlockTime return block time
func (d *DriverBase) GetBlockTime() int64 {
return d.blocktime
......
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