github.com/okex/exchain@v1.8.0/libs/ibc-go/modules/core/03-connection/simulation/decoder_test.go (about)

     1  package simulation_test
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/okex/exchain/libs/cosmos-sdk/types/kv"
     6  	tmkv "github.com/okex/exchain/libs/tendermint/libs/kv"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	// "github.com/cosmos/cosmos-sdk/types/kv"
    12  	"github.com/okex/exchain/libs/ibc-go/modules/core/03-connection/simulation"
    13  	"github.com/okex/exchain/libs/ibc-go/modules/core/03-connection/types"
    14  	host "github.com/okex/exchain/libs/ibc-go/modules/core/24-host"
    15  	"github.com/okex/exchain/libs/ibc-go/testing/simapp"
    16  )
    17  
    18  func TestDecodeStore(t *testing.T) {
    19  	app := simapp.Setup(false)
    20  	cdc := app.AppCodec()
    21  
    22  	connectionID := "connectionidone"
    23  
    24  	connection := types.ConnectionEnd{
    25  		ClientId: "clientidone",
    26  		Versions: types.ExportedVersionsToProto(types.GetCompatibleVersions()),
    27  	}
    28  
    29  	paths := types.ClientPaths{
    30  		Paths: []string{connectionID},
    31  	}
    32  
    33  	kvPairs := kv.Pairs{
    34  		Pairs: []kv.Pair{
    35  			{
    36  				Key: host.ClientConnectionsKey(connection.ClientId),
    37  				//Value: cdc.MustMarshal(&paths),
    38  				Value: cdc.GetProtocMarshal().MustMarshalBinaryBare(&paths),
    39  			},
    40  			{
    41  				Key: host.ConnectionKey(connectionID),
    42  				//Value: cdc.MustMarshal(&connection),
    43  				Value: cdc.GetProtocMarshal().MustMarshalBinaryBare(&connection),
    44  			},
    45  			{
    46  				Key:   []byte{0x99},
    47  				Value: []byte{0x99},
    48  			},
    49  		},
    50  	}
    51  	tests := []struct {
    52  		name        string
    53  		expectedLog string
    54  	}{
    55  		{"ClientPaths", fmt.Sprintf("ClientPaths A: %v\nClientPaths B: %v", paths, paths)},
    56  		{"ConnectionEnd", fmt.Sprintf("ConnectionEnd A: %v\nConnectionEnd B: %v", connection, connection)},
    57  		{"other", ""},
    58  	}
    59  
    60  	for i, tt := range tests {
    61  		i, tt := i, tt
    62  		t.Run(tt.name, func(t *testing.T) {
    63  			// 	res, found := simulation.NewDecodeStore(cdc, kvPairs.Pairs[i], kvPairs.Pairs[i])
    64  			kvA := tmkv.Pair{
    65  				Key:   kvPairs.Pairs[i].GetKey(),
    66  				Value: kvPairs.Pairs[i].GetValue(),
    67  			}
    68  			res, found := simulation.NewDecodeStore(cdc, kvA, kvA)
    69  			if i == len(tests)-1 {
    70  				require.False(t, found, string(kvPairs.Pairs[i].Key))
    71  				require.Empty(t, res, string(kvPairs.Pairs[i].Key))
    72  			} else {
    73  				require.True(t, found, string(kvPairs.Pairs[i].Key))
    74  				require.Equal(t, tt.expectedLog, res, string(kvPairs.Pairs[i].Key))
    75  			}
    76  		})
    77  	}
    78  }