-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(common): add docs for testutil and increase test coverage #1527
Merged
Merged
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
2ed7490
test(inflation): types coverage
Unique-Divine efac0d8
feat(wasm): no op handler + tests with updated shifter.wasm
Unique-Divine 773dee4
Merge branch 'master' into realu/test-inflation
Unique-Divine 2e7192a
linter
Unique-Divine b774c48
refactor: make it possible to use the encoding config without the app
Unique-Divine aa92edd
deps: remove usage of cosmossdk.io/depinject since it doesn't work ou…
Unique-Divine d263ffb
changelog
Unique-Divine 8a01ec1
small refactor for better var names
Unique-Divine 68c47ad
refactor: remove unused fn
Unique-Divine 2aa65ed
refactor(simapp): simapp fns are not used outside the simapp dir or t…
Unique-Divine 392d080
test(inflation): param set pairs
Unique-Divine e793851
test(inflation): test getters in params.go
Unique-Divine 062dbfc
Merge branch 'realu/test-inflation' into realu/test-inflation-2
Unique-Divine d526b2a
linter
Unique-Divine dc5559c
test(inflation): run the suite
Unique-Divine 7fb10e6
Squashed commit of the following:
Unique-Divine e4c1600
test(common): EnsureNibiruPrefix
Unique-Divine c19917b
test(sudo): remove unused fns and increase coverage
Unique-Divine bc33367
test(spot): wait another block for concurrency issue
Unique-Divine 743652a
test(spot): wait another block for concurrency issue
Unique-Divine 4e550a0
test(inflation): cover last few grpc queries
Unique-Divine 378ace5
Merge branch 'realu/test-inflation' into realu/test-sudo
Unique-Divine 7a47d59
ci: add concurrency statements to workflows
Unique-Divine 53d2d16
Merge branch 'realu/test-inflation' into realu/test-sudo
Unique-Divine 7780cc8
test(perp/cli): use the same server between runs for gen_market_test
Unique-Divine 253cb65
refactor: make registration aspect of the encoding config constructor…
Unique-Divine eaefe17
Merge branch 'master' into realu/test-inflation
Unique-Divine 2362461
(test.mk): add a test-coverage-integration command
Unique-Divine 85933c4
Merge branch 'realu/test-inflation' into realu/test-sudo
Unique-Divine c7d0d26
Merge branch 'realu/test-sudo' into realu/test-determinism
Unique-Divine 4327565
fix(ci): mistake in scheduling
Unique-Divine 1aa88ae
refactor(testutil): organise network files
Unique-Divine be071ea
Merge branch 'master' into realu/test-determinism
Unique-Divine 4e2c15b
refactor: DRY improvments for genesis cli tets
Unique-Divine 3bf66d6
test(common): document and test BankersRound
Unique-Divine 9659a54
fix(amm.go): small bug in ComputeSqrtDepth
Unique-Divine 182786c
docs(testutil/cli): documentation for the Network and Validator structs
Unique-Divine 35f04f5
Merge branch 'master' into realu/test-determinism
Unique-Divine bfb88d8
test(common): address utils test
Unique-Divine 9395e79
changelog + linter
Unique-Divine 0b5e87f
test(common): remove unused code + more tests
Unique-Divine 0a56cd2
simplify the 'with' functions
Unique-Divine d7ea816
fix finicky tests
Unique-Divine 582f274
Merge branch 'master' into realu/test-determinism
Unique-Divine cac831f
test(testutil): remove unused code + add tests
Unique-Divine 28191fe
test(testutil): more tests + better var names
Unique-Divine c313b59
refactor: ExecTx -> Network.ExecTxCmd
Unique-Divine b0022cd
Merge branch 'master' into realu/test-determinism
Unique-Divine 19a33bd
test,refactor: make getters to use in place of the 'PrintMnemonic' func
Unique-Divine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package common_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/NibiruChain/nibiru/x/common" | ||
"github.com/NibiruChain/nibiru/x/common/testutil" | ||
) | ||
|
||
func TestAddress(t *testing.T) { | ||
require.NotPanics(t, func() { | ||
_, addrs := testutil.PrivKeyAddressPairs(5) | ||
strs := common.AddrsToStrings(addrs...) | ||
addrsOut := common.StringsToAddrs(strs...) | ||
require.EqualValues(t, addrs, addrsOut) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the code more descriptive here and added tests for it. Since the |
||
const ( | ||
// number of decimal places | ||
Precision = 18 | ||
PrecisionExponent = 18 | ||
|
||
// bits required to represent the above precision | ||
// Ceiling[Log2[10^Precision - 1]] | ||
|
@@ -25,9 +25,11 @@ | |
) | ||
|
||
var ( | ||
precisionReuse = new(big.Int).Exp(big.NewInt(10), big.NewInt(Precision), nil) | ||
fivePrecision = new(big.Int).Quo(precisionReuse, big.NewInt(2)) | ||
oneInt = big.NewInt(1) | ||
// precisionInt: 10 ** PrecisionExponent | ||
precisionInt = new(big.Int).Exp(big.NewInt(10), big.NewInt(PrecisionExponent), nil) | ||
// halfPrecisionInt: (10 ** PrecisionExponent) / 2 | ||
halfPrecisionInt = new(big.Int).Quo(precisionInt, big.NewInt(2)) | ||
oneInt = big.NewInt(1) | ||
) | ||
|
||
// MustSqrtDec computes the square root of the input decimal using its | ||
|
@@ -119,8 +121,9 @@ | |
// |_____: / | $$$ | | ||
// |________| | ||
|
||
// Remove a Precision amount of rightmost digits and perform bankers rounding | ||
// on the remainder (gaussian rounding) on the digits which have been removed. | ||
// ChopPrecisionAndRound: Remove a Precision amount of rightmost digits and | ||
// perform bankers rounding on the remainder (gaussian rounding) on the digits | ||
// which have been removed. | ||
// | ||
// Mutates the input. Use the non-mutative version if that is undesired | ||
func ChopPrecisionAndRound(d *big.Int) *big.Int { | ||
|
@@ -133,20 +136,39 @@ | |
return d | ||
} | ||
|
||
// get the truncated quotient and remainder | ||
// Divide out the 'precisionInt', which truncates to a quotient and remainder. | ||
quo, rem := d, big.NewInt(0) | ||
quo, rem = quo.QuoRem(d, precisionReuse, rem) | ||
quo, rem = quo.QuoRem(d, precisionInt, rem) | ||
|
||
if rem.Sign() == 0 { // remainder is zero | ||
return BankersRound(quo, rem, halfPrecisionInt) | ||
} | ||
|
||
// BankersRound: Banker's rounding is a method commonly used in banking and | ||
// accounting to reduce roudning bias when processing large volumes of rounded | ||
// numbers. | ||
// | ||
// 1. If the remainder < half precision, round down | ||
// 2. If the remainder > half precision, round up | ||
// 3. If remainder == half precision, round to the nearest even number | ||
// | ||
// The name comes from the idea that it provides egalitarian rounding that | ||
// doesn't consistently favor one party over another (e.g. always rounding up). | ||
// With this method, rounding errors tend to cancel out rather than | ||
// accumulating in one direction. | ||
func BankersRound(quo, rem, halfPrecision *big.Int) *big.Int { | ||
// Zero remainder after dividing precision means => no rounding is needed. | ||
if rem.Sign() == 0 { | ||
return quo | ||
} | ||
|
||
switch rem.Cmp(fivePrecision) { | ||
// Nonzero remainder after dividing precision means => do banker's rounding | ||
switch rem.Cmp(halfPrecision) { | ||
case -1: | ||
return quo | ||
case 1: | ||
return quo.Add(quo, oneInt) | ||
default: // bankers rounding must take place | ||
default: | ||
// default case: bankers rounding must take place | ||
// always round to an even number | ||
if quo.Bit(0) == 0 { | ||
return quo | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Searched with the LSP and and found that this type alias was largely unused, so I removed some of the dead code.