Skip to content

Commit

Permalink
Unit Tests for Fund ValidateBasic and Drip function (#100)
Browse files Browse the repository at this point in the history
* Test: add test for fund ValidateBasic

* Test: add test for Airdrop Drip

* Tidy: Goimports-ed

* Test: add test for MsgValidateBasic

* Refactor: remove junk test code
  • Loading branch information
Josumner authored Jul 19, 2021
1 parent 8f3d9dd commit 8ee135e
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions x/airdrop/types/airdrop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package types

import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

var (
addr = sdk.AccAddress([]byte("addr________________"))
addrInvalid = sdk.AccAddress([]byte(""))
)

func TestFundValidateBasic(t *testing.T) {
amount := sdk.NewInt64Coin("test", 1)
fundPosDrip := Fund{
Amount: &amount,
DripAmount: sdk.NewInt(1),
}
fundNilDrip := Fund{
Amount: &amount,
DripAmount: sdk.NewInt(0),
}
fundNegDrip := Fund{
Amount: &amount,
DripAmount: sdk.NewInt(-1),
}
require.NoError(t, fundPosDrip.ValidateBasic())
require.Error(t, fundNilDrip.ValidateBasic())
require.Error(t, fundNegDrip.ValidateBasic())
}

func TestFundDrip(t *testing.T) {
amount := sdk.NewInt64Coin("test", 10)
fund := Fund{
Amount: &amount,
DripAmount: sdk.NewInt(2),
}
fundHighDrip := Fund{
Amount: &amount,
DripAmount: sdk.NewInt(100),
}
fund, _ = fund.Drip()
fundHighDrip, _ = fundHighDrip.Drip()
fmt.Println(fundHighDrip.Amount.Amount)
require.Equal(t, fund.Amount.Amount, sdk.NewInt(8))
require.Equal(t, fundHighDrip.Amount.Amount.Int64(), int64(0))
}

func TestMsgAirdropValidateBasic (t *testing.T) {
amount := sdk.NewInt64Coin("test", 100)
require.NoError(t, NewMsgAirDrop(addr, amount, sdk.NewInt(20)).ValidateBasic())
require.Error(t, NewMsgAirDrop(addrInvalid, amount, sdk.NewInt(20)).ValidateBasic())
}

0 comments on commit 8ee135e

Please sign in to comment.