Skip to content

Commit

Permalink
Cherry-pick types/rat: Fix overflowing in printing
Browse files Browse the repository at this point in the history
This now uses the underlying golang big.rat's string function,
instead of casting to num and den which are int64s.

Closes #1258
  • Loading branch information
ValarDragon authored and cwgoes committed Jul 2, 2018
1 parent 8be3c46 commit 809f0e5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# Changelog

## 0.20.0

*TBD*

BREAKING CHANGES
* Change default ports from 466xx to 266xx
* AltBytes renamed to Memo, now a string, max 100 characters, costs a bit of gas
* Transactions now take a list of Messages
* Signers of a transaction now only sign over their account and sequence number
* Removed MsgChangePubKey from auth
* Removed setPubKey from account mapper

FEATURES
* [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag
* [lcd] Queried TXs now include the tx hash to identify each tx
* [mockapp] CompleteSetup() no longer takes a testing parameter
* [governance] Implemented MVP
* Supported proposal types: just binary (pass/fail) TextProposals for now
* Proposals need deposits to be votable; deposits are burned if proposal fails
* Delegators delegate votes to validator by default but can override (for their stake)
* [tools] make get_tools installs tendermint's linter, and gometalinter
* [tools] Switch gometalinter to the stable version
* [tools] Add checking for misspellings and for incorrectly formatted files in circle CI
* [server] Default config now creates a profiler at port 6060, and increase p2p send/recv rates

FIXES
* \#1259 - fix bug where certain tests that could have a nil pointer in defer
* \#1052 - Make all now works
* Retry on HTTP request failure in CLI tests, add option to retry tests in Makefile
* Fixed bug where chain ID wasn't passed properly in x/bank REST handler
* Fixed bug where `democli account` didn't decode the account data correctly
* \#1343 - fixed unnecessary parallelism in CI
* \#1258 - printing big.rat's can no longer overflow int64

## 0.19.0

*June 13, 2018*
Expand Down
2 changes: 1 addition & 1 deletion types/rational.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r Rat) Mul(r2 Rat) Rat { return Rat{*new(big.Rat).Mul(&(r.Rat), &(r2.Ra
func (r Rat) Quo(r2 Rat) Rat { return Rat{*new(big.Rat).Quo(&(r.Rat), &(r2.Rat))} } // Quo - quotient
func (r Rat) Add(r2 Rat) Rat { return Rat{*new(big.Rat).Add(&(r.Rat), &(r2.Rat))} } // Add - addition
func (r Rat) Sub(r2 Rat) Rat { return Rat{*new(big.Rat).Sub(&(r.Rat), &(r2.Rat))} } // Sub - subtraction
func (r Rat) String() string { return fmt.Sprintf("%v/%v", r.Num(), r.Denom()) }
func (r Rat) String() string { return r.Rat.String() }

var (
zero = big.NewInt(0)
Expand Down
13 changes: 12 additions & 1 deletion types/rational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestEqualities(t *testing.T) {

}

func TestArithmatic(t *testing.T) {
func TestArithmetic(t *testing.T) {
tests := []struct {
r1, r2 Rat
resMul, resDiv, resAdd, resSub Rat
Expand Down Expand Up @@ -297,3 +297,14 @@ func TestRatsEqual(t *testing.T) {
}

}

func TestStringOverflow(t *testing.T) {
// two random 64 bit primes
rat1 := NewRat(5164315003622678713, 4389711697696177267)
rat2 := NewRat(-3179849666053572961, 8459429845579852627)
rat3 := rat1.Add(rat2)
assert.Equal(t,
"29728537197630860939575850336935951464/37134458148982045574552091851127630409",
rat3.String(),
)
}

0 comments on commit 809f0e5

Please sign in to comment.