Skip to content

Commit

Permalink
adapt validate bucket split
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jan 12, 2024
1 parent eb2ef67 commit 57e706b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions action/protocol/staking/handler_candidate_endorsement.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *Protocol) endorseCandidate(ctx context.Context, csm CandidateStateManag
func (p *Protocol) unEndorseCandidate(ctx context.Context, csm CandidateStateManager, esm *EndorsementStateManager, caller address.Address, bucket *VoteBucket, cand *Candidate) error {
blkCtx := protocol.MustGetBlockCtx(ctx)

Check warning on line 64 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L63-L64

Added lines #L63 - L64 were not covered by tests

if err := p.validateUnEndorse(ctx, csm, esm, caller, bucket); err != nil {
if err := p.validateUnEndorse(ctx, esm, caller, bucket); err != nil {
return err

Check warning on line 67 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L66-L67

Added lines #L66 - L67 were not covered by tests
}
if err := esm.Put(bucket.Index, &Endorsement{
Expand All @@ -75,17 +75,29 @@ func (p *Protocol) unEndorseCandidate(ctx context.Context, csm CandidateStateMan
}

func (p *Protocol) validateEndorse(ctx context.Context, csm CandidateStateManager, esm *EndorsementStateManager, caller address.Address, bucket *VoteBucket, cand *Candidate) ReceiptError {
validators := []bucketValidator{
withBucketOwner(caller),
withBucketMinAmount(p.config.RegistrationConsts.MinSelfStake),
withBucketStake(true),
withBucketCandidate(cand.Owner),
withBucketSelfStaked(false),
withBucketEndorsed(false),
blkCtx := protocol.MustGetBlockCtx(ctx)
if err := validateBucketOwner(bucket, caller); err != nil {
return err

Check warning on line 80 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L77-L80

Added lines #L77 - L80 were not covered by tests
}
if err := validateBucketMinAmount(bucket, p.config.RegistrationConsts.MinSelfStake); err != nil {
return err

Check warning on line 83 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L82-L83

Added lines #L82 - L83 were not covered by tests
}
return validateBucket(ctx, csm, esm, bucket, validators...)
if err := validateBucketStake(bucket, true); err != nil {
return err

Check warning on line 86 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L85-L86

Added lines #L85 - L86 were not covered by tests
}
if err := validateBucketCandidate(bucket, cand.Owner); err != nil {
return err

Check warning on line 89 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L88-L89

Added lines #L88 - L89 were not covered by tests
}
if err := validateBucketSelfStake(csm, bucket, false); err != nil {
return err

Check warning on line 92 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L91-L92

Added lines #L91 - L92 were not covered by tests
}
return validateBucketEndorsement(esm, bucket, false, blkCtx.BlockHeight)

Check warning on line 94 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L94

Added line #L94 was not covered by tests
}

func (p *Protocol) validateUnEndorse(ctx context.Context, csm CandidateStateManager, esm *EndorsementStateManager, caller address.Address, bucket *VoteBucket) ReceiptError {
return validateBucket(ctx, csm, esm, bucket, withBucketOwner(caller), withBucketEndorsed(true))
func (p *Protocol) validateUnEndorse(ctx context.Context, esm *EndorsementStateManager, caller address.Address, bucket *VoteBucket) ReceiptError {
blkCtx := protocol.MustGetBlockCtx(ctx)
if err := validateBucketOwner(bucket, caller); err != nil {
return err

Check warning on line 100 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L97-L100

Added lines #L97 - L100 were not covered by tests
}
return validateBucketEndorsement(esm, bucket, true, blkCtx.BlockHeight)

Check warning on line 102 in action/protocol/staking/handler_candidate_endorsement.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/staking/handler_candidate_endorsement.go#L102

Added line #L102 was not covered by tests
}

0 comments on commit 57e706b

Please sign in to comment.