Commit c47322b3 authored by linj's avatar linj

add auto test for burn mint

parent 3cc1f310
......@@ -19,6 +19,7 @@ type tokenAutoTest struct {
WithdrawCaseArr []autotest.WithdrawCase `toml:"WithdrawCase,omitempty"`
TokenRevokeCaseArr []TokenRevokeCase `toml:"TokenRevokeCase,omitempty"`
TokenMintCaseArr []TokenMintCase `toml:"TokenMintCase,omitempty"`
TokenBurnCaseArr []TokenBurnCase `toml:"TokenBurnCase,omitempty"`
}
func init() {
......
......@@ -25,6 +25,15 @@ dep = ["tokenPre"]
id = "tokenMint"
command = "send token mint -a 100 -s TC -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
dep = ["tokenFinish"]
amount = "100"
checkItem = ["balance"]
[[TokenBurnCase]]
id = "tokenBurn"
command = "send token burn -a 50 -s TC -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
dep = ["tokenMint"]
amount = "50"
checkItem = ["balance"]
#send to token for precreate
[[TransferCase]]
......
......@@ -6,6 +6,8 @@ package autotest
import (
"github.com/33cn/chain33/cmd/autotest/types"
"strconv"
)
// TokenPreCreateCase token precreatecase command
......@@ -63,6 +65,8 @@ func (testCase *TokenFinishCreateCase) SendCommand(packID string) (types.PackFun
// TokenMintCase token mint case
type TokenMintCase struct {
types.BaseCase
Amount string `toml:"amount"`
}
// TokenMintPack token mint pack command
......@@ -75,3 +79,95 @@ func (testCase *TokenMintCase) SendCommand(packID string) (types.PackFunc, error
return types.DefaultSend(testCase, &TokenMintPack{}, packID)
}
// GetCheckHandlerMap get check handle for map
func (pack *TokenMintPack) GetCheckHandlerMap() interface{} {
funcMap := make(types.CheckHandlerMapDiscard, 2)
funcMap["balance"] = pack.checkBalance
return funcMap
}
func (pack *TokenMintPack) checkBalance(txInfo map[string]interface{}) bool {
logArr := txInfo["receipt"].(map[string]interface{})["logs"].([]interface{})
logTokenBurn := logArr[1].(map[string]interface{})["log"].(map[string]interface{})
logAccBurn := logArr[2].(map[string]interface{})["log"].(map[string]interface{})
interCase := pack.TCase.(*TokenMintCase)
amount1, _ := strconv.ParseInt(interCase.Amount, 10, 64)
amount := amount1 * 1e8
pack.FLog.Info("MintDetails", "TestID", pack.PackID,
"TokenPrev", logTokenBurn["prev"].(map[string]interface{})["total"].(string),
"TokenCurr", logTokenBurn["current"].(map[string]interface{})["total"].(string),
"AccPrev", logAccBurn["prev"].(map[string]interface{})["balance"].(string),
"AccCurr", logAccBurn["current"].(map[string]interface{})["balance"].(string),
"amount", amount1)
totalCurrent := parseInt64(logTokenBurn["current"].(map[string]interface{})["total"])
totalPrev := parseInt64(logTokenBurn["prev"].(map[string]interface{})["total"])
accCurrent := parseInt64(logAccBurn["current"].(map[string]interface{})["balance"])
accPrev := parseInt64(logAccBurn["prev"].(map[string]interface{})["balance"])
return totalCurrent - amount == totalPrev && accCurrent - amount == accPrev
}
// TokenBurnCase token mint case
type TokenBurnCase struct {
types.BaseCase
Amount string `toml:"amount"`
}
// TokenBurnPack token mint pack command
type TokenBurnPack struct {
types.BaseCasePack
}
// SendCommand send command function
func (testCase *TokenBurnCase) SendCommand(packID string) (types.PackFunc, error) {
return types.DefaultSend(testCase, &TokenBurnPack{}, packID)
}
// GetCheckHandlerMap get check handle for map
func (pack *TokenBurnPack) GetCheckHandlerMap() interface{} {
funcMap := make(types.CheckHandlerMapDiscard, 2)
funcMap["balance"] = pack.checkBalance
return funcMap
}
func (pack *TokenBurnPack) checkBalance(txInfo map[string]interface{}) bool {
logArr := txInfo["receipt"].(map[string]interface{})["logs"].([]interface{})
logTokenBurn := logArr[1].(map[string]interface{})["log"].(map[string]interface{})
logAccBurn := logArr[2].(map[string]interface{})["log"].(map[string]interface{})
interCase := pack.TCase.(*TokenBurnCase)
amount1, _ := strconv.ParseInt(interCase.Amount, 10, 64)
amount := amount1 * 1e8
pack.FLog.Info("BurnDetails", "TestID", pack.PackID,
"TokenPrev", logTokenBurn["prev"].(map[string]interface{})["total"].(string),
"TokenCurr", logTokenBurn["current"].(map[string]interface{})["total"].(string),
"AccPrev", logAccBurn["prev"].(map[string]interface{})["balance"].(string),
"AccCurr", logAccBurn["current"].(map[string]interface{})["balance"].(string),
"amount", amount1)
totalCurrent := parseInt64(logTokenBurn["current"].(map[string]interface{})["total"])
totalPrev := parseInt64(logTokenBurn["prev"].(map[string]interface{})["total"])
accCurrent := parseInt64(logAccBurn["current"].(map[string]interface{})["balance"])
accPrev := parseInt64(logAccBurn["prev"].(map[string]interface{})["balance"])
return totalCurrent + amount == totalPrev && accCurrent + amount == accPrev
}
func parseInt64(s interface{}) int64 {
i, _ := strconv.ParseInt(s.(string), 10, 64)
return i
}
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