-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1fe1dd
commit 96b58b4
Showing
2 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
50 changes: 41 additions & 9 deletions
50
go-utils/abi-bindings/Teleporter/TeleporterMessenger/packing.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
go-utils/abi-bindings/Teleporter/TeleporterMessenger/packing_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package teleportermessenger | ||
|
||
import ( | ||
"bytes" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func testTeleporterMessage(messageID int64) TeleporterMessage { | ||
m := TeleporterMessage{ | ||
MessageID: big.NewInt(messageID), | ||
SenderAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"), | ||
DestinationAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"), | ||
RequiredGasLimit: big.NewInt(2), | ||
AllowedRelayerAddresses: []common.Address{ | ||
common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"), | ||
}, | ||
Receipts: []TeleporterMessageReceipt{ | ||
{ | ||
ReceivedMessageID: big.NewInt(1), | ||
RelayerRewardAddress: common.HexToAddress("0x0123456789abcdef0123456789abcdef01234567"), | ||
}, | ||
}, | ||
Message: []byte{1, 2, 3, 4}, | ||
} | ||
return m | ||
} | ||
|
||
func TestPackUnpackTeleporterMessage(t *testing.T) { | ||
var ( | ||
messageID int64 = 4 | ||
) | ||
message := testTeleporterMessage(messageID) | ||
|
||
b, err := PackSendCrossChainMessageEvent(common.HexToHash("0x03"), message) | ||
if err != nil { | ||
t.Errorf("failed to pack teleporter message: %v", err) | ||
t.FailNow() | ||
} | ||
|
||
unpacked, err := UnpackTeleporterMessage(b) | ||
if err != nil { | ||
t.Errorf("failed to unpack teleporter message: %v", err) | ||
t.FailNow() | ||
} | ||
|
||
for i := 0; i < len(message.AllowedRelayerAddresses); i++ { | ||
require.Equal(t, unpacked.AllowedRelayerAddresses[i], message.AllowedRelayerAddresses[i]) | ||
} | ||
|
||
for i := 0; i < len(message.Receipts); i++ { | ||
require.Equal(t, message.Receipts[i].ReceivedMessageID, unpacked.Receipts[i].ReceivedMessageID) | ||
require.Equal(t, message.Receipts[i].RelayerRewardAddress, unpacked.Receipts[i].RelayerRewardAddress) | ||
} | ||
|
||
require.True(t, bytes.Equal(message.Message, unpacked.Message)) | ||
} |