Skip to content

Commit

Permalink
Merge pull request #462 from ava-labs/gstuart/test-fix-2
Browse files Browse the repository at this point in the history
E2E flaky test fix
  • Loading branch information
geoff-vball authored Jul 31, 2024
2 parents e9b5f51 + 7a89b56 commit c032a58
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 28 deletions.
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
}
28 changes: 18 additions & 10 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 All @@ -463,8 +470,9 @@ 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))
var newValidatorNodes []*tmpnet.Node
newValidatorNodes = append(newValidatorNodes, n.extraNodes[0:count]...)
n.extraNodes = n.extraNodes[count:]

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

0 comments on commit c032a58

Please sign in to comment.