Make coins denoms case insensitive (#3092)
This commit is contained in:
parent
eac7d6939d
commit
500fa2b694
|
@ -12,6 +12,7 @@ BREAKING CHANGES
|
|||
* Gaia
|
||||
|
||||
* SDK
|
||||
* [\#3064](https://github.com/cosmos/cosmos-sdk/issues/3064) Sanitize `sdk.Coin` denom. Coins denoms are now case insensitive, i.e. 100fooToken equals to 100FOOTOKEN.
|
||||
|
||||
* Tendermint
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm
|
|||
func NewDefaultGenesisAccount(addr sdk.AccAddress) GenesisAccount {
|
||||
accAuth := auth.NewBaseAccountWithAddress(addr)
|
||||
coins := sdk.Coins{
|
||||
sdk.NewCoin("fooToken", sdk.NewInt(1000)),
|
||||
sdk.NewCoin("footoken", sdk.NewInt(1000)),
|
||||
sdk.NewCoin(bondDenom, freeFermionsAcc),
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,6 @@ func TestGaiaGenesisValidation(t *testing.T) {
|
|||
func TestNewDefaultGenesisAccount(t *testing.T) {
|
||||
addr := secp256k1.GenPrivKeySecp256k1([]byte("")).PubKey().Address()
|
||||
acc := NewDefaultGenesisAccount(sdk.AccAddress(addr))
|
||||
require.Equal(t, sdk.NewInt(1000), acc.Coins.AmountOf("fooToken"))
|
||||
require.Equal(t, sdk.NewInt(1000), acc.Coins.AmountOf("footoken"))
|
||||
require.Equal(t, sdk.NewInt(150), acc.Coins.AmountOf(bondDenom))
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestGaiaCLIMinimumFees(t *testing.T) {
|
|||
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", gaiacliHome, servAddr, chainID)
|
||||
|
||||
// start gaiad server with minimum fees
|
||||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("gaiad start --home=%s --rpc.laddr=%v --p2p.laddr=%v --minimum_fees=2feeToken", gaiadHome, servAddr, p2pAddr))
|
||||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("gaiad start --home=%s --rpc.laddr=%v --p2p.laddr=%v --minimum_fees=2feetoken", gaiadHome, servAddr, p2pAddr))
|
||||
|
||||
defer proc.Stop(false)
|
||||
tests.WaitForTMStart(port)
|
||||
|
@ -64,7 +64,7 @@ func TestGaiaCLIFeesDeduction(t *testing.T) {
|
|||
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", gaiacliHome, servAddr, chainID)
|
||||
|
||||
// start gaiad server with minimum fees
|
||||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("gaiad start --home=%s --rpc.laddr=%v --p2p.laddr=%v --minimum_fees=1fooToken", gaiadHome, servAddr, p2pAddr))
|
||||
proc := tests.GoExecuteTWithStdout(t, fmt.Sprintf("gaiad start --home=%s --rpc.laddr=%v --p2p.laddr=%v --minimum_fees=1footoken", gaiadHome, servAddr, p2pAddr))
|
||||
|
||||
defer proc.Stop(false)
|
||||
tests.WaitForTMStart(port)
|
||||
|
@ -74,29 +74,29 @@ func TestGaiaCLIFeesDeduction(t *testing.T) {
|
|||
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --home=%s", gaiacliHome))
|
||||
|
||||
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||
require.Equal(t, int64(1000), fooAcc.GetCoins().AmountOf("fooToken").Int64())
|
||||
require.Equal(t, int64(1000), fooAcc.GetCoins().AmountOf("footoken").Int64())
|
||||
|
||||
// test simulation
|
||||
success := executeWrite(t, fmt.Sprintf(
|
||||
"gaiacli tx send %v --amount=1000fooToken --to=%s --from=foo --fee=1fooToken --dry-run", flags, barAddr), app.DefaultKeyPass)
|
||||
"gaiacli tx send %v --amount=1000footoken --to=%s --from=foo --fee=1footoken --dry-run", flags, barAddr), app.DefaultKeyPass)
|
||||
require.True(t, success)
|
||||
tests.WaitForNextNBlocksTM(1, port)
|
||||
// ensure state didn't change
|
||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||
require.Equal(t, int64(1000), fooAcc.GetCoins().AmountOf("fooToken").Int64())
|
||||
require.Equal(t, int64(1000), fooAcc.GetCoins().AmountOf("footoken").Int64())
|
||||
|
||||
// insufficient funds (coins + fees)
|
||||
success = executeWrite(t, fmt.Sprintf(
|
||||
"gaiacli tx send %v --amount=1000fooToken --to=%s --from=foo --fee=1fooToken", flags, barAddr), app.DefaultKeyPass)
|
||||
"gaiacli tx send %v --amount=1000footoken --to=%s --from=foo --fee=1footoken", flags, barAddr), app.DefaultKeyPass)
|
||||
require.False(t, success)
|
||||
tests.WaitForNextNBlocksTM(1, port)
|
||||
// ensure state didn't change
|
||||
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
|
||||
require.Equal(t, int64(1000), fooAcc.GetCoins().AmountOf("fooToken").Int64())
|
||||
require.Equal(t, int64(1000), fooAcc.GetCoins().AmountOf("footoken").Int64())
|
||||
|
||||
// test success (transfer = coins + fees)
|
||||
success = executeWrite(t, fmt.Sprintf(
|
||||
"gaiacli tx send %v --fee=300fooToken --amount=500fooToken --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
||||
"gaiacli tx send %v --fee=300footoken --amount=500footoken --to=%s --from=foo", flags, barAddr), app.DefaultKeyPass)
|
||||
require.True(t, success)
|
||||
cleanupDirs(gaiadHome, gaiacliHome)
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ func TestGaiadCollectGentxs(t *testing.T) {
|
|||
_ = executeInit(t, fmt.Sprintf("gaiad init -o --moniker=foo --home=%s", gaiadHome))
|
||||
// Add account to genesis.json
|
||||
executeWriteCheckErr(t, fmt.Sprintf(
|
||||
"gaiad add-genesis-account %s 150%s,1000fooToken --home=%s", fooAddr, stakeTypes.DefaultBondDenom, gaiadHome))
|
||||
"gaiad add-genesis-account %s 150%s,1000footoken --home=%s", fooAddr, stakeTypes.DefaultBondDenom, gaiadHome))
|
||||
executeWrite(t, fmt.Sprintf("cat %s%sconfig%sgenesis.json", gaiadHome, string(os.PathSeparator), string(os.PathSeparator)))
|
||||
// Write gentx file
|
||||
executeWriteCheckErr(t, fmt.Sprintf(
|
||||
|
@ -732,7 +732,7 @@ func initializeFixtures(t *testing.T) (chainID, servAddr, port, gaiadHome, gaiac
|
|||
chainID = executeInit(t, fmt.Sprintf("gaiad init -o --moniker=foo --home=%s", gaiadHome))
|
||||
|
||||
executeWriteCheckErr(t, fmt.Sprintf(
|
||||
"gaiad add-genesis-account %s 150%s,1000fooToken --home=%s", fooAddr, stakeTypes.DefaultBondDenom, gaiadHome))
|
||||
"gaiad add-genesis-account %s 150%s,1000footoken --home=%s", fooAddr, stakeTypes.DefaultBondDenom, gaiadHome))
|
||||
executeWrite(t, fmt.Sprintf("cat %s%sconfig%sgenesis.json", gaiadHome, string(os.PathSeparator), string(os.PathSeparator)))
|
||||
executeWriteCheckErr(t, fmt.Sprintf(
|
||||
"gaiad gentx --name=foo --home=%s --home-client=%s", gaiadHome, gaiacliHome), app.DefaultKeyPass)
|
||||
|
|
|
@ -180,7 +180,7 @@ func initTestnet(config *cfg.Config, cdc *codec.Codec) error {
|
|||
accs = append(accs, app.GenesisAccount{
|
||||
Address: addr,
|
||||
Coins: sdk.Coins{
|
||||
sdk.NewInt64Coin(fmt.Sprintf("%sToken", nodeDirName), 1000),
|
||||
sdk.NewInt64Coin(fmt.Sprintf("%stoken", nodeDirName), 1000),
|
||||
sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 150),
|
||||
},
|
||||
})
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestEncoding(t *testing.T) {
|
|||
sendMsg := MsgSend{
|
||||
From: addr1,
|
||||
To: addr2,
|
||||
Amount: sdk.Coins{sdk.NewCoin("testCoins", sdk.NewInt(100))},
|
||||
Amount: sdk.Coins{sdk.NewCoin("testcoins", sdk.NewInt(100))},
|
||||
}
|
||||
|
||||
// Construct transaction
|
||||
|
@ -55,7 +55,7 @@ func TestEncoding(t *testing.T) {
|
|||
issueMsg := MsgIssue{
|
||||
Issuer: addr1,
|
||||
Receiver: addr2,
|
||||
Coin: sdk.Coin{"testCoin", sdk.NewInt(100)},
|
||||
Coin: sdk.NewCoin("testcoin", sdk.NewInt(100)),
|
||||
}
|
||||
|
||||
signBytes = issueMsg.GetSignBytes()
|
||||
|
|
|
@ -33,8 +33,8 @@ gaiacli keys add validator
|
|||
|
||||
# Add that key into the genesis.app_state.accounts array in the genesis file
|
||||
# NOTE: this command lets you set the number of coins. Make sure this account has some coins
|
||||
# with the genesis.app_state.stake.params.bond_denom denom, the default is STAKE
|
||||
gaiad add-genesis-account $(gaiacli keys show validator -a) 1000STAKE,1000validatorToken
|
||||
# with the genesis.app_state.stake.params.bond_denom denom, the default is stake
|
||||
gaiad add-genesis-account $(gaiacli keys show validator -a) 1000stake,1000validatortoken
|
||||
|
||||
# Generate the transaction that creates your validator
|
||||
gaiad gentx --name validator
|
||||
|
|
|
@ -30,6 +30,9 @@ func NewCoin(denom string, amount Int) Coin {
|
|||
if amount.LT(ZeroInt()) {
|
||||
panic(fmt.Sprintf("negative coin amount: %v\n", amount))
|
||||
}
|
||||
if strings.ToLower(denom) != denom {
|
||||
panic(fmt.Sprintf("denom cannot contain upper case characters: %s\n", denom))
|
||||
}
|
||||
|
||||
return Coin{
|
||||
Denom: denom,
|
||||
|
@ -132,7 +135,8 @@ func (coins Coins) String() string {
|
|||
return out[:len(out)-1]
|
||||
}
|
||||
|
||||
// IsValid asserts the Coins are sorted and have positive amounts.
|
||||
// IsValid asserts the Coins are sorted, have positive amount,
|
||||
// and Denom does not contain upper case characters.
|
||||
func (coins Coins) IsValid() bool {
|
||||
switch len(coins) {
|
||||
case 0:
|
||||
|
@ -143,6 +147,9 @@ func (coins Coins) IsValid() bool {
|
|||
lowDenom := coins[0].Denom
|
||||
|
||||
for _, coin := range coins[1:] {
|
||||
if strings.ToLower(coin.Denom) != coin.Denom {
|
||||
return false
|
||||
}
|
||||
if coin.Denom <= lowDenom {
|
||||
return false
|
||||
}
|
||||
|
@ -320,6 +327,9 @@ func (coins Coins) Empty() bool {
|
|||
|
||||
// Returns the amount of a denom from coins
|
||||
func (coins Coins) AmountOf(denom string) Int {
|
||||
if strings.ToLower(denom) != denom {
|
||||
panic(fmt.Sprintf("denom cannot contain upper case characters: %s\n", denom))
|
||||
}
|
||||
switch len(coins) {
|
||||
case 0:
|
||||
return ZeroInt()
|
||||
|
@ -457,7 +467,11 @@ func ParseCoin(coinStr string) (coin Coin, err error) {
|
|||
return Coin{}, fmt.Errorf("failed to parse coin amount: %s", amountStr)
|
||||
}
|
||||
|
||||
return Coin{denomStr, amount}, nil
|
||||
if denomStr != strings.ToLower(denomStr) {
|
||||
return Coin{}, fmt.Errorf("denom cannot contain upper case characters: %s", denomStr)
|
||||
}
|
||||
|
||||
return NewCoin(denomStr, amount), nil
|
||||
}
|
||||
|
||||
// ParseCoins will parse out a list of coins separated by commas.
|
||||
|
|
|
@ -11,10 +11,12 @@ import (
|
|||
// Coin tests
|
||||
|
||||
func TestCoin(t *testing.T) {
|
||||
require.Panics(t, func() { NewInt64Coin("A", -1) })
|
||||
require.Panics(t, func() { NewCoin("A", NewInt(-1)) })
|
||||
require.Equal(t, NewInt(5), NewInt64Coin("A", 5).Amount)
|
||||
require.Equal(t, NewInt(5), NewCoin("A", NewInt(5)).Amount)
|
||||
require.Panics(t, func() { NewInt64Coin("a", -1) })
|
||||
require.Panics(t, func() { NewCoin("a", NewInt(-1)) })
|
||||
require.Panics(t, func() { NewInt64Coin("Atom", 10) })
|
||||
require.Panics(t, func() { NewCoin("Atom", NewInt(10)) })
|
||||
require.Equal(t, NewInt(5), NewInt64Coin("a", 5).Amount)
|
||||
require.Equal(t, NewInt(5), NewCoin("a", NewInt(5)).Amount)
|
||||
}
|
||||
|
||||
func TestSameDenomAsCoin(t *testing.T) {
|
||||
|
@ -23,8 +25,7 @@ func TestSameDenomAsCoin(t *testing.T) {
|
|||
inputTwo Coin
|
||||
expected bool
|
||||
}{
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("a", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 1), true},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
||||
{NewInt64Coin("steak", 1), NewInt64Coin("steak", 10), true},
|
||||
}
|
||||
|
@ -41,8 +42,7 @@ func TestIsEqualCoin(t *testing.T) {
|
|||
inputTwo Coin
|
||||
expected bool
|
||||
}{
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("a", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 1), true},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
||||
{NewInt64Coin("steak", 1), NewInt64Coin("steak", 10), false},
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ func TestPlusCoin(t *testing.T) {
|
|||
expected Coin
|
||||
shouldPanic bool
|
||||
}{
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), NewInt64Coin("A", 2), false},
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 0), NewInt64Coin("A", 1), false},
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("B", 1), NewInt64Coin("A", 1), true},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 1), NewInt64Coin("a", 2), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 0), NewInt64Coin("a", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), NewInt64Coin("a", 1), true},
|
||||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
|
@ -82,11 +82,11 @@ func TestMinusCoin(t *testing.T) {
|
|||
expected Coin
|
||||
shouldPanic bool
|
||||
}{
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("B", 1), NewInt64Coin("A", 1), true},
|
||||
{NewInt64Coin("A", 10), NewInt64Coin("A", 1), NewInt64Coin("A", 9), false},
|
||||
{NewInt64Coin("A", 5), NewInt64Coin("A", 3), NewInt64Coin("A", 2), false},
|
||||
{NewInt64Coin("A", 5), NewInt64Coin("A", 0), NewInt64Coin("A", 5), false},
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 5), Coin{}, true},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), NewInt64Coin("a", 1), true},
|
||||
{NewInt64Coin("a", 10), NewInt64Coin("a", 1), NewInt64Coin("a", 9), false},
|
||||
{NewInt64Coin("a", 5), NewInt64Coin("a", 3), NewInt64Coin("a", 2), false},
|
||||
{NewInt64Coin("a", 5), NewInt64Coin("a", 0), NewInt64Coin("a", 5), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 5), Coin{}, true},
|
||||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
|
@ -102,7 +102,7 @@ func TestMinusCoin(t *testing.T) {
|
|||
inputOne Coin
|
||||
inputTwo Coin
|
||||
expected int64
|
||||
}{NewInt64Coin("A", 1), NewInt64Coin("A", 1), 0}
|
||||
}{NewInt64Coin("a", 1), NewInt64Coin("a", 1), 0}
|
||||
res := tc.inputOne.Minus(tc.inputTwo)
|
||||
require.Equal(t, tc.expected, res.Amount.Int64())
|
||||
}
|
||||
|
@ -113,9 +113,9 @@ func TestIsGTECoin(t *testing.T) {
|
|||
inputTwo Coin
|
||||
expected bool
|
||||
}{
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), true},
|
||||
{NewInt64Coin("A", 2), NewInt64Coin("A", 1), true},
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("B", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 1), true},
|
||||
{NewInt64Coin("a", 2), NewInt64Coin("a", 1), true},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
||||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
|
@ -130,8 +130,8 @@ func TestIsLTCoin(t *testing.T) {
|
|||
inputTwo Coin
|
||||
expected bool
|
||||
}{
|
||||
{NewInt64Coin("A", 1), NewInt64Coin("A", 1), false},
|
||||
{NewInt64Coin("A", 2), NewInt64Coin("A", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 1), false},
|
||||
{NewInt64Coin("a", 2), NewInt64Coin("a", 1), false},
|
||||
{NewInt64Coin("a", 0), NewInt64Coin("b", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("b", 1), false},
|
||||
{NewInt64Coin("a", 1), NewInt64Coin("a", 1), false},
|
||||
|
@ -145,11 +145,11 @@ func TestIsLTCoin(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCoinIsZero(t *testing.T) {
|
||||
coin := NewInt64Coin("A", 0)
|
||||
coin := NewInt64Coin("a", 0)
|
||||
res := coin.IsZero()
|
||||
require.True(t, res)
|
||||
|
||||
coin = NewInt64Coin("A", 1)
|
||||
coin = NewInt64Coin("a", 1)
|
||||
res = coin.IsZero()
|
||||
require.False(t, res)
|
||||
}
|
||||
|
@ -163,10 +163,10 @@ func TestIsZeroCoins(t *testing.T) {
|
|||
expected bool
|
||||
}{
|
||||
{Coins{}, true},
|
||||
{Coins{NewInt64Coin("A", 0)}, true},
|
||||
{Coins{NewInt64Coin("A", 0), NewInt64Coin("B", 0)}, true},
|
||||
{Coins{NewInt64Coin("A", 1)}, false},
|
||||
{Coins{NewInt64Coin("A", 0), NewInt64Coin("B", 1)}, false},
|
||||
{Coins{NewInt64Coin("a", 0)}, true},
|
||||
{Coins{NewInt64Coin("a", 0), NewInt64Coin("b", 0)}, true},
|
||||
{Coins{NewInt64Coin("a", 1)}, false},
|
||||
{Coins{NewInt64Coin("a", 0), NewInt64Coin("b", 1)}, false},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -182,12 +182,12 @@ func TestEqualCoins(t *testing.T) {
|
|||
expected bool
|
||||
}{
|
||||
{Coins{}, Coins{}, true},
|
||||
{Coins{NewInt64Coin("A", 0)}, Coins{NewInt64Coin("A", 0)}, true},
|
||||
{Coins{NewInt64Coin("A", 0), NewInt64Coin("B", 1)}, Coins{NewInt64Coin("A", 0), NewInt64Coin("B", 1)}, true},
|
||||
{Coins{NewInt64Coin("A", 0)}, Coins{NewInt64Coin("B", 0)}, false},
|
||||
{Coins{NewInt64Coin("A", 0)}, Coins{NewInt64Coin("A", 1)}, false},
|
||||
{Coins{NewInt64Coin("A", 0)}, Coins{NewInt64Coin("A", 0), NewInt64Coin("B", 1)}, false},
|
||||
{Coins{NewInt64Coin("A", 0), NewInt64Coin("B", 1)}, Coins{NewInt64Coin("B", 1), NewInt64Coin("A", 0)}, true},
|
||||
{Coins{NewInt64Coin("a", 0)}, Coins{NewInt64Coin("a", 0)}, true},
|
||||
{Coins{NewInt64Coin("a", 0), NewInt64Coin("b", 1)}, Coins{NewInt64Coin("a", 0), NewInt64Coin("b", 1)}, true},
|
||||
{Coins{NewInt64Coin("a", 0)}, Coins{NewInt64Coin("b", 0)}, false},
|
||||
{Coins{NewInt64Coin("a", 0)}, Coins{NewInt64Coin("a", 1)}, false},
|
||||
{Coins{NewInt64Coin("a", 0)}, Coins{NewInt64Coin("a", 0), NewInt64Coin("b", 1)}, false},
|
||||
{Coins{NewInt64Coin("a", 0), NewInt64Coin("b", 1)}, Coins{NewInt64Coin("b", 1), NewInt64Coin("a", 0)}, true},
|
||||
}
|
||||
|
||||
for tcnum, tc := range cases {
|
||||
|
@ -206,11 +206,11 @@ func TestPlusCoins(t *testing.T) {
|
|||
inputTwo Coins
|
||||
expected Coins
|
||||
}{
|
||||
{Coins{{"A", one}, {"B", one}}, Coins{{"A", one}, {"B", one}}, Coins{{"A", two}, {"B", two}}},
|
||||
{Coins{{"A", zero}, {"B", one}}, Coins{{"A", zero}, {"B", zero}}, Coins{{"B", one}}},
|
||||
{Coins{{"A", two}}, Coins{{"B", zero}}, Coins{{"A", two}}},
|
||||
{Coins{{"A", one}}, Coins{{"A", one}, {"B", two}}, Coins{{"A", two}, {"B", two}}},
|
||||
{Coins{{"A", zero}, {"B", zero}}, Coins{{"A", zero}, {"B", zero}}, Coins(nil)},
|
||||
{Coins{{"a", one}, {"b", one}}, Coins{{"a", one}, {"b", one}}, Coins{{"a", two}, {"b", two}}},
|
||||
{Coins{{"a", zero}, {"b", one}}, Coins{{"a", zero}, {"b", zero}}, Coins{{"b", one}}},
|
||||
{Coins{{"a", two}}, Coins{{"b", zero}}, Coins{{"a", two}}},
|
||||
{Coins{{"a", one}}, Coins{{"a", one}, {"b", two}}, Coins{{"a", two}, {"b", two}}},
|
||||
{Coins{{"a", zero}, {"b", zero}}, Coins{{"a", zero}, {"b", zero}}, Coins(nil)},
|
||||
}
|
||||
|
||||
for tcIndex, tc := range cases {
|
||||
|
@ -231,11 +231,11 @@ func TestMinusCoins(t *testing.T) {
|
|||
expected Coins
|
||||
shouldPanic bool
|
||||
}{
|
||||
{Coins{{"A", two}}, Coins{{"A", one}, {"B", two}}, Coins{{"A", one}, {"B", two}}, true},
|
||||
{Coins{{"A", two}}, Coins{{"B", zero}}, Coins{{"A", two}}, false},
|
||||
{Coins{{"A", one}}, Coins{{"B", zero}}, Coins{{"A", one}}, false},
|
||||
{Coins{{"A", one}, {"B", one}}, Coins{{"A", one}}, Coins{{"B", one}}, false},
|
||||
{Coins{{"A", one}, {"B", one}}, Coins{{"A", two}}, Coins{}, true},
|
||||
{Coins{{"a", two}}, Coins{{"a", one}, {"b", two}}, Coins{{"a", one}, {"b", two}}, true},
|
||||
{Coins{{"a", two}}, Coins{{"b", zero}}, Coins{{"a", two}}, false},
|
||||
{Coins{{"a", one}}, Coins{{"b", zero}}, Coins{{"a", one}}, false},
|
||||
{Coins{{"a", one}, {"b", one}}, Coins{{"a", one}}, Coins{{"b", one}}, false},
|
||||
{Coins{{"a", one}, {"b", one}}, Coins{{"a", two}}, Coins{}, true},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
|
@ -251,38 +251,44 @@ func TestMinusCoins(t *testing.T) {
|
|||
|
||||
func TestCoins(t *testing.T) {
|
||||
good := Coins{
|
||||
{"GAS", NewInt(1)},
|
||||
{"MINERAL", NewInt(1)},
|
||||
{"gas", NewInt(1)},
|
||||
{"mineral", NewInt(1)},
|
||||
{"tree", NewInt(1)},
|
||||
}
|
||||
mixedCase := Coins{
|
||||
{"gAs", NewInt(1)},
|
||||
{"MineraL", NewInt(1)},
|
||||
{"TREE", NewInt(1)},
|
||||
}
|
||||
empty := Coins{
|
||||
{"GOLD", NewInt(0)},
|
||||
{"gold", NewInt(0)},
|
||||
}
|
||||
null := Coins{}
|
||||
badSort1 := Coins{
|
||||
{"TREE", NewInt(1)},
|
||||
{"GAS", NewInt(1)},
|
||||
{"MINERAL", NewInt(1)},
|
||||
{"tree", NewInt(1)},
|
||||
{"gas", NewInt(1)},
|
||||
{"mineral", NewInt(1)},
|
||||
}
|
||||
|
||||
// both are after the first one, but the second and third are in the wrong order
|
||||
badSort2 := Coins{
|
||||
{"GAS", NewInt(1)},
|
||||
{"TREE", NewInt(1)},
|
||||
{"MINERAL", NewInt(1)},
|
||||
{"gas", NewInt(1)},
|
||||
{"tree", NewInt(1)},
|
||||
{"mineral", NewInt(1)},
|
||||
}
|
||||
badAmt := Coins{
|
||||
{"GAS", NewInt(1)},
|
||||
{"TREE", NewInt(0)},
|
||||
{"MINERAL", NewInt(1)},
|
||||
{"gas", NewInt(1)},
|
||||
{"tree", NewInt(0)},
|
||||
{"mineral", NewInt(1)},
|
||||
}
|
||||
dup := Coins{
|
||||
{"GAS", NewInt(1)},
|
||||
{"GAS", NewInt(1)},
|
||||
{"MINERAL", NewInt(1)},
|
||||
{"gas", NewInt(1)},
|
||||
{"gas", NewInt(1)},
|
||||
{"mineral", NewInt(1)},
|
||||
}
|
||||
|
||||
assert.True(t, good.IsValid(), "Coins are valid")
|
||||
assert.False(t, mixedCase.IsValid(), "Coins denoms contain upper case characters")
|
||||
assert.True(t, good.IsPositive(), "Expected coins to be positive: %v", good)
|
||||
assert.False(t, null.IsPositive(), "Expected coins to not be positive: %v", null)
|
||||
assert.True(t, good.IsAllGTE(empty), "Expected %v to be >= %v", good, empty)
|
||||
|
@ -299,11 +305,11 @@ func TestCoinsGT(t *testing.T) {
|
|||
two := NewInt(2)
|
||||
|
||||
assert.False(t, Coins{}.IsAllGT(Coins{}))
|
||||
assert.True(t, Coins{{"A", one}}.IsAllGT(Coins{}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllGT(Coins{{"A", one}}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllGT(Coins{{"B", one}}))
|
||||
assert.True(t, Coins{{"A", one}, {"B", one}}.IsAllGT(Coins{{"B", one}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllGT(Coins{{"B", two}}))
|
||||
assert.True(t, Coins{{"a", one}}.IsAllGT(Coins{}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllGT(Coins{{"a", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllGT(Coins{{"b", one}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", one}}.IsAllGT(Coins{{"b", one}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllGT(Coins{{"b", two}}))
|
||||
}
|
||||
|
||||
func TestCoinsGTE(t *testing.T) {
|
||||
|
@ -311,11 +317,11 @@ func TestCoinsGTE(t *testing.T) {
|
|||
two := NewInt(2)
|
||||
|
||||
assert.True(t, Coins{}.IsAllGTE(Coins{}))
|
||||
assert.True(t, Coins{{"A", one}}.IsAllGTE(Coins{}))
|
||||
assert.True(t, Coins{{"A", one}}.IsAllGTE(Coins{{"A", one}}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllGTE(Coins{{"B", one}}))
|
||||
assert.True(t, Coins{{"A", one}, {"B", one}}.IsAllGTE(Coins{{"B", one}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllGTE(Coins{{"B", two}}))
|
||||
assert.True(t, Coins{{"a", one}}.IsAllGTE(Coins{}))
|
||||
assert.True(t, Coins{{"a", one}}.IsAllGTE(Coins{{"a", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllGTE(Coins{{"b", one}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", one}}.IsAllGTE(Coins{{"b", one}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllGTE(Coins{{"b", two}}))
|
||||
}
|
||||
|
||||
func TestCoinsLT(t *testing.T) {
|
||||
|
@ -323,14 +329,14 @@ func TestCoinsLT(t *testing.T) {
|
|||
two := NewInt(2)
|
||||
|
||||
assert.False(t, Coins{}.IsAllLT(Coins{}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllLT(Coins{}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllLT(Coins{{"A", one}}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllLT(Coins{{"B", one}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllLT(Coins{{"B", one}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllLT(Coins{{"B", two}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllLT(Coins{{"A", one}, {"B", one}}))
|
||||
assert.True(t, Coins{{"A", one}, {"B", one}}.IsAllLT(Coins{{"A", one}, {"B", two}}))
|
||||
assert.True(t, Coins{}.IsAllLT(Coins{{"A", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllLT(Coins{}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllLT(Coins{{"a", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllLT(Coins{{"b", one}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllLT(Coins{{"b", one}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllLT(Coins{{"b", two}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllLT(Coins{{"a", one}, {"b", one}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", one}}.IsAllLT(Coins{{"a", one}, {"b", two}}))
|
||||
assert.True(t, Coins{}.IsAllLT(Coins{{"a", one}}))
|
||||
}
|
||||
|
||||
func TestCoinsLTE(t *testing.T) {
|
||||
|
@ -338,14 +344,14 @@ func TestCoinsLTE(t *testing.T) {
|
|||
two := NewInt(2)
|
||||
|
||||
assert.True(t, Coins{}.IsAllLTE(Coins{}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllLTE(Coins{}))
|
||||
assert.True(t, Coins{{"A", one}}.IsAllLTE(Coins{{"A", one}}))
|
||||
assert.False(t, Coins{{"A", one}}.IsAllLTE(Coins{{"B", one}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllLTE(Coins{{"B", one}}))
|
||||
assert.False(t, Coins{{"A", one}, {"B", one}}.IsAllLTE(Coins{{"B", two}}))
|
||||
assert.True(t, Coins{{"A", one}, {"B", one}}.IsAllLTE(Coins{{"A", one}, {"B", one}}))
|
||||
assert.True(t, Coins{{"A", one}, {"B", one}}.IsAllLTE(Coins{{"A", one}, {"B", two}}))
|
||||
assert.True(t, Coins{}.IsAllLTE(Coins{{"A", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllLTE(Coins{}))
|
||||
assert.True(t, Coins{{"a", one}}.IsAllLTE(Coins{{"a", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAllLTE(Coins{{"b", one}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllLTE(Coins{{"b", one}}))
|
||||
assert.False(t, Coins{{"a", one}, {"b", one}}.IsAllLTE(Coins{{"b", two}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", one}}.IsAllLTE(Coins{{"a", one}, {"b", one}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", one}}.IsAllLTE(Coins{{"a", one}, {"b", two}}))
|
||||
assert.True(t, Coins{}.IsAllLTE(Coins{{"a", one}}))
|
||||
}
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
|
@ -382,32 +388,32 @@ func TestParse(t *testing.T) {
|
|||
|
||||
func TestSortCoins(t *testing.T) {
|
||||
good := Coins{
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("TREE", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("mineral", 1),
|
||||
NewInt64Coin("tree", 1),
|
||||
}
|
||||
empty := Coins{
|
||||
NewInt64Coin("GOLD", 0),
|
||||
NewInt64Coin("gold", 0),
|
||||
}
|
||||
badSort1 := Coins{
|
||||
NewInt64Coin("TREE", 1),
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("tree", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("mineral", 1),
|
||||
}
|
||||
badSort2 := Coins{ // both are after the first one, but the second and third are in the wrong order
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("TREE", 1),
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("tree", 1),
|
||||
NewInt64Coin("mineral", 1),
|
||||
}
|
||||
badAmt := Coins{
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("TREE", 0),
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("tree", 0),
|
||||
NewInt64Coin("mineral", 1),
|
||||
}
|
||||
dup := Coins{
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("mineral", 1),
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
|
@ -438,16 +444,16 @@ func TestAmountOf(t *testing.T) {
|
|||
NewInt64Coin(" ", 0),
|
||||
}
|
||||
case3 := Coins{
|
||||
NewInt64Coin("GOLD", 0),
|
||||
NewInt64Coin("gold", 0),
|
||||
}
|
||||
case4 := Coins{
|
||||
NewInt64Coin("GAS", 1),
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("TREE", 1),
|
||||
NewInt64Coin("gas", 1),
|
||||
NewInt64Coin("mineral", 1),
|
||||
NewInt64Coin("tree", 1),
|
||||
}
|
||||
case5 := Coins{
|
||||
NewInt64Coin("MINERAL", 1),
|
||||
NewInt64Coin("TREE", 1),
|
||||
NewInt64Coin("mineral", 1),
|
||||
NewInt64Coin("tree", 1),
|
||||
}
|
||||
case6 := Coins{
|
||||
NewInt64Coin("", 6),
|
||||
|
@ -456,7 +462,7 @@ func TestAmountOf(t *testing.T) {
|
|||
NewInt64Coin(" ", 7),
|
||||
}
|
||||
case8 := Coins{
|
||||
NewInt64Coin("GAS", 8),
|
||||
NewInt64Coin("gas", 8),
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
|
@ -481,8 +487,10 @@ func TestAmountOf(t *testing.T) {
|
|||
for _, tc := range cases {
|
||||
assert.Equal(t, NewInt(tc.amountOf), tc.coins.AmountOf(""))
|
||||
assert.Equal(t, NewInt(tc.amountOfSpace), tc.coins.AmountOf(" "))
|
||||
assert.Equal(t, NewInt(tc.amountOfGAS), tc.coins.AmountOf("GAS"))
|
||||
assert.Equal(t, NewInt(tc.amountOfMINERAL), tc.coins.AmountOf("MINERAL"))
|
||||
assert.Equal(t, NewInt(tc.amountOfTREE), tc.coins.AmountOf("TREE"))
|
||||
assert.Equal(t, NewInt(tc.amountOfGAS), tc.coins.AmountOf("gas"))
|
||||
assert.Equal(t, NewInt(tc.amountOfMINERAL), tc.coins.AmountOf("mineral"))
|
||||
assert.Equal(t, NewInt(tc.amountOfTREE), tc.coins.AmountOf("tree"))
|
||||
}
|
||||
|
||||
assert.Panics(t, func() { cases[0].coins.AmountOf("Invalid") })
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ func TestContextWithCustom(t *testing.T) {
|
|||
logger := NewMockLogger()
|
||||
voteinfos := []abci.VoteInfo{{}}
|
||||
meter := types.NewGasMeter(10000)
|
||||
minFees := types.Coins{types.NewInt64Coin("feeCoin", 1)}
|
||||
minFees := types.Coins{types.NewInt64Coin("feetoken", 1)}
|
||||
|
||||
ctx = types.NewContext(nil, header, ischeck, logger)
|
||||
require.Equal(t, header, ctx.BlockHeader())
|
||||
|
@ -182,5 +182,5 @@ func TestContextWithCustom(t *testing.T) {
|
|||
require.Equal(t, logger, ctx.Logger())
|
||||
require.Equal(t, voteinfos, ctx.VoteInfos())
|
||||
require.Equal(t, meter, ctx.GasMeter())
|
||||
require.Equal(t, minFees, types.Coins{types.NewInt64Coin("feeCoin", 1)})
|
||||
require.Equal(t, minFees, types.Coins{types.NewInt64Coin("feetoken", 1)})
|
||||
}
|
||||
|
|
|
@ -709,7 +709,7 @@ func TestAdjustFeesByGas(t *testing.T) {
|
|||
want sdk.Coins
|
||||
}{
|
||||
{"nil coins", args{sdk.Coins{}, 100000}, sdk.Coins{}},
|
||||
{"nil coins", args{sdk.Coins{sdk.NewInt64Coin("A", 10), sdk.NewInt64Coin("B", 0)}, 100000}, sdk.Coins{sdk.NewInt64Coin("A", 20), sdk.NewInt64Coin("B", 10)}},
|
||||
{"nil coins", args{sdk.Coins{sdk.NewInt64Coin("a", 10), sdk.NewInt64Coin("b", 0)}, 100000}, sdk.Coins{sdk.NewInt64Coin("a", 20), sdk.NewInt64Coin("b", 10)}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -179,7 +179,7 @@ func GetCmdDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||
Long: strings.TrimSpace(`
|
||||
Submit a deposit for an acive proposal. You can find the proposal-id by running gaiacli query gov proposals:
|
||||
|
||||
$ gaiacli tx gov deposit 1 10STAKE --from mykey
|
||||
$ gaiacli tx gov deposit 1 10stake --from mykey
|
||||
`),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
type CodeType = sdk.CodeType
|
||||
|
||||
const (
|
||||
DefaultCodespace sdk.CodespaceType = "STAKE"
|
||||
DefaultCodespace sdk.CodespaceType = "stake"
|
||||
|
||||
CodeInvalidValidator CodeType = 101
|
||||
CodeInvalidDelegation CodeType = 102
|
||||
|
|
|
@ -21,7 +21,7 @@ const (
|
|||
ValidatorUpdateDelay int64 = 1
|
||||
|
||||
// Default bondable coin denomination
|
||||
DefaultBondDenom = "STAKE"
|
||||
DefaultBondDenom = "stake"
|
||||
)
|
||||
|
||||
// nolint - Keys for parameter access
|
||||
|
|
Loading…
Reference in New Issue