Skip to content

Commit e66a8d4

Browse files
committed
test relayer reward redemption
addresses review comment #139 (comment)
1 parent cb00351 commit e66a8d4

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

tests/add_fee_amount.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ func AddFeeAmount(network network.Network) {
100100
subnetAInfo.TeleporterMessenger.CheckRelayerRewardAmount(&bind.CallOpts{}, fundedAddress, mockTokenAddress)
101101
Expect(err).Should(BeNil())
102102
Expect(amount).Should(Equal(additionalFeeAmount.Add(additionalFeeAmount, initFeeAmount)))
103+
104+
utils.RedeemRelayerRewardsAndConfirm(
105+
ctx, subnetAInfo, mockToken, mockTokenAddress, fundedKey, amount,
106+
)
103107
}

tests/basic_send_receive.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/Teleporter/TeleporterMessenger"
99
"github.com/ava-labs/teleporter/tests/network"
1010
"github.com/ava-labs/teleporter/tests/utils"
11+
localUtils "github.com/ava-labs/teleporter/tests/utils/local-network-utils"
1112
"github.com/ethereum/go-ethereum/common"
1213
. "github.com/onsi/gomega"
1314
)
@@ -25,19 +26,36 @@ func BasicSendReceive(network network.Network) {
2526
subnets := network.GetSubnetsInfo()
2627
subnetAInfo := subnets[0]
2728
subnetBInfo := subnets[1]
29+
teleporterContractAddress := network.GetTeleporterContractAddress()
2830
fundedAddress, fundedKey := network.GetFundedAccountInfo()
2931

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

37+
feeAmount := big.NewInt(1)
38+
feeTokenAddress, feeToken := localUtils.DeployExampleERC20(
39+
ctx,
40+
fundedKey,
41+
subnetAInfo,
42+
)
43+
localUtils.ExampleERC20Approve(
44+
ctx,
45+
feeToken,
46+
teleporterContractAddress,
47+
big.NewInt(0).Mul(big.NewInt(1e18),
48+
big.NewInt(10)),
49+
subnetAInfo,
50+
fundedKey,
51+
)
52+
3553
sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{
3654
DestinationChainID: subnetBInfo.BlockchainID,
3755
DestinationAddress: fundedAddress,
3856
FeeInfo: teleportermessenger.TeleporterFeeInfo{
39-
FeeTokenAddress: fundedAddress,
40-
Amount: big.NewInt(0),
57+
FeeTokenAddress: feeTokenAddress,
58+
Amount: feeAmount,
4159
},
4260
RequiredGasLimit: big.NewInt(1),
4361
AllowedRelayerAddresses: []common.Address{},
@@ -71,7 +89,9 @@ func BasicSendReceive(network network.Network) {
7189
//
7290
// Send a transaction to Subnet B to issue a Warp Message from the Teleporter contract to Subnet A
7391
//
92+
7493
sendCrossChainMessageInput.DestinationChainID = subnetAInfo.BlockchainID
94+
sendCrossChainMessageInput.FeeInfo.Amount = big.NewInt(0)
7595
receipt, teleporterMessageID = utils.SendCrossChainMessageAndWaitForAcceptance(
7696
ctx,
7797
subnetBInfo,
@@ -94,4 +114,8 @@ func BasicSendReceive(network network.Network) {
94114
)
95115
Expect(err).Should(BeNil())
96116
Expect(delivered).Should(BeTrue())
117+
118+
utils.RedeemRelayerRewardsAndConfirm(
119+
ctx, subnetAInfo, feeToken, feeTokenAddress, fundedKey, feeAmount,
120+
)
97121
}

tests/utils/utils.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/ava-labs/subnet-evm/params"
2121
predicateutils "github.com/ava-labs/subnet-evm/predicate"
2222
"github.com/ava-labs/subnet-evm/x/warp"
23+
exampleerc20 "github.com/ava-labs/teleporter/abi-bindings/go/Mocks/ExampleERC20"
2324
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/Teleporter/TeleporterMessenger"
2425
gasUtils "github.com/ava-labs/teleporter/utils/gas-utils"
2526
"github.com/ethereum/go-ethereum/common"
@@ -159,6 +160,49 @@ func RetryMessageExecutionAndWaitForAcceptance(
159160
return receipt
160161
}
161162

163+
func RedeemRelayerRewardsAndConfirm(
164+
ctx context.Context,
165+
subnet SubnetTestInfo,
166+
feeToken *exampleerc20.ExampleERC20,
167+
feeTokenAddress common.Address,
168+
relayerKey *ecdsa.PrivateKey,
169+
expectedAmount *big.Int,
170+
) *types.Receipt {
171+
relayerAddress := crypto.PubkeyToAddress(relayerKey.PublicKey)
172+
173+
balanceBeforeRedemption, err := feeToken.BalanceOf(
174+
&bind.CallOpts{}, relayerAddress,
175+
)
176+
Expect(err).Should(BeNil())
177+
178+
tx_opts, err := bind.NewKeyedTransactorWithChainID(
179+
relayerKey, subnet.ChainIDInt,
180+
)
181+
Expect(err).Should(BeNil())
182+
transaction, err := subnet.TeleporterMessenger.RedeemRelayerRewards(
183+
tx_opts, feeTokenAddress,
184+
)
185+
Expect(err).Should(BeNil())
186+
receipt, err := bind.WaitMined(ctx, subnet.ChainRPCClient, transaction)
187+
Expect(err).Should(BeNil())
188+
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
189+
190+
balanceAfterRedemption, err := feeToken.BalanceOf(
191+
&bind.CallOpts{}, relayerAddress,
192+
)
193+
Expect(err).Should(BeNil())
194+
195+
Expect(balanceAfterRedemption).Should(
196+
Equal(
197+
big.NewInt(0).Add(
198+
balanceBeforeRedemption, expectedAmount,
199+
),
200+
),
201+
)
202+
203+
return receipt
204+
}
205+
162206
func SendSpecifiedReceiptsAndWaitForAcceptance(
163207
ctx context.Context,
164208
originChainID ids.ID,

0 commit comments

Comments
 (0)