Skip to content

Commit

Permalink
ellector.GetExtendedParticipantList to return pubkeys of validators
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Dec 28, 2023
1 parent 574fa11 commit d8f7e16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contract/elector/elector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type executor interface {
}

type Validator struct {
Pubkey tlb.Bits256
Stake int64
MaxFactor int64
Address ton.AccountID
Expand Down Expand Up @@ -67,6 +68,7 @@ func GetParticipantListExtended(ctx context.Context, electorAddr ton.AccountID,
}
v.Validator.AdnlAddr.Hex()
validators = append(validators, Validator{
Pubkey: v.ID,
Stake: int64(v.Validator.Stake),
MaxFactor: int64(v.Validator.MaxFactor),
Address: accountID,
Expand Down
6 changes: 6 additions & 0 deletions contract/elector/elector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"testing"

"github.com/tonkeeper/tongo/tlb"
"github.com/tonkeeper/tongo/ton"
"github.com/tonkeeper/tongo/tvm"
)
Expand All @@ -27,13 +28,18 @@ func TestGetExtendedParticipantList(t *testing.T) {
if len(participants.Validators) != 316 {
t.Fatalf("got: %v, want: 316", len(participants.Validators))
}
pubkeys := make(map[tlb.Bits256]struct{})
for _, validator := range participants.Validators {
if validator.Stake < math.MaxInt32 {
t.Fatalf("stake looks too low: %v", validator.Stake)
}
if validator.MaxFactor != 196608 {
t.Fatalf("got: %v, want: 196608", validator.MaxFactor)
}
if _, ok := pubkeys[validator.Pubkey]; ok {
t.Fatalf("two validators have the same pubkey")
}
pubkeys[validator.Pubkey] = struct{}{}
}

}

0 comments on commit d8f7e16

Please sign in to comment.