refactor(types)!: remove IntProto and DecProto (#16918)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Robert Zaremba
2023-07-12 22:16:28 +00:00
committed by GitHub
co-authored by Julien Robert
parent 74c351e2fd
commit bc4ccab74b
9 changed files with 747 additions and 2041 deletions
+10 -5
View File
@@ -4,6 +4,8 @@ import (
"bytes"
"fmt"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
@@ -16,12 +18,15 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.LastTotalPowerKey):
var powerA, powerB sdk.IntProto
cdc.MustUnmarshal(kvA.Value, &powerA)
cdc.MustUnmarshal(kvB.Value, &powerB)
var powerA, powerB math.Int
if err := powerA.Unmarshal(kvA.Value); err != nil {
panic(err)
}
if err := powerB.Unmarshal(kvB.Value); err != nil {
panic(err)
}
return fmt.Sprintf("%v\n%v", powerA, powerB)
case bytes.Equal(kvA.Key[:1], types.ValidatorsKey):
var validatorA, validatorB types.Validator
+3 -1
View File
@@ -33,10 +33,12 @@ func TestDecodeStore(t *testing.T) {
del := types.NewDelegation(delAddr1, valAddr1, math.LegacyOneDec())
ubd := types.NewUnbondingDelegation(delAddr1, valAddr1, 15, bondTime, math.OneInt(), 1)
red := types.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, math.OneInt(), math.LegacyOneDec(), 0)
oneIntBz, err := math.OneInt().Marshal()
require.NoError(t, err)
kvPairs := kv.Pairs{
Pairs: []kv.Pair{
{Key: types.LastTotalPowerKey, Value: cdc.MustMarshal(&sdk.IntProto{Int: math.OneInt()})},
{Key: types.LastTotalPowerKey, Value: oneIntBz},
{Key: types.GetValidatorKey(valAddr1), Value: cdc.MustMarshal(&val)},
{Key: types.LastValidatorPowerKey, Value: valAddr1.Bytes()},
{Key: types.GetDelegationKey(delAddr1, valAddr1), Value: cdc.MustMarshal(&del)},