-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFreeze(t *testing.T) { | ||
_, pub1, addr1 := KeyTestPubAddr() | ||
|
||
// Not enough starting coins to move | ||
account1 := NewCustomAccount(addr1, nil, nil, pub1, 1, 2) | ||
err := account1.FreezeCoins(NewTestCoins("abc", 1)) | ||
require.NotNil(t, err) | ||
err = account1.FreezeCoins(NewTestCoins("abc", 0)) | ||
require.NotNil(t, err) | ||
|
||
// Not enough coins chosen | ||
coinSymbol := "ab1" | ||
coins := NewTestCoins(coinSymbol, 100) | ||
frozenCoins := NewTestCoins(coinSymbol, 0) | ||
account2 := NewCustomAccount(addr1, coins, frozenCoins, pub1, 1, 2) | ||
|
||
err = account2.FreezeCoins(NewTestCoins(coinSymbol, 0)) | ||
require.NotNil(t, err) | ||
|
||
// Too many coins to freeze | ||
err = account2.FreezeCoins(NewTestCoins(coinSymbol, 101)) | ||
require.NotNil(t, err) | ||
|
||
// Can freeze | ||
err = account2.FreezeCoins(NewTestCoins(coinSymbol, 1)) | ||
require.Nil(t, err) | ||
require.Equal(t, true, types.NewInt(99).Equal(account2.Coins.AmountOf(coinSymbol))) | ||
require.Equal(t, true, types.NewInt(1).Equal(account2.FrozenCoins.AmountOf(coinSymbol))) | ||
} |
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,23 @@ | ||
// nolint noalias | ||
package types | ||
|
||
import ( | ||
"github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// coins to more than cover the fee | ||
func NewTestCoins(symbol string, amount int64) sdk.Coins { | ||
return sdk.Coins{ | ||
sdk.NewInt64Coin(symbol, amount), | ||
} | ||
} | ||
|
||
func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { | ||
key := secp256k1.GenPrivKey() | ||
pub := key.PubKey() | ||
addr := sdk.AccAddress(pub.Address()) | ||
return key, pub, addr | ||
} |