github.com/Finschia/finschia-sdk@v0.48.1/x/foundation/keeper/internal/member_test.go (about)

     1  package internal_test
     2  
     3  import (
     4  	"time"
     5  
     6  	sdk "github.com/Finschia/finschia-sdk/types"
     7  	"github.com/Finschia/finschia-sdk/x/foundation"
     8  )
     9  
    10  func (s *KeeperTestSuite) TestUpdateDecisionPolicy() {
    11  	config := foundation.DefaultConfig()
    12  	testCases := map[string]struct {
    13  		policy foundation.DecisionPolicy
    14  		valid  bool
    15  	}{
    16  		"valid policy": {
    17  			policy: &foundation.ThresholdDecisionPolicy{
    18  				Threshold: sdk.OneDec(),
    19  				Windows: &foundation.DecisionPolicyWindows{
    20  					VotingPeriod: time.Hour,
    21  				},
    22  			},
    23  			valid: true,
    24  		},
    25  		"invalid policy (invalid min execution period)": {
    26  			policy: &foundation.ThresholdDecisionPolicy{
    27  				Threshold: sdk.OneDec(),
    28  				Windows: &foundation.DecisionPolicyWindows{
    29  					VotingPeriod:       time.Hour,
    30  					MinExecutionPeriod: time.Hour + config.MaxExecutionPeriod,
    31  				},
    32  			},
    33  		},
    34  	}
    35  
    36  	for name, tc := range testCases {
    37  		s.Run(name, func() {
    38  			ctx, _ := s.ctx.CacheContext()
    39  
    40  			err := s.impl.UpdateDecisionPolicy(ctx, tc.policy)
    41  			if tc.valid {
    42  				s.Require().NoError(err)
    43  			} else {
    44  				s.Require().Error(err)
    45  			}
    46  		})
    47  	}
    48  }
    49  
    50  func (s *KeeperTestSuite) TestUpdateMembers() {
    51  	testCases := map[string]struct {
    52  		updates []foundation.MemberRequest
    53  		valid   bool
    54  	}{
    55  		"add a new member": {
    56  			updates: []foundation.MemberRequest{
    57  				{
    58  					Address: s.stranger.String(),
    59  				},
    60  			},
    61  			valid: true,
    62  		},
    63  		"remove a member": {
    64  			updates: []foundation.MemberRequest{
    65  				{
    66  					Address: s.members[0].String(),
    67  					Remove:  true,
    68  				},
    69  			},
    70  			valid: true,
    71  		},
    72  		"remove a non-member": {
    73  			updates: []foundation.MemberRequest{
    74  				{
    75  					Address: s.stranger.String(),
    76  					Remove:  true,
    77  				},
    78  			},
    79  		},
    80  		"long metadata": {
    81  			updates: []foundation.MemberRequest{
    82  				{
    83  					Address:  s.stranger.String(),
    84  					Metadata: string(make([]rune, 256)),
    85  				},
    86  			},
    87  		},
    88  	}
    89  
    90  	for name, tc := range testCases {
    91  		s.Run(name, func() {
    92  			ctx, _ := s.ctx.CacheContext()
    93  
    94  			err := s.impl.UpdateMembers(ctx, tc.updates)
    95  			if tc.valid {
    96  				s.Require().NoError(err)
    97  			} else {
    98  				s.Require().Error(err)
    99  			}
   100  		})
   101  	}
   102  }