-
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 (#1365)
* fix: update swap keys for possibly overlapped keys * chore: lint fix * chore: update changelog * chore: use address.LengthPrefix to check length * Revert "chore: use address.LengthPrefix to check length" This reverts commit b33165b. * chore: add denom validation for string type denom
- Loading branch information
1 parent
5e2cd7f
commit e31eb43
Showing
6 changed files
with
104 additions
and
15 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
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) | ||
}) | ||
} | ||
} |
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