Commit c7e1fe00 authored by duanjinfei's avatar duanjinfei

fix chain evm problem and add case

parent 0b1adad5
......@@ -20,7 +20,9 @@
"endTokenId": 100,
"accStartIndex": 0,
"sendTranAfterSleep": 120,
"everyCaseTxCount": 1,
"isGetAccBalance": false,
"isUseNotSameAcc": false,
"transferType": [29]
}
......
......@@ -30,13 +30,15 @@ func main() {
arrFormat := tool.ParseAccountConfig("./config/account.json")
parseContractConfig := tool.ParseContractConfig("./config/contractConfig.json")
for _, caseType := range tool.Cfg.TransferType {
tranList, verifyFunc := operator.GetTranFunc(caseType, accIndex, 9, nonceMap, arrFormat, tool.Cfg.RpcNode, parseContractConfig)
tranList, verifyFunc := operator.GetTranFunc(caseType, accIndex, tool.Cfg.EveryCaseTxCount, nonceMap, arrFormat, tool.Cfg.RpcNode, parseContractConfig)
if tranList == nil || verifyFunc == nil {
break
}
txArr = append(txArr, tranList...)
verifyFuncArr = append(verifyFuncArr, verifyFunc)
accIndex += 9
if tool.Cfg.IsUseNotSameAcc {
accIndex += 9
}
}
}
......
......@@ -209,6 +209,15 @@ func InitErc721AccTransfer(txArr []*types.Transaction, nonce uint64, contractLen
return nil, 0
}
txArr = append(txArr, tx)
nonce += 1
auth.Nonce = big.NewInt(int64(nonce))
tx, err = newERC721.SetApprovalForAllFrom(auth, accArr.ToAddr[i], contractMap[j][constant.TOKEN721_TRANSFER], true)
if err != nil {
log.Error("Init account - erc721 setApprovalForAllFrom err:", err.Error())
return nil, 0
}
txArr = append(txArr, tx)
log.Info("Init account - transferFrom 721 successful,tx:", tx.Hash().Hex())
nonce += 1
}
......@@ -290,6 +299,8 @@ func InitCaseAccount(client *ethclient.Client, txArr []*types.Transaction) []*ty
accArr := tool.ParseAccountConfig("./config/account.json")
auth, err := bind.NewKeyedTransactorWithChainID(tool.Cfg.DeployPrv, tool.Cfg.ChainId)
auth.NoSend = true
auth.GasLimit = 500000
auth.GasPrice = big.NewInt(10000000000)
amount := big.NewInt(0)
amount.SetString("10000000000000000000", 10)
trade := &coin.Trade{
......
......@@ -1080,6 +1080,7 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
beforeAddrErc20Bal[testAccArr.FromAddr[i]] = fromBal
oneErc20Trade.ToAddr = []common.Address{testAccArr.ToAddr[i]}
oneErc20Trade.FromAddr = testAccArr.FromAddr[i]
auth, err := bind.NewKeyedTransactorWithChainID(testAccArr.FromPrv[i], tool.Cfg.ChainId)
if err != nil {
log.Errorf("DeployTokenTransfer func newKeyedTransactorWithChainID err:", err)
......@@ -1106,6 +1107,7 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
}
log.Infof("ERC20 After to addr:%s,toBal:%s", testAccArr.ToAddr[i].Hex(), to.String())
if to.Sub(to, beforeAddrErc20Bal[testAccArr.ToAddr[i]]).Cmp(amount) != 0 {
log.Error("To addr balance verify failed")
res = false
}
......@@ -1115,7 +1117,8 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
log.Error("Get erc20 balanceOf error:", err.Error())
res = false
}
if beforeAddrErc20Bal[testAccArr.FromAddr[i]].Sub(beforeAddrErc20Bal[testAccArr.FromAddr[i]], from).Cmp(amount) != 1 {
if beforeAddrErc20Bal[testAccArr.FromAddr[i]].Sub(beforeAddrErc20Bal[testAccArr.FromAddr[i]], from).Cmp(amount) != 0 {
log.Error("From addr balance verify failed")
res = false
}
}
......@@ -1159,6 +1162,7 @@ func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractM
log.Infof("ERC20 Before from addr:%s,fromBal:%s", testAccArr.FromAddr[i].Hex(), fromBal.String())
beforeAddrErc20Bal[testAccArr.FromAddr[i]] = fromBal
oneErc20Trade.ToAddr = []common.Address{toAddr}
oneErc20Trade.FromAddr = testAccArr.FromAddr[i]
auth, err := bind.NewKeyedTransactorWithChainID(testAccArr.FromPrv[i], tool.Cfg.ChainId)
if err != nil {
log.Errorf("DeployTokenTransfer func newKeyedTransactorWithChainID err:", err)
......@@ -1193,7 +1197,7 @@ func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractM
res = false
}
log.Infof("ERC20 After from addr:%s,fromBal:%s", testAccArr.FromAddr[i].Hex(), from.String())
if beforeAddrErc20Bal[testAccArr.FromAddr[i]].Sub(beforeAddrErc20Bal[testAccArr.FromAddr[i]], from).Cmp(amount) != 1 {
if beforeAddrErc20Bal[testAccArr.FromAddr[i]].Sub(beforeAddrErc20Bal[testAccArr.FromAddr[i]], from).Cmp(amount) != 0 {
res = false
}
}
......@@ -1295,8 +1299,8 @@ func PrReErc721TranCase(startIndex int, txCount int, testAccArr *tool.AccArrForm
value, _ := accountNonceMap.Load(testAccArr.FromAddr[i])
auth.Nonce = big.NewInt(value.(int64))
auth.NoSend = true
auth.GasLimit = 500000
auth.GasPrice = big.NewInt(10000000000)
auth.GasLimit = 6000000
auth.GasPrice = big.NewInt(200000000000)
tx, err := erc721Trade.Erc721TransferFromSignTx(auth, tokenTransfer)
if err != nil {
log.Error("Erc721TransferFromSignTx error:", err.Error())
......@@ -1384,8 +1388,8 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
erc721Trade.TokenId = big.NewInt(int64(startIndex))
auth.Nonce = big.NewInt(nonce)
auth.NoSend = true
auth.GasLimit = 500000
auth.GasPrice = big.NewInt(10000000000)
auth.GasLimit = 5000000
auth.GasPrice = big.NewInt(100000000000)
tx, err := erc721Trade.Erc721TransferFromSignTx(auth, tokenTransfer)
if err != nil {
log.Error("Erc721TransferFromSignTx error:", err.Error())
......@@ -1404,7 +1408,7 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
log.Error("Get erc721 bal error:", err.Error())
res = false
}
log.Info("Erc721 接受者相关 From balance:", fromErc721Bal.String())
log.Info("Erc721 发送者相关 From balance:", fromErc721Bal.String())
if beforeFromErc721Bal.Sub(beforeFromErc721Bal, fromErc721Bal).Cmp(big.NewInt(int64(txCount))) != 0 {
res = false
}
......@@ -1415,7 +1419,7 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
log.Error("Get erc721 bal error:", err.Error())
res = false
}
log.Info("Erc721 接受者相关 To balance:", toErc721Bal.String())
log.Info("Erc721 发送者相关 To balance:", toErc721Bal.String())
if toErc721Bal.Sub(toErc721Bal, beforeToErc721Bal[receiveToAddr]).Cmp(big.NewInt(1)) != 0 {
res = false
}
......
......@@ -14,12 +14,12 @@ import (
func TestGetContractAbi(t *testing.T) {
// 连接以太坊网络
client, err := ethclient.Dial("http://54.72.101.87:50000")
client, err := ethclient.Dial("http://192.168.1.114:50000")
if err != nil {
log.Fatal(err)
}
// 从合约地址获取合约代码
contractAddress := common.HexToAddress("0xfb1bF24c0C7e7C1B89c4A496aACf01aBF26C0B94")
contractAddress := common.HexToAddress("0x502336Ad1DABCa0F3C06098F72E79265D66bC374")
//code, err := client.CodeAt(context.Background(), contractAddress, nil)
//if err != nil {
......@@ -41,12 +41,12 @@ func TestGetContractAbi(t *testing.T) {
}
log.Info("balance:", balance.String())
receipt, err := client.TransactionReceipt(context.Background(), common.HexToHash("0x478828957ad9314d1d11e36d0a94142b89df6c74d4688d396a06953fdaa998c5"))
receipt, err := client.TransactionReceipt(context.Background(), common.HexToHash("0x732f529095537e2abb13a4737693cb6d740531bc05bd0fb2fee3a1ebd8893ebf"))
if err != nil {
log.Fatal("Get receipt error:", err.Error())
return
}
log.Info("status:", receipt.Status, ",tranNonce:", receipt.TransactionIndex, ",GasUsed:", receipt.GasUsed)
log.Info("status:", receipt.Status, ",tranNonce:", receipt.TransactionIndex, ",GasUsed:", receipt.GasUsed, ",blockNumber:", receipt.BlockNumber, ",logs:", receipt.Logs)
}
func TestGetErc20Balance(t *testing.T) {
......
......@@ -30,6 +30,8 @@ type ConfigJson struct {
AccStartIndex int `json:"accStartIndex"`
SendTranAfterSleep int `json:"sendTranAfterSleep"`
IsGetAccBalance bool `json:"isGetAccBalance"`
IsUseNotSameAcc bool `json:"isUseNotSameAcc"`
EveryCaseTxCount int `json:"everyCaseTxCount"`
}
type Config struct {
......@@ -50,6 +52,8 @@ type Config struct {
AccStartIndex int
SendTranAfterSleep int
IsGetAccBalance bool
IsUseNotSameAcc bool
EveryCaseTxCount int
}
type AccArr struct {
......@@ -117,6 +121,8 @@ func ParseConfig(path string) {
AccStartIndex: cfgJson.AccStartIndex,
SendTranAfterSleep: cfgJson.SendTranAfterSleep,
IsGetAccBalance: cfgJson.IsGetAccBalance,
IsUseNotSameAcc: cfgJson.IsUseNotSameAcc,
EveryCaseTxCount: cfgJson.EveryCaseTxCount,
}
}
......
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