Skip to content

Commit

Permalink
ethapi: add basic test for sendcondtionaltrx
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Mar 31, 2023
1 parent 8224654 commit b07e548
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -376,6 +377,9 @@ func TestEthClient(t *testing.T) {
"TestDiffAccounts": {
func(t *testing.T) { testDiffAccounts(t, client) },
},
"TestSendTransactionConditional": {
func(t *testing.T) { testSendTransactionConditional(t, client) },
},
// DO not have TestAtFunctions now, because we do not have pending block now
}

Expand Down Expand Up @@ -660,3 +664,45 @@ func testDiffAccounts(t *testing.T, client *rpc.Client) {
}
}
}

func testSendTransactionConditional(t *testing.T, client *rpc.Client) {
ec := NewClient(client)

if err := sendTransactionConditional(ec); err != nil {
t.Fatalf("error: %v", err)
}
}

func sendTransactionConditional(ec *Client) error {
chainID, err := ec.ChainID(context.Background())
if err != nil {
return err
}

nonce, err := ec.PendingNonceAt(context.Background(), testAddr)
if err != nil {
return err
}

signer := types.LatestSignerForChainID(chainID)

tx, err := types.SignNewTx(testKey, signer, &types.LegacyTx{
Nonce: nonce,
To: &common.Address{2},
Value: big.NewInt(1),
Gas: 22000,
GasPrice: big.NewInt(params.InitialBaseFee),
})
if err != nil {
return err
}

root := common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
return ec.SendTransactionConditional(context.Background(), tx, ethapi.TransactionOpts{
KnownAccounts: map[common.Address]ethapi.AccountStorage{
testAddr: ethapi.AccountStorage{
StorageRoot: &root,
},
},
})
}

0 comments on commit b07e548

Please sign in to comment.