Skip to content

Commit

Permalink
addl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CreatureDev committed Oct 5, 2023
1 parent 5c5a725 commit 22d44cb
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 7 deletions.
2 changes: 1 addition & 1 deletion model/client/account/account_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ func TestValidate(t *testing.T) {

err := s.Validate()

assert.EqualError(t, err, "no account ID specified")
assert.ErrorContains(t, err, "missing xrpl address")
}
11 changes: 11 additions & 0 deletions model/client/account/account_currencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package account
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/test"
)
Expand Down Expand Up @@ -55,3 +56,13 @@ func TestAccountCurrenciesResponse(t *testing.T) {
t.Error(err)
}
}

func TestAccountCurrenciesValidation(t *testing.T) {
s := AccountCurrenciesRequest{
Account: "",
}
err := s.Validate()

assert.ErrorContains(t, err, "missing xrpl address")

}
11 changes: 11 additions & 0 deletions model/client/account/account_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package account
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/ledger"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand Down Expand Up @@ -110,3 +111,13 @@ func TestAccountInfoResponse(t *testing.T) {
t.Error(err)
}
}

func TestAccountInfoValidate(t *testing.T) {
s := AccountInfoRequest{
Account: "",
}

err := s.Validate()

assert.ErrorContains(t, err, "missing xrpl address")
}
17 changes: 17 additions & 0 deletions model/client/account/account_lines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package account
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/test"
)
Expand Down Expand Up @@ -74,3 +75,19 @@ func TestAccountLinesResponse(t *testing.T) {
t.Error(err)
}
}

func TestAccountLinesValidate(t *testing.T) {
s := AccountLinesRequest{
Account: "",
}

err := s.Validate()

assert.ErrorContains(t, err, "missing xrpl address")

s.Account = "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
s.Limit = 2
err = s.Validate()

assert.ErrorContains(t, err, "invalid limit")
}
12 changes: 12 additions & 0 deletions model/client/admin/status/print_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package status

type PrintRequest struct {
}

func (*PrintRequest) Method() string {
return "print"
}

func (*PrintRequest) Validate() error {
return nil
}
5 changes: 5 additions & 0 deletions model/client/admin/status/print_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package status

type PrintResponse struct {
App map[string]any `json:"app"`
}
13 changes: 13 additions & 0 deletions model/client/channel/channel_authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package channel
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xrpl-go/model/transactions/types"
"github.com/xyield/xrpl-go/test"
)
Expand Down Expand Up @@ -39,3 +40,15 @@ func TestChannelAuthorizeResponse(t *testing.T) {
t.Error(err)
}
}

func TestChannelAuthorizeValidate(t *testing.T) {
s := ChannelAuthorizeRequest{}
err := s.Validate()
assert.ErrorContains(t, err, "missing channel id")

s = ChannelAuthorizeRequest{
ChannelID: "abc",
}
err = s.Validate()
assert.Nil(t, err)
}
12 changes: 6 additions & 6 deletions model/client/ledger/ledger_entry_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *LedgerEntryRequest) Validate() error {
}

if setCount != 1 {
return fmt.Errorf("ledger entry: exactly one ledger entry object may be requested")
return fmt.Errorf("ledger entry: exactly one ledger entry object may be requested, found %d", setCount)
}

return nil
Expand Down Expand Up @@ -133,7 +133,7 @@ func (*OfferEntryReq) LedgerEntryRequestField() {}

func (r *OfferEntryReq) Validate() error {
if err := r.Account.Validate(); err != nil {
return fmt.Errorf("offer entry: %w", err)
return fmt.Errorf("offer entry account: %w", err)
}
return nil
}
Expand All @@ -149,9 +149,9 @@ func (r *RippleStateEntryReq) Validate() error {
if len(r.Accounts) != 2 {
return fmt.Errorf("ripple state entry requires two accounts")
}
for _, a := range r.Accounts {
for i, a := range r.Accounts {
if err := a.Validate(); err != nil {
return fmt.Errorf("ripple state entry: %w", err)
return fmt.Errorf("ripple state entry account %d: %w", i+1, err)
}
}
return nil
Expand All @@ -166,7 +166,7 @@ func (*EscrowEntryReq) LedgerEntryRequestField() {}

func (r *EscrowEntryReq) Validate() error {
if err := r.Owner.Validate(); err != nil {
return fmt.Errorf("escrow entry: %w", err)
return fmt.Errorf("escrow entry owner: %w", err)
}
return nil
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func (*TicketEntryReq) LedgerEntryRequestField() {}

func (r *TicketEntryReq) Validate() error {
if err := r.Account.Validate(); err != nil {
return fmt.Errorf("ticket entry: %w", err)
return fmt.Errorf("ticket entry account: %w", err)
}
return nil
}
Expand Down
58 changes: 58 additions & 0 deletions model/client/ledger/ledger_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ledger
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xyield/xrpl-go/model/client/common"
"github.com/xyield/xrpl-go/model/ledger"
"github.com/xyield/xrpl-go/model/transactions/types"
Expand Down Expand Up @@ -72,3 +73,60 @@ func TestLedgerEntryResponse(t *testing.T) {
t.Error(err)
}
}

func TestLedgerEntryValidate(t *testing.T) {
off := &OfferEntryReq{}
err := off.Validate()
assert.ErrorContains(t, err, "offer")
off.Account = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn"
err = off.Validate()
assert.Nil(t, err)

rs := RippleStateEntryReq{}
err = rs.Validate()
assert.ErrorContains(t, err, "requires two accounts")
rs.Accounts = []types.Address{"rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn", ""}
err = rs.Validate()
assert.ErrorContains(t, err, "account 2")
rs.Accounts[1] = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCc"
err = rs.Validate()
assert.Nil(t, err)

esc := EscrowEntryReq{}
err = esc.Validate()
assert.ErrorContains(t, err, "escrow entry owner")
esc.Owner = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn"
err = esc.Validate()
assert.Nil(t, err)

dep := DepositPreauthEntryReq{}
err = dep.Validate()
assert.ErrorContains(t, err, "deposit preauth")
dep.Owner = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn"
err = dep.Validate()
assert.ErrorContains(t, err, "authorized")
dep.Authorized = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCC"
err = dep.Validate()
assert.Nil(t, err)

tick := TicketEntryReq{}
err = tick.Validate()
assert.ErrorContains(t, err, "ticket")
tick.Account = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn"
err = tick.Validate()
assert.Nil(t, err)

s := LedgerEntryRequest{}
err = s.Validate()
assert.ErrorContains(t, err, "0")
s.AccountRoot = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn"
err = s.Validate()
assert.Nil(t, err)
s.Offer = off
err = s.Validate()
assert.ErrorContains(t, err, "2")
s.AccountRoot = ""
s.Offer = &OfferEntryReq{}
err = s.Validate()
assert.ErrorContains(t, err, "ledger entry offer")
}
3 changes: 3 additions & 0 deletions model/transactions/types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type Address string

func (a Address) Validate() error {
characters := []string{"0", "O", "I", "l"}
if len(a) == 0 {
return fmt.Errorf("missing xrpl address")
}
if len(a) < 25 || len(a) > 35 {
return fmt.Errorf("invalid xrpl address length")
}
Expand Down

0 comments on commit 22d44cb

Please sign in to comment.