Skip to content

Commit

Permalink
fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
libangzhu authored and vipwzw committed Dec 15, 2022
1 parent f76cfda commit f060723
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 16 additions & 12 deletions rpc/ethrpc/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ func (e *ethHandler) GetTransactionByHash(txhash common.Hash) (*types.Transactio
req.Hash = txhash.Bytes()

txdetail, err := e.cli.QueryTx(&req)
if err != nil {
return nil, err
if err != nil || txdetail == nil {
log.Error("GetTransactionByHash", "QueryTx,err:", err, "txHash:", txhash.String())
//查询不到,不返回错误,直接返回空,与ethereum 保持一致
return nil, nil
}
var blockHash []byte
if txdetail.Tx != nil {
Expand All @@ -169,7 +171,7 @@ func (e *ethHandler) GetTransactionByHash(txhash common.Hash) (*types.Transactio
return txs[0], nil
}
}
log.Error("eth_getTransactionByHash", "err", "transaction not exist")
log.Error("eth_getTransactionByHash", "transaction not exist,err", txhash.String())
return nil, nil

}
Expand All @@ -180,21 +182,23 @@ func (e *ethHandler) GetTransactionReceipt(txhash common.Hash) (*types.Receipt,
var req ctypes.ReqHashes
var blockHash []byte
req.Hashes = append(req.Hashes, txhash.Bytes())
txdetails, err := e.cli.GetTransactionByHash(&req)
if err != nil {
return nil, err
txdetail, err := e.cli.QueryTx(&ctypes.ReqHash{Hash: txhash.Bytes()})
if err != nil || txdetail == nil {
log.Error("GetTransactionReceipt", "QueryTx,err:", err, "txHash:", txhash.String())
//查询不到,不返回错误,直接返回空,与ethereum 保持一致
return nil, nil
}
if len(txdetails.GetTxs()) == 0 { //如果平行链查不到,则去主链查询
return nil, errors.New("transaction not exist")
}
blockNum := txdetails.GetTxs()[0].Height

blockNum := txdetail.GetHeight()
hashReply, err := e.cli.GetBlockHash(&ctypes.ReqInt{Height: blockNum})
if err == nil {
blockHash = hashReply.GetHash()
}

_, receipts, err := types.TxDetailsToEthReceipts(txdetails, common.BytesToHash(blockHash), e.cfg)
var txdetails ctypes.TransactionDetails
txdetails.Txs = append(txdetails.Txs, txdetail)
_, receipts, err := types.TxDetailsToEthReceipts(&txdetails, common.BytesToHash(blockHash), e.cfg)
if err != nil {
log.Error("GetTransactionReceipt", "QueryTx,err:", err)
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion rpc/ethrpc/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ func TestEthHandler_GetTransaction(t *testing.T) {
t.Log(err)
return
}
qapi.On("GetTransactionByHash", mock.Anything).Return(&details, nil)
detail := details.GetTxs()[0]
qapi.On("QueryTx", mock.Anything).Return(detail, nil)
qapi.On("GetBlockHash", mock.Anything).Return(&ctypes.ReplyHash{Hash: common.FromHex("0xea482c18fa9c7665e826fa4a1f3d1e77250fde41535e2b66e43baaa320763206")}, nil)
hexhash := "0xdd99c27b9d5892d485962fb33befad420f655ef75da1a8ca4f8f9873ab10de34"
txs, err := ethCli.GetTransactionByHash(common.HexToHash(hexhash))
Expand Down

0 comments on commit f060723

Please sign in to comment.