Commit 75478c00 authored by duanjinfei's avatar duanjinfei

add test case

parent 48656f35
...@@ -163,6 +163,8 @@ func InitErc721AccMint(txArr []*types.Transaction, nonce uint64, contractLen int ...@@ -163,6 +163,8 @@ func InitErc721AccMint(txArr []*types.Transaction, nonce uint64, contractLen int
for i := 0; i < len(accArr.FromAddr); i++ { for i := 0; i < len(accArr.FromAddr); i++ {
tokenIds = append(tokenIds, big.NewInt(int64(i))) tokenIds = append(tokenIds, big.NewInt(int64(i)))
} }
auth.GasLimit = 10000000
auth.GasPrice = big.NewInt(10000000)
auth.Nonce = big.NewInt(int64(nonce)) auth.Nonce = big.NewInt(int64(nonce))
of, err := newERC721.BalanceOf(&bind.CallOpts{}, tool.Cfg.DeployAddr) of, err := newERC721.BalanceOf(&bind.CallOpts{}, tool.Cfg.DeployAddr)
if err != nil { if err != nil {
...@@ -462,6 +464,11 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map, ...@@ -462,6 +464,11 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map,
{ {
return PrReOneErc20TranCase(txCount, arr, contractArr[3], nonceMap, txArr, client) return PrReOneErc20TranCase(txCount, arr, contractArr[3], nonceMap, txArr, client)
} }
// 部分相关-多层-erc20-transferFrom-发送者相关
case 30:
{
return PrReOneErc20TranCase1(txCount, arr, contractArr[6], nonceMap, txArr, client)
}
// Erc20 approve // Erc20 approve
case 26: case 26:
{ {
......
...@@ -1120,6 +1120,80 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa ...@@ -1120,6 +1120,80 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
return resTxArr, verify return resTxArr, verify
} }
// PrReOneErc20TranCase1 多层-erc20-transferFrom-接受者相关
func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractMap map[string]common.Address, accountNonceMap *sync.Map, resTxArr []*types.Transaction, client *ethclient.Client) ([]*types.Transaction, func() bool) {
amount := big.NewInt(1000000000000)
oneErc20Trade := &contractErc20.OneErc20Trade{
TokenTransferAddr: contractMap[constant.TOKEN20_TRANSFER],
Erc20Addr: contractMap[constant.ERC20],
Amount: amount,
}
tokenTransfer, err := erc20.NewOneTokenTransfer(contractMap[constant.ONE_TOKEN20_TRANSFER], client)
if err != nil {
return nil, nil
}
erc20Contract, err := erc20.NewERC20(contractMap[constant.ERC20], client)
if err != nil {
log.Error("NewTokenTransfer error:", err.Error())
return nil, nil
}
beforeAddrErc20Bal := make(map[common.Address]*big.Int, 0)
toAddr := testAccArr.ToAddr[0]
toBal, err := erc20Contract.BalanceOf(&bind.CallOpts{}, toAddr)
if err != nil {
log.Error("Get erc20 balanceOf error:", err.Error())
return nil, nil
}
beforeAddrErc20Bal[toAddr] = toBal
for i := 0; i < txCount; i++ {
fromBal, err := erc20Contract.BalanceOf(&bind.CallOpts{}, testAccArr.FromAddr[i])
if err != nil {
log.Error("Get erc20 balanceOf error:", err.Error())
return nil, nil
}
beforeAddrErc20Bal[testAccArr.FromAddr[i]] = fromBal
oneErc20Trade.ToAddr = []common.Address{testAccArr.ToAddr[i]}
auth, err := bind.NewKeyedTransactorWithChainID(testAccArr.FromPrv[i], tool.Cfg.ChainId)
if err != nil {
log.Errorf("DeployTokenTransfer func newKeyedTransactorWithChainID err:", err)
}
value, _ := accountNonceMap.Load(testAccArr.FromAddr[i])
auth.Nonce = big.NewInt(value.(int64))
auth.NoSend = true
auth.GasLimit = 500000
auth.GasPrice = big.NewInt(10000000000)
tx, err := oneErc20Trade.Erc20OneTransferTx(auth, tokenTransfer)
if err != nil {
return nil, nil
}
log.Info("Erc20OneTransferTx tx:", tx.Hash().Hex())
resTxArr = append(resTxArr, tx)
}
verify := func() bool {
res := true
to, err := erc20Contract.BalanceOf(&bind.CallOpts{}, toAddr)
if err != nil {
log.Error("Get erc20 balanceOf error:", err.Error())
res = false
}
if to.Sub(to, beforeAddrErc20Bal[toAddr]).Cmp(new(big.Int).Mul(big.NewInt(int64(txCount)), amount)) != 0 {
res = false
}
for i := 0; i < txCount; i++ {
from, err := erc20Contract.BalanceOf(&bind.CallOpts{}, testAccArr.FromAddr[i])
if err != nil {
log.Error("Get erc20 balanceOf error:", err.Error())
res = false
}
if beforeAddrErc20Bal[testAccArr.FromAddr[i]].Sub(beforeAddrErc20Bal[testAccArr.FromAddr[i]], from).Cmp(amount) != 1 {
res = false
}
}
return res
}
return resTxArr, verify
}
// PrSpErc20ApproveTranCase 单层-erc20-approve // PrSpErc20ApproveTranCase 单层-erc20-approve
func PrSpErc20ApproveTranCase(txCount int, testAccArr *tool.AccArrFormat, contractMap map[string]common.Address, accountNonceMap *sync.Map, resTxArr []*types.Transaction, client *ethclient.Client) ([]*types.Transaction, func() bool) { func PrSpErc20ApproveTranCase(txCount int, testAccArr *tool.AccArrFormat, contractMap map[string]common.Address, accountNonceMap *sync.Map, resTxArr []*types.Transaction, client *ethclient.Client) ([]*types.Transaction, func() bool) {
amount := big.NewInt(0) amount := big.NewInt(0)
......
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