github.com/Finschia/finschia-sdk@v0.48.1/x/evidence/simulation/decoder_test.go (about)

     1  package simulation_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/Finschia/finschia-sdk/crypto/keys/ed25519"
    11  	"github.com/Finschia/finschia-sdk/simapp"
    12  	sdk "github.com/Finschia/finschia-sdk/types"
    13  	"github.com/Finschia/finschia-sdk/types/kv"
    14  	"github.com/Finschia/finschia-sdk/x/evidence/simulation"
    15  	"github.com/Finschia/finschia-sdk/x/evidence/types"
    16  )
    17  
    18  func TestDecodeStore(t *testing.T) {
    19  	app := simapp.Setup(false)
    20  	dec := simulation.NewDecodeStore(app.EvidenceKeeper)
    21  
    22  	delPk1 := ed25519.GenPrivKey().PubKey()
    23  
    24  	ev := &types.Equivocation{
    25  		Height:           10,
    26  		Time:             time.Now().UTC(),
    27  		Power:            1000,
    28  		ConsensusAddress: sdk.ConsAddress(delPk1.Address()).String(),
    29  	}
    30  
    31  	evBz, err := app.EvidenceKeeper.MarshalEvidence(ev)
    32  	require.NoError(t, err)
    33  
    34  	kvPairs := kv.Pairs{
    35  		Pairs: []kv.Pair{
    36  			{
    37  				Key:   types.KeyPrefixEvidence,
    38  				Value: evBz,
    39  			},
    40  			{
    41  				Key:   []byte{0x99},
    42  				Value: []byte{0x99},
    43  			},
    44  		},
    45  	}
    46  	tests := []struct {
    47  		name        string
    48  		expectedLog string
    49  	}{
    50  		{"Evidence", fmt.Sprintf("%v\n%v", ev, ev)},
    51  		{"other", ""},
    52  	}
    53  
    54  	for i, tt := range tests {
    55  		i, tt := i, tt
    56  		t.Run(tt.name, func(t *testing.T) {
    57  			switch i {
    58  			case len(tests) - 1:
    59  				require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
    60  			default:
    61  				require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
    62  			}
    63  		})
    64  	}
    65  }