Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rhp4): Return 0 for nonexistent accounts #129

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions rhp/v4/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions testutil/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading