Skip to content

Commit

Permalink
test relayer reward redemption
Browse files Browse the repository at this point in the history
addresses review comment #139 (comment)
  • Loading branch information
feuGeneA committed Nov 22, 2023
1 parent cb00351 commit e66a8d4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/add_fee_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ func AddFeeAmount(network network.Network) {
subnetAInfo.TeleporterMessenger.CheckRelayerRewardAmount(&bind.CallOpts{}, fundedAddress, mockTokenAddress)
Expect(err).Should(BeNil())
Expect(amount).Should(Equal(additionalFeeAmount.Add(additionalFeeAmount, initFeeAmount)))

utils.RedeemRelayerRewardsAndConfirm(
ctx, subnetAInfo, mockToken, mockTokenAddress, fundedKey, amount,
)
}
28 changes: 26 additions & 2 deletions tests/basic_send_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/Teleporter/TeleporterMessenger"
"github.com/ava-labs/teleporter/tests/network"
"github.com/ava-labs/teleporter/tests/utils"
localUtils "github.com/ava-labs/teleporter/tests/utils/local-network-utils"
"github.com/ethereum/go-ethereum/common"
. "github.com/onsi/gomega"
)
Expand All @@ -25,19 +26,36 @@ func BasicSendReceive(network network.Network) {
subnets := network.GetSubnetsInfo()
subnetAInfo := subnets[0]
subnetBInfo := subnets[1]
teleporterContractAddress := network.GetTeleporterContractAddress()
fundedAddress, fundedKey := network.GetFundedAccountInfo()

//
// Send a transaction to Subnet A to issue a Warp Message from the Teleporter contract to Subnet B
//
ctx := context.Background()

feeAmount := big.NewInt(1)
feeTokenAddress, feeToken := localUtils.DeployExampleERC20(
ctx,
fundedKey,
subnetAInfo,
)
localUtils.ExampleERC20Approve(
ctx,
feeToken,
teleporterContractAddress,
big.NewInt(0).Mul(big.NewInt(1e18),
big.NewInt(10)),
subnetAInfo,
fundedKey,
)

sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{
DestinationChainID: subnetBInfo.BlockchainID,
DestinationAddress: fundedAddress,
FeeInfo: teleportermessenger.TeleporterFeeInfo{
FeeTokenAddress: fundedAddress,
Amount: big.NewInt(0),
FeeTokenAddress: feeTokenAddress,
Amount: feeAmount,
},
RequiredGasLimit: big.NewInt(1),
AllowedRelayerAddresses: []common.Address{},
Expand Down Expand Up @@ -71,7 +89,9 @@ func BasicSendReceive(network network.Network) {
//
// Send a transaction to Subnet B to issue a Warp Message from the Teleporter contract to Subnet A
//

sendCrossChainMessageInput.DestinationChainID = subnetAInfo.BlockchainID
sendCrossChainMessageInput.FeeInfo.Amount = big.NewInt(0)
receipt, teleporterMessageID = utils.SendCrossChainMessageAndWaitForAcceptance(
ctx,
subnetBInfo,
Expand All @@ -94,4 +114,8 @@ func BasicSendReceive(network network.Network) {
)
Expect(err).Should(BeNil())
Expect(delivered).Should(BeTrue())

utils.RedeemRelayerRewardsAndConfirm(
ctx, subnetAInfo, feeToken, feeTokenAddress, fundedKey, feeAmount,
)
}
44 changes: 44 additions & 0 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/subnet-evm/params"
predicateutils "github.com/ava-labs/subnet-evm/predicate"
"github.com/ava-labs/subnet-evm/x/warp"
exampleerc20 "github.com/ava-labs/teleporter/abi-bindings/go/Mocks/ExampleERC20"
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/Teleporter/TeleporterMessenger"
gasUtils "github.com/ava-labs/teleporter/utils/gas-utils"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -159,6 +160,49 @@ func RetryMessageExecutionAndWaitForAcceptance(
return receipt
}

func RedeemRelayerRewardsAndConfirm(
ctx context.Context,
subnet SubnetTestInfo,
feeToken *exampleerc20.ExampleERC20,
feeTokenAddress common.Address,
relayerKey *ecdsa.PrivateKey,
expectedAmount *big.Int,
) *types.Receipt {
relayerAddress := crypto.PubkeyToAddress(relayerKey.PublicKey)

balanceBeforeRedemption, err := feeToken.BalanceOf(
&bind.CallOpts{}, relayerAddress,
)
Expect(err).Should(BeNil())

tx_opts, err := bind.NewKeyedTransactorWithChainID(
relayerKey, subnet.ChainIDInt,
)
Expect(err).Should(BeNil())
transaction, err := subnet.TeleporterMessenger.RedeemRelayerRewards(
tx_opts, feeTokenAddress,
)
Expect(err).Should(BeNil())
receipt, err := bind.WaitMined(ctx, subnet.ChainRPCClient, transaction)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))

balanceAfterRedemption, err := feeToken.BalanceOf(
&bind.CallOpts{}, relayerAddress,
)
Expect(err).Should(BeNil())

Expect(balanceAfterRedemption).Should(
Equal(
big.NewInt(0).Add(
balanceBeforeRedemption, expectedAmount,
),
),
)

return receipt
}

func SendSpecifiedReceiptsAndWaitForAcceptance(
ctx context.Context,
originChainID ids.ID,
Expand Down

0 comments on commit e66a8d4

Please sign in to comment.