-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase x/oracle unit test coverage (#782)
* chore: increasce test coverage * rename variables Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> * moved test vars and const to test_utils * add comments to keys * fix string unit test * add changelog Co-authored-by: Adam Moser <63419657+toteki@users.noreply.github.com> Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com>
- Loading branch information
1 parent
8090261
commit 2343d70
Showing
4 changed files
with
258 additions
and
0 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,128 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/umee-network/umee/v2/x/oracle/types" | ||
) | ||
|
||
func TestDenomString(t *testing.T) { | ||
testCases := []struct { | ||
denom types.Denom | ||
expectedStr string | ||
}{ | ||
{ | ||
denom: types.DenomUmee, | ||
expectedStr: "base_denom: uumee\nsymbol_denom: umee\nexponent: 6\n", | ||
}, | ||
{ | ||
denom: types.DenomLuna, | ||
expectedStr: "base_denom: ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0\nsymbol_denom: LUNA\nexponent: 6\n", | ||
}, | ||
{ | ||
denom: types.DenomAtom, | ||
expectedStr: "base_denom: ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\nsymbol_denom: ATOM\nexponent: 6\n", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
require.Equal(t, testCase.expectedStr, testCase.denom.String()) | ||
} | ||
} | ||
|
||
func TestDenomEqual(t *testing.T) { | ||
testCases := []struct { | ||
denom types.Denom | ||
denomCompared types.Denom | ||
equal bool | ||
}{ | ||
{ | ||
denom: types.DenomUmee, | ||
denomCompared: types.DenomUmee, | ||
equal: true, | ||
}, | ||
{ | ||
denom: types.DenomUmee, | ||
denomCompared: types.DenomLuna, | ||
equal: false, | ||
}, | ||
{ | ||
denom: types.DenomLuna, | ||
denomCompared: types.DenomLuna, | ||
equal: true, | ||
}, | ||
{ | ||
denom: types.DenomAtom, | ||
denomCompared: types.DenomAtom, | ||
equal: true, | ||
}, | ||
{ | ||
denom: types.DenomAtom, | ||
denomCompared: types.DenomLuna, | ||
equal: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
require.Equal(t, testCase.equal, testCase.denom.Equal(&testCase.denomCompared)) | ||
} | ||
} | ||
|
||
func TestDenomListString(t *testing.T) { | ||
testCases := []struct { | ||
denomList types.DenomList | ||
expectedStr string | ||
}{ | ||
{ | ||
denomList: types.DenomList{types.DenomUmee}, | ||
expectedStr: "base_denom: uumee\nsymbol_denom: umee\nexponent: 6", | ||
}, | ||
{ | ||
denomList: types.DenomList{types.DenomAtom, types.DenomLuna}, | ||
expectedStr: "base_denom: ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\nsymbol_denom: ATOM\nexponent: 6\n\nbase_denom: ibc/0EF15DF2F02480ADE0BB6E85D9EBB5DAEA2836D3860E9F97F9AADE4F57A31AA0\nsymbol_denom: LUNA\nexponent: 6", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
require.Equal(t, testCase.expectedStr, testCase.denomList.String()) | ||
} | ||
} | ||
|
||
func TestDenomListContains(t *testing.T) { | ||
testCases := []struct { | ||
denomList types.DenomList | ||
denomSymbol string | ||
symbolInList bool | ||
}{ | ||
{ | ||
denomList: types.DenomList{types.DenomUmee}, | ||
denomSymbol: types.DenomUmee.SymbolDenom, | ||
symbolInList: true, | ||
}, | ||
{ | ||
denomList: types.DenomList{types.DenomUmee}, | ||
denomSymbol: types.DenomLuna.SymbolDenom, | ||
symbolInList: false, | ||
}, | ||
{ | ||
denomList: types.DenomList{types.DenomUmee, types.DenomAtom}, | ||
denomSymbol: types.DenomLuna.SymbolDenom, | ||
symbolInList: false, | ||
}, | ||
{ | ||
denomList: types.DenomList{types.DenomUmee, types.DenomAtom}, | ||
denomSymbol: types.DenomAtom.SymbolDenom, | ||
symbolInList: true, | ||
}, | ||
{ | ||
denomList: types.DenomList{types.DenomUmee, types.DenomAtom, types.DenomLuna}, | ||
denomSymbol: types.DenomLuna.SymbolDenom, | ||
symbolInList: true, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
require.Equal(t, testCase.symbolInList, testCase.denomList.Contains(testCase.denomSymbol)) | ||
} | ||
} |
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,108 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/umee-network/umee/v2/app" | ||
"github.com/umee-network/umee/v2/x/oracle/types" | ||
) | ||
|
||
func TestGetExchangeRateKey(t *testing.T) { | ||
testCases := []struct { | ||
denom string | ||
// KeyPrefixExchangeRate | []byte(denom) | 0 | ||
expectedKey []byte | ||
}{ | ||
{ | ||
denom: app.BondDenom, | ||
expectedKey: []byte{0x1, 0x75, 0x75, 0x6d, 0x65, 0x65, 0x0}, | ||
}, | ||
{ | ||
denom: types.IbcDenomLuna, | ||
expectedKey: []byte{0x1, 0x69, 0x62, 0x63, 0x2f, 0x30, 0x45, 0x46, 0x31, 0x35, 0x44, 0x46, 0x32, 0x46, 0x30, 0x32, 0x34, 0x38, 0x30, 0x41, 0x44, 0x45, 0x30, 0x42, 0x42, 0x36, 0x45, 0x38, 0x35, 0x44, 0x39, 0x45, 0x42, 0x42, 0x35, 0x44, 0x41, 0x45, 0x41, 0x32, 0x38, 0x33, 0x36, 0x44, 0x33, 0x38, 0x36, 0x30, 0x45, 0x39, 0x46, 0x39, 0x37, 0x46, 0x39, 0x41, 0x41, 0x44, 0x45, 0x34, 0x46, 0x35, 0x37, 0x41, 0x33, 0x31, 0x41, 0x41, 0x30, 0x0}, | ||
}, | ||
{ | ||
denom: types.IbcDenomAtom, | ||
expectedKey: []byte{0x1, 0x69, 0x62, 0x63, 0x2f, 0x32, 0x37, 0x33, 0x39, 0x34, 0x46, 0x42, 0x30, 0x39, 0x32, 0x44, 0x32, 0x45, 0x43, 0x43, 0x44, 0x35, 0x36, 0x31, 0x32, 0x33, 0x43, 0x37, 0x34, 0x46, 0x33, 0x36, 0x45, 0x34, 0x43, 0x31, 0x46, 0x39, 0x32, 0x36, 0x30, 0x30, 0x31, 0x43, 0x45, 0x41, 0x44, 0x41, 0x39, 0x43, 0x41, 0x39, 0x37, 0x45, 0x41, 0x36, 0x32, 0x32, 0x42, 0x32, 0x35, 0x46, 0x34, 0x31, 0x45, 0x35, 0x45, 0x42, 0x32, 0x0}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
actualKey := types.GetExchangeRateKey(testCase.denom) | ||
require.Equalf(t, testCase.expectedKey, actualKey, "test %d - expected key: %s should be the same as actual key: %s", i, testCase.expectedKey, actualKey) | ||
} | ||
} | ||
|
||
func TestGetFeederDelegationKey(t *testing.T) { | ||
testCases := []struct { | ||
val sdk.ValAddress | ||
// KeyPrefixFeederDelegation | lengthPrefixed(addr) | ||
expectedKey []byte | ||
}{ | ||
{ | ||
val: []byte("addr________________"), | ||
expectedKey: []byte{0x2, 0x14, 0x61, 0x64, 0x64, 0x72, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
actualKey := types.GetFeederDelegationKey(testCase.val) | ||
require.Equalf(t, testCase.expectedKey, actualKey, "test %d - expected key: %s should be the same as actual key: %s", i, testCase.expectedKey, actualKey) | ||
} | ||
} | ||
|
||
func TestGetMissCounterKey(t *testing.T) { | ||
testCases := []struct { | ||
val sdk.ValAddress | ||
// KeyPrefixMissCounter | lengthPrefixed(addr) | ||
expectedKey []byte | ||
}{ | ||
{ | ||
val: []byte("addr________________"), | ||
expectedKey: []byte{0x3, 0x14, 0x61, 0x64, 0x64, 0x72, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
actualKey := types.GetMissCounterKey(testCase.val) | ||
require.Equalf(t, testCase.expectedKey, actualKey, "test %d - expected key: %s should be the same as actual key: %s", i, testCase.expectedKey, actualKey) | ||
} | ||
} | ||
|
||
func TestGetAggregateExchangeRatePrevoteKey(t *testing.T) { | ||
testCases := []struct { | ||
val sdk.ValAddress | ||
// KeyPrefixAggregateExchangeRatePrevote | lengthPrefixed(addr) | ||
expectedKey []byte | ||
}{ | ||
{ | ||
val: []byte("addr________________"), | ||
expectedKey: []byte{0x4, 0x14, 0x61, 0x64, 0x64, 0x72, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
actualKey := types.GetAggregateExchangeRatePrevoteKey(testCase.val) | ||
require.Equalf(t, testCase.expectedKey, actualKey, "test %d - expected key: %s should be the same as actual key: %s", i, testCase.expectedKey, actualKey) | ||
} | ||
} | ||
|
||
func TestGetAggregateExchangeRateVoteKey(t *testing.T) { | ||
testCases := []struct { | ||
val sdk.ValAddress | ||
// KeyPrefixAggregateExchangeRateVote | lengthPrefixed(addr) | ||
expectedKey []byte | ||
}{ | ||
{ | ||
val: []byte("addr________________"), | ||
expectedKey: []byte{0x5, 0x14, 0x61, 0x64, 0x64, 0x72, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f}, | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
actualKey := types.GetAggregateExchangeRateVoteKey(testCase.val) | ||
require.Equalf(t, testCase.expectedKey, actualKey, "test %d - expected key: %s should be the same as actual key: %s", i, testCase.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