-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update swap keys for possibly overlapped keys
- Loading branch information
1 parent
5e2cd7f
commit 8ea4861
Showing
2 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSwapKey(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fromDenom string | ||
toDenom string | ||
expectedKey []byte | ||
}{ | ||
{ | ||
name: "swapKey", | ||
fromDenom: "cony", | ||
toDenom: "peb", | ||
expectedKey: []byte{0x1, 0x4, 0x63, 0x6f, 0x6e, 0x79, 0x3, 0x70, 0x65, 0x62}, | ||
//expectedKey: append(swapPrefix, append(append([]byte{byte(len("cony"))}, []byte("cony")...), append([]byte{byte(len("peb"))}, []byte("peb")...)...)...), | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actualKey := swapKey(tc.fromDenom, tc.toDenom) | ||
require.Equal(t, tc.expectedKey, actualKey) | ||
}) | ||
} | ||
} | ||
|
||
func TestSwappedKey(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fromDenom string | ||
toDenom string | ||
expectedKey []byte | ||
}{ | ||
{ | ||
name: "swappedKey", | ||
fromDenom: "cony", | ||
toDenom: "peb", | ||
expectedKey: []byte{0x3, 0x4, 0x63, 0x6f, 0x6e, 0x79, 0x3, 0x70, 0x65, 0x62}, | ||
//expectedKey: append(swappedKeyPrefix, append(append([]byte{byte(len("cony"))}, []byte("cony")...), append([]byte{byte(len("peb"))}, []byte("peb")...)...)...), | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actualKey := swappedKey(tc.fromDenom, tc.toDenom) | ||
require.Equal(t, tc.expectedKey, actualKey) | ||
}) | ||
} | ||
} |