Skip to content

Commit

Permalink
[PVM, DAC] Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Dec 8, 2023
1 parent b80e3de commit 9324bbe
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 4 deletions.
141 changes: 139 additions & 2 deletions vms/platformvm/dac/camino_add_member_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func TestAddMemberProposalCreateProposalState(t *testing.T) {

func TestAddMemberProposalStateAddVote(t *testing.T) {
voterAddr1 := ids.ShortID{1}
voterAddr2 := ids.ShortID{1}
voterAddr3 := ids.ShortID{1}
voterAddr2 := ids.ShortID{2}
voterAddr3 := ids.ShortID{3}

tests := map[string]struct {
proposal *AddMemberProposalState
Expand Down Expand Up @@ -464,3 +464,140 @@ func TestAddMemberProposalCreateFinishedProposalState(t *testing.T) {
})
}
}

func TestAddMemberProposalStateIsSuccessful(t *testing.T) {
tests := map[string]struct {
proposal *AddMemberProposalState
expectedSuccessful bool
expectedOriginalProposal *AddMemberProposalState
}{
// Case, when most voted weight is less, than 50% of votes is impossible, cause proposal only has 2 options
"Not successful: total voted weight is less, than 50% of total allowed voters": {
proposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 25},
{Value: false, Weight: 26},
},
},
TotalAllowedVoters: 102,
},
expectedSuccessful: false,
expectedOriginalProposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 25},
{Value: false, Weight: 26},
},
},
TotalAllowedVoters: 102,
},
},
"Successful": {
proposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 25},
{Value: false, Weight: 26},
},
},
TotalAllowedVoters: 100,
},
expectedSuccessful: true,
expectedOriginalProposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 25},
{Value: false, Weight: 26},
},
},
TotalAllowedVoters: 100,
},
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
require.Equal(t, tt.expectedSuccessful, tt.proposal.IsSuccessful())
require.Equal(t, tt.expectedOriginalProposal, tt.proposal)
})
}
}

func TestAddMemberProposalStateCanBeFinished(t *testing.T) {
tests := map[string]struct {
proposal *AddMemberProposalState
expectedCanBeFinished bool
expectedOriginalProposal *AddMemberProposalState
}{
"Can not be finished: most voted weight is less than 50% of total allowed voters and not everyone had voted": {
proposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 50},
{Value: false},
},
},
TotalAllowedVoters: 100,
},
expectedCanBeFinished: false,
expectedOriginalProposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 50},
{Value: false},
},
},
TotalAllowedVoters: 100,
},
},
"Can be finished: everyone had voted": {
proposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 50},
{Value: false, Weight: 50},
},
},
TotalAllowedVoters: 100,
},
expectedCanBeFinished: true,
expectedOriginalProposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 50},
{Value: false, Weight: 50},
},
},
TotalAllowedVoters: 100,
},
},
"Can be finished: most voted weight is greater than 50% of total allowed voters": {
proposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 51},
{Value: false},
},
},
TotalAllowedVoters: 100,
},
expectedCanBeFinished: true,
expectedOriginalProposal: &AddMemberProposalState{
SimpleVoteOptions: SimpleVoteOptions[bool]{
Options: []SimpleVoteOption[bool]{
{Value: true, Weight: 51},
{Value: false},
},
},
TotalAllowedVoters: 100,
},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
require.Equal(t, tt.expectedCanBeFinished, tt.proposal.CanBeFinished())
require.Equal(t, tt.expectedOriginalProposal, tt.proposal)
})
}
}
155 changes: 155 additions & 0 deletions vms/platformvm/dac/camino_base_fee_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,158 @@ func TestBaseFeeProposalCreateFinishedProposalState(t *testing.T) {
})
}
}

func TestBaseFeeProposalStateIsSuccessful(t *testing.T) {
tests := map[string]struct {
proposal *BaseFeeProposalState
expectedSuccessful bool
expectedOriginalProposal *BaseFeeProposalState
}{
"Not successful: most voted weight is less, than 50% of votes": {
proposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 20},
{Value: 2, Weight: 21},
{Value: 3, Weight: 10},
},
},
TotalAllowedVoters: 100,
},
expectedSuccessful: false,
expectedOriginalProposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 20},
{Value: 2, Weight: 21},
{Value: 3, Weight: 10},
},
},
TotalAllowedVoters: 100,
},
},
"Not successful: total voted weight is less, than 50% of total allowed voters": {
proposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 25},
{Value: 2, Weight: 26},
},
},
TotalAllowedVoters: 102,
},
expectedSuccessful: false,
expectedOriginalProposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 25},
{Value: 2, Weight: 26},
},
},
TotalAllowedVoters: 102,
},
},
"Successful": {
proposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 25},
{Value: 2, Weight: 26},
},
},
TotalAllowedVoters: 100,
},
expectedSuccessful: true,
expectedOriginalProposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 25},
{Value: 2, Weight: 26},
},
},
TotalAllowedVoters: 100,
},
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
require.Equal(t, tt.expectedSuccessful, tt.proposal.IsSuccessful())
require.Equal(t, tt.expectedOriginalProposal, tt.proposal)
})
}
}

func TestBaseFeeProposalStateCanBeFinished(t *testing.T) {
tests := map[string]struct {
proposal *BaseFeeProposalState
expectedCanBeFinished bool
expectedOriginalProposal *BaseFeeProposalState
}{
"Can not be finished: most voted weight is less than 50% of total allowed voters and not everyone had voted": {
proposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 50},
},
},
TotalAllowedVoters: 100,
},
expectedCanBeFinished: false,
expectedOriginalProposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 50},
},
},
TotalAllowedVoters: 100,
},
},
"Can be finished: everyone had voted": {
proposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 50},
{Value: 2, Weight: 50},
},
},
TotalAllowedVoters: 100,
},
expectedCanBeFinished: true,
expectedOriginalProposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 50},
{Value: 2, Weight: 50},
},
},
TotalAllowedVoters: 100,
},
},
"Can be finished: most voted weight is greater than 50% of total allowed voters": {
proposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 51},
},
},
TotalAllowedVoters: 100,
},
expectedCanBeFinished: true,
expectedOriginalProposal: &BaseFeeProposalState{
SimpleVoteOptions: SimpleVoteOptions[uint64]{
Options: []SimpleVoteOption[uint64]{
{Value: 1, Weight: 51},
},
},
TotalAllowedVoters: 100,
},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
require.Equal(t, tt.expectedCanBeFinished, tt.proposal.CanBeFinished())
require.Equal(t, tt.expectedOriginalProposal, tt.proposal)
})
}
}
Loading

0 comments on commit 9324bbe

Please sign in to comment.