Skip to content

Commit

Permalink
Merge pull request #4593 from onflow/petera/fix-execution-data-proto-…
Browse files Browse the repository at this point in the history
…conversion
  • Loading branch information
peterargue authored Aug 2, 2023
2 parents cc1eac5 + e74c055 commit 6ece1c3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions engine/common/rpc/convert/execution_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func TrieUpdateToMessage(t *ledger.TrieUpdate) (*entities.TrieUpdate, error) {
}

paths := make([][]byte, len(t.Paths))
for i, path := range t.Paths {
paths[i] = path[:]
for i := range t.Paths {
paths[i] = t.Paths[i][:]
}

payloads := make([]*entities.Payload, len(t.Payloads))
Expand Down
18 changes: 16 additions & 2 deletions engine/common/rpc/convert/execution_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/onflow/flow-go/engine/common/rpc/convert"
"github.com/onflow/flow-go/ledger/common/testutils"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/executiondatasync/execution_data"
"github.com/onflow/flow-go/utils/unittest"
)

func TestConvertBlockExecutionData1(t *testing.T) {
func TestConvertBlockExecutionData(t *testing.T) {
t.Parallel()

chain := flow.Testnet.Chain() // this is used by the AddressFixture
Expand All @@ -21,7 +22,12 @@ func TestConvertBlockExecutionData1(t *testing.T) {
chunks := 5
chunkData := make([]*execution_data.ChunkExecutionData, 0, chunks)
for i := 0; i < chunks-1; i++ {
chunkData = append(chunkData, unittest.ChunkExecutionDataFixture(t, execution_data.DefaultMaxBlobSize/5, unittest.WithChunkEvents(events)))
ced := unittest.ChunkExecutionDataFixture(t,
0, // updates set explicitly to target 160-320KB per chunk
unittest.WithChunkEvents(events),
unittest.WithTrieUpdate(testutils.TrieUpdateFixture(5, 32*1024, 64*1024)),
)
chunkData = append(chunkData, ced)
}
makeServiceTx := func(ced *execution_data.ChunkExecutionData) {
// proposal key and payer are empty addresses for service tx
Expand All @@ -46,6 +52,7 @@ func TestConvertBlockExecutionData1(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, chunkData[0], chunkReConverted)
assert.True(t, chunkData[0].TrieUpdate.Equals(chunkReConverted.TrieUpdate))
})

t.Run("block execution data conversions", func(t *testing.T) {
Expand All @@ -56,5 +63,12 @@ func TestConvertBlockExecutionData1(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, blockData, converted)
for i, chunk := range blockData.ChunkExecutionDatas {
if chunk.TrieUpdate == nil {
assert.Nil(t, converted.ChunkExecutionDatas[i].TrieUpdate)
} else {
assert.True(t, chunk.TrieUpdate.Equals(converted.ChunkExecutionDatas[i].TrieUpdate))
}
}
})
}
8 changes: 7 additions & 1 deletion utils/unittest/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2472,12 +2472,18 @@ func WithChunkEvents(events flow.EventsList) func(*execution_data.ChunkExecution
}
}

func WithTrieUpdate(trieUpdate *ledger.TrieUpdate) func(*execution_data.ChunkExecutionData) {
return func(conf *execution_data.ChunkExecutionData) {
conf.TrieUpdate = trieUpdate
}
}

func ChunkExecutionDataFixture(t *testing.T, minSize int, opts ...func(*execution_data.ChunkExecutionData)) *execution_data.ChunkExecutionData {
collection := CollectionFixture(5)
ced := &execution_data.ChunkExecutionData{
Collection: &collection,
Events: flow.EventsList{},
TrieUpdate: testutils.TrieUpdateFixture(1, 1, 8),
TrieUpdate: testutils.TrieUpdateFixture(2, 1, 8),
}

for _, opt := range opts {
Expand Down

0 comments on commit 6ece1c3

Please sign in to comment.