github.com/okex/exchain@v1.8.0/libs/ibc-go/modules/apps/transfer/simulation/decoder_test.go (about)

     1  package simulation_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/okex/exchain/libs/cosmos-sdk/types/kv"
    10  	"github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/simulation"
    11  	"github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/types"
    12  	"github.com/okex/exchain/libs/ibc-go/testing/simapp"
    13  	tmkv "github.com/okex/exchain/libs/tendermint/libs/kv"
    14  )
    15  
    16  func TestDecodeStore(t *testing.T) {
    17  	app := simapp.Setup(false)
    18  	dec := simulation.NewDecodeStore(app.TransferKeeper)
    19  
    20  	trace := types.DenomTrace{
    21  		BaseDenom: "uatom",
    22  		Path:      "transfer/channelToA",
    23  	}
    24  
    25  	kvPairs := kv.Pairs{
    26  		Pairs: []kv.Pair{
    27  			{
    28  				Key:   types.PortKey,
    29  				Value: []byte(types.PortID),
    30  			},
    31  			{
    32  				Key:   types.DenomTraceKey,
    33  				Value: app.TransferKeeper.MustMarshalDenomTrace(trace),
    34  			},
    35  			{
    36  				Key:   []byte{0x99},
    37  				Value: []byte{0x99},
    38  			},
    39  		},
    40  	}
    41  	tests := []struct {
    42  		name        string
    43  		expectedLog string
    44  	}{
    45  		{"PortID", fmt.Sprintf("Port A: %s\nPort B: %s", types.PortID, types.PortID)},
    46  		{"DenomTrace", fmt.Sprintf("DenomTrace A: %s\nDenomTrace B: %s", trace.IBCDenom(), trace.IBCDenom())},
    47  		{"other", ""},
    48  	}
    49  
    50  	for i, tt := range tests {
    51  		i, tt := i, tt
    52  		t.Run(tt.name, func(t *testing.T) {
    53  			if i == len(tests)-1 {
    54  				//require.Panics(t, func() { dec(nil, kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
    55  				kvA := tmkv.Pair{
    56  					Key:   kvPairs.Pairs[i].GetKey(),
    57  					Value: kvPairs.Pairs[i].GetValue(),
    58  				}
    59  				require.Panics(t, func() { dec(nil, kvA, kvA) }, tt.name)
    60  			} else {
    61  				kvA := tmkv.Pair{
    62  					Key:   kvPairs.Pairs[i].GetKey(),
    63  					Value: kvPairs.Pairs[i].GetValue(),
    64  				}
    65  				//require.Equal(t, tt.expectedLog, dec(nil, kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
    66  				require.Equal(t, tt.expectedLog, dec(nil, kvA, kvA), tt.name)
    67  			}
    68  		})
    69  	}
    70  }