github.com/Finschia/finschia-sdk@v0.48.1/simapp/utils_test.go (about)

     1  package simapp
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  	"github.com/tendermint/tendermint/abci/types"
     9  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
    10  
    11  	"github.com/Finschia/finschia-sdk/codec"
    12  	"github.com/Finschia/finschia-sdk/std"
    13  	sdk "github.com/Finschia/finschia-sdk/types"
    14  	"github.com/Finschia/finschia-sdk/types/kv"
    15  	"github.com/Finschia/finschia-sdk/types/module"
    16  	authtypes "github.com/Finschia/finschia-sdk/x/auth/types"
    17  )
    18  
    19  func makeCodec(bm module.BasicManager) *codec.LegacyAmino {
    20  	cdc := codec.NewLegacyAmino()
    21  
    22  	bm.RegisterLegacyAminoCodec(cdc)
    23  	std.RegisterLegacyAminoCodec(cdc)
    24  
    25  	return cdc
    26  }
    27  
    28  func TestSetup(t *testing.T) {
    29  	app := Setup(false)
    30  	ctx := app.BaseApp.NewContext(false, tmproto.Header{})
    31  
    32  	app.InitChain(
    33  		types.RequestInitChain{
    34  			AppStateBytes: []byte("{}"),
    35  			ChainId:       "test-chain-id",
    36  		},
    37  	)
    38  
    39  	acc := app.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(authtypes.FeeCollectorName))
    40  	require.NotNil(t, acc)
    41  }
    42  
    43  func TestGetSimulationLog(t *testing.T) {
    44  	cdc := makeCodec(ModuleBasics)
    45  
    46  	decoders := make(sdk.StoreDecoderRegistry)
    47  	decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" }
    48  
    49  	tests := []struct {
    50  		store       string
    51  		kvPairs     []kv.Pair
    52  		expectedLog string
    53  	}{
    54  		{
    55  			"Empty",
    56  			[]kv.Pair{{}},
    57  			"",
    58  		},
    59  		{
    60  			authtypes.StoreKey,
    61  			[]kv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: cdc.MustMarshal(uint64(10))}},
    62  			"10",
    63  		},
    64  		{
    65  			"OtherStore",
    66  			[]kv.Pair{{Key: []byte("key"), Value: []byte("value")}},
    67  			fmt.Sprintf("store A %X => %X\nstore B %X => %X\n", []byte("key"), []byte("value"), []byte("key"), []byte("value")),
    68  		},
    69  	}
    70  
    71  	for _, tt := range tests {
    72  		tt := tt
    73  		t.Run(tt.store, func(t *testing.T) {
    74  			require.Equal(t, tt.expectedLog, GetSimulationLog(tt.store, decoders, tt.kvPairs, tt.kvPairs), tt.store)
    75  		})
    76  	}
    77  }