-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: intial GenesisState Validate test (#99)
* test: intial GenesisState Validate test * Fix: fix basic first tests * Test: test Validate and NewGenesisState * Fix: let AllowList be empty * Tidy: goimports genesis_test.go * Refactor: increase test coverage * Refactor: remove unnecessary code and rename vars
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/airdrop/types" | ||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var ( | ||
addr = sdk.AccAddress([]byte("addr________________")) | ||
invalidAddr = sdk.AccAddress([]byte("\n\n\n\n\taddr________________\t\n\n\n\n\n")) | ||
) | ||
|
||
func TestNewGenesisState(t *testing.T) { | ||
p := types.NewParams() | ||
expectedFunds := []types.ActiveFund{ | ||
{ | ||
Sender: addr.String(), | ||
Fund: &types.Fund{ | ||
Amount: &sdk.Coin{Denom: "test", Amount: sdk.NewInt(10)}, | ||
DripAmount: sdk.NewInt(1), | ||
}, | ||
}, | ||
} | ||
expectedState := &types.GenesisState{ | ||
Params: p, | ||
Funds: expectedFunds, | ||
} | ||
require.Equal(t, expectedState.GetFunds(), expectedFunds) | ||
require.Equal(t, expectedState.Params, p) | ||
} | ||
|
||
func TestValidateGenesisState(t *testing.T) { | ||
p1 := types.Params{ | ||
AllowList: []string{ | ||
addr.String(), // valid address | ||
}, | ||
} | ||
p2 := types.Params{ | ||
AllowList: []string{ | ||
invalidAddr.String(), // invalid address | ||
}, | ||
} | ||
funds := []types.ActiveFund{ | ||
{ | ||
Sender: addr.String(), | ||
Fund: &types.Fund{ | ||
Amount: &sdk.Coin{ | ||
Denom: "test", | ||
Amount: sdk.NewInt(10), | ||
}, | ||
DripAmount: sdk.NewInt(1), | ||
}, | ||
}, | ||
} | ||
gen1 := types.NewGenesisState(p1, funds) | ||
gen2 := types.NewGenesisState(p2, funds) | ||
require.NoError(t, gen1.Validate()) | ||
require.Error(t, gen2.Validate()) | ||
} |