Skip to content

Commit

Permalink
Updated test files
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Aug 15, 2023
1 parent f302367 commit 2cef0ca
Show file tree
Hide file tree
Showing 19 changed files with 751 additions and 661 deletions.
13 changes: 7 additions & 6 deletions types/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
TestDenomEmpty = ""
TestDenomInvalid = "i"
TestDenomOne = "one"
TestDenomTwo = "two"

TestIntEmpty = sdk.Int{}
TestIntNegative = sdk.NewInt(-1000)
Expand All @@ -45,10 +46,10 @@ var (

TestCoinsNil sdk.Coins = nil
TestCoinsEmpty = sdk.Coins{}
TestCoinsEmptyDenom = sdk.Coins{sdk.Coin{Denom: TestDenomEmpty, Amount: TestIntPositive}}
TestCoinsInvalidDenom = sdk.Coins{sdk.Coin{Denom: TestDenomInvalid, Amount: TestIntPositive}}
TestCoinsEmptyAmount = sdk.Coins{sdk.Coin{Denom: TestDenomOne, Amount: TestIntEmpty}}
TestCoinsNegativeAmount = sdk.Coins{sdk.Coin{Denom: TestDenomOne, Amount: TestIntNegative}}
TestCoinsZeroAmount = sdk.Coins{sdk.Coin{Denom: TestDenomOne, Amount: TestIntZero}}
TestCoinsPositiveAmount = sdk.Coins{sdk.Coin{Denom: TestDenomOne, Amount: TestIntPositive}}
TestCoinsEmptyDenom = sdk.Coins{TestCoinEmptyDenom}
TestCoinsInvalidDenom = sdk.Coins{TestCoinInvalidDenom}
TestCoinsEmptyAmount = sdk.Coins{TestCoinEmptyAmount}
TestCoinsNegativeAmount = sdk.Coins{TestCoinNegativeAmount}
TestCoinsZeroAmount = sdk.Coins{TestCoinZeroAmount}
TestCoinsPositiveAmount = sdk.Coins{TestCoinPositiveAmount}
)
26 changes: 13 additions & 13 deletions x/deposit/types/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestDeposit_GetAddress(t *testing.T) {
{
"empty",
fields{
Address: "",
Address: hubtypes.TestAddrEmpty,
},
nil,
},
Expand Down Expand Up @@ -58,14 +58,14 @@ func TestDeposit_Validate(t *testing.T) {
{
"empty address",
fields{
Address: "",
Address: hubtypes.TestAddrEmpty,
},
true,
},
{
"invalid address",
fields{
Address: "sent",
Address: hubtypes.TestAddrInvalid,
},
true,
},
Expand All @@ -80,23 +80,23 @@ func TestDeposit_Validate(t *testing.T) {
"10 bytes address",
fields{
Address: hubtypes.TestBech32AccAddr10Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}},
Coins: hubtypes.TestCoinsPositiveAmount,
},
false,
},
{
"20 bytes address",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}},
Coins: hubtypes.TestCoinsPositiveAmount,
},
false,
},
{
"30 bytes address",
fields{
Address: hubtypes.TestBech32AccAddr30Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}},
Coins: hubtypes.TestCoinsPositiveAmount,
},
false,
},
Expand All @@ -112,55 +112,55 @@ func TestDeposit_Validate(t *testing.T) {
"empty coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{},
Coins: hubtypes.TestCoinsEmpty,
},
true,
},
{
"empty denom coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: ""}},
Coins: hubtypes.TestCoinsEmptyDenom,
},
true,
},
{
"invalid denom coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "o"}},
Coins: hubtypes.TestCoinsInvalidDenom,
},
true,
},
{
"nil amount coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}},
Coins: hubtypes.TestCoinsEmptyAmount,
},
true,
},
{
"negative amount coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}},
Coins: hubtypes.TestCoinsNegativeAmount,
},
true,
},
{
"zero amount coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}},
Coins: hubtypes.TestCoinsZeroAmount,
},
true,
},
{
"positive amount coins",
fields{
Address: hubtypes.TestBech32AccAddr20Bytes,
Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}},
Coins: hubtypes.TestCoinsPositiveAmount,
},
false,
},
Expand Down
10 changes: 4 additions & 6 deletions x/node/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"crypto/rand"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
Expand Down Expand Up @@ -47,7 +46,7 @@ func TestAddressFromNodeForInactiveAtKey(t *testing.T) {
addr = make([]byte, i)
_, _ = rand.Read(addr)

key = NodeForInactiveAtKey(time.Now(), addr)
key = NodeForInactiveAtKey(hubtypes.TestTimeNow, addr)
require.Equal(
t,
hubtypes.NodeAddress(addr),
Expand Down Expand Up @@ -102,7 +101,6 @@ func TestInactiveNodeKey(t *testing.T) {

func TestNodeForInactiveAtKey(t *testing.T) {
var (
at = time.Now()
addr []byte
)

Expand All @@ -113,15 +111,15 @@ func TestNodeForInactiveAtKey(t *testing.T) {
if i < 256 {
require.Equal(
t,
append(append(NodeForInactiveAtKeyPrefix, sdk.FormatTimeBytes(at)...), address.MustLengthPrefix(addr)...),
NodeForInactiveAtKey(at, addr),
append(append(NodeForInactiveAtKeyPrefix, sdk.FormatTimeBytes(hubtypes.TestTimeNow)...), address.MustLengthPrefix(addr)...),
NodeForInactiveAtKey(hubtypes.TestTimeNow, addr),
)

continue
}

require.Panics(t, func() {
NodeForInactiveAtKey(at, addr)
NodeForInactiveAtKey(hubtypes.TestTimeNow, addr)
})
}
}
Expand Down
Loading

0 comments on commit 2cef0ca

Please sign in to comment.