github.com/turingchain2020/turingchain@v1.1.21/system/dapp/coins/autotest/transferCase.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package autotest 6 7 import ( 8 "strconv" 9 10 "github.com/turingchain2020/turingchain/cmd/autotest/types" 11 ) 12 13 // TransferCase transfer case 14 type TransferCase struct { 15 types.BaseCase 16 From string `toml:"from"` 17 To string `toml:"to"` 18 Amount string `toml:"amount"` 19 } 20 21 // TransferPack transfer pack 22 type TransferPack struct { 23 types.BaseCasePack 24 } 25 26 // SendCommand sed command 27 func (testCase *TransferCase) SendCommand(packID string) (types.PackFunc, error) { 28 29 return types.DefaultSend(testCase, &TransferPack{}, packID) 30 } 31 32 // GetCheckHandlerMap get check handle for map 33 func (pack *TransferPack) GetCheckHandlerMap() interface{} { 34 35 funcMap := make(types.CheckHandlerMapDiscard, 2) 36 funcMap["balance"] = pack.checkBalance 37 38 return funcMap 39 } 40 41 func (pack *TransferPack) checkBalance(txInfo map[string]interface{}) bool { 42 /*fromAddr := txInfo["tx"].(map[string]interface{})["from"].(string) 43 toAddr := txInfo["tx"].(map[string]interface{})["to"].(string)*/ 44 interCase := pack.TCase.(*TransferCase) 45 feeStr := txInfo["tx"].(map[string]interface{})["fee"].(string) 46 logArr := txInfo["receipt"].(map[string]interface{})["logs"].([]interface{}) 47 logFee := logArr[0].(map[string]interface{})["log"].(map[string]interface{}) 48 logSend := logArr[1].(map[string]interface{})["log"].(map[string]interface{}) 49 logRecv := logArr[2].(map[string]interface{})["log"].(map[string]interface{}) 50 fee, err := strconv.ParseFloat(feeStr, 64) 51 if err != nil { 52 return false 53 } 54 Amount, err := strconv.ParseFloat(interCase.Amount, 64) 55 if err != nil { 56 return false 57 } 58 59 pack.FLog.Info("TransferBalanceDetails", "TestID", pack.PackID, 60 "Fee", feeStr, "Amount", interCase.Amount, 61 "FromPrev", logSend["prev"].(map[string]interface{})["balance"].(string), 62 "FromCurr", logSend["current"].(map[string]interface{})["balance"].(string), 63 "ToPrev", logRecv["prev"].(map[string]interface{})["balance"].(string), 64 "ToCurr", logRecv["current"].(map[string]interface{})["balance"].(string)) 65 66 depositCheck := true 67 //transfer to contract, deposit 68 if len(logArr) == 4 { 69 logDeposit := logArr[3].(map[string]interface{})["log"].(map[string]interface{}) 70 depositCheck = types.CheckBalanceDeltaWithAddr(logDeposit, interCase.From, Amount) 71 } 72 73 return types.CheckBalanceDeltaWithAddr(logFee, interCase.From, -fee) && 74 types.CheckBalanceDeltaWithAddr(logSend, interCase.From, -Amount) && 75 types.CheckBalanceDeltaWithAddr(logRecv, interCase.To, Amount) && depositCheck 76 }