|
4 | 4 | package platformvm
|
5 | 5 |
|
6 | 6 | import (
|
| 7 | + "bytes" |
7 | 8 | "context"
|
8 | 9 | "errors"
|
9 | 10 | "testing"
|
@@ -1687,46 +1688,46 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) {
|
1687 | 1688 | nodeID,
|
1688 | 1689 | constants.PrimaryNetworkID,
|
1689 | 1690 | height,
|
1690 |
| - uPrimaryTx.Signer.Key()), |
1691 |
| - ) |
| 1691 | + uPrimaryTx.Signer.Key(), |
| 1692 | + )) |
1692 | 1693 | }
|
1693 | 1694 | for height := primaryEndHeight; height < primaryRestartHeight; height++ {
|
1694 |
| - require.ErrorIs(checkValidatorBlsKeyIsSet( |
| 1695 | + err := checkValidatorBlsKeyIsSet( |
1695 | 1696 | vm.State,
|
1696 | 1697 | nodeID,
|
1697 | 1698 | constants.PrimaryNetworkID,
|
1698 | 1699 | primaryEndHeight,
|
1699 |
| - uPrimaryTx.Signer.Key()), |
1700 |
| - database.ErrNotFound, |
| 1700 | + uPrimaryTx.Signer.Key(), |
1701 | 1701 | )
|
| 1702 | + require.ErrorIs(err, database.ErrNotFound) |
1702 | 1703 | }
|
1703 | 1704 | require.NoError(checkValidatorBlsKeyIsSet(
|
1704 | 1705 | vm.State,
|
1705 | 1706 | nodeID,
|
1706 | 1707 | constants.PrimaryNetworkID,
|
1707 | 1708 | primaryRestartHeight,
|
1708 |
| - uPrimaryRestartTx.Signer.Key()), |
1709 |
| - ) |
| 1709 | + uPrimaryRestartTx.Signer.Key(), |
| 1710 | + )) |
1710 | 1711 |
|
1711 | 1712 | for height := subnetStartHeight; height < subnetEndHeight; height++ {
|
1712 | 1713 | require.NoError(checkValidatorBlsKeyIsSet(
|
1713 | 1714 | vm.State,
|
1714 | 1715 | nodeID,
|
1715 | 1716 | subnetID,
|
1716 | 1717 | height,
|
1717 |
| - uPrimaryTx.Signer.Key()), |
1718 |
| - ) |
| 1718 | + uPrimaryTx.Signer.Key(), |
| 1719 | + )) |
1719 | 1720 | }
|
1720 | 1721 |
|
1721 | 1722 | for height := subnetEndHeight; height <= primaryRestartHeight; height++ {
|
1722 |
| - require.ErrorIs(checkValidatorBlsKeyIsSet( |
| 1723 | + err := checkValidatorBlsKeyIsSet( |
1723 | 1724 | vm.State,
|
1724 | 1725 | nodeID,
|
1725 | 1726 | subnetID,
|
1726 | 1727 | primaryEndHeight,
|
1727 |
| - uPrimaryTx.Signer.Key()), |
1728 |
| - database.ErrNotFound, |
| 1728 | + uPrimaryTx.Signer.Key(), |
1729 | 1729 | )
|
| 1730 | + require.ErrorIs(err, database.ErrNotFound) |
1730 | 1731 | }
|
1731 | 1732 | }
|
1732 | 1733 |
|
@@ -1884,8 +1885,8 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) {
|
1884 | 1885 | nodeID,
|
1885 | 1886 | constants.PrimaryNetworkID,
|
1886 | 1887 | height,
|
1887 |
| - emptySigner.Key()), |
1888 |
| - ) |
| 1888 | + emptySigner.Key(), |
| 1889 | + )) |
1889 | 1890 | }
|
1890 | 1891 | }
|
1891 | 1892 |
|
@@ -2086,17 +2087,17 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) {
|
2086 | 2087 | nodeID,
|
2087 | 2088 | constants.PrimaryNetworkID,
|
2088 | 2089 | height,
|
2089 |
| - emptySigner.Key()), |
2090 |
| - ) |
| 2090 | + emptySigner.Key(), |
| 2091 | + )) |
2091 | 2092 | }
|
2092 | 2093 | for height := subnetStartHeight; height < subnetEndHeight; height++ {
|
2093 | 2094 | require.NoError(checkValidatorBlsKeyIsSet(
|
2094 | 2095 | vm.State,
|
2095 | 2096 | nodeID,
|
2096 | 2097 | subnetID,
|
2097 | 2098 | height,
|
2098 |
| - emptySigner.Key()), |
2099 |
| - ) |
| 2099 | + emptySigner.Key(), |
| 2100 | + )) |
2100 | 2101 | }
|
2101 | 2102 | }
|
2102 | 2103 |
|
@@ -2130,12 +2131,18 @@ func checkValidatorBlsKeyIsSet(
|
2130 | 2131 | }
|
2131 | 2132 |
|
2132 | 2133 | val, found := vals[nodeID]
|
2133 |
| - if !found { |
| 2134 | + switch { |
| 2135 | + case !found: |
2134 | 2136 | return database.ErrNotFound
|
2135 |
| - } |
2136 |
| - if val.PublicKey != expectedBlsKey { |
| 2137 | + case expectedBlsKey == val.PublicKey: |
| 2138 | + return nil |
| 2139 | + case expectedBlsKey == nil && val.PublicKey != nil: |
2137 | 2140 | 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 |
2138 | 2147 | }
|
2139 |
| - |
2140 |
| - return nil |
2141 | 2148 | }
|
0 commit comments