-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6744 from onflow/jord/6622-chunk-service-events
Chunk Data Model supports per-chunk service event mapping
- Loading branch information
Showing
13 changed files
with
713 additions
and
48 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
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,81 @@ | ||
package execution | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/onflow/flow-go/utils/slices" | ||
"github.com/onflow/flow-go/utils/unittest" | ||
) | ||
|
||
// makeBlockExecutionResultFixture makes a BlockExecutionResult fixture | ||
// with the specified allocation of service events to chunks. | ||
func makeBlockExecutionResultFixture(serviceEventsPerChunk []int) *BlockExecutionResult { | ||
fixture := new(BlockExecutionResult) | ||
for _, nServiceEvents := range serviceEventsPerChunk { | ||
fixture.collectionExecutionResults = append(fixture.collectionExecutionResults, | ||
CollectionExecutionResult{ | ||
serviceEvents: unittest.EventsFixture(nServiceEvents), | ||
convertedServiceEvents: unittest.ServiceEventsFixture(nServiceEvents), | ||
}) | ||
} | ||
return fixture | ||
} | ||
|
||
// Tests that ServiceEventCountForChunk method works as expected under various circumstances: | ||
func TestBlockExecutionResult_ServiceEventCountForChunk(t *testing.T) { | ||
t.Run("no service events", func(t *testing.T) { | ||
nChunks := rand.Intn(10) + 1 // always contains at least system chunk | ||
blockResult := makeBlockExecutionResultFixture(make([]int, nChunks)) | ||
// all chunks should have 0 service event count | ||
for chunkIndex := 0; chunkIndex < nChunks; chunkIndex++ { | ||
count := blockResult.ServiceEventCountForChunk(chunkIndex) | ||
assert.Equal(t, uint16(0), count) | ||
} | ||
}) | ||
t.Run("service events only in system chunk", func(t *testing.T) { | ||
nChunks := rand.Intn(10) + 2 // at least 2 chunks | ||
// add between 1 and 10 service events, all in the system chunk | ||
serviceEventAllocation := make([]int, nChunks) | ||
nServiceEvents := rand.Intn(10) + 1 | ||
serviceEventAllocation[nChunks-1] = nServiceEvents | ||
|
||
blockResult := makeBlockExecutionResultFixture(serviceEventAllocation) | ||
// all non-system chunks should have zero service event count | ||
for chunkIndex := 0; chunkIndex < nChunks-1; chunkIndex++ { | ||
count := blockResult.ServiceEventCountForChunk(chunkIndex) | ||
assert.Equal(t, uint16(0), count) | ||
} | ||
// the system chunk should contain all service events | ||
assert.Equal(t, uint16(nServiceEvents), blockResult.ServiceEventCountForChunk(nChunks-1)) | ||
}) | ||
t.Run("service events only outside system chunk", func(t *testing.T) { | ||
nChunks := rand.Intn(10) + 2 // at least 2 chunks | ||
// add 1 service event to all non-system chunks | ||
serviceEventAllocation := slices.Fill(1, nChunks) | ||
serviceEventAllocation[nChunks-1] = 0 | ||
|
||
blockResult := makeBlockExecutionResultFixture(serviceEventAllocation) | ||
// all non-system chunks should have 1 service event | ||
for chunkIndex := 0; chunkIndex < nChunks-1; chunkIndex++ { | ||
count := blockResult.ServiceEventCountForChunk(chunkIndex) | ||
assert.Equal(t, uint16(1), count) | ||
} | ||
// the system chunk service event count should include all service events | ||
assert.Equal(t, uint16(0), blockResult.ServiceEventCountForChunk(nChunks-1)) | ||
}) | ||
t.Run("service events in both system chunk and other chunks", func(t *testing.T) { | ||
nChunks := rand.Intn(10) + 2 // at least 2 chunks | ||
// add 1 service event to all chunks (including system chunk) | ||
serviceEventAllocation := slices.Fill(1, nChunks) | ||
|
||
blockResult := makeBlockExecutionResultFixture(serviceEventAllocation) | ||
// all chunks should have service event count of 1 | ||
for chunkIndex := 0; chunkIndex < nChunks; chunkIndex++ { | ||
count := blockResult.ServiceEventCountForChunk(chunkIndex) | ||
assert.Equal(t, uint16(1), count) | ||
} | ||
}) | ||
} |
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,29 @@ | ||
package rlp_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/onflow/go-ethereum/rlp" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestRLPStructFieldOrder tests the field ordering property of RLP encoding. | ||
// It provides evidence that RLP encoding depends on struct field ordering. | ||
func TestRLPStructFieldOrder(t *testing.T) { | ||
a := struct { | ||
A uint32 // A first | ||
B uint32 | ||
}{A: 2, B: 3} | ||
|
||
b := struct { | ||
B uint32 // B first | ||
A uint32 | ||
}{A: 2, B: 3} | ||
|
||
abin, err := rlp.EncodeToBytes(a) | ||
require.NoError(t, err) | ||
bbin, err := rlp.EncodeToBytes(b) | ||
require.NoError(t, err) | ||
assert.NotEqual(t, abin, bbin) | ||
} |
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
Oops, something went wrong.