Skip to content

Commit

Permalink
ripple path test
Browse files Browse the repository at this point in the history
  • Loading branch information
CreatureDev committed Apr 11, 2023
1 parent f8b3cd0 commit cd510ef
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 19 deletions.
33 changes: 14 additions & 19 deletions model/client/path/ripple_path_find_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
)

type RipplePathFindRequest struct {
SourceAccount types.Address `json:"source_account"`
DestinationAccount types.Address `json:"destination_account"`
DestinationAmount types.CurrencyAmount `json:"destination_amount"`
SendMax types.CurrencyAmount `json:"send_max,omitempty"`
SourceCurrencies []SourceCurrency `json:"source_currencies,omitempty"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"`
SourceAccount types.Address `json:"source_account"`
DestinationAccount types.Address `json:"destination_account"`
DestinationAmount types.CurrencyAmount `json:"destination_amount"`
SendMax types.CurrencyAmount `json:"send_max,omitempty"`
SourceCurrencies []types.IssuedCurrencyAmount `json:"source_currencies,omitempty"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"`
}

func (*RipplePathFindRequest) Method() string {
Expand All @@ -23,13 +23,13 @@ func (*RipplePathFindRequest) Method() string {

func (r *RipplePathFindRequest) UnmarshalJSON(data []byte) error {
type rpfHelper struct {
SourceAccount types.Address `json:"source_account"`
DestinationAccount types.Address `json:"destination_account"`
DestinationAmount json.RawMessage `json:"destination_amount"`
SendMax json.RawMessage `json:"send_max,omitempty"`
SourceCurrencies []SourceCurrency `json:"source_currencies,omitempty"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex json.RawMessage `json:"ledger_index,omitempty"`
SourceAccount types.Address `json:"source_account"`
DestinationAccount types.Address `json:"destination_account"`
DestinationAmount json.RawMessage `json:"destination_amount"`
SendMax json.RawMessage `json:"send_max,omitempty"`
SourceCurrencies []types.IssuedCurrencyAmount `json:"source_currencies,omitempty"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex json.RawMessage `json:"ledger_index,omitempty"`
}
var h rpfHelper
if err := json.Unmarshal(data, &h); err != nil {
Expand Down Expand Up @@ -65,8 +65,3 @@ func (r *RipplePathFindRequest) UnmarshalJSON(data []byte) error {
return nil

}

type SourceCurrency struct {
Currency string `json:"currency"`
Issuer types.Address `json:"issuer,omitempty"`
}
201 changes: 201 additions & 0 deletions model/client/path/ripple_path_find_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package path

import (
"testing"

"github.com/xyield/xrpl-go/model/transactions"
"github.com/xyield/xrpl-go/model/transactions/types"
"github.com/xyield/xrpl-go/test"
)

func TestRipplePathFindRequest(t *testing.T) {
s := RipplePathFindRequest{
SourceAccount: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
DestinationAccount: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
DestinationAmount: types.IssuedCurrencyAmount{
Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
Currency: "USD",
Value: "0.001",
},
SourceCurrencies: []types.IssuedCurrencyAmount{
{
Currency: "XRP",
},
{
Currency: "USD",
},
},
}

j := `{
"source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"destination_amount": {
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
"currency": "USD",
"value": "0.001"
},
"source_currencies": [
{
"currency": "XRP"
},
{
"currency": "USD"
}
]
}`
if err := test.SerializeAndDeserialize(t, s, j); err != nil {
t.Error(err)
}
}

func TestRipplePathFindResponse(t *testing.T) {
s := RipplePathFindResponse{
Alternatives: []PathAlternative{
{
PathsComputed: [][]transactions.PathStep{
{
{
Currency: "USD",
Issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
},
{
Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
},
},
{
{
Currency: "USD",
Issuer: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1",
},
{
Account: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1",
},
{
Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
},
},
{
{
Currency: "USD",
Issuer: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1",
},
{
Account: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1",
},
{
Account: "rLpq4LgabRfm1xEX5dpWfJovYBH6g7z99q",
},
{
Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
},
},
{
{
Currency: "USD",
Issuer: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1",
},
{
Account: "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1",
},
{
Account: "rPuBoajMjFoDjweJBrtZEBwUMkyruxpwwV",
},
{
Account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
},
},
},
SourceAmount: types.XRPCurrencyAmount(256987),
},
},
DestinationAccount: "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
DestinationCurrencies: []string{
"015841551A748AD2C1F76FF6ECB0CCCD00000000",
"JOE",
"DYM",
"EUR",
"CNY",
"MXN",
"BTC",
"USD",
"XRP",
},
}

j := `{
"alternatives": [
{
"paths_computed": [
[
{
"currency": "USD",
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
},
{
"account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
}
],
[
{
"currency": "USD",
"issuer": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"
},
{
"account": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"
},
{
"account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
}
],
[
{
"currency": "USD",
"issuer": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"
},
{
"account": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"
},
{
"account": "rLpq4LgabRfm1xEX5dpWfJovYBH6g7z99q"
},
{
"account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
}
],
[
{
"currency": "USD",
"issuer": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"
},
{
"account": "rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"
},
{
"account": "rPuBoajMjFoDjweJBrtZEBwUMkyruxpwwV"
},
{
"account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
}
]
],
"source_amount": "256987"
}
],
"destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"destination_currencies": [
"015841551A748AD2C1F76FF6ECB0CCCD00000000",
"JOE",
"DYM",
"EUR",
"CNY",
"MXN",
"BTC",
"USD",
"XRP"
]
}`
if err := test.SerializeAndDeserialize(t, s, j); err != nil {
t.Error(err)
}
}

0 comments on commit cd510ef

Please sign in to comment.