From 12dcfc50949381200055d1ac85ffd298605117ef Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 4 Dec 2024 08:21:39 -0800 Subject: [PATCH] fix(rhp4): Return 0 for nonexistent accounts --- rhp/v4/rpc_test.go | 11 +++++++++-- testutil/host.go | 5 +---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rhp/v4/rpc_test.go b/rhp/v4/rpc_test.go index f09be58..a869635 100644 --- a/rhp/v4/rpc_test.go +++ b/rhp/v4/rpc_test.go @@ -625,6 +625,7 @@ func TestRPCRenew(t *testing.T) { func TestAccounts(t *testing.T) { n, genesis := testutil.V2Network() hostKey, renterKey := types.GeneratePrivateKey(), types.GeneratePrivateKey() + account := proto4.Account(renterKey.PublicKey()) cm, s, w := startTestNode(t, n, genesis) @@ -673,7 +674,13 @@ func TestAccounts(t *testing.T) { revision := formResult.Contract cs := cm.TipState() - account := proto4.Account(renterKey.PublicKey()) + + balance, err := rhp4.RPCAccountBalance(context.Background(), transport, account) + if err != nil { + t.Fatal(err) + } else if !balance.IsZero() { + t.Fatal("expected zero balance") + } accountFundAmount := types.Siacoins(25) fundResult, err := rhp4.RPCFundAccounts(context.Background(), transport, cs, renterKey, revision, []proto4.AccountDeposit{ @@ -713,7 +720,7 @@ func TestAccounts(t *testing.T) { } // verify the account balance - balance, err := rhp4.RPCAccountBalance(context.Background(), transport, account) + balance, err = rhp4.RPCAccountBalance(context.Background(), transport, account) if err != nil { t.Fatal(err) } else if !balance.Equals(accountFundAmount) { diff --git a/testutil/host.go b/testutil/host.go index c0af3f9..b5b4407 100644 --- a/testutil/host.go +++ b/testutil/host.go @@ -210,10 +210,7 @@ func (ec *EphemeralContractor) ReviseV2Contract(contractID types.FileContractID, func (ec *EphemeralContractor) AccountBalance(account proto4.Account) (types.Currency, error) { ec.mu.Lock() defer ec.mu.Unlock() - balance, ok := ec.accounts[account] - if !ok { - return types.Currency{}, errors.New("account not found") - } + balance, _ := ec.accounts[account] return balance, nil }