diff --git a/accounts/abi/bind/backends/simulated_test.go b/accounts/abi/bind/backends/simulated_test.go index a41d168411..712e334e31 100644 --- a/accounts/abi/bind/backends/simulated_test.go +++ b/accounts/abi/bind/backends/simulated_test.go @@ -58,6 +58,11 @@ func TestSimulatedBackend(t *testing.T) { t.Fatalf("err should be `ethereum.NotFound` but received %v", err) } + pendingCount, _ := sim.PendingTransactionCount(context.Background()) + if pendingCount != 0 { + t.Errorf("expected pending tx count of 0 got %v", pendingCount) + } + // generate a transaction and confirm you can retrieve it head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1)) @@ -72,6 +77,11 @@ func TestSimulatedBackend(t *testing.T) { t.Fatal("error sending transaction") } + pendingCount, _ = sim.PendingTransactionCount(context.Background()) + if pendingCount != 1 { + t.Errorf("expected pending tx count of 1 got %v", pendingCount) + } + txHash = tx.Hash() _, isPending, err = sim.TransactionByHash(context.Background(), txHash) if err != nil { @@ -89,6 +99,25 @@ func TestSimulatedBackend(t *testing.T) { if isPending { t.Fatal("transaction should not have pending status") } + + to := crypto.PubkeyToAddress(testKey.PublicKey) + tx = types.NewTransaction(1, to, big.NewInt(1024), params.TxGas, gasPrice, nil) + signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, key) + if err != nil { + t.Errorf("could not sign tx: %v", err) + } + err = sim.SendTransaction(context.Background(), signedTx) + if err != nil { + t.Errorf("could not add tx to pending block: %v", err) + } + + balance, err := sim.PendingBalanceAt(context.Background(), to) + if err != nil { + t.Errorf("could not get pending balance: %v", err) + } + if balance.Cmp(big.NewInt(1024)) != 0 { + t.Errorf("pendingBalance not match, want: 1024 have: %d", balance.Int64()) + } } var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")