Skip to content

Commit

Permalink
fix commit structure to 32 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Nov 14, 2024
1 parent 6df2e94 commit 8756074
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/core/04-channel/v2/types/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func CommitAcknowledgement(acknowledgement Acknowledgement) []byte {
buf = append(buf, hash[:]...)
}

buf = append([]byte{byte(2)}, buf...)

hash := sha256.Sum256(buf)
return append([]byte{byte(2)}, hash[:]...)
return hash[:]
}
16 changes: 16 additions & 0 deletions modules/core/04-channel/v2/types/commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,19 @@ func TestCommitPacket(t *testing.T) {

require.Len(t, commitment, 32)
}

func TestCommitAcknowledgement(t *testing.T) {
ack := types.Acknowledgement{
AcknowledgementResults: []types.AcknowledgementResult{
{
AppName: "doesntmatter",
RecvPacketResult: types.RecvPacketResult{
Status: 0, // doesnt matter
Acknowledgement: []byte("some bytes"),
},
},
},
}
commitment := types.CommitAcknowledgement(ack)
require.Equal(t, "f03b4667413e56aaf086663267913e525c442b56fa1af4fa3f3dab9f37044c5b", hex.EncodeToString(commitment))
}
24 changes: 24 additions & 0 deletions modules/core/24-host/v2/packet_keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v2_test

import (
"encoding/hex"
"testing"

v2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2"
"github.com/stretchr/testify/require"
)

func TestPacketCommitmentKey(t *testing.T) {
actual := hex.EncodeToString(v2.PacketCommitmentKey("channel-0", 1))
require.Equal(t, "6368616e6e656c2d30010000000000000001", actual)
}

func TestPacketReceiptKey(t *testing.T) {
actual := hex.EncodeToString(v2.PacketReceiptKey("channel-0", 1))
require.Equal(t, "6368616e6e656c2d30020000000000000001", actual)
}

func TestPacketAcknowledgementKey(t *testing.T) {
actual := hex.EncodeToString(v2.PacketAcknowledgementKey("channel-0", 1))
require.Equal(t, "6368616e6e656c2d30030000000000000001", actual)
}

0 comments on commit 8756074

Please sign in to comment.