diff --git a/types/test_utils.go b/types/test_utils.go index 56e563ce..21ec0703 100644 --- a/types/test_utils.go +++ b/types/test_utils.go @@ -29,6 +29,7 @@ var ( TestDenomEmpty = "" TestDenomInvalid = "i" TestDenomOne = "one" + TestDenomTwo = "two" TestIntEmpty = sdk.Int{} TestIntNegative = sdk.NewInt(-1000) @@ -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} ) diff --git a/x/deposit/types/deposit_test.go b/x/deposit/types/deposit_test.go index 48c3c75d..8a57bb36 100644 --- a/x/deposit/types/deposit_test.go +++ b/x/deposit/types/deposit_test.go @@ -21,7 +21,7 @@ func TestDeposit_GetAddress(t *testing.T) { { "empty", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, nil, }, @@ -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, }, @@ -80,7 +80,7 @@ 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, }, @@ -88,7 +88,7 @@ func TestDeposit_Validate(t *testing.T) { "20 bytes address", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Coins: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -96,7 +96,7 @@ func TestDeposit_Validate(t *testing.T) { "30 bytes address", fields{ Address: hubtypes.TestBech32AccAddr30Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Coins: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -112,7 +112,7 @@ func TestDeposit_Validate(t *testing.T) { "empty coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{}, + Coins: hubtypes.TestCoinsEmpty, }, true, }, @@ -120,7 +120,7 @@ func TestDeposit_Validate(t *testing.T) { "empty denom coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: ""}}, + Coins: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -128,7 +128,7 @@ func TestDeposit_Validate(t *testing.T) { "invalid denom coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "o"}}, + Coins: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -136,7 +136,7 @@ func TestDeposit_Validate(t *testing.T) { "nil amount coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + Coins: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -144,7 +144,7 @@ func TestDeposit_Validate(t *testing.T) { "negative amount coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + Coins: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -152,7 +152,7 @@ func TestDeposit_Validate(t *testing.T) { "zero amount coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + Coins: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -160,7 +160,7 @@ func TestDeposit_Validate(t *testing.T) { "positive amount coins", fields{ Address: hubtypes.TestBech32AccAddr20Bytes, - Coins: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Coins: hubtypes.TestCoinsPositiveAmount, }, false, }, diff --git a/x/node/types/keys_test.go b/x/node/types/keys_test.go index 5f2042e8..2fda626d 100644 --- a/x/node/types/keys_test.go +++ b/x/node/types/keys_test.go @@ -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" @@ -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), @@ -102,7 +101,6 @@ func TestInactiveNodeKey(t *testing.T) { func TestNodeForInactiveAtKey(t *testing.T) { var ( - at = time.Now() addr []byte ) @@ -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) }) } } diff --git a/x/node/types/msg_test.go b/x/node/types/msg_test.go index 834c0031..63eafeb8 100644 --- a/x/node/types/msg_test.go +++ b/x/node/types/msg_test.go @@ -24,14 +24,14 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -46,8 +46,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "from 10 bytes", fields{ From: hubtypes.TestBech32AccAddr10Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -56,8 +56,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "from 20 bytes", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -66,8 +66,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "from 30 bytes", fields{ From: hubtypes.TestBech32AccAddr30Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -76,17 +76,15 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices nil", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, - RemoteURL: "https://remote.url:443", + GigabytePrices: hubtypes.TestCoinsNil, }, - false, + true, }, { "gigabyte_prices empty", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsEmpty, }, true, }, @@ -94,7 +92,7 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices empty denom", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: ""}}, + GigabytePrices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -102,7 +100,7 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices invalid denom", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "o"}}, + GigabytePrices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -110,7 +108,7 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices empty amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + GigabytePrices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -118,7 +116,7 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices negative amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + GigabytePrices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -126,7 +124,7 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices zero amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + GigabytePrices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -134,8 +132,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "gigabyte_prices positive amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -144,18 +142,18 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices nil", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, HourlyPrices: nil, RemoteURL: "https://remote.url:443", }, - false, + true, }, { "hourly_prices empty", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsEmpty, }, true, }, @@ -163,8 +161,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices empty denom", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: ""}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -172,8 +170,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices invalid denom", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "o"}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -181,8 +179,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices empty amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -190,8 +188,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices negative amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -199,8 +197,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices zero amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -208,8 +206,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "hourly_prices positive amount", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -218,8 +216,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "remote_url empty", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "", }, true, @@ -228,8 +226,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "remote_url 72 chars", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: strings.Repeat("r", 72), }, true, @@ -238,8 +236,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "remote_url invalid", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "invalid", }, true, @@ -248,8 +246,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "remote_url invalid scheme", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "tcp://remote.url:80", }, true, @@ -258,8 +256,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "remote_url without port", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url", }, true, @@ -268,8 +266,8 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { "remote_url with port", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -305,14 +303,14 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -367,7 +365,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices empty", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsEmpty, }, true, }, @@ -375,7 +373,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices empty denom", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: ""}}, + GigabytePrices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -383,7 +381,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices invalid denom", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "o"}}, + GigabytePrices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -391,7 +389,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices empty amount", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + GigabytePrices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -399,7 +397,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices negative amount", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + GigabytePrices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -407,7 +405,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices zero amount", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + GigabytePrices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -415,7 +413,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { "gigabyte_prices positive amount", fields{ From: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, HourlyPrices: nil, RemoteURL: "https://remote.url:443", }, @@ -436,7 +434,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{}, + HourlyPrices: hubtypes.TestCoinsEmpty, }, true, }, @@ -445,7 +443,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: ""}}, + HourlyPrices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -454,7 +452,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "o"}}, + HourlyPrices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -463,7 +461,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + HourlyPrices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -472,7 +470,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + HourlyPrices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -481,7 +479,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + HourlyPrices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -490,7 +488,7 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32NodeAddr20Bytes, GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", }, false, @@ -584,14 +582,14 @@ func TestMsgUpdateStatusRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -688,14 +686,14 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -743,7 +741,7 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { "node_address empty", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - NodeAddress: "", + NodeAddress: hubtypes.TestAddrEmpty, }, true, }, @@ -751,7 +749,7 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { "node_address invalid", fields{ From: hubtypes.TestBech32AccAddr20Bytes, - NodeAddress: "invalid", + NodeAddress: hubtypes.TestAddrInvalid, }, true, }, @@ -841,6 +839,7 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32AccAddr20Bytes, NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Hours: 1000, + Denom: hubtypes.TestDenomOne, }, false, }, @@ -861,6 +860,7 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Hours: 0, Gigabytes: 1000, + Denom: hubtypes.TestDenomOne, }, false, }, @@ -873,7 +873,7 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { Gigabytes: 0, Denom: "", }, - false, + true, }, { "denom invalid", diff --git a/x/node/types/node_test.go b/x/node/types/node_test.go index 859581d6..c059d170 100644 --- a/x/node/types/node_test.go +++ b/x/node/types/node_test.go @@ -23,7 +23,7 @@ func TestNode_GetAddress(t *testing.T) { { "address empty", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, nil, }, @@ -64,100 +64,100 @@ func TestNode_GigabytePrice(t *testing.T) { { "gigabyte_prices nil and denom empty", fields{ - GigabytePrices: nil, + GigabytePrices: hubtypes.TestCoinsNil, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, - true, + hubtypes.TestCoinEmpty, + false, }, { "gigabyte_prices empty and denom empty", fields{ - GigabytePrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsEmpty, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "gigabyte_prices 1000one and denom empty", fields{ - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "gigabyte_prices nil and denom one", fields{ - GigabytePrices: nil, + GigabytePrices: hubtypes.TestCoinsNil, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "gigabyte_prices empty and denom one", fields{ - GigabytePrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsEmpty, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "gigabyte_prices 1000one and denom one", fields{ - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + hubtypes.TestCoinPositiveAmount, true, }, { "gigabyte_prices nil and denom two", fields{ - GigabytePrices: nil, + GigabytePrices: hubtypes.TestCoinsNil, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "gigabyte_prices empty and denom two", fields{ - GigabytePrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsEmpty, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "gigabyte_prices 1000one and denom two", fields{ - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, } @@ -194,34 +194,34 @@ func TestNode_HourlyPrice(t *testing.T) { { "hourly_prices nil and denom empty", fields{ - HourlyPrices: nil, + HourlyPrices: hubtypes.TestCoinsNil, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, - true, + hubtypes.TestCoinEmpty, + false, }, { "hourly_prices empty and denom empty", fields{ - HourlyPrices: sdk.Coins{}, + HourlyPrices: hubtypes.TestCoinsEmpty, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "hourly_prices 1000one and denom empty", fields{ - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { @@ -230,31 +230,31 @@ func TestNode_HourlyPrice(t *testing.T) { HourlyPrices: nil, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "hourly_prices empty and denom one", fields{ - HourlyPrices: sdk.Coins{}, + HourlyPrices: hubtypes.TestCoinsEmpty, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "hourly_prices 1000one and denom one", fields{ - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + hubtypes.TestCoinPositiveAmount, true, }, { @@ -263,31 +263,31 @@ func TestNode_HourlyPrice(t *testing.T) { HourlyPrices: nil, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "hourly_prices empty and denom two", fields{ - HourlyPrices: sdk.Coins{}, + HourlyPrices: hubtypes.TestCoinsEmpty, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "hourly_prices 1000one and denom two", fields{ - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, } @@ -325,14 +325,14 @@ func TestNode_Validate(t *testing.T) { { "address empty", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, true, }, { "address invalid", fields{ - Address: "invalid", + Address: hubtypes.TestAddrInvalid, }, true, }, @@ -347,12 +347,12 @@ func TestNode_Validate(t *testing.T) { "address 10 bytes", fields{ Address: hubtypes.TestBech32NodeAddr10Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -360,12 +360,12 @@ func TestNode_Validate(t *testing.T) { "address 20 bytes", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -373,12 +373,12 @@ func TestNode_Validate(t *testing.T) { "address 30 bytes", fields{ Address: hubtypes.TestBech32NodeAddr30Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -386,20 +386,20 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices nil", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsNil, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, - false, + true, }, { "gigabyte_prices empty", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsEmpty, }, true, }, @@ -407,7 +407,7 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices empty denom", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: ""}}, + GigabytePrices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -415,7 +415,7 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices invalid denom", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "o"}}, + GigabytePrices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -423,7 +423,7 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices empty amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + GigabytePrices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -431,7 +431,7 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices negative amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + GigabytePrices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -439,7 +439,7 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices zero amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + GigabytePrices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -447,12 +447,12 @@ func TestNode_Validate(t *testing.T) { "gigabyte_prices positive amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -460,21 +460,21 @@ func TestNode_Validate(t *testing.T) { "hourly_prices nil", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsNil, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, - false, + true, }, { "hourly_prices empty", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsEmpty, }, true, }, @@ -482,8 +482,8 @@ func TestNode_Validate(t *testing.T) { "hourly_prices empty denom", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: ""}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -491,8 +491,8 @@ func TestNode_Validate(t *testing.T) { "hourly_prices invalid denom", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "o"}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -500,8 +500,8 @@ func TestNode_Validate(t *testing.T) { "hourly_prices empty amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -509,8 +509,8 @@ func TestNode_Validate(t *testing.T) { "hourly_prices negative amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -518,8 +518,8 @@ func TestNode_Validate(t *testing.T) { "hourly_prices zero amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -527,12 +527,12 @@ func TestNode_Validate(t *testing.T) { "hourly_prices positive amount", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -540,8 +540,8 @@ func TestNode_Validate(t *testing.T) { "remote_url empty", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "", }, true, @@ -550,8 +550,8 @@ func TestNode_Validate(t *testing.T) { "remote_url 72 chars", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: strings.Repeat("r", 72), }, true, @@ -560,8 +560,8 @@ func TestNode_Validate(t *testing.T) { "remote_url invalid", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "invalid", }, true, @@ -570,8 +570,8 @@ func TestNode_Validate(t *testing.T) { "remote_url invalid scheme", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "tcp://remote.url:80", }, true, @@ -580,8 +580,8 @@ func TestNode_Validate(t *testing.T) { "remote_url without port", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url", }, true, @@ -590,12 +590,12 @@ func TestNode_Validate(t *testing.T) { "remote_url with port", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -603,10 +603,10 @@ func TestNode_Validate(t *testing.T) { "inactive_at empty", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Time{}, + InactiveAt: hubtypes.TestTimeZero, }, true, }, @@ -614,12 +614,12 @@ func TestNode_Validate(t *testing.T) { "inactive_at now", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -627,10 +627,10 @@ func TestNode_Validate(t *testing.T) { "status unspecified", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusUnspecified, }, true, @@ -639,12 +639,12 @@ func TestNode_Validate(t *testing.T) { "status active", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -652,10 +652,10 @@ func TestNode_Validate(t *testing.T) { "status inactive_pending", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusInactivePending, }, true, @@ -664,12 +664,12 @@ func TestNode_Validate(t *testing.T) { "status inactive", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Time{}, + InactiveAt: hubtypes.TestTimeZero, Status: hubtypes.StatusInactive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -677,12 +677,12 @@ func TestNode_Validate(t *testing.T) { "status_at empty", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Time{}, + StatusAt: hubtypes.TestTimeZero, }, true, }, @@ -690,12 +690,12 @@ func TestNode_Validate(t *testing.T) { "status_at now", fields{ Address: hubtypes.TestBech32NodeAddr20Bytes, - GigabytePrices: nil, - HourlyPrices: nil, + GigabytePrices: hubtypes.TestCoinsPositiveAmount, + HourlyPrices: hubtypes.TestCoinsPositiveAmount, RemoteURL: "https://remote.url:443", - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, diff --git a/x/node/types/params_test.go b/x/node/types/params_test.go index 0decb367..74f833e0 100644 --- a/x/node/types/params_test.go +++ b/x/node/types/params_test.go @@ -5,6 +5,8 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + + hubtypes "github.com/sentinel-official/hub/types" ) func TestParams_Validate(t *testing.T) { @@ -29,58 +31,62 @@ func TestParams_Validate(t *testing.T) { { "deposit empty", fields{ - Deposit: sdk.Coin{}, + Deposit: hubtypes.TestCoinEmpty, }, true, }, { "deposit empty denom", fields{ - Deposit: sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinEmptyDenom, }, true, }, { "deposit invalid denom", fields{ - Deposit: sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinInvalidDenom, }, true, }, { "deposit empty amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.Int{}}, + Deposit: hubtypes.TestCoinEmptyAmount, }, true, }, { "deposit negative amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}, + Deposit: hubtypes.TestCoinNegativeAmount, }, true, }, { "deposit zero amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}, + Deposit: hubtypes.TestCoinZeroAmount, }, true, }, { "deposit positive amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "active_duration negative", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: -1000, }, true, @@ -88,7 +94,7 @@ func TestParams_Validate(t *testing.T) { { "active_duration zero", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 0, }, true, @@ -96,316 +102,368 @@ func TestParams_Validate(t *testing.T) { { "active_duration positive", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_gigabyte_prices nil", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxGigabytePrices: nil, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxGigabytePrices: nil, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_gigabyte_prices empty", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxGigabytePrices: hubtypes.TestCoinsEmpty, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_gigabyte_prices empty denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}}, + MaxGigabytePrices: hubtypes.TestCoinsEmptyDenom, }, true, }, { "max_gigabyte_prices invalid denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}}, + MaxGigabytePrices: hubtypes.TestCoinsInvalidDenom, }, true, }, { "max_gigabyte_prices empty amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + MaxGigabytePrices: hubtypes.TestCoinsEmptyAmount, }, true, }, { "max_gigabyte_prices negative amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + MaxGigabytePrices: hubtypes.TestCoinsNegativeAmount, }, true, }, { "max_gigabyte_prices zero amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + MaxGigabytePrices: hubtypes.TestCoinsZeroAmount, }, true, }, { "max_gigabyte_prices positive amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxGigabytePrices: hubtypes.TestCoinsPositiveAmount, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_gigabyte_prices nil", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinGigabytePrices: nil, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MinGigabytePrices: nil, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_gigabyte_prices empty", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MinGigabytePrices: hubtypes.TestCoinsEmpty, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_gigabyte_prices empty denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}}, + MinGigabytePrices: hubtypes.TestCoinsEmptyDenom, }, true, }, { "min_gigabyte_prices invalid denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}}, + MinGigabytePrices: hubtypes.TestCoinsInvalidDenom, }, true, }, { "min_gigabyte_prices empty amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + MinGigabytePrices: hubtypes.TestCoinsEmptyAmount, }, true, }, { "min_gigabyte_prices negative amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + MinGigabytePrices: hubtypes.TestCoinsNegativeAmount, }, true, }, { "min_gigabyte_prices zero amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + MinGigabytePrices: hubtypes.TestCoinsZeroAmount, }, true, }, { "min_gigabyte_prices positive amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinGigabytePrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MinGigabytePrices: hubtypes.TestCoinsPositiveAmount, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_hourly_prices nil", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxHourlyPrices: nil, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxHourlyPrices: nil, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_hourly_prices empty", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxHourlyPrices: hubtypes.TestCoinsEmpty, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_hourly_prices empty denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}}, + MaxHourlyPrices: hubtypes.TestCoinsEmptyDenom, }, true, }, { "max_hourly_prices invalid denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}}, + MaxHourlyPrices: hubtypes.TestCoinsInvalidDenom, }, true, }, { "max_hourly_prices empty amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + MaxHourlyPrices: hubtypes.TestCoinsEmptyAmount, }, true, }, { "max_hourly_prices negative amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + MaxHourlyPrices: hubtypes.TestCoinsNegativeAmount, }, true, }, { "max_hourly_prices zero amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + MaxHourlyPrices: hubtypes.TestCoinsZeroAmount, }, true, }, { "max_hourly_prices positive amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxHourlyPrices: hubtypes.TestCoinsPositiveAmount, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_hourly_prices nil", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinHourlyPrices: nil, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MinHourlyPrices: nil, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_hourly_prices empty", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MinHourlyPrices: hubtypes.TestCoinsEmpty, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_hourly_prices empty denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}}, + MinHourlyPrices: hubtypes.TestCoinsEmptyDenom, }, true, }, { "min_hourly_prices invalid denom", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}}, + MinHourlyPrices: hubtypes.TestCoinsInvalidDenom, }, true, }, { "min_hourly_prices empty amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + MinHourlyPrices: hubtypes.TestCoinsEmptyAmount, }, true, }, { "min_hourly_prices negative amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + MinHourlyPrices: hubtypes.TestCoinsNegativeAmount, }, true, }, { "min_hourly_prices zero amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + MinHourlyPrices: hubtypes.TestCoinsZeroAmount, }, true, }, { "min_hourly_prices positive amount", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinHourlyPrices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MinHourlyPrices: hubtypes.TestCoinsPositiveAmount, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "max_subscription_gigabytes negative", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, MaxSubscriptionGigabytes: -1000, }, @@ -414,19 +472,22 @@ func TestParams_Validate(t *testing.T) { { "max_subscription_gigabytes zero", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, MaxSubscriptionGigabytes: 0, StakingShare: sdk.NewDecWithPrec(1, 0), }, - false, + true, }, { "max_subscription_gigabytes positive", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, StakingShare: sdk.NewDecWithPrec(1, 0), }, false, @@ -434,8 +495,9 @@ func TestParams_Validate(t *testing.T) { { "min_subscription_gigabytes negative", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, MinSubscriptionGigabytes: -1000, }, true, @@ -443,19 +505,23 @@ func TestParams_Validate(t *testing.T) { { "min_subscription_gigabytes zero", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, MinSubscriptionGigabytes: 0, StakingShare: sdk.NewDecWithPrec(1, 0), }, - false, + true, }, { "min_subscription_gigabytes positive", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, - MinSubscriptionGigabytes: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, StakingShare: sdk.NewDecWithPrec(1, 0), }, false, @@ -463,66 +529,82 @@ func TestParams_Validate(t *testing.T) { { "max_subscription_hours negative", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxSubscriptionHours: -1000, + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: -1000, }, true, }, { "max_subscription_hours zero", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxSubscriptionHours: 0, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 0, + StakingShare: sdk.NewDecWithPrec(1, 0), }, - false, + true, }, { "max_subscription_hours positive", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MaxSubscriptionHours: 1000, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "min_subscription_hours negative", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinSubscriptionHours: -1000, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: -1000, + StakingShare: sdk.NewDecWithPrec(1, 0), }, true, }, { "min_subscription_hours zero", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinSubscriptionHours: 0, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 0, + StakingShare: sdk.NewDecWithPrec(1, 0), }, - false, + true, }, { "min_subscription_hours positive", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - MinSubscriptionHours: 1000, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "staking_share empty", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, StakingShare: sdk.Dec{}, }, @@ -531,7 +613,7 @@ func TestParams_Validate(t *testing.T) { { "staking_share -10", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, StakingShare: sdk.NewDecWithPrec(-10, 0), }, @@ -540,7 +622,7 @@ func TestParams_Validate(t *testing.T) { { "staking_share -1", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, StakingShare: sdk.NewDecWithPrec(-1, 0), }, @@ -549,7 +631,7 @@ func TestParams_Validate(t *testing.T) { { "staking_share -0.5", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, ActiveDuration: 1000, StakingShare: sdk.NewDecWithPrec(-5, 1), }, @@ -558,36 +640,52 @@ func TestParams_Validate(t *testing.T) { { "staking_share 0", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - StakingShare: sdk.NewDecWithPrec(0, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(0, 0), }, false, }, { "staking_share 0.5", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - StakingShare: sdk.NewDecWithPrec(5, 1), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(5, 1), }, false, }, { "staking_share 1", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - StakingShare: sdk.NewDecWithPrec(1, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(1, 0), }, false, }, { "staking_share 10", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - ActiveDuration: 1000, - StakingShare: sdk.NewDecWithPrec(10, 0), + Deposit: hubtypes.TestCoinPositiveAmount, + ActiveDuration: 1000, + MaxSubscriptionGigabytes: 1000, + MinSubscriptionGigabytes: 1, + MaxSubscriptionHours: 1000, + MinSubscriptionHours: 1, + StakingShare: sdk.NewDecWithPrec(10, 0), }, true, }, diff --git a/x/plan/types/msg_test.go b/x/plan/types/msg_test.go index 57e90e90..bb8ee477 100644 --- a/x/plan/types/msg_test.go +++ b/x/plan/types/msg_test.go @@ -24,14 +24,14 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -48,6 +48,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr10Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -57,6 +58,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -66,6 +68,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr30Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -91,6 +94,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -118,6 +122,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -127,9 +132,9 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: nil, + Prices: hubtypes.TestCoinsNil, }, - false, + true, }, { "prices empty", @@ -137,7 +142,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{}, + Prices: hubtypes.TestCoinsEmpty, }, true, }, @@ -147,7 +152,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}}, + Prices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -157,7 +162,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + Prices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -167,7 +172,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}}, + Prices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -177,7 +182,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + Prices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -187,7 +192,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + Prices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -197,7 +202,7 @@ func TestMsgCreateRequest_ValidateBasic(t *testing.T) { From: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Prices: hubtypes.TestCoinsPositiveAmount, }, false, }, @@ -231,14 +236,14 @@ func TestMsgUpdateStatusRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -358,14 +363,14 @@ func TestMsgLinkNodeRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -425,7 +430,7 @@ func TestMsgLinkNodeRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32ProvAddr20Bytes, ID: 1000, - NodeAddress: "", + NodeAddress: hubtypes.TestAddrEmpty, }, true, }, @@ -434,7 +439,7 @@ func TestMsgLinkNodeRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32ProvAddr20Bytes, ID: 1000, - NodeAddress: "invalid", + NodeAddress: hubtypes.TestAddrInvalid, }, true, }, @@ -503,14 +508,14 @@ func TestMsgUnlinkNodeRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -570,7 +575,7 @@ func TestMsgUnlinkNodeRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32ProvAddr20Bytes, ID: 1000, - NodeAddress: "", + NodeAddress: hubtypes.TestAddrEmpty, }, true, }, @@ -579,7 +584,7 @@ func TestMsgUnlinkNodeRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32ProvAddr20Bytes, ID: 1000, - NodeAddress: "invalid", + NodeAddress: hubtypes.TestAddrInvalid, }, true, }, @@ -648,14 +653,14 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -717,7 +722,7 @@ func TestMsgSubscribeRequest_ValidateBasic(t *testing.T) { ID: 1000, Denom: "", }, - false, + true, }, { "denom invalid", diff --git a/x/plan/types/plan_test.go b/x/plan/types/plan_test.go index 93500e8b..e950be5d 100644 --- a/x/plan/types/plan_test.go +++ b/x/plan/types/plan_test.go @@ -22,7 +22,7 @@ func TestPlan_GetProviderAddress(t *testing.T) { { "empty", fields{ - ProviderAddress: "", + ProviderAddress: hubtypes.TestAddrEmpty, }, nil, }, @@ -63,135 +63,102 @@ func TestPlan_Price(t *testing.T) { { "nil prices and empty denom", fields{ - Prices: nil, + Prices: hubtypes.TestCoinsNil, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, - true, + hubtypes.TestCoinEmpty, + false, }, { "nil prices and one denom", fields{ - Prices: nil, + Prices: hubtypes.TestCoinsNil, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "nil prices and two denom", fields{ - Prices: nil, + Prices: hubtypes.TestCoinsNil, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "empty prices and empty denom", fields{ - Prices: sdk.Coins{}, + Prices: hubtypes.TestCoinsEmpty, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "empty prices and one denom", fields{ - Prices: sdk.Coins{}, + Prices: hubtypes.TestCoinsEmpty, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { "empty prices and two denom", fields{ - Prices: sdk.Coins{}, + Prices: hubtypes.TestCoinsEmpty, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { - "1one prices and empty denom", + "1000one prices and empty denom", fields{ - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1)}}, + Prices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "", + denom: hubtypes.TestDenomEmpty, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, { - "1one prices and one denom", + "1000one prices and one denom", fields{ - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1)}}, + Prices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "one", + denom: hubtypes.TestDenomOne, }, - sdk.Coin{Denom: "one", Amount: sdk.NewInt(1)}, + hubtypes.TestCoinPositiveAmount, true, }, { - "1one prices and two denom", + "1000one prices and two denom", fields{ - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1)}}, + Prices: hubtypes.TestCoinsPositiveAmount, }, args{ - denom: "two", + denom: hubtypes.TestDenomTwo, }, - sdk.Coin{Amount: sdk.NewInt(0)}, + hubtypes.TestCoinEmpty, false, }, - { - "1two prices and empty denom", - fields{ - Prices: sdk.Coins{sdk.Coin{Denom: "two", Amount: sdk.NewInt(1)}}, - }, - args{ - denom: "", - }, - sdk.Coin{Amount: sdk.NewInt(0)}, - false, - }, - { - "1two prices and one denom", - fields{ - Prices: sdk.Coins{sdk.Coin{Denom: "two", Amount: sdk.NewInt(1)}}, - }, - args{ - denom: "one", - }, - sdk.Coin{Amount: sdk.NewInt(0)}, - false, - }, - { - "1two prices and two denom", - fields{ - Prices: sdk.Coins{sdk.Coin{Denom: "two", Amount: sdk.NewInt(1)}}, - }, - args{ - denom: "two", - }, - sdk.Coin{Denom: "two", Amount: sdk.NewInt(1)}, - true, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -238,8 +205,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -247,7 +215,7 @@ func TestPlan_Validate(t *testing.T) { "provider_address empty", fields{ ID: 1000, - ProviderAddress: "", + ProviderAddress: hubtypes.TestAddrEmpty, }, true, }, @@ -255,7 +223,7 @@ func TestPlan_Validate(t *testing.T) { "provider_address invalid", fields{ ID: 1000, - ProviderAddress: "invalid", + ProviderAddress: hubtypes.TestAddrInvalid, }, true, }, @@ -274,8 +242,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr10Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -286,8 +255,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -298,8 +268,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr30Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -328,8 +299,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -360,8 +332,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -372,11 +345,11 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: nil, + Prices: hubtypes.TestCoinsNil, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, - false, + true, }, { "prices empty", @@ -385,7 +358,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{}, + Prices: hubtypes.TestCoinsEmpty, }, true, }, @@ -396,7 +369,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}}, + Prices: hubtypes.TestCoinsEmptyDenom, }, true, }, @@ -407,7 +380,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.Int{}}}, + Prices: hubtypes.TestCoinsEmptyAmount, }, true, }, @@ -418,7 +391,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "o"}}, + Prices: hubtypes.TestCoinsInvalidDenom, }, true, }, @@ -429,7 +402,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + Prices: hubtypes.TestCoinsNegativeAmount, }, true, }, @@ -440,7 +413,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + Prices: hubtypes.TestCoinsZeroAmount, }, true, }, @@ -451,9 +424,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, - Prices: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -464,6 +437,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusUnspecified, }, true, @@ -475,8 +449,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -487,6 +462,7 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusInactivePending, }, true, @@ -498,8 +474,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusInactive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -510,8 +487,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Time{}, + StatusAt: hubtypes.TestTimeZero, }, true, }, @@ -522,8 +500,9 @@ func TestPlan_Validate(t *testing.T) { ProviderAddress: hubtypes.TestBech32ProvAddr20Bytes, Duration: 1000, Gigabytes: 1000, + Prices: hubtypes.TestCoinsPositiveAmount, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, diff --git a/x/provider/types/msg_test.go b/x/provider/types/msg_test.go index 7899d5b2..ff86da91 100644 --- a/x/provider/types/msg_test.go +++ b/x/provider/types/msg_test.go @@ -23,14 +23,14 @@ func TestMsgRegisterRequest_ValidateBasic(t *testing.T) { { "from empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "from invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -223,14 +223,14 @@ func TestMsgUpdateRequest_ValidateBasic(t *testing.T) { { "address empty", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "address invalid", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, diff --git a/x/provider/types/params_test.go b/x/provider/types/params_test.go index c5c8ac73..eb2b5cf0 100644 --- a/x/provider/types/params_test.go +++ b/x/provider/types/params_test.go @@ -4,6 +4,8 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + + hubtypes "github.com/sentinel-official/hub/types" ) func TestParams_Validate(t *testing.T) { @@ -19,35 +21,35 @@ func TestParams_Validate(t *testing.T) { { "empty denom deposit", fields{ - Deposit: sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinEmptyDenom, }, true, }, { "invalid denom deposit", fields{ - Deposit: sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinInvalidDenom, }, true, }, { "empty amount deposit", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.Int{}}, + Deposit: hubtypes.TestCoinEmptyAmount, }, true, }, { "negative amount deposit", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}, + Deposit: hubtypes.TestCoinNegativeAmount, }, true, }, { "zero amount deposit", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}, + Deposit: hubtypes.TestCoinZeroAmount, StakingShare: sdk.NewDec(0), }, false, @@ -55,7 +57,7 @@ func TestParams_Validate(t *testing.T) { { "positive amount deposit", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.NewDec(0), }, false, @@ -63,7 +65,7 @@ func TestParams_Validate(t *testing.T) { { "empty staking share", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.Dec{}, }, true, @@ -71,7 +73,7 @@ func TestParams_Validate(t *testing.T) { { "less than 0 staking share", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.NewDec(-1), }, true, @@ -79,7 +81,7 @@ func TestParams_Validate(t *testing.T) { { "equals to 0 staking share", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.NewDec(0), }, false, @@ -87,7 +89,7 @@ func TestParams_Validate(t *testing.T) { { "less than 1 staking share", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.NewDecWithPrec(1, 1), }, false, @@ -95,7 +97,7 @@ func TestParams_Validate(t *testing.T) { { "equals to 1 staking share", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.NewDec(1), }, false, @@ -103,7 +105,7 @@ func TestParams_Validate(t *testing.T) { { "greater than 1 staking share", fields{ - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, StakingShare: sdk.NewDec(2), }, true, diff --git a/x/provider/types/provider_test.go b/x/provider/types/provider_test.go index e2c6da7d..05739bdb 100644 --- a/x/provider/types/provider_test.go +++ b/x/provider/types/provider_test.go @@ -24,7 +24,7 @@ func TestProvider_GetAddress(t *testing.T) { { "empty", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, nil, }, @@ -69,14 +69,14 @@ func TestProvider_Validate(t *testing.T) { { "empty address", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, true, }, { "invalid address", fields{ - Address: "invalid", + Address: hubtypes.TestAddrInvalid, }, true, }, diff --git a/x/session/types/keys_test.go b/x/session/types/keys_test.go index dcf2ff6a..dfab9170 100644 --- a/x/session/types/keys_test.go +++ b/x/session/types/keys_test.go @@ -3,11 +3,12 @@ package types import ( "crypto/rand" "testing" - "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/stretchr/testify/require" + + hubtypes "github.com/sentinel-official/hub/types" ) func TestSessionForAccountKey(t *testing.T) { @@ -37,11 +38,10 @@ func TestSessionForAccountKey(t *testing.T) { func TestSessionForInactiveAtKey(t *testing.T) { for i := 0; i < 512; i += 64 { - at := time.Now() require.Equal( t, - append(append(SessionForInactiveAtKeyPrefix, sdk.FormatTimeBytes(at)...), sdk.Uint64ToBigEndian(uint64(i))...), - SessionForInactiveAtKey(at, uint64(i)), + append(append(SessionForInactiveAtKeyPrefix, sdk.FormatTimeBytes(hubtypes.TestTimeNow)...), sdk.Uint64ToBigEndian(uint64(i))...), + SessionForInactiveAtKey(hubtypes.TestTimeNow, uint64(i)), ) } } @@ -81,7 +81,7 @@ func TestIDFromSessionForInactiveAtKey(t *testing.T) { ) for i := 1; i <= 256; i += 64 { - key = SessionForInactiveAtKey(time.Now(), uint64(i)) + key = SessionForInactiveAtKey(hubtypes.TestTimeNow, uint64(i)) require.Equal( t, uint64(i), diff --git a/x/session/types/msg_test.go b/x/session/types/msg_test.go index a95ce28f..26ff192e 100644 --- a/x/session/types/msg_test.go +++ b/x/session/types/msg_test.go @@ -22,14 +22,14 @@ func TestMsgStartRequest_ValidateBasic(t *testing.T) { { "empty from", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "invalid from", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -82,7 +82,7 @@ func TestMsgStartRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32AccAddr20Bytes, ID: 1000, - Address: "", + Address: hubtypes.TestAddrEmpty, }, true, }, @@ -91,7 +91,7 @@ func TestMsgStartRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32AccAddr20Bytes, ID: 1000, - Address: "invalid", + Address: hubtypes.TestAddrInvalid, }, true, }, @@ -160,14 +160,14 @@ func TestMsgUpdateDetailsRequest_ValidateBasic(t *testing.T) { { "empty from", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "invalid from", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -476,14 +476,14 @@ func TestMsgEndRequest_ValidateBasic(t *testing.T) { { "empty from", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "invalid from", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, diff --git a/x/session/types/session_test.go b/x/session/types/session_test.go index 4d0676fa..fc5237d8 100644 --- a/x/session/types/session_test.go +++ b/x/session/types/session_test.go @@ -22,7 +22,7 @@ func TestSession_GetAddress(t *testing.T) { { "empty", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, nil, }, @@ -58,7 +58,7 @@ func TestSession_GetNodeAddress(t *testing.T) { { "empty", fields{ - NodeAddress: "", + NodeAddress: hubtypes.TestAddrEmpty, }, nil, }, @@ -115,9 +115,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -138,9 +138,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -180,9 +180,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -195,9 +195,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -210,9 +210,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -255,9 +255,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -358,9 +358,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(0), Download: sdk.NewInt(0)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -373,9 +373,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(0), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -399,9 +399,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(0)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -414,9 +414,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -441,9 +441,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 0, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -456,9 +456,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -471,7 +471,7 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Time{}, + InactiveAt: hubtypes.TestTimeZero, }, true, }, @@ -484,9 +484,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -499,7 +499,7 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusUnspecified, }, true, @@ -513,9 +513,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -528,9 +528,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusInactivePending, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -543,9 +543,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -558,9 +558,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Time{}, + StatusAt: hubtypes.TestTimeZero, }, true, }, @@ -573,9 +573,9 @@ func TestSession_Validate(t *testing.T) { Address: hubtypes.TestBech32AccAddr20Bytes, Bandwidth: hubtypes.Bandwidth{Upload: sdk.NewInt(1000), Download: sdk.NewInt(1000)}, Duration: 1000, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, diff --git a/x/subscription/types/allocation_test.go b/x/subscription/types/allocation_test.go index 4c424ea1..60ccd0f7 100644 --- a/x/subscription/types/allocation_test.go +++ b/x/subscription/types/allocation_test.go @@ -21,7 +21,7 @@ func TestAllocation_GetAddress(t *testing.T) { { "empty account address", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, nil, }, @@ -59,14 +59,14 @@ func TestAllocation_Validate(t *testing.T) { { "empty account address", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, true, }, { "invalid account address", fields{ - Address: "invalid", + Address: hubtypes.TestAddrInvalid, }, true, }, diff --git a/x/subscription/types/keys_test.go b/x/subscription/types/keys_test.go index 00ad717a..2334c8c4 100644 --- a/x/subscription/types/keys_test.go +++ b/x/subscription/types/keys_test.go @@ -3,20 +3,20 @@ package types import ( "crypto/rand" "testing" - "time" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/stretchr/testify/require" + + hubtypes "github.com/sentinel-official/hub/types" ) func TestSubscriptionForInactiveAtKey(t *testing.T) { for i := 0; i < 512; i += 64 { - at := time.Now() require.Equal( t, - append(append(SubscriptionForInactiveAtKeyPrefix, sdk.FormatTimeBytes(at)...), sdk.Uint64ToBigEndian(uint64(i))...), - SubscriptionForInactiveAtKey(at, uint64(i)), + append(append(SubscriptionForInactiveAtKeyPrefix, sdk.FormatTimeBytes(hubtypes.TestTimeNow)...), sdk.Uint64ToBigEndian(uint64(i))...), + SubscriptionForInactiveAtKey(hubtypes.TestTimeNow, uint64(i)), ) } } @@ -179,7 +179,7 @@ func TestIDFromSubscriptionForInactiveAtKey(t *testing.T) { ) for i := 1; i <= 256; i += 64 { - key = SubscriptionForInactiveAtKey(time.Now(), uint64(i)) + key = SubscriptionForInactiveAtKey(hubtypes.TestTimeNow, uint64(i)) require.Equal( t, uint64(i), @@ -320,7 +320,7 @@ func TestIDFromPayoutForNextAtKey(t *testing.T) { ) for i := 1; i <= 256; i += 64 { - key = PayoutForNextAtKey(time.Now(), uint64(i)) + key = PayoutForNextAtKey(hubtypes.TestTimeNow, uint64(i)) require.Equal( t, uint64(i), diff --git a/x/subscription/types/msg_test.go b/x/subscription/types/msg_test.go index 33fe05a6..cc03209b 100644 --- a/x/subscription/types/msg_test.go +++ b/x/subscription/types/msg_test.go @@ -21,14 +21,14 @@ func TestMsgCancelRequest_ValidateBasic(t *testing.T) { { "empty from", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "invalid from", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -108,14 +108,14 @@ func TestMsgAllocateRequest_ValidateBasic(t *testing.T) { { "empty from", fields{ - From: "", + From: hubtypes.TestAddrEmpty, }, true, }, { "invalid from", fields{ - From: "invalid", + From: hubtypes.TestAddrInvalid, }, true, }, @@ -179,7 +179,7 @@ func TestMsgAllocateRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32AccAddr20Bytes, ID: 1000, - Address: "", + Address: hubtypes.TestAddrEmpty, }, true, }, @@ -188,7 +188,7 @@ func TestMsgAllocateRequest_ValidateBasic(t *testing.T) { fields{ From: hubtypes.TestBech32AccAddr20Bytes, ID: 1000, - Address: "invalid", + Address: hubtypes.TestAddrInvalid, }, true, }, diff --git a/x/subscription/types/payout_test.go b/x/subscription/types/payout_test.go index 025bc6fa..f262ce51 100644 --- a/x/subscription/types/payout_test.go +++ b/x/subscription/types/payout_test.go @@ -5,6 +5,8 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + + hubtypes "github.com/sentinel-official/hub/types" ) func TestPayout_Validate(t *testing.T) { @@ -31,7 +33,8 @@ func TestPayout_Validate(t *testing.T) { fields{ ID: 1000, Hours: 1000, - NextAt: time.Now(), + Price: hubtypes.TestCoinPositiveAmount, + NextAt: hubtypes.TestTimeNow, }, false, }, @@ -54,38 +57,36 @@ func TestPayout_Validate(t *testing.T) { { "hours positive", fields{ - ID: 1000, - Hours: 1000, - NextAt: time.Now(), + ID: 1000, + Hours: 1000, + Price: hubtypes.TestCoinPositiveAmount, }, false, }, { "price empty", fields{ - ID: 1000, - Hours: 1000, - Price: sdk.Coin{}, - NextAt: time.Now(), + ID: 1000, + Hours: 1000, + Price: hubtypes.TestCoinEmpty, }, - false, + true, }, { "price empty denom", fields{ - ID: 1000, - Hours: 1000, - Price: sdk.Coin{Denom: ""}, - NextAt: time.Now(), + ID: 1000, + Hours: 1000, + Price: hubtypes.TestCoinEmpty, }, - false, + true, }, { "price invalid denom", fields{ ID: 1000, Hours: 1000, - Price: sdk.Coin{Denom: "o", Amount: sdk.NewInt(1000)}, + Price: hubtypes.TestCoinInvalidDenom, }, true, }, @@ -94,7 +95,7 @@ func TestPayout_Validate(t *testing.T) { fields{ ID: 1000, Hours: 1000, - Price: sdk.Coin{Denom: "one", Amount: sdk.Int{}}, + Price: hubtypes.TestCoinEmptyAmount, }, true, }, @@ -103,7 +104,7 @@ func TestPayout_Validate(t *testing.T) { fields{ ID: 1000, Hours: 1000, - Price: sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}, + Price: hubtypes.TestCoinNegativeAmount, }, true, }, @@ -112,17 +113,16 @@ func TestPayout_Validate(t *testing.T) { fields{ ID: 1000, Hours: 1000, - Price: sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}, + Price: hubtypes.TestCoinZeroAmount, }, true, }, { "price positive amount", fields{ - ID: 1000, - Hours: 1000, - Price: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, - NextAt: time.Now(), + ID: 1000, + Hours: 1000, + Price: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -131,16 +131,18 @@ func TestPayout_Validate(t *testing.T) { fields{ ID: 1000, Hours: 1000, - NextAt: time.Time{}, + Price: hubtypes.TestCoinPositiveAmount, + NextAt: hubtypes.TestTimeZero, }, - true, + false, }, { "next_at positive", fields{ ID: 1000, Hours: 1000, - NextAt: time.Now(), + Price: hubtypes.TestCoinPositiveAmount, + NextAt: hubtypes.TestTimeNow, }, false, }, diff --git a/x/subscription/types/subscription_test.go b/x/subscription/types/subscription_test.go index 1e455635..d3ef0833 100644 --- a/x/subscription/types/subscription_test.go +++ b/x/subscription/types/subscription_test.go @@ -23,7 +23,7 @@ func TestBaseSubscription_GetAddress(t *testing.T) { { "empty", fields{ - Address: "", + Address: hubtypes.TestAddrEmpty, }, nil, }, @@ -72,9 +72,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -82,7 +82,7 @@ func TestBaseSubscription_Validate(t *testing.T) { "address empty", fields{ ID: 1000, - Address: "", + Address: hubtypes.TestAddrEmpty, }, true, }, @@ -90,7 +90,7 @@ func TestBaseSubscription_Validate(t *testing.T) { "address invalid", fields{ ID: 1000, - Address: "invalid", + Address: hubtypes.TestAddrInvalid, }, true, }, @@ -107,9 +107,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr10Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -118,9 +118,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -129,9 +129,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr30Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -140,7 +140,7 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr30Bytes, - InactiveAt: time.Time{}, + InactiveAt: hubtypes.TestTimeZero, }, true, }, @@ -149,9 +149,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr30Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -169,9 +169,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -180,9 +180,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusInactivePending, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -191,9 +191,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusInactive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -202,9 +202,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Time{}, + StatusAt: hubtypes.TestTimeZero, }, true, }, @@ -213,9 +213,9 @@ func TestBaseSubscription_Validate(t *testing.T) { fields{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, false, }, @@ -248,7 +248,7 @@ func TestNodeSubscription_GetNodeAddress(t *testing.T) { { "node_address empty", fields{ - NodeAddress: "", + NodeAddress: hubtypes.TestAddrEmpty, }, nil, }, @@ -292,14 +292,14 @@ func TestNodeSubscription_Validate(t *testing.T) { { "node_address empty", fields{ - NodeAddress: "", + NodeAddress: hubtypes.TestAddrEmpty, }, true, }, { "node_address invalid", fields{ - NodeAddress: "invalid", + NodeAddress: hubtypes.TestAddrInvalid, }, true, }, @@ -315,6 +315,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr10Bytes, Gigabytes: 1000, + Deposit: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -323,6 +324,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, + Deposit: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -331,6 +333,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr30Bytes, Gigabytes: 1000, + Deposit: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -365,6 +368,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, + Deposit: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -381,6 +385,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Hours: 1000, + Deposit: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -389,25 +394,25 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{}, + Deposit: hubtypes.TestCoinEmpty, }, - false, + true, }, { "deposit empty denom", fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{Denom: "", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinEmptyDenom, }, - false, + true, }, { "deposit invalid denom", fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{Denom: "d", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinInvalidDenom, }, true, }, @@ -416,7 +421,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{Denom: "one", Amount: sdk.Int{}}, + Deposit: hubtypes.TestCoinEmptyAmount, }, true, }, @@ -425,7 +430,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}, + Deposit: hubtypes.TestCoinNegativeAmount, }, true, }, @@ -434,7 +439,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}, + Deposit: hubtypes.TestCoinZeroAmount, }, true, }, @@ -443,7 +448,7 @@ func TestNodeSubscription_Validate(t *testing.T) { fields{ NodeAddress: hubtypes.TestBech32NodeAddr20Bytes, Gigabytes: 1000, - Deposit: sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}, + Deposit: hubtypes.TestCoinPositiveAmount, }, false, }, @@ -454,9 +459,9 @@ func TestNodeSubscription_Validate(t *testing.T) { BaseSubscription: &BaseSubscription{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, NodeAddress: tt.fields.NodeAddress, Gigabytes: tt.fields.Gigabytes, @@ -506,7 +511,7 @@ func TestPlanSubscription_Validate(t *testing.T) { PlanID: 1000, Denom: "", }, - false, + true, }, { "denom invalid", @@ -531,9 +536,9 @@ func TestPlanSubscription_Validate(t *testing.T) { BaseSubscription: &BaseSubscription{ ID: 1000, Address: hubtypes.TestBech32AccAddr20Bytes, - InactiveAt: time.Now(), + InactiveAt: hubtypes.TestTimeNow, Status: hubtypes.StatusActive, - StatusAt: time.Now(), + StatusAt: hubtypes.TestTimeNow, }, PlanID: tt.fields.PlanID, Denom: tt.fields.Denom,