-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
call eth transaction receipt directly (#10344)
* call eth transaction receipt directly * update * update and fix tests * fix tests * tests * add tests * update * fix types * update * update * udpate * update * addressed comments
- Loading branch information
1 parent
23e04b4
commit 6d97bdc
Showing
9 changed files
with
157 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" | ||
) | ||
|
||
// GetTxBlock calls eth_getTransactionReceipt on the eth client to obtain a tx receipt | ||
func GetTxBlock(client client.Client, txHash common.Hash) (*big.Int, common.Hash, error) { | ||
receipt := types.Receipt{} | ||
err := client.CallContext(context.Background(), &receipt, "eth_getTransactionReceipt", txHash) | ||
if err != nil { | ||
return nil, common.Hash{}, err | ||
} | ||
|
||
if receipt.Status != 1 { | ||
return nil, common.Hash{}, nil | ||
} | ||
|
||
return receipt.GetBlockNumber(), receipt.GetBlockHash(), nil | ||
} |
72 changes: 72 additions & 0 deletions
72
core/services/ocr2/plugins/ocr2keeper/evm21/core/utils_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
evmClientMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" | ||
) | ||
|
||
func TestUtils_GetTxBlock(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
txHash common.Hash | ||
ethCallError error | ||
receipt *types.Receipt | ||
status uint64 | ||
}{ | ||
{ | ||
name: "success", | ||
txHash: common.HexToHash("0xc48fbf05edaf18f6aaa7de24de28528546b874bb03728d624ca407b8fed582a3"), | ||
receipt: &types.Receipt{ | ||
Status: 1, | ||
BlockNumber: big.NewInt(2000), | ||
}, | ||
status: 1, | ||
}, | ||
{ | ||
name: "failure - eth call error", | ||
txHash: common.HexToHash("0xc48fbf05edaf18f6aaa7de24de28528546b874bb03728d624ca407b8fed582a3"), | ||
ethCallError: fmt.Errorf("eth call failed"), | ||
}, | ||
{ | ||
name: "failure - tx does not exist", | ||
txHash: common.HexToHash("0xc48fbf05edaf18f6aaa7de24de28528546b874bb03728d624ca407b8fed582a3"), | ||
receipt: &types.Receipt{ | ||
Status: 0, | ||
}, | ||
status: 0, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
client := new(evmClientMocks.Client) | ||
client.On("CallContext", mock.Anything, mock.Anything, "eth_getTransactionReceipt", tt.txHash). | ||
Return(tt.ethCallError).Run(func(args mock.Arguments) { | ||
receipt := tt.receipt | ||
if receipt != nil { | ||
res := args.Get(1).(*types.Receipt) | ||
res.Status = receipt.Status | ||
res.TxHash = receipt.TxHash | ||
res.BlockNumber = receipt.BlockNumber | ||
res.BlockHash = receipt.BlockHash | ||
} | ||
}) | ||
|
||
bn, bh, err := GetTxBlock(client, tt.txHash) | ||
if tt.ethCallError != nil { | ||
assert.Equal(t, tt.ethCallError, err) | ||
} else { | ||
assert.Equal(t, tt.status, tt.receipt.Status) | ||
assert.Equal(t, tt.receipt.BlockNumber, bn) | ||
assert.Equal(t, tt.receipt.BlockHash, bh) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters