Skip to content

Commit

Permalink
ExchangeRate stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Sep 18, 2023
1 parent 4b8e857 commit de0f9d4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 76 deletions.
3 changes: 2 additions & 1 deletion proto/umee/oracle/v1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ message AvgCounter {

// ExchangeRate stores exchange rate with timestamp
message ExchangeRate {
option (gogoproto.equal) = false;
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;

string rate = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
Expand Down
143 changes: 71 additions & 72 deletions x/oracle/types/oracle.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions x/oracle/types/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ func ParseExchangeRateTuples(tuplesStr string) (ExchangeRateTuples, error) {

return tuples, nil
}

func (v ExchangeRate) String() string {
bz, _ := json.Marshal(v)
return string(bz)
}
13 changes: 10 additions & 3 deletions x/oracle/types/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package types

import (
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"gotest.tools/v3/assert"
"github.com/stretchr/testify/assert"
)

func TestAggregateExchangeRatePrevoteString(t *testing.T) {
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestExchangeRateTuplesString(t *testing.T) {
func TestParseExchangeRateTuples(t *testing.T) {
valid := "uumee:123.0,uatom:123.123"
_, err := ParseExchangeRateTuples(valid)
assert.NilError(t, err)
assert.NoError(t, err)

duplicatedDenom := "uumee:100.0,uatom:123.123,uatom:121233.123"
_, err = ParseExchangeRateTuples(duplicatedDenom)
Expand All @@ -72,5 +73,11 @@ func TestParseExchangeRateTuples(t *testing.T) {
assert.ErrorContains(t, err, "invalid exchange rate")

_, err = ParseExchangeRateTuples("")
assert.NilError(t, err)
assert.NoError(t, err)
}

func TestExchangeRateString(t *testing.T) {
t1 := time.Date(2022, 9, 18, 15, 55, 01, 0, time.UTC)
er := ExchangeRate{Rate: sdk.MustNewDecFromStr("1.5"), Timestamp: t1}
assert.Equal(t, `{"rate":"1.500000000000000000","timestamp":"2022-09-18T15:55:01Z"}`, er.String())
}

0 comments on commit de0f9d4

Please sign in to comment.