-
Notifications
You must be signed in to change notification settings - Fork 841
Fully populate test context #3943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
|
@@ -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")) | ||
|
|
@@ -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 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was nil previously. |
||
|
|
||
| ValidatorState: validatorState, | ||
| ChainDataDir: tb.TempDir(), | ||
|
|
||
There was a problem hiding this comment.
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.