cosmos-sdk/x/bank/simulation/decoder.go
Federico Kunze 0234ad324e
ibc-transfer: sims updates (#7123)
* ibc-transfer: sims updates

* params and genesis

* sim tests

* update module.go

* remove dontcover

* Update x/ibc-transfer/simulation/decoder.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
2020-08-21 04:52:46 -04:00

40 lines
966 B
Go

package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
// SupplyUnmarshaler defines the expected encoding store functions.
type SupplyUnmarshaler interface {
UnmarshalSupply([]byte) (exported.SupplyI, error)
}
// NewDecodeStore returns a function closure that unmarshals the KVPair's values
// to the corresponding types.
func NewDecodeStore(cdc SupplyUnmarshaler) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.SupplyKey):
supplyA, err := cdc.UnmarshalSupply(kvA.Value)
if err != nil {
panic(err)
}
supplyB, err := cdc.UnmarshalSupply(kvB.Value)
if err != nil {
panic(err)
}
return fmt.Sprintf("%v\n%v", supplyA, supplyB)
default:
panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
}
}
}