2023-01-23 14:37:43 +00:00
|
|
|
package itests
|
|
|
|
|
|
|
|
import (
|
2023-01-23 16:50:40 +00:00
|
|
|
"bytes"
|
2023-01-23 14:37:43 +00:00
|
|
|
"context"
|
2023-01-27 15:13:38 +00:00
|
|
|
"encoding/binary"
|
2023-01-23 16:50:40 +00:00
|
|
|
"encoding/hex"
|
2023-01-23 14:37:43 +00:00
|
|
|
"encoding/json"
|
|
|
|
"os"
|
2023-01-24 11:10:38 +00:00
|
|
|
"strings"
|
2023-01-23 14:37:43 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-openapi/spec"
|
2023-01-23 16:50:40 +00:00
|
|
|
"github.com/gregdhill/go-openrpc/parse"
|
|
|
|
orpctypes "github.com/gregdhill/go-openrpc/types"
|
2023-01-23 14:37:43 +00:00
|
|
|
manet "github.com/multiformats/go-multiaddr/net"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-01-23 16:50:40 +00:00
|
|
|
"github.com/xeipuuv/gojsonschema"
|
2023-01-23 14:37:43 +00:00
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
2023-01-23 17:22:25 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2023-01-23 16:50:40 +00:00
|
|
|
|
2023-01-23 17:22:25 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2023-01-23 16:50:40 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
2023-01-24 13:12:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet/key"
|
2023-01-23 16:50:40 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2023-01-23 14:37:43 +00:00
|
|
|
)
|
|
|
|
|
2023-01-26 17:39:50 +00:00
|
|
|
// TODO generate this using reflection. It's the same as the EthAPI except every return value is a json.RawMessage
|
2023-01-23 14:37:43 +00:00
|
|
|
type ethAPIRaw struct {
|
|
|
|
EthAccounts func(context.Context) (json.RawMessage, error)
|
|
|
|
EthBlockNumber func(context.Context) (json.RawMessage, error)
|
2023-06-21 17:36:04 +00:00
|
|
|
EthCall func(context.Context, ethtypes.EthCall, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
|
2023-01-23 14:37:43 +00:00
|
|
|
EthChainId func(context.Context) (json.RawMessage, error)
|
2023-11-29 10:17:10 +00:00
|
|
|
EthEstimateGas func(context.Context, jsonrpc.RawParams) (json.RawMessage, error)
|
2023-01-23 14:37:43 +00:00
|
|
|
EthFeeHistory func(context.Context, ethtypes.EthUint64, string, []float64) (json.RawMessage, error)
|
|
|
|
EthGasPrice func(context.Context) (json.RawMessage, error)
|
2023-06-21 17:36:04 +00:00
|
|
|
EthGetBalance func(context.Context, ethtypes.EthAddress, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
|
2023-01-23 14:37:43 +00:00
|
|
|
EthGetBlockByHash func(context.Context, ethtypes.EthHash, bool) (json.RawMessage, error)
|
|
|
|
EthGetBlockByNumber func(context.Context, string, bool) (json.RawMessage, error)
|
|
|
|
EthGetBlockTransactionCountByHash func(context.Context, ethtypes.EthHash) (json.RawMessage, error)
|
|
|
|
EthGetBlockTransactionCountByNumber func(context.Context, ethtypes.EthUint64) (json.RawMessage, error)
|
2023-06-21 17:36:04 +00:00
|
|
|
EthGetCode func(context.Context, ethtypes.EthAddress, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
|
2023-01-23 14:37:43 +00:00
|
|
|
EthGetFilterChanges func(context.Context, ethtypes.EthFilterID) (json.RawMessage, error)
|
|
|
|
EthGetFilterLogs func(context.Context, ethtypes.EthFilterID) (json.RawMessage, error)
|
|
|
|
EthGetLogs func(context.Context, *ethtypes.EthFilterSpec) (json.RawMessage, error)
|
2023-06-21 17:36:04 +00:00
|
|
|
EthGetStorageAt func(context.Context, ethtypes.EthAddress, ethtypes.EthBytes, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
|
2023-01-23 14:37:43 +00:00
|
|
|
EthGetTransactionByBlockHashAndIndex func(context.Context, ethtypes.EthHash, ethtypes.EthUint64) (json.RawMessage, error)
|
|
|
|
EthGetTransactionByBlockNumberAndIndex func(context.Context, ethtypes.EthUint64, ethtypes.EthUint64) (json.RawMessage, error)
|
|
|
|
EthGetTransactionByHash func(context.Context, *ethtypes.EthHash) (json.RawMessage, error)
|
2023-06-21 17:36:04 +00:00
|
|
|
EthGetTransactionCount func(context.Context, ethtypes.EthAddress, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
|
2023-01-23 14:37:43 +00:00
|
|
|
EthGetTransactionReceipt func(context.Context, ethtypes.EthHash) (json.RawMessage, error)
|
|
|
|
EthMaxPriorityFeePerGas func(context.Context) (json.RawMessage, error)
|
|
|
|
EthNewBlockFilter func(context.Context) (json.RawMessage, error)
|
|
|
|
EthNewFilter func(context.Context, *ethtypes.EthFilterSpec) (json.RawMessage, error)
|
|
|
|
EthNewPendingTransactionFilter func(context.Context) (json.RawMessage, error)
|
|
|
|
EthSendRawTransaction func(context.Context, ethtypes.EthBytes) (json.RawMessage, error)
|
|
|
|
EthSubscribe func(context.Context, string, *ethtypes.EthSubscriptionParams) (json.RawMessage, error)
|
|
|
|
EthUninstallFilter func(context.Context, ethtypes.EthFilterID) (json.RawMessage, error)
|
|
|
|
EthUnsubscribe func(context.Context, ethtypes.EthSubscriptionID) (json.RawMessage, error)
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
func TestEthOpenRPCConformance(t *testing.T) {
|
2023-01-23 14:37:43 +00:00
|
|
|
kit.QuietAllLogsExcept("events", "messagepool")
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
// specs/eth_openrpc.json is built from https://github.com/ethereum/execution-apis
|
2023-01-23 14:37:43 +00:00
|
|
|
specJSON, err := os.ReadFile("specs/eth_openrpc.json")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
specParsed := orpctypes.NewOpenRPCSpec1()
|
2023-01-26 17:01:39 +00:00
|
|
|
err = json.Unmarshal(specJSON, specParsed)
|
2023-01-23 14:37:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
parse.GetTypes(specParsed, specParsed.Objects)
|
|
|
|
|
|
|
|
schemas := make(map[string]spec.Schema)
|
|
|
|
for _, method := range specParsed.Methods {
|
|
|
|
if method.Result != nil {
|
2023-01-23 16:50:40 +00:00
|
|
|
schemas[method.Name] = method.Result.Schema
|
2023-01-23 14:37:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC(), kit.WithEthRPC())
|
|
|
|
ens.InterconnectAll().BeginMining(10 * time.Millisecond)
|
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
contractHex, err := os.ReadFile("contracts/EventMatrix.hex")
|
2023-01-23 16:50:40 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// strip any trailing newlines from the file
|
|
|
|
contractHex = bytes.TrimRight(contractHex, "\n")
|
|
|
|
|
|
|
|
contractBin, err := hex.DecodeString(string(contractHex))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
senderKey, senderEthAddr, senderFilAddr := client.EVM().NewAccount()
|
|
|
|
_, receiverEthAddr, _ := client.EVM().NewAccount()
|
|
|
|
kit.SendFunds(ctx, t, client, senderFilAddr, types.FromFil(1000))
|
2023-01-23 16:50:40 +00:00
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
deployerAddr, err := client.EVM().WalletDefaultAddress(ctx)
|
2023-01-23 16:50:40 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-24 11:10:38 +00:00
|
|
|
pendingTransactionFilterID, err := client.EthNewPendingTransactionFilter(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
blockFilterID, err := client.EthNewBlockFilter(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
filterAllLogs := kit.NewEthFilterBuilder().FromBlockEpoch(0).Filter()
|
2023-01-24 11:10:38 +00:00
|
|
|
|
|
|
|
logFilterID, err := client.EthNewFilter(ctx, filterAllLogs)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
uninstallableFilterID, err := client.EthNewFilter(ctx, filterAllLogs)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
rawSignedEthTx := createRawSignedEthTx(ctx, t, client, senderEthAddr, receiverEthAddr, senderKey, contractBin)
|
2023-01-23 17:22:25 +00:00
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
result := client.EVM().DeployContract(ctx, deployerAddr, contractBin)
|
|
|
|
contractAddr, err := address.NewIDAddress(result.ActorID)
|
2023-01-23 17:22:25 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
contractEthAddr := ethtypes.EthAddress(result.EthAddress)
|
2023-01-23 17:22:25 +00:00
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
messageWithEvents, blockHashWithMessage, blockNumberWithMessage := waitForMessageWithEvents(ctx, t, client, deployerAddr, contractAddr)
|
2023-01-23 17:22:25 +00:00
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
// create a json-rpc client that returns raw json responses
|
|
|
|
var ethapi ethAPIRaw
|
|
|
|
|
2023-01-23 14:37:43 +00:00
|
|
|
netAddr, err := manet.ToNetAddr(client.ListenAddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
rpcAddr := "ws://" + netAddr.String() + "/rpc/v1"
|
|
|
|
|
|
|
|
closer, err := jsonrpc.NewClient(ctx, rpcAddr, "Filecoin", ðapi, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
testCases := []struct {
|
2023-01-26 17:07:17 +00:00
|
|
|
method string
|
|
|
|
variant string // suffix applied to the test name to distinguish different variants of a method call
|
|
|
|
call func(*ethAPIRaw) (json.RawMessage, error)
|
|
|
|
skipReason string
|
2023-01-23 14:37:43 +00:00
|
|
|
}{
|
2023-01-26 12:10:42 +00:00
|
|
|
// Alphabetical order
|
2023-01-23 16:50:40 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
method: "eth_accounts",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthAccounts(context.Background())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-23 14:37:43 +00:00
|
|
|
{
|
|
|
|
method: "eth_blockNumber",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthBlockNumber(context.Background())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_call",
|
|
|
|
variant: "latest",
|
2023-01-23 16:50:40 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthCall(context.Background(), ethtypes.EthCall{
|
|
|
|
From: &senderEthAddr,
|
|
|
|
Data: contractBin,
|
2023-06-21 17:36:04 +00:00
|
|
|
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
|
2023-01-23 16:50:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_chainId",
|
2023-01-23 16:50:40 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthChainId(context.Background())
|
2023-01-23 16:50:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_estimateGas",
|
2023-01-23 16:50:40 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-11-29 10:17:10 +00:00
|
|
|
gasParams, err := json.Marshal(ethtypes.EthEstimateGasParams{Tx: ethtypes.EthCall{
|
2023-01-26 12:10:42 +00:00
|
|
|
From: &senderEthAddr,
|
|
|
|
Data: contractBin,
|
2023-11-29 10:17:10 +00:00
|
|
|
}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return ethapi.EthEstimateGas(ctx, gasParams)
|
2023-01-23 16:50:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_feeHistory",
|
2023-01-23 16:50:40 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-02-10 22:42:08 +00:00
|
|
|
return ethapi.EthFeeHistory(context.Background(), ethtypes.EthUint64(2), "latest", nil)
|
2023-01-23 16:50:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_gasPrice",
|
2023-01-23 16:50:40 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthGasPrice(context.Background())
|
2023-01-23 16:50:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-23 14:37:43 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getBalance",
|
|
|
|
variant: "blocknumber",
|
2023-01-23 14:37:43 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-06-21 17:36:04 +00:00
|
|
|
blockParam, _ := ethtypes.NewEthBlockNumberOrHashFromHexString("0x0")
|
2023-05-03 17:24:36 +00:00
|
|
|
return ethapi.EthGetBalance(context.Background(), contractEthAddr, blockParam)
|
2023-01-23 14:37:43 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-23 16:50:40 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
method: "eth_getBlockByHash",
|
|
|
|
variant: "txhashes",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetBlockByHash(context.Background(), blockHashWithMessage, false)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
method: "eth_getBlockByHash",
|
|
|
|
variant: "txfull",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetBlockByHash(context.Background(), blockHashWithMessage, true)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
method: "eth_getBlockByNumber",
|
|
|
|
variant: "earliest",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetBlockByNumber(context.Background(), "earliest", true)
|
|
|
|
},
|
2023-02-09 13:14:48 +00:00
|
|
|
skipReason: "earliest block is not supported",
|
2023-01-23 16:50:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-24 11:10:38 +00:00
|
|
|
method: "eth_getBlockByNumber",
|
2023-01-23 16:50:40 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetBlockByNumber(context.Background(), blockNumberWithMessage.Hex(), true)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-23 17:09:35 +00:00
|
|
|
{
|
|
|
|
method: "eth_getBlockTransactionCountByHash",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetBlockTransactionCountByHash(context.Background(), blockHashWithMessage)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
method: "eth_getBlockTransactionCountByNumber",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetBlockTransactionCountByNumber(context.Background(), blockNumberWithMessage)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getCode",
|
|
|
|
variant: "blocknumber",
|
2023-01-23 17:09:35 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-06-21 17:36:04 +00:00
|
|
|
return ethapi.EthGetCode(context.Background(), contractEthAddr, ethtypes.NewEthBlockNumberOrHashFromNumber(blockNumberWithMessage))
|
2023-01-23 17:09:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getFilterChanges",
|
|
|
|
variant: "pendingtransaction",
|
2023-01-23 17:09:35 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return a.EthGetFilterChanges(ctx, pendingTransactionFilterID)
|
2023-01-23 17:09:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getFilterChanges",
|
|
|
|
variant: "block",
|
2023-01-23 17:09:35 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return a.EthGetFilterChanges(ctx, blockFilterID)
|
2023-01-23 17:09:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-23 17:22:25 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getFilterChanges",
|
|
|
|
variant: "logs",
|
2023-01-23 17:22:25 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return a.EthGetFilterChanges(ctx, logFilterID)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
method: "eth_getFilterLogs",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return a.EthGetFilterLogs(ctx, logFilterID)
|
2023-01-23 17:22:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-24 11:10:38 +00:00
|
|
|
{
|
|
|
|
method: "eth_getLogs",
|
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
|
|
|
return ethapi.EthGetLogs(context.Background(), filterAllLogs)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getStorageAt",
|
|
|
|
variant: "blocknumber",
|
2023-01-24 11:10:38 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-06-21 17:36:04 +00:00
|
|
|
blockParam, _ := ethtypes.NewEthBlockNumberOrHashFromHexString("0x0")
|
2023-05-03 17:24:36 +00:00
|
|
|
return ethapi.EthGetStorageAt(context.Background(), contractEthAddr, ethtypes.EthBytes{0}, blockParam)
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getTransactionByBlockHashAndIndex",
|
2023-01-24 11:10:38 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthGetTransactionByBlockHashAndIndex(context.Background(), blockHashWithMessage, ethtypes.EthUint64(0))
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
2023-02-09 13:14:48 +00:00
|
|
|
skipReason: "unimplemented",
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getTransactionByBlockNumberAndIndex",
|
2023-01-24 11:10:38 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthGetTransactionByBlockNumberAndIndex(context.Background(), blockNumberWithMessage, ethtypes.EthUint64(0))
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
2023-02-09 13:14:48 +00:00
|
|
|
skipReason: "unimplemented",
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getTransactionByHash",
|
2023-01-24 11:10:38 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthGetTransactionByHash(context.Background(), &messageWithEvents)
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getTransactionCount",
|
|
|
|
variant: "blocknumber",
|
2023-01-24 11:10:38 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-06-21 17:36:04 +00:00
|
|
|
return ethapi.EthGetTransactionCount(context.Background(), senderEthAddr, ethtypes.NewEthBlockNumberOrHashFromNumber(blockNumberWithMessage))
|
2023-01-24 11:10:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-01-24 14:03:31 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_getTransactionReceipt",
|
2023-01-24 14:03:31 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthGetTransactionReceipt(context.Background(), messageWithEvents)
|
2023-01-24 14:03:31 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-23 16:50:40 +00:00
|
|
|
|
2023-01-24 11:27:18 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_maxPriorityFeePerGas",
|
2023-01-24 11:27:18 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthMaxPriorityFeePerGas(context.Background())
|
2023-01-24 11:27:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_newBlockFilter",
|
2023-01-24 11:27:18 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthNewBlockFilter(context.Background())
|
2023-01-24 11:27:18 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-26 12:10:42 +00:00
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_newFilter",
|
2023-01-24 13:12:31 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthNewFilter(context.Background(), filterAllLogs)
|
2023-01-24 13:12:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_newPendingTransactionFilter",
|
2023-01-24 13:12:31 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthNewPendingTransactionFilter(context.Background())
|
2023-01-24 13:12:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_sendRawTransaction",
|
2023-01-24 13:12:31 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return ethapi.EthSendRawTransaction(context.Background(), rawSignedEthTx)
|
2023-01-24 13:12:31 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-24 14:03:31 +00:00
|
|
|
{
|
2023-01-26 12:10:42 +00:00
|
|
|
method: "eth_uninstallFilter",
|
2023-01-24 14:03:31 +00:00
|
|
|
call: func(a *ethAPIRaw) (json.RawMessage, error) {
|
2023-01-26 12:10:42 +00:00
|
|
|
return a.EthUninstallFilter(ctx, uninstallableFilterID)
|
2023-01-24 14:03:31 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-23 14:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2023-01-26 17:01:39 +00:00
|
|
|
tc := tc
|
2023-01-23 16:50:40 +00:00
|
|
|
name := tc.method
|
|
|
|
if tc.variant != "" {
|
|
|
|
name += "_" + tc.variant
|
|
|
|
}
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-01-26 17:07:17 +00:00
|
|
|
if tc.skipReason != "" {
|
|
|
|
t.Skipf(tc.skipReason)
|
|
|
|
}
|
|
|
|
|
2023-01-23 14:37:43 +00:00
|
|
|
schema, ok := schemas[tc.method]
|
|
|
|
require.True(t, ok, "method not found in openrpc spec")
|
|
|
|
|
|
|
|
resp, err := tc.call(ðapi)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
respJson, err := json.Marshal(resp)
|
2023-01-23 14:37:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
loader := gojsonschema.NewGoLoader(schema)
|
|
|
|
resploader := gojsonschema.NewBytesLoader(respJson)
|
|
|
|
result, err := gojsonschema.Validate(loader, resploader)
|
2023-01-23 14:37:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
if !result.Valid() {
|
2023-01-24 11:10:38 +00:00
|
|
|
if len(result.Errors()) == 1 && strings.Contains(result.Errors()[0].String(), "Must validate one and only one schema (oneOf)") {
|
|
|
|
// Ignore this error, since it seems the openrpc spec can't handle it
|
|
|
|
// New transaction and block filters have the same schema: an array of 32 byte hashes
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
niceRespJson, err := json.MarshalIndent(resp, "", " ")
|
|
|
|
if err == nil {
|
|
|
|
t.Logf("response was %s", niceRespJson)
|
|
|
|
}
|
2023-01-23 14:37:43 +00:00
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
schemaJson, err := json.MarshalIndent(schema, "", " ")
|
|
|
|
if err == nil {
|
|
|
|
t.Logf("schema was %s", schemaJson)
|
|
|
|
}
|
2023-01-23 14:37:43 +00:00
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
// check against https://www.jsonschemavalidator.net/
|
2023-01-23 14:37:43 +00:00
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
for _, desc := range result.Errors() {
|
|
|
|
t.Logf("- %s\n", desc)
|
|
|
|
}
|
2023-01-23 14:37:43 +00:00
|
|
|
|
2023-01-23 16:50:40 +00:00
|
|
|
t.Errorf("response did not validate")
|
|
|
|
}
|
|
|
|
})
|
2023-01-23 14:37:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-24 13:12:31 +00:00
|
|
|
|
|
|
|
func createRawSignedEthTx(ctx context.Context, t *testing.T, client *kit.TestFullNode, senderEthAddr ethtypes.EthAddress, receiverEthAddr ethtypes.EthAddress, senderKey *key.Key, contractBin []byte) []byte {
|
2023-11-29 10:17:10 +00:00
|
|
|
gasParams, err := json.Marshal(ethtypes.EthEstimateGasParams{Tx: ethtypes.EthCall{
|
2023-01-24 13:12:31 +00:00
|
|
|
From: &senderEthAddr,
|
|
|
|
Data: contractBin,
|
2023-11-29 10:17:10 +00:00
|
|
|
}})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gaslimit, err := client.EthEstimateGas(ctx, gasParams)
|
2023-01-24 13:12:31 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tx := ethtypes.EthTxArgs{
|
|
|
|
ChainID: build.Eip155ChainId,
|
|
|
|
Value: big.NewInt(100),
|
|
|
|
Nonce: 0,
|
|
|
|
To: &receiverEthAddr,
|
|
|
|
MaxFeePerGas: types.NanoFil,
|
|
|
|
MaxPriorityFeePerGas: big.Int(maxPriorityFeePerGas),
|
|
|
|
GasLimit: int(gaslimit),
|
|
|
|
V: big.Zero(),
|
|
|
|
R: big.Zero(),
|
|
|
|
S: big.Zero(),
|
|
|
|
}
|
|
|
|
|
|
|
|
client.EVM().SignTransaction(&tx, senderKey.PrivateKey)
|
|
|
|
signed, err := tx.ToRlpSignedMsg()
|
|
|
|
require.NoError(t, err)
|
|
|
|
return signed
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitForMessageWithEvents(ctx context.Context, t *testing.T, client *kit.TestFullNode, sender address.Address, target address.Address) (ethtypes.EthHash, ethtypes.EthHash, ethtypes.EthUint64) {
|
2023-01-27 15:13:38 +00:00
|
|
|
vals := []uint64{44, 27, 19, 12}
|
|
|
|
inputData := []byte{}
|
|
|
|
for _, v := range vals {
|
|
|
|
buf := make([]byte, 32)
|
|
|
|
binary.BigEndian.PutUint64(buf[24:], v)
|
|
|
|
inputData = append(inputData, buf...)
|
|
|
|
}
|
|
|
|
|
2023-01-24 13:12:31 +00:00
|
|
|
// send a message that exercises event logs
|
2023-02-01 16:41:01 +00:00
|
|
|
ret, err := client.EVM().InvokeSolidity(ctx, sender, target, kit.EventMatrixContract.Fn["logEventThreeIndexedWithData"], inputData)
|
|
|
|
require.NoError(t, err)
|
2023-01-27 15:13:38 +00:00
|
|
|
require.True(t, ret.Receipt.ExitCode.IsSuccess(), "contract execution failed")
|
2023-01-24 13:12:31 +00:00
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
msgHash, err := client.EthGetTransactionHashByCid(ctx, ret.Message)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, msgHash)
|
2023-01-24 13:12:31 +00:00
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
ts, err := client.ChainGetTipSet(ctx, ret.TipSet)
|
|
|
|
require.NoError(t, err)
|
2023-01-24 13:12:31 +00:00
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
blockNumber := ethtypes.EthUint64(ts.Height())
|
2023-01-24 13:12:31 +00:00
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
tsCid, err := ts.Key().Cid()
|
|
|
|
require.NoError(t, err)
|
2023-01-24 13:12:31 +00:00
|
|
|
|
2023-01-27 15:13:38 +00:00
|
|
|
blockHash, err := ethtypes.EthHashFromCid(tsCid)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return *msgHash, blockHash, blockNumber
|
2023-01-24 13:12:31 +00:00
|
|
|
}
|