-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow 4 decimal places in slashing rateparamter (#491)
closed: babylonlabs-io/pm#182 Changes: - allow slashing rate to have 4 decimal places - add parameter validation to check whether minimal slashing output is not dust under BTC standard rules
- Loading branch information
1 parent
6659e30
commit 8b7ce11
Showing
10 changed files
with
215 additions
and
13 deletions.
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
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
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,75 @@ | ||
package btcstaking_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"github.com/babylonlabs-io/babylon/btcstaking" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsSlashingRateValid(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
rate sdkmath.LegacyDec | ||
expected bool | ||
}{ | ||
{ | ||
name: "valid rate - 0.5", | ||
rate: sdkmath.LegacyNewDecWithPrec(5, 1), // 0.5 | ||
expected: true, | ||
}, | ||
{ | ||
name: "valid rate - 0.25", | ||
rate: sdkmath.LegacyNewDecWithPrec(25, 2), // 0.25 | ||
expected: true, | ||
}, | ||
{ | ||
name: "valid rate - 0.255", | ||
rate: sdkmath.LegacyNewDecWithPrec(255, 3), // 0.255 | ||
expected: true, | ||
}, | ||
{ | ||
name: "valid rate - 0.2555", | ||
rate: sdkmath.LegacyNewDecWithPrec(2555, 4), // 0.2555 | ||
expected: true, | ||
}, | ||
{ | ||
name: "valid rate - 0.99", | ||
rate: sdkmath.LegacyNewDecWithPrec(99, 2), // 0.99 | ||
expected: true, | ||
}, | ||
{ | ||
name: "invalid rate - 0", | ||
rate: sdkmath.LegacyZeroDec(), | ||
expected: false, | ||
}, | ||
{ | ||
name: "invalid rate - 1", | ||
rate: sdkmath.LegacyOneDec(), | ||
expected: false, | ||
}, | ||
{ | ||
name: "invalid rate - negative", | ||
rate: sdkmath.LegacyNewDecWithPrec(-5, 1), // -0.5 | ||
expected: false, | ||
}, | ||
{ | ||
name: "invalid rate - too many decimal places", | ||
rate: sdkmath.LegacyNewDecWithPrec(25555, 5), // 0.25555 | ||
expected: false, | ||
}, | ||
{ | ||
name: "invalid rate - greater than 1", | ||
rate: sdkmath.LegacyNewDecWithPrec(15, 1), // 1.5 | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := btcstaking.IsSlashingRateValid(tc.rate) | ||
require.Equal(t, tc.expected, result) | ||
}) | ||
} | ||
} |
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
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