Commit Graph

42 Commits

Author SHA1 Message Date
gribanoid
96662df62f
fix(math): double method call (#15768)
## Description
The `init` method of the `Rand` struct was called twice: in the constructor and in the `init` function.
Closes: #XXXX



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

* [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] added `!` to the type prefix if API or client breaking change
* [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
* [ ] provided a link to the relevant issue or specification
* [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
* [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
* [ ] added a changelog entry to `CHANGELOG.md`
* [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
* [ ] updated the relevant documentation or specification
* [ ] reviewed "Files changed" and left comments if necessary
* [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

* [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] confirmed `!` in the type prefix if API or client breaking change
* [ ] confirmed all author checklist items have been addressed 
* [ ] reviewed state machine logic
* [ ] reviewed API design and naming
* [ ] reviewed documentation is accurate
* [ ] reviewed tests and test coverage
* [ ] manually tested (if applicable)
2023-04-10 15:34:10 +00:00
Facundo Medica
43cfdfe618
fix(math): FormatInt returns error on empty string (#15714) 2023-04-06 14:10:30 +00:00
Jacob Gadikian
8c182e7d77
style: lints for core, math, simapp, and tests (#15638) 2023-03-31 09:30:29 +02:00
Jacob Gadikian
b009a75eea
style: make lint-fix everything (#15631)
Co-authored-by: Julien Robert <julien@rbrt.fr>
2023-03-30 17:27:39 +00:00
Marko
1f2875d445
style: gofumpt linting (#15605) 2023-03-30 06:27:38 +00:00
Matt Kocubinski
ba9d4df6d0
chore(math): fix changelog link (#15531)
Fixing a changelog link.
2023-03-23 14:49:21 +00:00
Matt Kocubinski
7204a5d4dd
chore: math v1.0.0 (#15530)
Update Changelog in preparation for tagging math/v1.0.0
2023-03-23 15:44:12 +01:00
Matt Kocubinski
4db99fc1a5
fix(math): Dec marshal shouldn't have side effects (#15506)
## Description

Ref: https://github.com/cosmos/cosmos-sdk/issues/15170
Included in: #15515 

Required to resolve a discrepancy between the sign mode being implemented in #15170 and the existing legacy one.

When calling tx builder [SetMsgs](4a6a1e3cb8/x/auth/tx/builder.go (L208)) messages are coerced to an any type in [NewAnyWithValue](4a6a1e3cb8/codec/types/any.go (L61)). This marshals a message as proto bytes. If a message has cosmos.Dec typed fields, and they are set to nil, the will be set to 0 during seriazliation in the [Dec.Marshal](88909d6f2b/math/dec.go (L801)) implementation.

This side effect *changes* the output of a JSON marshal before and after the call to Dec.Marshal, as shown below.

```go
rates := &stakingtypes.CommissionRates{}
MarshalJson(rates)
// {"rate":"0","max_rate":"0","max_change_rate":"0"}

MarshalProto(rates)

MarshalJson(rates)
//{"rate":"0.000000000000000000","max_rate":"0.000000000000000000","max_change_rate":"0.000000000000000000"}
```

An integration is test is also committed asserting the (now fixed) behavior above.  Its asserts should be changed once a release of math is made and `/tests/go.mod` is updated.



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

* [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] added `!` to the type prefix if API or client breaking change
* [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
* [ ] provided a link to the relevant issue or specification
* [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
* [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
* [ ] added a changelog entry to `CHANGELOG.md`
* [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
* [ ] updated the relevant documentation or specification
* [ ] reviewed "Files changed" and left comments if necessary
* [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

* [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] confirmed `!` in the type prefix if API or client breaking change
* [ ] confirmed all author checklist items have been addressed 
* [ ] reviewed state machine logic
* [ ] reviewed API design and naming
* [ ] reviewed documentation is accurate
* [ ] reviewed tests and test coverage
* [ ] manually tested (if applicable)
2023-03-22 19:48:36 +00:00
Julien Robert
46169d0bff
ci: add changelog reminder (#15459) 2023-03-21 14:44:24 +01:00
Jeancarlo Barrios
8aa0d035d8
test(math): added integer file to fix test (#15490) 2023-03-20 22:55:34 +00:00
Julien Robert
41c8529ff9
chore: bump cometbft to v0.37.0-rc3 (#15220) 2023-03-01 16:30:41 +01:00
Julien Robert
1273c05ada
test(math): fix FormatDec test (#15215) 2023-02-28 14:57:42 +00:00
dependabot[bot]
b1603227e5
build(deps): Bump github.com/stretchr/testify from 1.8.1 to 1.8.2 (#15172)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-02-27 19:49:52 +00:00
Marko
2b484a241f
feat: add rand funcs to math (#15043) 2023-02-18 18:39:46 +00:00
Julien Robert
88909d6f2b
fix(math): check for negative precision (#14922)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2023-02-06 17:55:10 +01:00
Marko
8cf814fb8c
refactor: moving value codecs to a single place (#14912) 2023-02-06 09:38:20 +01:00
Julien Robert
f719cd32ad
refactor: remove upgrade as dependency of the SDK (#14882) 2023-02-02 11:51:11 +00:00
dependabot[bot]
2c61d7896a
build(deps): Bump cosmossdk.io/core from 0.5.0 to 0.5.1 (#14811)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2023-01-27 16:37:30 +01:00
testinginprod
ed17f2d437
feat: add collections key encoders and value encoders for common types. (#14760)
Co-authored-by: testinginprod <testinginprod@somewhere.idk>
2023-01-27 11:10:54 +01:00
Julien Robert
d5d39c0538
fix: do not flatten events attributes by event types (#14691)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2023-01-19 19:42:46 +00:00
Julien Robert
538f7ce723
ci: make sonarcloud more quiet (#14585)
Co-authored-by: Marko <marbar3778@yahoo.com>
2023-01-12 10:24:56 +00:00
Denver
a10ada1ae1
test: Added test cases for precisionMultiplier (#14576)
Co-authored-by: Hyunwoo Lee <denver@Hyunwoos-MacBook-Pro-2.local>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2023-01-12 06:41:47 +00:00
Jacob Gadikian
1bb0629846
chore: iavl-v0.20-alpha1 and cosmos-db (#14411)
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
2022-12-28 21:42:00 +01:00
Emmanuel T Odeke
d301d15ed7
feat: math: add generics versions of Max, Min to cater to all numeric types (#14166) 2022-12-25 07:26:59 +00:00
Emmanuel T Odeke
d247e7a3b0
fix: math: add LegacyNewDecFromStr fuzzers + remove unnecessary error wrapping (#14252) 2022-12-11 09:02:51 +00:00
Emmanuel T Odeke
3e85182baa
perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010)
Optimizes and tests FormatInt by removing inefficient string
concatenation but also making it so much clearer with how one would
express adding thousand separators in natural language. It uses
a combination of strings.Builder whose values can be grown

The performance improvement is stark in every dimension:

```shell
$ benchstat before.txt after3.txt
name                          old time/op    new time/op    delta
DecimalValueRendererFormat-8    4.48µs ± 1%    2.11µs ± 2%  -52.90%  (p=0.000 n=10+10)

name                          old alloc/op   new alloc/op   delta
DecimalValueRendererFormat-8    3.62kB ± 0%    0.78kB ± 0%  -78.59%  (p=0.000 n=10+10)

name                          old allocs/op  new allocs/op  delta
DecimalValueRendererFormat-8      83.0 ± 0%      28.0 ± 0%  -66.27%  (p=0.000 n=10+10)
```

While here, also simplified zero padding for LegacyNewDecFromStr
simply by using strings.Repeat instead of a convoluted
fmt.Sprintf+strconv.Itoa.

Fixes #14008
Fixes #14003

Co-authored-by: Marko <marbar3778@yahoo.com>
2022-11-29 21:00:47 +00:00
Julien Robert
ae91105fec
ci: configure monorepo sonarcloud (#13944) 2022-11-23 10:47:18 +00:00
dependabot[bot]
d3010793ea
build(deps): Bump github.com/stretchr/testify from 1.8.0 to 1.8.1 in /tools/cosmovisor (#13637)
* build(deps): Bump github.com/stretchr/testify in /tools/cosmovisor

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* build(deps): Bump github.com/stretchr/testify from 1.8.0 to 1.8.1 in /tools/cosmovisor for all modules

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2022-10-24 20:33:20 +02:00
Amaury
10ac33edb8
refactor: Move FormatCoins to core (#13306)
* refactor: Move FormatCoins to `core`

* Rename to shorter names

* Add chaneglog

* Don't panic

* add comments

* go mod tidy

* fix changelog

* move structs to top

* Fix test

* go mod tidy

* Refactor tests
2022-10-19 11:21:24 +00:00
Julien Robert
9bae8a817f
build(deps): bump go minimum version to go 1.19 (#13397) 2022-09-27 21:02:02 +02:00
Julien Robert
55373cb614
feat: add uint IsNil method (#13381) 2022-09-25 09:19:50 +00:00
Julien Robert
6d0ef15b0a
refactor: migrate to cosmos/gogoproto (#13070) 2022-09-08 17:27:48 +00:00
Jacob Gadikian
0943a70215
chore: fix linting issues exposed by fixing golangci-lint (#12895)
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2022-08-11 22:00:24 +02:00
Emmanuel T Odeke
f002e54d26
perf: math: precompute & use square of precisionReuse instead of 2 repeated computations (#12794) 2022-08-02 10:00:08 -04:00
Jacob Gadikian
53347cd3f2
feat: go workspaces (#12675)
* go workspaces

* tidy

* catch all 11 modules

* go.mod no longer replaces modules in the sdk

* correct ics23 import

* indirect in indirect list

* fix cosmovisor
2022-07-26 21:35:31 +02:00
Amaury
eee23d9531
refactor: Move sdk.Dec to math package (#12634)
## Description





---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-07-20 15:13:45 +00:00
dependabot[bot]
4813098724
build(deps): Bump github.com/stretchr/testify in /math (#12514)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.0 to 1.8.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.0...v1.8.0)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2022-07-11 19:27:33 +02:00
Emmanuel T Odeke
b2af716bf7
math: derive marshalled byte length from copy, not blind assumptions (#12010)
The specification of "copy", the builtin function per
https://pkg.go.dev/builtin#copy, says that it returns the minimum of
len(src) and len(dst) when invoked as:

   copy(dst, src)

of which the prior code blindly assumed that everytime that
copy is invoked that the buffer provided had enough size
to accomodate the contents of *.MarshalTo but this isn't true
at all if len(data) is less than the values of .Marshal()
2022-05-23 12:08:11 +02:00
Emmanuel T Odeke
54d764b9a8
fix: math: fix Uint.Unmarshal's lack of negative value checking (#11996)
This change adds a negative value check to Uint.Unmarshal,
which coincidentally is fixed by refactoring for code reuse.
While here, added tests to ensure we don't regress.

Fixes #11995
2022-05-19 20:28:06 +00:00
Jacob Gadikian
55054282d2
chore: gofumpt (#11839)
* fumpt using main not master...

* be more descriptive

* fumpt

* fix nits

Co-authored-by: Julien Robert <julien@rbrt.fr>
2022-05-19 10:55:27 +02:00
Aleksandr Bezobchuk
51fd676950
chore: update module path for math module (#11821) 2022-04-29 10:02:55 -04:00
Aleksandr Bezobchuk
4f04beae34
refactor!: create math go sub module (#11788) 2022-04-28 14:05:21 -04:00