github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/mint/simulation/decoder_test.go (about)

     1  package simulation
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv"
    10  
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    12  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    13  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/internal/types"
    14  )
    15  
    16  func makeTestCodec() (cdc *codec.Codec) {
    17  	cdc = codec.New()
    18  	sdk.RegisterCodec(cdc)
    19  	return
    20  }
    21  
    22  func TestDecodeStore(t *testing.T) {
    23  	cdc := makeTestCodec()
    24  	minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15))
    25  
    26  	kvPairs := tmkv.Pairs{
    27  		tmkv.Pair{Key: types.MinterKey, Value: cdc.MustMarshalBinaryLengthPrefixed(minter)},
    28  		tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}},
    29  	}
    30  	tests := []struct {
    31  		name        string
    32  		expectedLog string
    33  	}{
    34  		{"Minter", fmt.Sprintf("%v\n%v", minter, minter)},
    35  		{"other", ""},
    36  	}
    37  
    38  	for i, tt := range tests {
    39  		i, tt := i, tt
    40  		t.Run(tt.name, func(t *testing.T) {
    41  			switch i {
    42  			case len(tests) - 1:
    43  				require.Panics(t, func() { DecodeStore(cdc, kvPairs[i], kvPairs[i]) }, tt.name)
    44  			default:
    45  				require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name)
    46  			}
    47  		})
    48  	}
    49  }