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

E2E flaky test fix #462

Merged
merged 7 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 19 additions & 9 deletions tests/flows/teleporter_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
subnetBInfo,
newTeleporterAddress,
fundedKey,
offchainMessageB)
offchainMessageB,
)

// Send a message using old Teleporter version to test messenger using new Teleporter version.
// Message should be received successfully since we haven't updated mininum Teleporter version yet.
Expand All @@ -99,7 +100,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
testMessengerB,
fundedKey,
"message_1",
true)
true,
)

// Update minimum Teleporter version on destination chain
opts, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetBInfo.EVMChainID)
Expand All @@ -117,7 +119,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
// Verify that minTeleporterVersion updated
minTeleporterVersionUpdatedEvent, err := utils.GetEventFromLogs(
receipt.Logs,
testMessengerB.ParseMinTeleporterVersionUpdated)
testMessengerB.ParseMinTeleporterVersionUpdated,
)
Expect(err).Should(BeNil())
Expect(minTeleporterVersionUpdatedEvent.OldMinTeleporterVersion.Cmp(minTeleporterVersion)).Should(Equal(0))
Expect(minTeleporterVersionUpdatedEvent.NewMinTeleporterVersion.Cmp(latestVersionB)).Should(Equal(0))
Expand All @@ -134,12 +137,14 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
testMessengerB,
fundedKey,
"message_2",
false)
false,
)

// Update the subnets to use new Teleporter messengers
network.SetTeleporterContractAddress(newTeleporterAddress)
cChainInfo = network.GetPrimaryNetworkInfo()
subnetAInfo, subnetBInfo = utils.GetTwoSubnets(network)

utils.SendExampleCrossChainMessageAndVerify(
ctx,
network,
Expand All @@ -150,7 +155,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
testMessengerC,
fundedKey,
"message_3",
false)
false,
)

// Call addProtocolVersion on subnetA to register the new Teleporter version
utils.AddProtocolVersionAndWaitForAcceptance(
Expand All @@ -159,11 +165,13 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
cChainInfo,
newTeleporterAddress,
fundedKey,
offchainMessageC)
offchainMessageC,
)

// Send a message from A->B, which previously failed, but now using the new Teleporter version.
// Teleporter versions should match, so message should be received successfully.
utils.SendExampleCrossChainMessageAndVerify(ctx,
utils.SendExampleCrossChainMessageAndVerify(
ctx,
network,
subnetBInfo,
testMessengerB,
Expand All @@ -172,7 +180,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
testMessengerC,
fundedKey,
"message_4",
true)
true,
)

// To make sure all subnets are using the same Teleporter version, call addProtocolVersion on subnetA
// to register the new Teleporter version
Expand All @@ -182,7 +191,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
subnetAInfo,
newTeleporterAddress,
fundedKey,
offchainMessageA)
offchainMessageA,
)

latestVersionA, err := subnetAInfo.TeleporterRegistry.LatestVersion(&bind.CallOpts{})
Expect(err).Should(BeNil())
Expand Down
3 changes: 2 additions & 1 deletion tests/interfaces/local_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type LocalNetwork interface {
deployerAddress common.Address,
contractAddress common.Address,
fundedKey *ecdsa.PrivateKey,
updateNetworkTeleporter bool)
updateNetworkTeleporter bool,
)
GetNetworkID() uint32
Dir() string
}
25 changes: 16 additions & 9 deletions tests/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"os"
"slices"
"sort"
"time"

"github.com/ava-labs/avalanchego/api/info"
Expand Down Expand Up @@ -44,7 +45,7 @@ type LocalNetwork struct {
primaryNetworkInfo *interfaces.SubnetTestInfo
subnetsInfo map[ids.ID]*interfaces.SubnetTestInfo

extraNodes []*tmpnet.Node // to add as more subnet vaidators in the tests
extraNodes []*tmpnet.Node // to add as more subnet validators in the tests

globalFundedKey *ecdsa.PrivateKey

Expand Down Expand Up @@ -90,7 +91,8 @@ func NewLocalNetwork(
Expect(err).Should(BeNil())
warpChainConfigPath := f.Name()

allNodes := extraNodes // to be appended w/ subnet validators
var allNodes []*tmpnet.Node
allNodes = append(allNodes, extraNodes...) // to be appended w/ subnet validators

var subnets []*tmpnet.Subnet
for _, subnetSpec := range subnetSpecs {
Expand Down Expand Up @@ -140,7 +142,7 @@ func NewLocalNetwork(
setupProposerVM(ctx, globalFundedKey, network, subnet.SubnetID)
}

res := &LocalNetwork{
localNetwork := &LocalNetwork{
primaryNetworkInfo: &interfaces.SubnetTestInfo{},
subnetsInfo: make(map[ids.ID]*interfaces.SubnetTestInfo),
extraNodes: extraNodes,
Expand All @@ -149,10 +151,10 @@ func NewLocalNetwork(
warpChainConfigPath: warpChainConfigPath,
}
for _, subnet := range network.Subnets {
res.setSubnetValues(subnet)
localNetwork.setSubnetValues(subnet)
}
res.setPrimaryNetworkValues()
return res
localNetwork.setPrimaryNetworkValues()
return localNetwork
}

// Should be called after setSubnetValues for all subnets
Expand Down Expand Up @@ -331,17 +333,22 @@ func (n *LocalNetwork) DeployTeleporterRegistryContracts(

log.Info("Deployed TeleporterRegistry contract",
"subnet", subnetInfo.SubnetID.Hex(),
"address", teleporterRegistryAddress.Hex())
"address", teleporterRegistryAddress.Hex(),
)
}

log.Info("Deployed TeleporterRegistry contracts to all subnets")
}

// Returns all subnet info sorted in lexicographic order of SubnetName.
func (n *LocalNetwork) GetSubnetsInfo() []interfaces.SubnetTestInfo {
subnetsInfo := make([]interfaces.SubnetTestInfo, 0, len(n.subnetsInfo))
for _, subnetInfo := range n.subnetsInfo {
subnetsInfo = append(subnetsInfo, *subnetInfo)
}
sort.Slice(subnetsInfo, func(i, j int) bool {
return subnetsInfo[i].SubnetName < subnetsInfo[j].SubnetName
})
return subnetsInfo
}

Expand Down Expand Up @@ -436,7 +443,7 @@ func (n *LocalNetwork) setAllSubnetValues() {
for _, subnetInfo := range n.subnetsInfo {
subnet := n.tmpnet.GetSubnet(subnetInfo.SubnetName)
Expect(subnet).ShouldNot(BeNil())
n.setSubnetValues(n.tmpnet.GetSubnet(subnetInfo.SubnetName))
n.setSubnetValues(subnet)
}

n.setPrimaryNetworkValues()
Expand Down Expand Up @@ -464,7 +471,7 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID,

// consume some of the extraNodes
newValidatorNodes := n.extraNodes[0:count]
defer slices.Delete(n.extraNodes, 0, int(count))
copy(n.extraNodes, n.extraNodes[count:])
Copy link
Contributor

Choose a reason for hiding this comment

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

This will still preserve the nodes to be deleted in n.extraNodes, since n.extraNodes[count:] is a subset. See example here: https://go.dev/play/p/z8RhPp136sr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by copying the newValidatorNodes from extraNodes and then just assigning extraNodes to the subset.


apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0])
Expect(err).Should(BeNil())
Expand Down
26 changes: 18 additions & 8 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func SendAddFeeAmountAndWaitForAcceptance(
transactor *teleportermessenger.TeleporterMessenger,
) *types.Receipt {
opts, err := bind.NewKeyedTransactorWithChainID(
senderKey, source.EVMChainID)
senderKey,
source.EVMChainID,
)
Expect(err).Should(BeNil())

tx, err := transactor.AddFeeAmount(opts, messageID, feeContractAddress, amount)
Expand All @@ -85,7 +87,8 @@ func SendAddFeeAmountAndWaitForAcceptance(
log.Info("Send AddFeeAmount transaction on source chain",
"messageID", messageID,
"sourceChainID", source.BlockchainID,
"destinationBlockchainID", destination.BlockchainID)
"destinationBlockchainID", destination.BlockchainID,
)

return receipt
}
Expand Down Expand Up @@ -900,7 +903,9 @@ func DeployTestMessenger(
subnet interfaces.SubnetTestInfo,
) (common.Address, *testmessenger.TestMessenger) {
opts, err := bind.NewKeyedTransactorWithChainID(
senderKey, subnet.EVMChainID)
senderKey,
subnet.EVMChainID,
)
Expect(err).Should(BeNil())
address, tx, exampleMessenger, err := testmessenger.DeployTestMessenger(
opts,
Expand Down Expand Up @@ -1004,7 +1009,8 @@ func SendExampleCrossChainMessageAndVerify(
// Check that message execution failed
messageExecutionFailedEvent, err := GetEventFromLogs(
receipt.Logs,
destination.TeleporterMessenger.ParseMessageExecutionFailed)
destination.TeleporterMessenger.ParseMessageExecutionFailed,
)
Expect(err).Should(BeNil())
Expect(messageExecutionFailedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:]))
}
Expand Down Expand Up @@ -1036,7 +1042,8 @@ func InitOffChainMessageChainConfig(
})
log.Info("Adding off-chain message to Warp chain config",
"messageID", unsignedMessage.ID(),
"blockchainID", subnet.BlockchainID.String())
"blockchainID", subnet.BlockchainID.String(),
)

return unsignedMessage, GetChainConfigWithOffChainMessages([]avalancheWarp.UnsignedMessage{*unsignedMessage})
}
Expand All @@ -1057,7 +1064,8 @@ func CreateOffChainRegistryMessage(
unsignedMessage, err := avalancheWarp.NewUnsignedMessage(
networkID,
subnet.BlockchainID,
addressedPayload.Bytes())
addressedPayload.Bytes(),
)
Expect(err).Should(BeNil())

return unsignedMessage
Expand Down Expand Up @@ -1097,7 +1105,8 @@ func CreateOffChainValidatorSetSigMessage(
unsignedMessage, err := avalancheWarp.NewUnsignedMessage(
networkID,
subnet.BlockchainID,
addressedPayload.Bytes())
addressedPayload.Bytes(),
)
Expect(err).Should(BeNil())

return unsignedMessage
Expand Down Expand Up @@ -1127,7 +1136,8 @@ func DeployNewTeleporterVersion(
teleporterDeployerAddress,
teleporterContractAddress,
fundedKey,
false)
false,
)
return teleporterContractAddress
}

Expand Down