diff --git a/rhp/v4/rpc_test.go b/rhp/v4/rpc_test.go index 266b06c..38a52d5 100644 --- a/rhp/v4/rpc_test.go +++ b/rhp/v4/rpc_test.go @@ -752,6 +752,19 @@ func TestAccounts(t *testing.T) { cs := cm.TipState() + // test operations against unknown account + token := proto4.AccountToken{ + Account: account, + ValidUntil: time.Now().Add(time.Hour), + } + + tokenSigHash := token.SigHash() + token.Signature = renterKey.SignHash(tokenSigHash) + _, err = rhp4.RPCVerifySector(context.Background(), transport, settings.Prices, token, types.Hash256{1}) + if err == nil || !strings.Contains(err.Error(), proto4.ErrNotEnoughFunds.Error()) { + t.Fatal(err) + } + balance, err := rhp4.RPCAccountBalance(context.Background(), transport, account) if err != nil { t.Fatal(err) @@ -803,6 +816,13 @@ func TestAccounts(t *testing.T) { } else if !balance.Equals(accountFundAmount) { t.Fatalf("expected %v, got %v", accountFundAmount, balance) } + + // drain account and try using it + _ = c.DebitAccount(account, proto4.Usage{RPC: accountFundAmount}) + _, err = rhp4.RPCVerifySector(context.Background(), transport, settings.Prices, token, types.Hash256{1}) + if err == nil || !strings.Contains(err.Error(), proto4.ErrNotEnoughFunds.Error()) { + t.Fatal(err) + } } func TestReadWriteSector(t *testing.T) { diff --git a/testutil/host.go b/testutil/host.go index 5fb8bc5..f22b617 100644 --- a/testutil/host.go +++ b/testutil/host.go @@ -252,10 +252,8 @@ func (ec *EphemeralContractor) DebitAccount(account proto4.Account, usage proto4 defer ec.mu.Unlock() balance, ok := ec.accounts[account] - if !ok { - return errors.New("account not found") - } else if balance.Cmp(usage.RenterCost()) < 0 { - return errors.New("insufficient funds") + if !ok || balance.Cmp(usage.RenterCost()) < 0 { + return proto4.ErrNotEnoughFunds } ec.accounts[account] = balance.Sub(usage.RenterCost()) return nil