|
| 1 | +//go:build all || unit |
| 2 | + |
| 3 | +package hiero |
| 4 | + |
| 5 | +// SPDX-License-Identifier: Apache-2.0 |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/hiero-ledger/hiero-sdk-go/v2/proto/services" |
| 11 | + "github.com/stretchr/testify/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestUnitContractLogInfo_ProtobufRoundTrip(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + |
| 17 | + logInfo := ContractLogInfo{ |
| 18 | + ContractID: ContractID{Contract: 7}, |
| 19 | + Bloom: []byte{1, 2, 3}, |
| 20 | + Topics: [][]byte{{4, 5}, {6, 7, 8}}, |
| 21 | + Data: []byte{9, 10, 11}, |
| 22 | + } |
| 23 | + |
| 24 | + actual := _ContractLogInfoFromProtobuf(logInfo._ToProtobuf()) |
| 25 | + |
| 26 | + assert.Equal(t, logInfo, actual) |
| 27 | +} |
| 28 | + |
| 29 | +func TestUnitContractLogInfo_FromProtobufNil(t *testing.T) { |
| 30 | + t.Parallel() |
| 31 | + |
| 32 | + assert.Equal(t, ContractLogInfo{}, _ContractLogInfoFromProtobuf(nil)) |
| 33 | +} |
| 34 | + |
| 35 | +func TestUnitContractLogInfo_FromProtobufNilContractID(t *testing.T) { |
| 36 | + t.Parallel() |
| 37 | + |
| 38 | + pb := &services.ContractLoginfo{ |
| 39 | + ContractID: nil, |
| 40 | + Bloom: []byte{1, 2, 3}, |
| 41 | + Topic: [][]byte{{4, 5}, {6}}, |
| 42 | + Data: []byte{7, 8}, |
| 43 | + } |
| 44 | + |
| 45 | + actual := _ContractLogInfoFromProtobuf(pb) |
| 46 | + |
| 47 | + assert.Equal(t, ContractID{}, actual.ContractID) |
| 48 | + assert.Equal(t, []byte{1, 2, 3}, actual.Bloom) |
| 49 | + assert.Equal(t, [][]byte{{4, 5}, {6}}, actual.Topics) |
| 50 | + assert.Equal(t, []byte{7, 8}, actual.Data) |
| 51 | +} |
| 52 | + |
| 53 | +func TestUnitContractLogInfo_EmptyTopicsRoundTrip(t *testing.T) { |
| 54 | + t.Parallel() |
| 55 | + |
| 56 | + logInfo := ContractLogInfo{ |
| 57 | + ContractID: ContractID{Contract: 9}, |
| 58 | + Bloom: []byte{1}, |
| 59 | + Topics: [][]byte{}, |
| 60 | + Data: []byte{2}, |
| 61 | + } |
| 62 | + |
| 63 | + actual := _ContractLogInfoFromProtobuf(logInfo._ToProtobuf()) |
| 64 | + |
| 65 | + assert.NotNil(t, actual.Topics) |
| 66 | + assert.Equal(t, 0, len(actual.Topics)) |
| 67 | + assert.Equal(t, logInfo, actual) |
| 68 | +} |
0 commit comments