github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/farm/types/proposal_test.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package types
     5  
     6  import (
     7  	"testing"
     8  
     9  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
    10  	"github.com/fibonacci-chain/fbc/x/common"
    11  	govTypes "github.com/fibonacci-chain/fbc/x/gov/types"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestNewManageWhiteListProposal(t *testing.T) {
    16  	tests := []struct {
    17  		title       string
    18  		description string
    19  		poolName    string
    20  		isAdded     bool
    21  		errCode     uint32
    22  	}{
    23  		{
    24  			"title",
    25  			"description",
    26  			"pool",
    27  			true,
    28  			sdk.CodeOK,
    29  		},
    30  		{
    31  			"",
    32  			"description",
    33  			"pool",
    34  			true,
    35  			govTypes.CodeInvalidContent,
    36  		},
    37  		{
    38  			common.GetFixedLengthRandomString(govTypes.MaxTitleLength + 1),
    39  			"description",
    40  			"pool",
    41  			true,
    42  			govTypes.CodeInvalidContent,
    43  		},
    44  		{
    45  			"title",
    46  			"",
    47  			"pool",
    48  			true,
    49  			govTypes.CodeInvalidContent,
    50  		},
    51  		{
    52  			"title",
    53  			common.GetFixedLengthRandomString(govTypes.MaxDescriptionLength + 1),
    54  			"pool",
    55  			true,
    56  			govTypes.CodeInvalidContent,
    57  		},
    58  		{
    59  			"title",
    60  			"description",
    61  			"",
    62  			true,
    63  			govTypes.CodeInvalidContent,
    64  		},
    65  	}
    66  
    67  	for _, test := range tests {
    68  		proposal := NewManageWhiteListProposal(test.title, test.description, test.poolName, true)
    69  
    70  		require.Equal(t, test.title, proposal.GetTitle())
    71  		require.Equal(t, test.description, proposal.GetDescription())
    72  		require.Equal(t, RouterKey, proposal.ProposalRoute())
    73  		require.Equal(t, proposalTypeManageWhiteList, proposal.ProposalType())
    74  
    75  		err := proposal.ValidateBasic()
    76  		if test.errCode != sdk.CodeOK {
    77  			require.Error(t, err)
    78  			testCode(t, err, test.errCode)
    79  		}
    80  
    81  		require.NotPanics(t, func() {
    82  			_ = proposal.String()
    83  		})
    84  	}
    85  }