Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: use avalanchego new *test packages #620

Merged
merged 7 commits into from
Aug 6, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.12

require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/ava-labs/avalanchego v1.11.10-prerelease
github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.10-prerelease h1:QUhVqvxrwDmsTvXXnKoePe5WU3Eh8GXB/QE2R2xHa0c=
github.com/ava-labs/avalanchego v1.11.10-prerelease/go.mod h1:ryRFbHr7sKmez4792NxzJS7AGiE+vd0Tez+qs2kmezE=
github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef h1:w0N/YXgNoXjDUwdFHGpWYq41uHxvBneHaJ+X0BxSj2w=
github.com/ava-labs/avalanchego v1.11.11-0.20240805141503-7e985b530bef/go.mod h1:9e0UPXJboybmgFjeTj+SFbK4ugbrdG4t68VdiUW5oQ8=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
3 changes: 2 additions & 1 deletion peer/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/enginetest"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -510,7 +511,7 @@ func TestHandleInvalidMessages(t *testing.T) {

nodeID := ids.GenerateTestNodeID()
requestID := uint32(1)
sender := &common.SenderTest{
sender := &enginetest.Sender{
SendAppErrorF: func(context.Context, ids.NodeID, uint32, int32, string) error {
return nil
},
Expand Down
5 changes: 3 additions & 2 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
commonEng "github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/enginetest"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/set"
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
test.expectedErr = nil

syncDisabledVM := &VM{}
appSender := &commonEng.SenderTest{T: t}
appSender := &enginetest.Sender{T: t}
appSender.SendAppGossipF = func(context.Context, commonEng.SendConfig, []byte) error { return nil }
appSender.SendAppRequestF = func(ctx context.Context, nodeSet set.Set[ids.NodeID], requestID uint32, request []byte) error {
nodeID, hasItem := nodeSet.Pop()
Expand Down Expand Up @@ -421,7 +422,7 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest, numBlocks int) *s
// off of a server VM.
type syncVMSetup struct {
serverVM *VM
serverAppSender *commonEng.SenderTest
serverAppSender *enginetest.Sender

includedAtomicTxs []*Tx
fundedAccounts map[*keystore.Key]*types.StateAccount
Expand Down
36 changes: 19 additions & 17 deletions plugin/evm/tx_gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"github.com/ava-labs/avalanchego/proto/pb/sdk"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/enginetest"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
agoUtils "github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/logging"
Expand All @@ -41,7 +43,7 @@ func TestEthTxGossip(t *testing.T) {
require := require.New(t)
ctx := context.Background()
snowCtx := utils.TestSnowContext()
validatorState := &validators.TestState{}
validatorState := &validatorstest.State{}
snowCtx.ValidatorState = validatorState

pk, err := secp256k1.NewPrivateKey()
Expand All @@ -51,7 +53,7 @@ func TestEthTxGossip(t *testing.T) {
genesisBytes, err := genesis.MarshalJSON()
require.NoError(err)

responseSender := &common.FakeSender{
responseSender := &enginetest.SenderStub{
SentAppResponse: make(chan []byte, 1),
}
vm := &VM{
Expand All @@ -69,7 +71,7 @@ func TestEthTxGossip(t *testing.T) {
nil,
make(chan common.Message),
nil,
&common.SenderTest{},
&enginetest.Sender{},
))
require.NoError(vm.SetState(ctx, snow.NormalOp))

Expand All @@ -78,7 +80,7 @@ func TestEthTxGossip(t *testing.T) {
}()

// sender for the peer requesting gossip from [vm]
peerSender := &common.FakeSender{
peerSender := &enginetest.SenderStub{
SentAppRequest: make(chan []byte, 1),
}

Expand Down Expand Up @@ -168,7 +170,7 @@ func TestAtomicTxGossip(t *testing.T) {
snowCtx := utils.TestSnowContext()
snowCtx.AVAXAssetID = ids.GenerateTestID()
snowCtx.XChainID = ids.GenerateTestID()
validatorState := &validators.TestState{
validatorState := &validatorstest.State{
GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) {
return ids.Empty, nil
},
Expand All @@ -184,7 +186,7 @@ func TestAtomicTxGossip(t *testing.T) {
genesisBytes, err := genesis.MarshalJSON()
require.NoError(err)

responseSender := &common.FakeSender{
responseSender := &enginetest.SenderStub{
SentAppResponse: make(chan []byte, 1),
}
vm := &VM{
Expand All @@ -202,7 +204,7 @@ func TestAtomicTxGossip(t *testing.T) {
nil,
make(chan common.Message),
nil,
&common.SenderTest{},
&enginetest.Sender{},
))
require.NoError(vm.SetState(ctx, snow.NormalOp))

Expand All @@ -211,7 +213,7 @@ func TestAtomicTxGossip(t *testing.T) {
}()

// sender for the peer requesting gossip from [vm]
peerSender := &common.FakeSender{
peerSender := &enginetest.SenderStub{
SentAppRequest: make(chan []byte, 1),
}
network, err := p2p.NewNetwork(logging.NoLog{}, peerSender, prometheus.NewRegistry(), "")
Expand Down Expand Up @@ -306,15 +308,15 @@ func TestEthTxPushGossipOutbound(t *testing.T) {
require := require.New(t)
ctx := context.Background()
snowCtx := utils.TestSnowContext()
snowCtx.ValidatorState = &validators.TestState{
snowCtx.ValidatorState = &validatorstest.State{
GetCurrentHeightF: func(context.Context) (uint64, error) {
return 0, nil
},
GetValidatorSetF: func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
return nil, nil
},
}
sender := &common.FakeSender{
sender := &enginetest.SenderStub{
SentAppGossip: make(chan []byte, 1),
}

Expand Down Expand Up @@ -377,7 +379,7 @@ func TestEthTxPushGossipInbound(t *testing.T) {
ctx := context.Background()
snowCtx := utils.TestSnowContext()

sender := &common.SenderTest{}
sender := &enginetest.Sender{}
vm := &VM{
p2pSender: sender,
ethTxPullGossiper: gossip.NoOpGossiper{},
Expand Down Expand Up @@ -439,7 +441,7 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) {
snowCtx := utils.TestSnowContext()
snowCtx.AVAXAssetID = ids.GenerateTestID()
snowCtx.XChainID = ids.GenerateTestID()
validatorState := &validators.TestState{
validatorState := &validatorstest.State{
GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) {
return ids.Empty, nil
},
Expand All @@ -455,7 +457,7 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) {
genesisBytes, err := genesis.MarshalJSON()
require.NoError(err)

sender := &common.FakeSender{
sender := &enginetest.SenderStub{
SentAppGossip: make(chan []byte, 1),
}
vm := &VM{
Expand All @@ -473,7 +475,7 @@ func TestAtomicTxPushGossipOutbound(t *testing.T) {
nil,
make(chan common.Message),
nil,
&common.FakeSender{},
&enginetest.SenderStub{},
))
require.NoError(vm.SetState(ctx, snow.NormalOp))

Expand Down Expand Up @@ -517,7 +519,7 @@ func TestAtomicTxPushGossipInbound(t *testing.T) {
snowCtx := utils.TestSnowContext()
snowCtx.AVAXAssetID = ids.GenerateTestID()
snowCtx.XChainID = ids.GenerateTestID()
validatorState := &validators.TestState{
validatorState := &validatorstest.State{
GetSubnetIDF: func(context.Context, ids.ID) (ids.ID, error) {
return ids.Empty, nil
},
Expand All @@ -533,7 +535,7 @@ func TestAtomicTxPushGossipInbound(t *testing.T) {
genesisBytes, err := genesis.MarshalJSON()
require.NoError(err)

sender := &common.SenderTest{}
sender := &enginetest.Sender{}
vm := &VM{
p2pSender: sender,
ethTxPullGossiper: gossip.NoOpGossiper{},
Expand All @@ -549,7 +551,7 @@ func TestAtomicTxPushGossipInbound(t *testing.T) {
nil,
make(chan common.Message),
nil,
&common.FakeSender{},
&enginetest.SenderStub{},
))
require.NoError(vm.SetState(ctx, snow.NormalOp))

Expand Down
23 changes: 13 additions & 10 deletions plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/utils/cb58"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
Expand All @@ -56,6 +56,7 @@ import (
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

commonEng "github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/enginetest"
constantsEng "github.com/ava-labs/avalanchego/utils/constants"

"github.com/ava-labs/coreth/consensus/dummy"
Expand Down Expand Up @@ -216,7 +217,7 @@ func NewContext() *snow.Context {
_ = aliaser.Alias(testCChainID, testCChainID.String())
_ = aliaser.Alias(testXChainID, "X")
_ = aliaser.Alias(testXChainID, testXChainID.String())
ctx.ValidatorState = &validators.TestState{
ctx.ValidatorState = &validatorstest.State{
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
subnetID, ok := map[ids.ID]ids.ID{
constantsEng.PlatformChainID: constantsEng.PrimaryNetworkID,
Expand Down Expand Up @@ -285,10 +286,11 @@ func GenesisVM(t *testing.T,
genesisJSON string,
configJSON string,
upgradeJSON string,
) (chan commonEng.Message,
) (
chan commonEng.Message,
*VM, database.Database,
*atomic.Memory,
*commonEng.SenderTest,
*enginetest.Sender,
) {
return GenesisVMWithClock(t, finishBootstrapping, genesisJSON, configJSON, upgradeJSON, mockable.Clock{})
}
Expand All @@ -302,15 +304,16 @@ func GenesisVMWithClock(
configJSON string,
upgradeJSON string,
clock mockable.Clock,
) (chan commonEng.Message,
) (
chan commonEng.Message,
*VM, database.Database,
*atomic.Memory,
*commonEng.SenderTest,
*enginetest.Sender,
) {
vm := &VM{clock: clock}
vm.p2pSender = &commonEng.FakeSender{}
vm.p2pSender = &enginetest.SenderStub{}
ctx, dbManager, genesisBytes, issuer, m := setupGenesis(t, genesisJSON)
appSender := &commonEng.SenderTest{T: t}
appSender := &enginetest.Sender{T: t}
appSender.CantSendAppGossip = true
appSender.SendAppGossipF = func(context.Context, commonEng.SendConfig, []byte) error { return nil }
err := vm.Initialize(
Expand Down Expand Up @@ -372,7 +375,7 @@ func addUTXO(sharedMemory *atomic.Memory, ctx *snow.Context, txID ids.ID, index
// GenesisVMWithUTXOs creates a GenesisVM and generates UTXOs in the X-Chain Shared Memory containing AVAX based on the [utxos] map
// Generates UTXOIDs by using a hash of the address in the [utxos] map such that the UTXOs will be generated deterministically.
// If [genesisJSON] is empty, defaults to using [genesisJSONLatest]
func GenesisVMWithUTXOs(t *testing.T, finishBootstrapping bool, genesisJSON string, configJSON string, upgradeJSON string, utxos map[ids.ShortID]uint64) (chan commonEng.Message, *VM, database.Database, *atomic.Memory, *commonEng.SenderTest) {
func GenesisVMWithUTXOs(t *testing.T, finishBootstrapping bool, genesisJSON string, configJSON string, upgradeJSON string, utxos map[ids.ShortID]uint64) (chan commonEng.Message, *VM, database.Database, *atomic.Memory, *enginetest.Sender) {
issuer, vm, db, sharedMemory, sender := GenesisVM(t, finishBootstrapping, genesisJSON, configJSON, upgradeJSON)
for addr, avaxAmount := range utxos {
txID, err := ids.ToID(hashing.ComputeHash256(addr.Bytes()))
Expand Down Expand Up @@ -3298,7 +3301,7 @@ func TestConfigureLogLevel(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
vm := &VM{}
ctx, dbManager, genesisBytes, issuer, _ := setupGenesis(t, test.genesisJSON)
appSender := &commonEng.SenderTest{T: t}
appSender := &enginetest.Sender{T: t}
appSender.CantSendAppGossip = true
appSender.SendAppGossipF = func(context.Context, commonEng.SendConfig, []byte) error { return nil }
err := vm.Initialize(
Expand Down
5 changes: 3 additions & 2 deletions plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/set"
Expand Down Expand Up @@ -262,7 +263,7 @@ func testWarpVMTransaction(t *testing.T, unsignedMessage *avalancheWarp.Unsigned
minimumValidPChainHeight := uint64(10)
getValidatorSetTestErr := errors.New("can't get validator set test error")

vm.ctx.ValidatorState = &validators.TestState{
vm.ctx.ValidatorState = &validatorstest.State{
// TODO: test both Primary Network / C-Chain and non-Primary Network
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
return ids.Empty, nil
Expand Down Expand Up @@ -425,7 +426,7 @@ func TestReceiveWarpMessage(t *testing.T) {
minimumValidPChainHeight := uint64(10)
getValidatorSetTestErr := errors.New("can't get validator set test error")

vm.ctx.ValidatorState = &validators.TestState{
vm.ctx.ValidatorState = &validatorstest.State{
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
return ids.Empty, nil
},
Expand Down
7 changes: 4 additions & 3 deletions precompile/contracts/warp/predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/snow/validators/validatorstest"
agoUtils "github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand Down Expand Up @@ -197,7 +198,7 @@ func createSnowCtx(validatorRanges []validatorRange) *snow.Context {
}

snowCtx := utils.TestSnowContext()
state := &validators.TestState{
state := &validatorstest.State{
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
return sourceSubnetID, nil
},
Expand Down Expand Up @@ -266,7 +267,7 @@ func TestWarpMessageFromPrimaryNetwork(t *testing.T) {
snowCtx.ChainID = ids.GenerateTestID()
snowCtx.CChainID = cChainID
snowCtx.NetworkID = networkID
snowCtx.ValidatorState = &validators.TestState{
snowCtx.ValidatorState = &validatorstest.State{
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
require.Equal(chainID, cChainID)
return constants.PrimaryNetworkID, nil // Return Primary Network SubnetID
Expand Down Expand Up @@ -666,7 +667,7 @@ func initWarpPredicateTests() {

snowCtx := utils.TestSnowContext()
snowCtx.NetworkID = networkID
state := &validators.TestState{
state := &validatorstest.State{
GetSubnetIDF: func(ctx context.Context, chainID ids.ID) (ids.ID, error) {
return sourceSubnetID, nil
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
set -euo pipefail

# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.11.10-prerelease'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'7e985b530beff5afe03967f5fa94a2eee998cb7a'}
4 changes: 2 additions & 2 deletions utils/snow.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"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/snow/validators/validatorstest"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
)
Expand All @@ -28,6 +28,6 @@ func TestSnowContext() *snow.Context {
BCLookup: ids.NewAliaser(),
Metrics: metrics.NewMultiGatherer(),
ChainDataDir: "",
ValidatorState: &validators.TestState{},
ValidatorState: &validatorstest.State{},
}
}
Loading