github.com/Finschia/finschia-sdk@v0.49.1/x/fswap/keeper/keys_test.go (about)

     1  package keeper
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestSwapKey(t *testing.T) {
    10  	tests := []struct {
    11  		name        string
    12  		fromDenom   string
    13  		toDenom     string
    14  		expectedKey []byte
    15  	}{
    16  		{
    17  			name:        "swapKey",
    18  			fromDenom:   "cony",
    19  			toDenom:     "peb",
    20  			expectedKey: []byte{0x1, 0x4, 0x63, 0x6f, 0x6e, 0x79, 0x3, 0x70, 0x65, 0x62},
    21  			// expectedKey: append(swapPrefix, append(append([]byte{byte(len("cony"))}, []byte("cony")...), append([]byte{byte(len("peb"))}, []byte("peb")...)...)...),
    22  		},
    23  	}
    24  	for _, tc := range tests {
    25  		t.Run(tc.name, func(t *testing.T) {
    26  			actualKey := swapKey(tc.fromDenom, tc.toDenom)
    27  			require.Equal(t, tc.expectedKey, actualKey)
    28  		})
    29  	}
    30  }
    31  
    32  func TestSwappedKey(t *testing.T) {
    33  	tests := []struct {
    34  		name        string
    35  		fromDenom   string
    36  		toDenom     string
    37  		expectedKey []byte
    38  	}{
    39  		{
    40  			name:        "swappedKey",
    41  			fromDenom:   "cony",
    42  			toDenom:     "peb",
    43  			expectedKey: []byte{0x3, 0x4, 0x63, 0x6f, 0x6e, 0x79, 0x3, 0x70, 0x65, 0x62},
    44  			// expectedKey: append(swappedKeyPrefix, append(append([]byte{byte(len("cony"))}, []byte("cony")...), append([]byte{byte(len("peb"))}, []byte("peb")...)...)...),
    45  		},
    46  	}
    47  	for _, tc := range tests {
    48  		t.Run(tc.name, func(t *testing.T) {
    49  			actualKey := swappedKey(tc.fromDenom, tc.toDenom)
    50  			require.Equal(t, tc.expectedKey, actualKey)
    51  		})
    52  	}
    53  }