Commit ccaf3350 authored by duanjinfei's avatar duanjinfei

five commit

parent c1ac0912
This diff is collapsed.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"goRoutine": 1, "goRoutine": 1,
"generateAccCount": 500, "generateAccCount": 500,
"isDeployContract": false, "isDeployContract": false,
"isInitAccountBalance": true, "isInitAccountBalance": false,
"startTokenId": 1, "startTokenId": 1,
"endTokenId": 100, "endTokenId": 100,
"transferType": [] "transferType": []
......
This diff is collapsed.
...@@ -25,15 +25,15 @@ func main() { ...@@ -25,15 +25,15 @@ func main() {
// 转账交易case // 转账交易case
if len(tool.Cfg.TransferType) != 0 { if len(tool.Cfg.TransferType) != 0 {
accIndex := 12 accIndex := 0
nonceMap := util.GetAccountNonce(tool.Cfg.RpcNode) nonceMap := util.GetAccountNonce(tool.Cfg.RpcNode)
arrFormat := tool.ParseAccountConfig("./config/account.json") arrFormat := tool.ParseAccountConfig("./config/account.json")
parseContractConfig := tool.ParseContractConfig("./config/contractConfig.json") parseContractConfig := tool.ParseContractConfig("./config/contractConfig.json")
for _, caseType := range tool.Cfg.TransferType { for _, caseType := range tool.Cfg.TransferType {
tranList, verifyFunc := operator.GetTranFunc(caseType, accIndex, 2, nonceMap, arrFormat, tool.Cfg.RpcNode, parseContractConfig) tranList, verifyFunc := operator.GetTranFunc(caseType, accIndex, 9, nonceMap, arrFormat, tool.Cfg.RpcNode, parseContractConfig)
txArr = append(txArr, tranList...) txArr = append(txArr, tranList...)
verifyFuncArr = append(verifyFuncArr, verifyFunc) verifyFuncArr = append(verifyFuncArr, verifyFunc)
accIndex += 2 accIndex += 9
} }
} }
......
...@@ -25,7 +25,7 @@ import ( ...@@ -25,7 +25,7 @@ import (
"time" "time"
) )
var tranChanel = make(chan *types.Transaction, 1000) //var tranChanel = make(chan *types.Transaction, 1000)
func GenerateAcc(count int) *tool.AccArr { func GenerateAcc(count int) *tool.AccArr {
fromAddr := make([]string, 0) fromAddr := make([]string, 0)
...@@ -85,7 +85,7 @@ func DeployContract(client *ethclient.Client, txRes []*types.Transaction) []*typ ...@@ -85,7 +85,7 @@ func DeployContract(client *ethclient.Client, txRes []*types.Transaction) []*typ
for _, deployFunc := range deploy.DeployFunc { for _, deployFunc := range deploy.DeployFunc {
auth.Nonce = big.NewInt(int64(nonce)) auth.Nonce = big.NewInt(int64(nonce))
contractAddr, transaction, contractType := deployFunc(auth, client) contractAddr, transaction, contractType := deployFunc(auth, client)
log.Info("contractAddr:", contractAddr) log.Info("contractAddr:", contractAddr, ", nonce:", nonce)
txRes = append(txRes, transaction) txRes = append(txRes, transaction)
contractMap[contractType] = contractAddr contractMap[contractType] = contractAddr
nonce += 1 nonce += 1
...@@ -285,30 +285,30 @@ func InitCaseAccount(client *ethclient.Client, txArr []*types.Transaction) []*ty ...@@ -285,30 +285,30 @@ func InitCaseAccount(client *ethclient.Client, txArr []*types.Transaction) []*ty
auth.NoSend = true auth.NoSend = true
amount := big.NewInt(0) amount := big.NewInt(0)
amount.SetString("10000000000000000000", 10) amount.SetString("10000000000000000000", 10)
//trade := &coin.Trade{ trade := &coin.Trade{
// FromPrv: tool.Cfg.DeployPrv, FromPrv: tool.Cfg.DeployPrv,
// FromNonce: big.NewInt(int64(nonce)), FromNonce: big.NewInt(int64(nonce)),
// Amount: amount, Amount: amount,
// Gas: big.NewInt(50000), Gas: big.NewInt(50000),
// GasPrice: big.NewInt(1000000000), GasPrice: big.NewInt(1000000000),
// ChainId: tool.Cfg.ChainId, ChainId: tool.Cfg.ChainId,
//} }
contractMap := tool.ParseContractConfig("./config/contractConfig.json") contractMap := tool.ParseContractConfig("./config/contractConfig.json")
contractLen := len(contractMap) contractLen := len(contractMap)
//初始化From账户-500tx //初始化From账户-500tx
//coinTxArr, nonce := InitAccountCoin(txArr, nonce, amount, accArr) coinTxArr, nonce := InitAccountCoin(txArr, nonce, amount, accArr)
//txArr = append(txArr, coinTxArr...) txArr = append(txArr, coinTxArr...)
//初始化转账合约账户余额-10tx //初始化转账合约账户余额-10tx
//contractCoinTxArr, nonce := InitContractCoin(txArr, nonce, contractLen, contractMap, trade) contractCoinTxArr, nonce := InitContractCoin(txArr, nonce, contractLen, contractMap, trade)
//txArr = append(txArr, contractCoinTxArr...) txArr = append(txArr, contractCoinTxArr...)
//// 初始化erc20 并且mint //// 初始化erc20 并且mint
//erc20TxArr, nonce := InitErc20Acc(txArr, nonce, contractLen, contractMap, accArr, client, auth) erc20TxArr, nonce := InitErc20Acc(txArr, nonce, contractLen, contractMap, accArr, client, auth)
//txArr = append(txArr, erc20TxArr...) txArr = append(txArr, erc20TxArr...)
////初始化erc721 并且mint ////初始化erc721 并且mint
//erc721MintTxArr, nonce := InitErc721AccMint(txArr, nonce, contractLen, contractMap, accArr, client, auth) //erc721MintTxArr, nonce := InitErc721AccMint(txArr, nonce, contractLen, contractMap, accArr, client, auth)
//txArr = append(txArr, erc721MintTxArr...) //txArr = append(txArr, erc721MintTxArr...)
erc721TransferTxArr, nonce := InitErc721AccTransfer(txArr, nonce, contractLen, contractMap, accArr, client, auth) //erc721TransferTxArr, nonce := InitErc721AccTransfer(txArr, nonce, contractLen, contractMap, accArr, client, auth)
txArr = append(txArr, erc721TransferTxArr...) //txArr = append(txArr, erc721TransferTxArr...)
log.Info("Init balance successful,wait send tran...........") log.Info("Init balance successful,wait send tran...........")
return txArr return txArr
} }
...@@ -330,7 +330,7 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map, ...@@ -330,7 +330,7 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map,
// 不相关-多层-调用合约转账 // 不相关-多层-调用合约转账
case 3: case 3:
{ {
return NrContractOneCoinTranCase(txCount, arr, contractArr[0], nonceMap, txArr, client) return NrContractOneCoinTranCase(txCount, arr, contractArr[1], nonceMap, txArr, client)
} }
// 不相关-单层-写变量 // 不相关-单层-写变量
case 4: case 4:
...@@ -340,12 +340,12 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map, ...@@ -340,12 +340,12 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map,
// 不相关-多层-写变量 // 不相关-多层-写变量
case 5: case 5:
{ {
return NrOneWRTranCase(arr, contractArr[0], nonceMap, txArr, client) return NrOneWRTranCase(arr, contractArr[1], nonceMap, txArr, client)
} }
// 不相关-单层-Erc20转账 // 不相关-单层-Erc20转账
case 6: case 6:
{ {
return NrErc20TranCase(txCount, arr, contractArr[0], nonceMap, txArr, client) return NrErc20TranCase(txCount, arr, contractArr[2], nonceMap, txArr, client)
} }
// 不相关-多层-Erc20转账 // 不相关-多层-Erc20转账
case 7: case 7:
...@@ -355,12 +355,12 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map, ...@@ -355,12 +355,12 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map,
// 不相关-单层-Erc721转账 // 不相关-单层-Erc721转账
case 8: case 8:
{ {
return NrErc721TranCase(startIndex, txCount, arr, contractArr[0], nonceMap, txArr, client) return NrErc721TranCase(startIndex, txCount, arr, contractArr[1], nonceMap, txArr, client)
} }
// 不相关-多层-Erc721转账 // 不相关-多层-Erc721转账
case 9: case 9:
{ {
return NrOneErc721TranCase(startIndex, txCount, arr, contractArr[0], nonceMap, txArr, client) return NrOneErc721TranCase(startIndex, txCount, arr, contractArr[2], nonceMap, txArr, client)
} }
// 部分相关-普通转账-接受者相关 // 部分相关-普通转账-接受者相关
case 10: case 10:
...@@ -473,30 +473,30 @@ func GetAccArr(arr *tool.AccArrFormat, startIndex int, count int) *tool.AccArrFo ...@@ -473,30 +473,30 @@ func GetAccArr(arr *tool.AccArrFormat, startIndex int, count int) *tool.AccArrFo
func SendTransaction(trans []*types.Transaction) { func SendTransaction(trans []*types.Transaction) {
client := tool.Cfg.RpcNode client := tool.Cfg.RpcNode
for i := 0; i < 8; i++ { //for i := 0; i < 8; i++ {
go func() { // go func() {
for { // for {
select { // select {
case tran := <-tranChanel: // case tran := <-tranChanel:
err := client.SendTransaction(context.Background(), tran) // err := client.SendTransaction(context.Background(), tran)
log.Info("Send tran:", tran.Hash()) // log.Info("Send tran:", tran.Hash(), ",nonce:", tran.Nonce())
if err != nil { // if err != nil {
log.Error("send tx error:", err.Error(), ",tx:", tran.Hash().Hex()) // log.Error("send tx error:", err.Error(), ",tx:", tran.Hash().Hex())
return // return
} // }
} // }
} // }
}() // }()
} //}
for i := 0; i < len(trans); i++ { for i := 0; i < len(trans); i++ {
tran := trans[i] tran := trans[i]
tranChanel <- tran //tranChanel <- tran
//err := client.SendTransaction(context.Background(), tran) err := client.SendTransaction(context.Background(), tran)
//log.Info("Send tran:", tran.Hash()) log.Info("Send tran:", tran.Hash())
//if err != nil { if err != nil {
// log.Error("send tx error:", err.Error(), ",tx:", tran.Hash().Hex()) log.Error("send tx error:", err.Error(), ",tx:", tran.Hash().Hex())
// return return
//} }
log.Info("Input count:", i) log.Info("Input count:", i)
} }
time.Sleep(time.Second * 120) time.Sleep(time.Second * 120)
......
...@@ -5,30 +5,36 @@ import ( ...@@ -5,30 +5,36 @@ import (
erc20 "contract-case/contract_abi/erc20_transfer/compile" erc20 "contract-case/contract_abi/erc20_transfer/compile"
erc721 "contract-case/contract_abi/erc721_transfer/compile" erc721 "contract-case/contract_abi/erc721_transfer/compile"
"contract-case/log" "contract-case/log"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"math/big" "math/big"
"strings"
"testing" "testing"
) )
func TestGetContractAbi(t *testing.T) { func TestGetContractAbi(t *testing.T) {
// 连接以太坊网络 // 连接以太坊网络
client, err := ethclient.Dial("http://15.161.177.5:26658") client, err := ethclient.Dial("http://54.72.101.87:50000")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
// 从合约地址获取合约代码 // 从合约地址获取合约代码
contractAddress := common.HexToAddress("0xacea4c028c233e5d896b5ea28eb1c24d64b937e2") contractAddress := common.HexToAddress("0xb11ba93a30352b831909db093b253fa51e152cb9")
code, err := client.CodeAt(context.Background(), contractAddress, nil) //code, err := client.CodeAt(context.Background(), contractAddress, nil)
if err != nil { //if err != nil {
log.Fatal("get contract code err:", err) // log.Fatal("get contract code err:", err)
} //}
// 解析ABI
//contractAbi, err := abi.JSON(strings.NewReader(string(code)))
//if err != nil {
// log.Fatal(err)
//}
// 打印ABI信息
//fmt.Println(contractAbi.Methods)
balance, err := client.BalanceAt(context.Background(), contractAddress, nil) balance, err := client.BalanceAt(context.Background(), contractAddress, nil)
if err != nil { if err != nil {
...@@ -36,14 +42,12 @@ func TestGetContractAbi(t *testing.T) { ...@@ -36,14 +42,12 @@ func TestGetContractAbi(t *testing.T) {
} }
log.Info("balance:", balance.String()) log.Info("balance:", balance.String())
// 解析ABI receipt, err := client.TransactionReceipt(context.Background(), common.HexToHash("0x0358adba05683b259434198ed760b4b9341f8ab041a8980d8d4a0182c4b6021e"))
contractAbi, err := abi.JSON(strings.NewReader(string(code)))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal("Get receipt error:", err.Error())
return
} }
log.Info("status:", receipt.Status, ",tranNonce:", receipt.TransactionIndex)
// 打印ABI信息
fmt.Println(contractAbi.Methods)
} }
func TestGetErc20Balance(t *testing.T) { func TestGetErc20Balance(t *testing.T) {
......
...@@ -44,28 +44,18 @@ func HexToAddress(addr string) common.Address { ...@@ -44,28 +44,18 @@ func HexToAddress(addr string) common.Address {
} }
func GetTxReceipt(client *ethclient.Client, txArr []*types.Transaction) { func GetTxReceipt(client *ethclient.Client, txArr []*types.Transaction) {
txChanel := make(chan common.Hash, 1000)
for i := 0; i < 8; i++ {
go func() {
select {
case hash := <-txChanel:
receipt, err := client.TransactionReceipt(context.Background(), hash)
if err != nil {
log.Error("Get tran receipt err:", err)
return
}
if receipt.Status == 0 {
log.Error("Receipt:", receipt)
} else {
log.Infof("Receipt: status: %d,gasUsed: %d", receipt.Status, receipt.GasUsed)
}
}
}()
}
for _, tx := range txArr { for _, tx := range txArr {
txChanel <- tx.Hash() receipt, err := client.TransactionReceipt(context.Background(), tx.Hash())
if err != nil {
log.Error("Get tran receipt err:", err)
return
}
if receipt.Status == 0 {
log.Error("Receipt:", receipt)
} else {
log.Infof("Receipt: status: %d,gasUsed: %d", receipt.Status, receipt.GasUsed)
}
} }
time.Sleep(time.Second * 10)
} }
func GetAccountNonce(client *ethclient.Client) *sync.Map { func GetAccountNonce(client *ethclient.Client) *sync.Map {
......
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