Skip to content

Commit 1e8f790

Browse files
Fix validator set diff tests (#1744)
1 parent 83f5eee commit 1e8f790

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

vms/platformvm/validator_set_property_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func TestGetValidatorsSetProperty(t *testing.T) {
189189
return fmt.Sprintf("failed GetValidatorSet: %s", err.Error())
190190
}
191191
if !reflect.DeepEqual(validatorsSet, res) {
192-
return fmt.Sprintf("failed validators set comparison: %s", err.Error())
192+
return "failed validators set comparison"
193193
}
194194
}
195195
}

vms/platformvm/vm_regression_test.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package platformvm
55

66
import (
7+
"bytes"
78
"context"
89
"errors"
910
"testing"
@@ -1687,46 +1688,46 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) {
16871688
nodeID,
16881689
constants.PrimaryNetworkID,
16891690
height,
1690-
uPrimaryTx.Signer.Key()),
1691-
)
1691+
uPrimaryTx.Signer.Key(),
1692+
))
16921693
}
16931694
for height := primaryEndHeight; height < primaryRestartHeight; height++ {
1694-
require.ErrorIs(checkValidatorBlsKeyIsSet(
1695+
err := checkValidatorBlsKeyIsSet(
16951696
vm.State,
16961697
nodeID,
16971698
constants.PrimaryNetworkID,
16981699
primaryEndHeight,
1699-
uPrimaryTx.Signer.Key()),
1700-
database.ErrNotFound,
1700+
uPrimaryTx.Signer.Key(),
17011701
)
1702+
require.ErrorIs(err, database.ErrNotFound)
17021703
}
17031704
require.NoError(checkValidatorBlsKeyIsSet(
17041705
vm.State,
17051706
nodeID,
17061707
constants.PrimaryNetworkID,
17071708
primaryRestartHeight,
1708-
uPrimaryRestartTx.Signer.Key()),
1709-
)
1709+
uPrimaryRestartTx.Signer.Key(),
1710+
))
17101711

17111712
for height := subnetStartHeight; height < subnetEndHeight; height++ {
17121713
require.NoError(checkValidatorBlsKeyIsSet(
17131714
vm.State,
17141715
nodeID,
17151716
subnetID,
17161717
height,
1717-
uPrimaryTx.Signer.Key()),
1718-
)
1718+
uPrimaryTx.Signer.Key(),
1719+
))
17191720
}
17201721

17211722
for height := subnetEndHeight; height <= primaryRestartHeight; height++ {
1722-
require.ErrorIs(checkValidatorBlsKeyIsSet(
1723+
err := checkValidatorBlsKeyIsSet(
17231724
vm.State,
17241725
nodeID,
17251726
subnetID,
17261727
primaryEndHeight,
1727-
uPrimaryTx.Signer.Key()),
1728-
database.ErrNotFound,
1728+
uPrimaryTx.Signer.Key(),
17291729
)
1730+
require.ErrorIs(err, database.ErrNotFound)
17301731
}
17311732
}
17321733

@@ -1884,8 +1885,8 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) {
18841885
nodeID,
18851886
constants.PrimaryNetworkID,
18861887
height,
1887-
emptySigner.Key()),
1888-
)
1888+
emptySigner.Key(),
1889+
))
18891890
}
18901891
}
18911892

@@ -2086,17 +2087,17 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) {
20862087
nodeID,
20872088
constants.PrimaryNetworkID,
20882089
height,
2089-
emptySigner.Key()),
2090-
)
2090+
emptySigner.Key(),
2091+
))
20912092
}
20922093
for height := subnetStartHeight; height < subnetEndHeight; height++ {
20932094
require.NoError(checkValidatorBlsKeyIsSet(
20942095
vm.State,
20952096
nodeID,
20962097
subnetID,
20972098
height,
2098-
emptySigner.Key()),
2099-
)
2099+
emptySigner.Key(),
2100+
))
21002101
}
21012102
}
21022103

@@ -2130,12 +2131,18 @@ func checkValidatorBlsKeyIsSet(
21302131
}
21312132

21322133
val, found := vals[nodeID]
2133-
if !found {
2134+
switch {
2135+
case !found:
21342136
return database.ErrNotFound
2135-
}
2136-
if val.PublicKey != expectedBlsKey {
2137+
case expectedBlsKey == val.PublicKey:
2138+
return nil
2139+
case expectedBlsKey == nil && val.PublicKey != nil:
21372140
return errors.New("unexpected BLS key")
2141+
case expectedBlsKey != nil && val.PublicKey == nil:
2142+
return errors.New("missing BLS key")
2143+
case !bytes.Equal(expectedBlsKey.Serialize(), val.PublicKey.Serialize()):
2144+
return errors.New("incorrect BLS key")
2145+
default:
2146+
return nil
21382147
}
2139-
2140-
return nil
21412148
}

0 commit comments

Comments
 (0)