Skip to content
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

Remove snow.DefaultContextTest #2518

Merged
merged 34 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6bf4918
Move `snow.DefaultContextTest` to `snowtest.EmptyContext`
dhrubabasu Dec 20, 2023
8e55ce7
update coreth
dhrubabasu Dec 20, 2023
82736a8
merged
dhrubabasu Dec 20, 2023
149131c
merged
dhrubabasu Dec 21, 2023
837fa3c
nit
dhrubabasu Dec 21, 2023
810b95f
reduce diff
dhrubabasu Dec 21, 2023
20b6a11
compilation
dhrubabasu Dec 21, 2023
6af8ad8
merged
dhrubabasu Dec 21, 2023
cc63c56
fix
dhrubabasu Dec 21, 2023
74c070a
Merge branch 'dev' into default-context-test
dhrubabasu Dec 21, 2023
915a353
nit
dhrubabasu Dec 21, 2023
89d5200
nit
dhrubabasu Dec 21, 2023
e8bb2c6
reduce usage of `EmptyContext`
dhrubabasu Dec 21, 2023
5ee452e
nits
dhrubabasu Dec 22, 2023
3f6194d
fix test
dhrubabasu Dec 22, 2023
1057700
nit
dhrubabasu Dec 22, 2023
cfba900
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
64f69d5
Use `CChainID`
dhrubabasu Dec 22, 2023
c65f28a
remove `EmptyContext`
dhrubabasu Dec 22, 2023
1d66446
update
dhrubabasu Dec 22, 2023
215d615
tidy
dhrubabasu Dec 22, 2023
f9c5742
minimize
dhrubabasu Dec 22, 2023
ceede08
nit
dhrubabasu Dec 22, 2023
dfb4917
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
19f0e49
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
6fba171
comment out erroring tests
dhrubabasu Dec 22, 2023
7d26115
nit
dhrubabasu Dec 22, 2023
bfe0130
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
476a2b8
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
8545f74
depend on coreth master
dhrubabasu Dec 22, 2023
82d3404
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
71bebdf
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
4ed8ae9
Merge branch 'dev' into default-context-test
dhrubabasu Dec 22, 2023
c29a4a0
Add a `snow.Context` param to `snowtest.ConsensusContext` (#2545)
dhrubabasu Dec 22, 2023
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/DataDog/zstd v1.5.2
github.com/Microsoft/go-winio v0.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231219231451-224728dbacb4
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231221211455-96dd057ec90d
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231219231451-224728dbacb4 h1:LXL5nSxcblyBFR5/zdO4TAqSWqoB15bT3sGb1Nkh7o4=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231219231451-224728dbacb4/go.mod h1:84JZyt3colgzGI/jOYGB5Wzxr/wNP0zjebHiWZjFthk=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231221211455-96dd057ec90d h1:RetXLIN9b3Dp9W7tu4qL3kJ328RhbLf02AEoaKLjo1Q=
github.com/ava-labs/coreth v0.12.9-rc.9.0.20231221211455-96dd057ec90d/go.mod h1:XgkdhKQfxOwilGrcrXEiUFXvWpFSID7U+dQ7otRrbiM=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 h1:mg9Uw6oZFJKytJxgxnl3uxZOs/SB8CVHg6Io4Tf99Zc=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
19 changes: 0 additions & 19 deletions snow/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,3 @@ type ConsensusContext struct {
// True iff this chain is currently state-syncing
StateSyncing utils.Atomic[bool]
}

func DefaultContextTest() *Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

sk, err := bls.NewSecretKey()
if err != nil {
panic(err)
}
pk := bls.PublicFromSecretKey(sk)
return &Context{
NetworkID: 0,
SubnetID: ids.Empty,
ChainID: ids.Empty,
NodeID: ids.EmptyNodeID,
PublicKey: pk,
Log: logging.NoLog{},
BCLookup: ids.NewAliaser(),
Metrics: metrics.NewOptionalGatherer(),
ChainDataDir: "",
}
}
6 changes: 3 additions & 3 deletions snow/engine/avalanche/state/unique_vertex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

"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/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/utils/hashing"
)

Expand All @@ -29,7 +29,7 @@ func newTestSerializer(t *testing.T, parse func(context.Context, []byte) (snowst
vm.ParseTxF = parse

baseDB := memdb.New()
ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
s := NewSerializer(
SerializerConfig{
ChainID: ctx.ChainID,
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestParseVertexWithIncorrectChainID(t *testing.T) {
func TestParseVertexWithInvalidTxs(t *testing.T) {
require := require.New(t)

ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
statelessVertex, err := vertex.Build( // regular, non-stop vertex
ctx.ChainID,
0,
Expand Down
6 changes: 3 additions & 3 deletions snow/networking/sender/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func TestSender_Bootstrap_Requests(t *testing.T) {
failedNodeID = ids.GenerateTestNodeID()
deadline = time.Second
requestID = uint32(1337)
ctx = snow.DefaultContextTest()
ctx = snowtest.EmptyContext()
heights = []uint64{1, 2, 3}
containerIDs = []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()}
engineType = p2p.EngineType_ENGINE_TYPE_SNOWMAN
Expand Down Expand Up @@ -885,7 +885,7 @@ func TestSender_Bootstrap_Responses(t *testing.T) {
destinationNodeID = ids.GenerateTestNodeID()
deadline = time.Second
requestID = uint32(1337)
ctx = snow.DefaultContextTest()
ctx = snowtest.EmptyContext()
summaryIDs = []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()}
summary = []byte{1, 2, 3}
engineType = p2p.EngineType_ENGINE_TYPE_AVALANCHE
Expand Down Expand Up @@ -1093,7 +1093,7 @@ func TestSender_Single_Request(t *testing.T) {
destinationNodeID = ids.GenerateTestNodeID()
deadline = time.Second
requestID = uint32(1337)
ctx = snow.DefaultContextTest()
ctx = snowtest.EmptyContext()
containerID = ids.GenerateTestID()
engineType = p2p.EngineType_ENGINE_TYPE_SNOWMAN
)
Expand Down
26 changes: 24 additions & 2 deletions snow/snowtest/snowtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import (

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
)

var (
Expand All @@ -35,9 +38,28 @@ func (noOpAcceptor) Accept(*snow.ConsensusContext, ids.ID, []byte) error {
return nil
}

func EmptyContext() *snow.Context {
sk, err := bls.NewSecretKey()
if err != nil {
panic(err)
}
pk := bls.PublicFromSecretKey(sk)
return &snow.Context{
NetworkID: 0,
SubnetID: ids.Empty,
ChainID: ids.Empty,
NodeID: ids.EmptyNodeID,
PublicKey: pk,
Log: logging.NoLog{},
BCLookup: ids.NewAliaser(),
Metrics: metrics.NewOptionalGatherer(),
ChainDataDir: "",
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is what we had before... but I still hate this... Are there places that we currently use EmptyContext that we could just be using Context?

Copy link
Contributor Author

@dhrubabasu dhrubabasu Dec 22, 2023

Choose a reason for hiding this comment

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

Removed EmptyContext altogether :)


func ConsensusContext() *snow.ConsensusContext {
return &snow.ConsensusContext{
Context: snow.DefaultContextTest(),
Context: EmptyContext(),
Registerer: prometheus.NewRegistry(),
AvalancheRegisterer: prometheus.NewRegistry(),
BlockAcceptor: noOpAcceptor{},
Expand All @@ -49,7 +71,7 @@ func ConsensusContext() *snow.ConsensusContext {
func Context(tb testing.TB, chainID ids.ID) *snow.Context {
require := require.New(tb)

ctx := snow.DefaultContextTest()
ctx := EmptyContext()

ctx.NetworkID = constants.UnitTestID
ctx.SubnetID = constants.PrimaryNetworkID
Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/txs/add_subnet_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
Expand All @@ -22,7 +22,7 @@ import (
func TestAddSubnetValidatorTxSyntacticVerify(t *testing.T) {
require := require.New(t)
clk := mockable.Clock{}
ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
signers := [][]*secp256k1.PrivateKey{preFundedKeys}

var (
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestAddSubnetValidatorTxSyntacticVerify(t *testing.T) {
func TestAddSubnetValidatorMarshal(t *testing.T) {
require := require.New(t)
clk := mockable.Clock{}
ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
signers := [][]*secp256k1.PrivateKey{preFundedKeys}

var (
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/create_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

func TestUnsignedCreateChainTxVerify(t *testing.T) {
ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
testSubnet1ID := ids.GenerateTestID()
testSubnet1ControlKeys := []*secp256k1.PrivateKey{
preFundedKeys[0],
Expand Down
29 changes: 15 additions & 14 deletions vms/platformvm/txs/executor/staker_tx_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
name: "fail syntactic verification",
backendF: func(*gomock.Controller) *Backend {
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand All @@ -128,7 +129,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
name: "not bootstrapped",
backendF: func(*gomock.Controller) *Backend {
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand All @@ -152,7 +153,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
CortinaTime: activeForkTime,
DurangoTime: mockable.MaxTime,
Expand All @@ -179,7 +180,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -208,7 +209,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -237,7 +238,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -267,7 +268,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -333,7 +334,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -368,7 +369,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -397,7 +398,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
bootstrapped := &utils.Atomic[bool]{}
bootstrapped.Set(true)
return &Backend{
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Config: &config.Config{
DurangoTime: activeForkTime, // activate latest fork
},
Expand Down Expand Up @@ -447,7 +448,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
AddSubnetValidatorFee: 1,
DurangoTime: activeForkTime, // activate latest fork,
},
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Bootstrapped: bootstrapped,
}
},
Expand Down Expand Up @@ -494,7 +495,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
DurangoTime: mockable.MaxTime,
AddSubnetValidatorFee: 1,
},
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Bootstrapped: bootstrapped,
}
},
Expand Down Expand Up @@ -545,7 +546,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) {
AddSubnetValidatorFee: 1,
DurangoTime: activeForkTime, // activate latest fork,
},
Ctx: snow.DefaultContextTest(),
Ctx: snowtest.EmptyContext(),
Bootstrapped: bootstrapped,
}
},
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/utxo/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestVerifySpendUTXOs(t *testing.T) {
require.NoError(t, fx.Bootstrapped())

h := &handler{
ctx: snow.DefaultContextTest(),
ctx: snowtest.EmptyContext(),
clk: &mockable.Clock{},
fx: fx,
}
Expand Down
3 changes: 2 additions & 1 deletion vms/proposervm/batched_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
Expand Down Expand Up @@ -1084,7 +1085,7 @@ func initTestRemoteProposerVM(
}, nil
}

ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
ctx.NodeID = ids.NodeIDFromCert(pTestCert)
ctx.ValidatorState = valState

Expand Down
3 changes: 2 additions & 1 deletion vms/proposervm/state_syncable_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/vms/proposervm/summary"

statelessblock "github.com/ava-labs/avalanchego/vms/proposervm/block"
Expand Down Expand Up @@ -81,7 +82,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) {
},
)

ctx := snow.DefaultContextTest()
ctx := snowtest.EmptyContext()
ctx.NodeID = ids.NodeIDFromCert(pTestCert)

require.NoError(vm.Initialize(
Expand Down
Loading
Loading