-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make packet commitments fixed length (#7564)
* make packet commitments fixed length * updated docs for packet commits
- Loading branch information
1 parent
a2d377c
commit 107ab75
Showing
3 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
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
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,58 @@ | ||
package types_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" | ||
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" | ||
) | ||
|
||
// TestCommitPacket is primarily used to document the expected commitment output | ||
// so that other implementations (such as the IBC Solidity) can replicate the | ||
// same commitment output. But it is also useful to catch any changes in the commitment. | ||
func TestCommitPacket(t *testing.T) { | ||
transferData, err := json.Marshal(transfertypes.FungibleTokenPacketData{ | ||
Denom: "uatom", | ||
Amount: "1000000", | ||
Sender: "sender", | ||
Receiver: "receiver", | ||
Memo: "memo", | ||
}) | ||
require.NoError(t, err) | ||
packet := types.Packet{ | ||
Sequence: 1, | ||
SourceChannel: "channel-0", | ||
DestinationChannel: "channel-1", | ||
TimeoutTimestamp: 100, | ||
Payloads: []types.Payload{ | ||
{ | ||
SourcePort: transfertypes.PortID, | ||
DestinationPort: transfertypes.PortID, | ||
Version: transfertypes.V1, | ||
Encoding: "application/json", | ||
Value: transferData, | ||
}, | ||
}, | ||
} | ||
commitment := types.CommitPacket(packet) | ||
require.Equal(t, "450194f2ce25b12487f65593e106d91367a1e5c90b2efc03ed78265a54cfcebe", hex.EncodeToString(commitment)) | ||
require.Len(t, commitment, 32) | ||
} | ||
|
||
// TestCommitAcknowledgement is primarily used to document the expected commitment output | ||
// so that other implementations (such as the IBC Solidity) can replicate the | ||
// same commitment output. But it is also useful to catch any changes in the commitment. | ||
func TestCommitAcknowledgement(t *testing.T) { | ||
ack := types.Acknowledgement{ | ||
AppAcknowledgements: [][]byte{ | ||
[]byte("some bytes"), | ||
}, | ||
} | ||
|
||
commitment := types.CommitAcknowledgement(ack) | ||
require.Equal(t, "f03b4667413e56aaf086663267913e525c442b56fa1af4fa3f3dab9f37044c5b", hex.EncodeToString(commitment)) | ||
} |
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,34 @@ | ||
package v2_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" | ||
) | ||
|
||
// TestPacketCommitmentKey is primarily used to document the expected key output | ||
// so that other implementations (such as the IBC Solidity) can replicate the | ||
// same key output. But it is also useful to catch any changes in the keys. | ||
func TestPacketCommitmentKey(t *testing.T) { | ||
actual := hex.EncodeToString(v2.PacketCommitmentKey("channel-0", 1)) | ||
require.Equal(t, "6368616e6e656c2d30010000000000000001", actual) | ||
} | ||
|
||
// TestPacketReceiptKey is primarily used to document the expected key output | ||
// so that other implementations (such as the IBC Solidity) can replicate the | ||
// same key output. But it is also useful to catch any changes in the keys. | ||
func TestPacketReceiptKey(t *testing.T) { | ||
actual := hex.EncodeToString(v2.PacketReceiptKey("channel-0", 1)) | ||
require.Equal(t, "6368616e6e656c2d30020000000000000001", actual) | ||
} | ||
|
||
// TestPacketAcknowledgementKey is primarily used to document the expected key output | ||
// so that other implementations (such as the IBC Solidity) can replicate the | ||
// same key output. But it is also useful to catch any changes in the keys. | ||
func TestPacketAcknowledgementKey(t *testing.T) { | ||
actual := hex.EncodeToString(v2.PacketAcknowledgementKey("channel-0", 1)) | ||
require.Equal(t, "6368616e6e656c2d30030000000000000001", actual) | ||
} |