Commit ccaf3350 authored by duanjinfei's avatar duanjinfei

five commit

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