Commit ec9fa4b1 authored by duanjinfei's avatar duanjinfei

add erc721 test case

parent a47658e0
...@@ -1252,6 +1252,88 @@ func PrReErc721TranCase(startIndex int, txCount int, testAccArr *tool.AccArrForm ...@@ -1252,6 +1252,88 @@ func PrReErc721TranCase(startIndex int, txCount int, testAccArr *tool.AccArrForm
return resTxArr, verify return resTxArr, verify
} }
// PrReErc721TranFromCase erc721-发送者相关
func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArrFormat, contractMap map[string]common.Address, accountNonceMap *sync.Map, resTxArr []*types.Transaction, client *ethclient.Client) ([]*types.Transaction, func() bool) {
erc721Trade := &contractErc721.Erc721Trade{
Erc721Addr: contractMap[constant.ERC721],
}
erc721Contract, err := erc721.NewERC721(contractMap[constant.ERC721], client)
if err != nil {
return nil, nil
}
tokenTransfer, err := erc721.NewNftTokenTransfer(contractMap[constant.TOKEN721_TRANSFER], client)
if err != nil {
return nil, nil
}
beforeToErc721Bal := make(map[common.Address]*big.Int, 0)
fromAddr := testAccArr.ToAddr[0]
beforeFromErc721Bal, err := erc721Contract.BalanceOf(&bind.CallOpts{}, fromAddr)
if err != nil {
log.Error("Get erc721 bal error:", err.Error())
return nil, nil
}
log.Info("Erc721 接受者相关 From balance:", beforeFromErc721Bal.String())
auth, err := bind.NewKeyedTransactorWithChainID(testAccArr.ToPrv[0], tool.Cfg.ChainId)
if err != nil {
log.Errorf("DeployTokenTransfer func newKeyedTransactorWithChainID err:", err)
}
value, _ := accountNonceMap.Load(fromAddr)
nonce := value.(int64)
auth.Nonce = big.NewInt(nonce)
for i := 0; i < txCount; i++ {
toAddr := testAccArr.FromAddr[i]
erc721Trade.ToAddr = toAddr
toErc721Bal, err := erc721Contract.BalanceOf(&bind.CallOpts{}, toAddr)
if err != nil {
log.Error("Get erc721 bal error:", err.Error())
return nil, nil
}
log.Info("Erc721 接受者相关 to balance:", toErc721Bal.String())
beforeToErc721Bal[toAddr] = toErc721Bal
erc721Trade.FromAddr = fromAddr
erc721Trade.TokenId = big.NewInt(int64(startIndex))
auth.NoSend = true
auth.GasLimit = 500000
auth.GasPrice = big.NewInt(10000000000)
tx, err := erc721Trade.Erc721TransferFromSignTx(auth, tokenTransfer)
if err != nil {
log.Error("Erc721TransferFromSignTx error:", err.Error())
return nil, nil
}
log.Info("Erc721TransferFromSignTx tx:", tx.Hash().Hex())
nonce++
startIndex++
resTxArr = append(resTxArr, tx)
}
verify := func() bool {
res := true
verifyToAddr := testAccArr.ToAddr[0]
fromErc721Bal, err := erc721Contract.BalanceOf(&bind.CallOpts{}, verifyToAddr)
if err != nil {
log.Error("Get erc721 bal error:", err.Error())
res = false
}
log.Info("Erc721 接受者相关 From balance:", fromErc721Bal.String())
if beforeFromErc721Bal.Sub(beforeFromErc721Bal, fromErc721Bal).Cmp(big.NewInt(int64(txCount))) != 0 {
res = false
}
for i := 0; i < txCount; i++ {
receiveToAddr := testAccArr.FromAddr[i]
toErc721Bal, err := erc721Contract.BalanceOf(&bind.CallOpts{}, receiveToAddr)
if err != nil {
log.Error("Get erc721 bal error:", err.Error())
res = false
}
log.Info("Erc721 接受者相关 To balance:", toErc721Bal.String())
if toErc721Bal.Sub(toErc721Bal, beforeToErc721Bal[receiveToAddr]).Cmp(big.NewInt(1)) != 0 {
res = false
}
}
return res
}
return resTxArr, verify
}
// PrReContractOneCoinTranTwiceCase 多层-合约转账- 先set合约的对象地址-〉调用合约的方法 :两笔交易并行发送,同一个块中执行 // PrReContractOneCoinTranTwiceCase 多层-合约转账- 先set合约的对象地址-〉调用合约的方法 :两笔交易并行发送,同一个块中执行
func PrReContractOneCoinTranTwiceCase(txCount int, testAccArr *tool.AccArrFormat, contractMap []map[string]common.Address, accountNonceMap *sync.Map, resTxArr []*types.Transaction, client *ethclient.Client) ([]*types.Transaction, func() bool) { func PrReContractOneCoinTranTwiceCase(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(100000000000000000) amount := big.NewInt(100000000000000000)
......
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