Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Oct 14, 2024
1 parent c12941b commit 75ecd7c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 27 deletions.
14 changes: 12 additions & 2 deletions tests/flows/teleporter/add_fee_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ func AddFeeAmount(network interfaces.Network, teleporter utils.TeleporterTestInf
)

// Relay message from Subnet A to Subnet B
deliveryReceipt := teleporter.RelayTeleporterMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true, fundedKey)
deliveryReceipt := teleporter.RelayTeleporterMessage(
ctx,
sendCrossChainMsgReceipt,
subnetAInfo,
subnetBInfo,
true,
fundedKey,
)
receiveEvent, err := utils.GetEventFromLogs(
deliveryReceipt.Logs,
teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage)
Expand Down Expand Up @@ -108,7 +115,10 @@ func AddFeeAmount(network interfaces.Network, teleporter utils.TeleporterTestInf
teleporter.RelayTeleporterMessage(ctx, sendSpecificReceiptsReceipt, subnetBInfo, subnetAInfo, true, fundedKey)

// Check message delivered
delivered, err = teleporter.TeleporterMessenger(subnetAInfo).MessageReceived(&bind.CallOpts{}, sendSpecificReceiptsMessageID)
delivered, err = teleporter.TeleporterMessenger(subnetAInfo).MessageReceived(
&bind.CallOpts{},
sendSpecificReceiptsMessageID,
)
Expect(err).Should(BeNil())
Expect(delivered).Should(BeTrue())

Expand Down
5 changes: 4 additions & 1 deletion tests/flows/teleporter/deliver_to_nonexistent_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func DeliverToNonExistentContract(network interfaces.Network, teleporter utils.T
// Wait for the transaction to be mined
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx.Hash())

sendEvent, err := utils.GetEventFromLogs(receipt.Logs, teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage)
sendEvent, err := utils.GetEventFromLogs(
receipt.Logs,
teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage,
)
Expect(err).Should(BeNil())
Expect(sendEvent.DestinationBlockchainID[:]).Should(Equal(subnetBInfo.BlockchainID[:]))

Expand Down
10 changes: 8 additions & 2 deletions tests/flows/teleporter/insufficient_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func InsufficientGas(network interfaces.Network, teleporter utils.TeleporterTest
// Wait for the transaction to be mined
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx.Hash())

event, err := utils.GetEventFromLogs(receipt.Logs, teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage)
event, err := utils.GetEventFromLogs(
receipt.Logs,
teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage,
)
Expect(err).Should(BeNil())
Expect(event.DestinationBlockchainID[:]).Should(Equal(subnetBInfo.BlockchainID[:]))

Expand Down Expand Up @@ -79,7 +82,10 @@ func InsufficientGas(network interfaces.Network, teleporter utils.TeleporterTest
failedMessageExecutionEvent.Message,
fundedKey,
)
executedEvent, err := utils.GetEventFromLogs(receipt.Logs, teleporter.TeleporterMessenger(subnetBInfo).ParseMessageExecuted)
executedEvent, err := utils.GetEventFromLogs(
receipt.Logs,
teleporter.TeleporterMessenger(subnetBInfo).ParseMessageExecuted,
)
Expect(err).Should(BeNil())
Expect(executedEvent.MessageID[:]).Should(Equal(messageID[:]))
Expect(executedEvent.SourceBlockchainID[:]).Should(Equal(subnetAInfo.BlockchainID[:]))
Expand Down
5 changes: 4 additions & 1 deletion tests/flows/teleporter/relayer_modifies_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func relayAlteredMessage(
network interfaces.LocalNetwork,
) {
// Fetch the Teleporter message from the logs
sendEvent, err := utils.GetEventFromLogs(sourceReceipt.Logs, teleporter.TeleporterMessenger(source).ParseSendCrossChainMessage)
sendEvent, err := utils.GetEventFromLogs(
sourceReceipt.Logs,
teleporter.TeleporterMessenger(source).ParseSendCrossChainMessage,
)
Expect(err).Should(BeNil())

signedWarpMessage := utils.ConstructSignedWarpMessage(ctx, sourceReceipt, source, destination)
Expand Down
5 changes: 4 additions & 1 deletion tests/flows/teleporter/resubmit_altered_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func ResubmitAlteredMessage(network interfaces.Network, teleporter utils.Telepor
Expect(delivered).Should(BeTrue())

// Get the Teleporter message from receive event
event, err := utils.GetEventFromLogs(receipt.Logs, teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage)
event, err := utils.GetEventFromLogs(
receipt.Logs,
teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage,
)
Expect(err).Should(BeNil())
Expect(event.MessageID[:]).Should(Equal(messageID[:]))
teleporterMessage := event.Message
Expand Down
12 changes: 9 additions & 3 deletions tests/flows/teleporter/retry_successful_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func RetrySuccessfulExecution(network interfaces.Network, teleporter utils.Telep
// Wait for the transaction to be mined
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx.Hash())

event, err := utils.GetEventFromLogs(receipt.Logs, teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage)
event, err := utils.GetEventFromLogs(
receipt.Logs,
teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage,
)
Expect(err).Should(BeNil())
Expect(event.DestinationBlockchainID[:]).Should(Equal(subnetBInfo.BlockchainID[:]))

Expand Down Expand Up @@ -92,8 +95,11 @@ func RetrySuccessfulExecution(network interfaces.Network, teleporter utils.Telep
//
optsB, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetBInfo.EVMChainID)
Expect(err).Should(BeNil())
tx, err =
teleporter.TeleporterMessenger(subnetBInfo).RetryMessageExecution(optsB, subnetAInfo.BlockchainID, deliveredTeleporterMessage)
tx, err = teleporter.TeleporterMessenger(subnetBInfo).RetryMessageExecution(
optsB,
subnetAInfo.BlockchainID,
deliveredTeleporterMessage,
)
Expect(err).Should(Not(BeNil()))
Expect(tx).Should(BeNil())
}
36 changes: 32 additions & 4 deletions tests/flows/teleporter/send_specific_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte
ctx, teleporter.TeleporterMessenger(subnetAInfo), subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedKey)

// Relay the message from SubnetA to SubnetB
deliveryReceipt1 := teleporter.RelayTeleporterMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true, fundedKey)
deliveryReceipt1 := teleporter.RelayTeleporterMessage(
ctx,
sendCrossChainMsgReceipt,
subnetAInfo,
subnetBInfo,
true,
fundedKey,
)
receiveEvent1, err := utils.GetEventFromLogs(
deliveryReceipt1.Logs,
teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage)
Expand All @@ -81,7 +88,14 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte
ctx, teleporter.TeleporterMessenger(subnetAInfo), subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedKey)

// Relay the message from SubnetA to SubnetB
deliveryReceipt2 := teleporter.RelayTeleporterMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true, fundedKey)
deliveryReceipt2 := teleporter.RelayTeleporterMessage(
ctx,
sendCrossChainMsgReceipt,
subnetAInfo,
subnetBInfo,
true,
fundedKey,
)
receiveEvent2, err := utils.GetEventFromLogs(
deliveryReceipt2.Logs,
teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage)
Expand Down Expand Up @@ -123,7 +137,14 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte
// Check the reward amounts.
// Even on external networks, the relayer should only have the expected fee amount
// for this asset because the asset contract was newly deployed by this test.
checkExpectedRewardAmounts(teleporter, subnetAInfo, receiveEvent1, receiveEvent2, mockTokenAddress, relayerFeePerMessage)
checkExpectedRewardAmounts(
teleporter,
subnetAInfo,
receiveEvent1,
receiveEvent2,
mockTokenAddress,
relayerFeePerMessage,
)

// If the network is internal to the test application, send a message from Subnet B to Subnet A to trigger
// the "regular" method of delivering receipts. The next message from B->A will contain the same receipts
Expand Down Expand Up @@ -181,7 +202,14 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte
receiveEvent.Message.Receipts)).Should(BeTrue())

// Check the reward amount remains the same
checkExpectedRewardAmounts(teleporter, subnetAInfo, receiveEvent1, receiveEvent2, mockTokenAddress, relayerFeePerMessage)
checkExpectedRewardAmounts(
teleporter,
subnetAInfo,
receiveEvent1,
receiveEvent2,
mockTokenAddress,
relayerFeePerMessage,
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/flows/teleporter/validator_churn.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func ValidatorChurn(network interfaces.LocalNetwork, teleporter utils.Teleporter
fundedKey,
)

sendEvent, err := utils.GetEventFromLogs(receipt.Logs, teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage)
sendEvent, err := utils.GetEventFromLogs(
receipt.Logs,
teleporter.TeleporterMessenger(subnetAInfo).ParseSendCrossChainMessage,
)
Expect(err).Should(BeNil())
sentTeleporterMessage := sendEvent.Message

Expand Down
1 change: 0 additions & 1 deletion tests/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ func (n *LocalNetwork) setPrimaryNetworkValues() {
n.primaryNetworkInfo.WSClient = chainWSClient
n.primaryNetworkInfo.RPCClient = chainRPCClient
n.primaryNetworkInfo.EVMChainID = chainIDInt

}

func (n *LocalNetwork) setSubnetValues(subnet *tmpnet.Subnet) {
Expand Down
46 changes: 35 additions & 11 deletions tests/utils/teleporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ func NewTeleporterTestInfo(subnets []interfaces.SubnetTestInfo) TeleporterTestIn
return t
}

func (t TeleporterTestInfo) TeleporterMessenger(subnet interfaces.SubnetTestInfo) *teleportermessenger.TeleporterMessenger {
func (t TeleporterTestInfo) TeleporterMessenger(
subnet interfaces.SubnetTestInfo,
) *teleportermessenger.TeleporterMessenger {
return t[subnet.BlockchainID].TeleporterMessenger
}

func (t TeleporterTestInfo) TeleporterMessengerAddress(subnet interfaces.SubnetTestInfo) common.Address {
return t[subnet.BlockchainID].TeleporterMessengerAddress
}

func (t TeleporterTestInfo) TeleporterRegistry(subnet interfaces.SubnetTestInfo) *teleporterregistry.TeleporterRegistry {
func (t TeleporterTestInfo) TeleporterRegistry(
subnet interfaces.SubnetTestInfo,
) *teleporterregistry.TeleporterRegistry {
return t[subnet.BlockchainID].TeleporterRegistry
}

Expand Down Expand Up @@ -428,12 +432,18 @@ func AddProtocolVersionAndWaitForAcceptance(

// Wait for tx to be accepted, and verify events emitted
receipt := SendTransactionAndWaitForSuccess(ctx, subnet, signedTx)
addProtocolVersionEvent, err := GetEventFromLogs(receipt.Logs, sourceTeleporterInfo.TeleporterRegistry.ParseAddProtocolVersion)
addProtocolVersionEvent, err := GetEventFromLogs(
receipt.Logs,
sourceTeleporterInfo.TeleporterRegistry.ParseAddProtocolVersion,
)
Expect(err).Should(BeNil())
Expect(addProtocolVersionEvent.Version.Cmp(expectedLatestVersion)).Should(Equal(0))
Expect(addProtocolVersionEvent.ProtocolAddress).Should(Equal(newTeleporterAddress))

versionUpdatedEvent, err := GetEventFromLogs(receipt.Logs, sourceTeleporterInfo.TeleporterRegistry.ParseLatestVersionUpdated)
versionUpdatedEvent, err := GetEventFromLogs(
receipt.Logs,
sourceTeleporterInfo.TeleporterRegistry.ParseLatestVersionUpdated,
)
Expect(err).Should(BeNil())
Expect(versionUpdatedEvent.OldVersion.Cmp(curLatestVersion)).Should(Equal(0))
Expect(versionUpdatedEvent.NewVersion.Cmp(expectedLatestVersion)).Should(Equal(0))
Expand Down Expand Up @@ -519,12 +529,18 @@ func ClearReceiptQueue(
// Relay message
teleporterInfo.RelayTeleporterMessage(ctx, receipt, source, destination, true, fundedKey)

outstandReceiptCount = GetOutstandingReceiptCount(teleporterInfo.TeleporterMessenger(source), destination.BlockchainID)
outstandReceiptCount = GetOutstandingReceiptCount(
teleporterInfo.TeleporterMessenger(source),
destination.BlockchainID,
)
}
log.Info("Receipt queue emptied")
}

func GetOutstandingReceiptCount(teleporterMessenger *teleportermessenger.TeleporterMessenger, destinationBlockchainID ids.ID) *big.Int {
func GetOutstandingReceiptCount(
teleporterMessenger *teleportermessenger.TeleporterMessenger,
destinationBlockchainID ids.ID,
) *big.Int {
size, err := teleporterMessenger.GetReceiptQueueSize(&bind.CallOpts{}, destinationBlockchainID)
Expect(err).Should(BeNil())
return size
Expand Down Expand Up @@ -581,7 +597,10 @@ func SendExampleCrossChainMessageAndVerify(

if expectSuccess {
// Check that message execution was successful
messageExecutedEvent, err := GetEventFromLogs(receipt.Logs, teleporterInfo.TeleporterMessenger(destination).ParseMessageExecuted)
messageExecutedEvent, err := GetEventFromLogs(
receipt.Logs,
teleporterInfo.TeleporterMessenger(destination).ParseMessageExecuted,
)
Expect(err).Should(BeNil())
Expect(messageExecutedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:]))
} else {
Expand Down Expand Up @@ -764,10 +783,15 @@ func InitOffChainMessageChainConfig(
teleporterAddress common.Address,
version uint64,
) (*avalancheWarp.UnsignedMessage, string) {
unsignedMessage := CreateOffChainRegistryMessage(networkID, subnet, registryAddress, teleporterregistry.ProtocolRegistryEntry{
Version: big.NewInt(int64(version)),
ProtocolAddress: teleporterAddress,
})
unsignedMessage := CreateOffChainRegistryMessage(
networkID,
subnet,
registryAddress,
teleporterregistry.ProtocolRegistryEntry{
Version: big.NewInt(int64(version)),
ProtocolAddress: teleporterAddress,
},
)
log.Info("Adding off-chain message to Warp chain config",
"messageID", unsignedMessage.ID(),
"blockchainID", subnet.BlockchainID.String(),
Expand Down

0 comments on commit 75ecd7c

Please sign in to comment.