Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions snow/consensus/snowman/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ func RecordPollSplitVoteNoChangeTest(t *testing.T, factory Factory) {

firstBlock := snowmantest.BuildChild(snowmantest.Genesis)
secondBlock := snowmantest.BuildChild(snowmantest.Genesis)
// Ensure that the blocks have at least one bit as a common prefix
for firstBlock.IDV.Bit(0) != secondBlock.IDV.Bit(0) {
secondBlock = snowmantest.BuildChild(snowmantest.Genesis)
}
Comment on lines +524 to +527
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test previously assumed that this was the case. In practice it was because all of our tests are deterministic, but adding an additional call to ids.GenerateTestNodeID() changed the seed.

This should now work generally.


require.NoError(sm.Add(firstBlock))
require.NoError(sm.Add(secondBlock))
Expand Down
34 changes: 20 additions & 14 deletions snow/snowtest/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
)

var (
PChainID = constants.PlatformChainID
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted the order to align with the rest of the file... Not really needed

XChainID = ids.GenerateTestID()
CChainID = ids.GenerateTestID()
PChainID = constants.PlatformChainID
AVAXAssetID = ids.GenerateTestID()

errMissing = errors.New("missing")
Expand Down Expand Up @@ -56,9 +59,12 @@ func Context(tb testing.TB, chainID ids.ID) *snow.Context {
require.NoError(err)
publicKey := secretKey.PublicKey()

memory := atomic.NewMemory(memdb.New())
sharedMemory := memory.NewSharedMemory(chainID)

aliaser := ids.NewAliaser()
require.NoError(aliaser.Alias(constants.PlatformChainID, "P"))
require.NoError(aliaser.Alias(constants.PlatformChainID, constants.PlatformChainID.String()))
require.NoError(aliaser.Alias(PChainID, "P"))
require.NoError(aliaser.Alias(PChainID, PChainID.String()))
require.NoError(aliaser.Alias(XChainID, "X"))
require.NoError(aliaser.Alias(XChainID, XChainID.String()))
require.NoError(aliaser.Alias(CChainID, "C"))
Expand All @@ -69,33 +75,33 @@ func Context(tb testing.TB, chainID ids.ID) *snow.Context {
return 0, nil
},
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
subnetID, ok := map[ids.ID]ids.ID{
constants.PlatformChainID: constants.PrimaryNetworkID,
XChainID: constants.PrimaryNetworkID,
CChainID: constants.PrimaryNetworkID,
}[chainID]
if !ok {
switch chainID {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically not required, but during my canoto work, I realized how crazy inefficient this map lookup is... It is also less code and probably more readable tbh

case PChainID, XChainID, CChainID:
return constants.PrimaryNetworkID, nil
default:
return ids.Empty, errMissing
}
return subnetID, nil
},
}

return &snow.Context{
NetworkID: constants.UnitTestID,
SubnetID: constants.PrimaryNetworkID,
ChainID: chainID,
NodeID: ids.EmptyNodeID,
NodeID: ids.GenerateTestNodeID(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was invalid previously. We will never populate the empty ID here in prod.

PublicKey: publicKey,
NetworkUpgrades: upgradetest.GetConfig(upgradetest.Latest),

XChainID: XChainID,
CChainID: CChainID,
AVAXAssetID: AVAXAssetID,

Log: logging.NoLog{},
BCLookup: aliaser,
Metrics: metrics.NewPrefixGatherer(),
Log: logging.NoLog{},
SharedMemory: sharedMemory,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was nil previously.

BCLookup: aliaser,
Metrics: metrics.NewPrefixGatherer(),

WarpSigner: warp.NewSigner(secretKey, constants.UnitTestID, chainID),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was nil previously.


ValidatorState: validatorState,
ChainDataDir: tb.TempDir(),
Expand Down