Commit 716ccb68 authored by mdj33's avatar mdj33 Committed by vipwzw

fix ut

parent 7847aa74
...@@ -85,7 +85,7 @@ func CheckCount(count int32) bool { ...@@ -85,7 +85,7 @@ func CheckCount(count int32) bool {
//CheckAmount 最小交易 1coin //CheckAmount 最小交易 1coin
func CheckAmount(amount, coinPrecision int64) bool { func CheckAmount(amount, coinPrecision int64) bool {
if amount < coinPrecision || amount >= types.MaxCoin { if amount < coinPrecision || amount >= types.MaxCoin*coinPrecision {
return false return false
} }
return true return true
......
...@@ -41,8 +41,8 @@ func NewMainAccount(cfg *types.Chain33Config, paraTitle, paraExecName, paraSymbo ...@@ -41,8 +41,8 @@ func NewMainAccount(cfg *types.Chain33Config, paraTitle, paraExecName, paraSymbo
} }
func assetDepositBalance(acc *account.DB, addr string, amount int64) (*types.Receipt, error) { func assetDepositBalance(acc *account.DB, addr string, amount int64) (*types.Receipt, error) {
if err := acc.CheckAmount(amount); err != nil { if !acc.CheckAmount(amount) {
return nil, err return nil, types.ErrAmount
} }
acc1 := acc.LoadAccount(addr) acc1 := acc.LoadAccount(addr)
copyacc := *acc1 copyacc := *acc1
...@@ -66,8 +66,8 @@ func assetDepositBalance(acc *account.DB, addr string, amount int64) (*types.Rec ...@@ -66,8 +66,8 @@ func assetDepositBalance(acc *account.DB, addr string, amount int64) (*types.Rec
} }
func assetWithdrawBalance(acc *account.DB, addr string, amount int64) (*types.Receipt, error) { func assetWithdrawBalance(acc *account.DB, addr string, amount int64) (*types.Receipt, error) {
if err := acc.CheckAmount(amount); err != nil { if !acc.CheckAmount(amount) {
return nil, err return nil, types.ErrAmount
} }
acc1 := acc.LoadAccount(addr) acc1 := acc.LoadAccount(addr)
if acc1.Balance-amount < 0 { if acc1.Balance-amount < 0 {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package executor package executor
import ( import (
"strings"
"testing" "testing"
apimock "github.com/33cn/chain33/client/mocks" apimock "github.com/33cn/chain33/client/mocks"
...@@ -39,7 +40,9 @@ func (s *suiteRelayLog) SetupSuite() { ...@@ -39,7 +40,9 @@ func (s *suiteRelayLog) SetupSuite() {
} }
s.db = new(mocks.KV) s.db = new(mocks.KV)
s.log = newRelayLog(order) cfg := types.NewChain33Config(strings.Replace(types.GetDefaultCfgstring(), "Title=\"local\"", "Title=\"chain33\"", 1))
s.log = newRelayLog(order, cfg)
} }
func (s *suiteRelayLog) TestSave() { func (s *suiteRelayLog) TestSave() {
......
...@@ -542,10 +542,16 @@ func tokenSell(cmd *cobra.Command, args []string) { ...@@ -542,10 +542,16 @@ func tokenSell(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "FormatFloatDisplay2Value.fee")) fmt.Fprintln(os.Stderr, errors.Wrapf(err, "FormatFloatDisplay2Value.fee"))
return return
} }
totalInt64 := int64(total * 1e8 / 1e6) //缺省一手是0.01个coin,如果精度小于100,就是1
oneHand := int64(1)
if cfg.CoinPrecision > 1e2 {
oneHand = cfg.CoinPrecision / 1e2
}
totalInt64 := int64(total * float64(cfg.CoinPrecision) / float64(oneHand))
params := &pty.TradeSellTx{ params := &pty.TradeSellTx{
TokenSymbol: symbol, TokenSymbol: symbol,
AmountPerBoardlot: 1e6, AmountPerBoardlot: oneHand,
MinBoardlot: min, MinBoardlot: min,
PricePerBoardlot: priceInt64, PricePerBoardlot: priceInt64,
TotalBoardlot: totalInt64, TotalBoardlot: totalInt64,
...@@ -710,10 +716,16 @@ func tokenBuyLimit(cmd *cobra.Command, args []string) { ...@@ -710,10 +716,16 @@ func tokenBuyLimit(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "FormatFloatDisplay2Value.fee")) fmt.Fprintln(os.Stderr, errors.Wrapf(err, "FormatFloatDisplay2Value.fee"))
return return
} }
totalInt64 := int64(total * 1e8 / 1e6) //缺省一手是0.01个coin,如果精度小于100,就是1
oneHand := int64(1)
if cfg.CoinPrecision > 1e2 {
oneHand = cfg.CoinPrecision / 1e2
}
totalInt64 := int64(total * float64(cfg.CoinPrecision) / float64(oneHand))
params := &pty.TradeBuyLimitTx{ params := &pty.TradeBuyLimitTx{
TokenSymbol: symbol, TokenSymbol: symbol,
AmountPerBoardlot: 1e6, AmountPerBoardlot: oneHand,
MinBoardlot: min, MinBoardlot: min,
PricePerBoardlot: priceInt64, PricePerBoardlot: priceInt64,
TotalBoardlot: totalInt64, TotalBoardlot: totalInt64,
......
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