-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615d0fe
commit f32ee4d
Showing
6 changed files
with
127 additions
and
23 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,27 @@ | ||
package service | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/streamingfast/bstream" | ||
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1" | ||
) | ||
|
||
func sortClocksDistributor(clockDistributor map[uint64]*pbsubstreams.Clock) (sortedClockDistributor []*pbsubstreams.Clock) { | ||
sortedClockDistributor = make([]*pbsubstreams.Clock, 0, len(clockDistributor)) | ||
for _, clock := range clockDistributor { | ||
sortedClockDistributor = append(sortedClockDistributor, clock) | ||
} | ||
|
||
sort.Slice(sortedClockDistributor, func(i, j int) bool { return sortedClockDistributor[i].Number < sortedClockDistributor[j].Number }) | ||
return | ||
} | ||
|
||
func irreversibleCursorFromClock(clock *pbsubstreams.Clock) *bstream.Cursor { | ||
return &bstream.Cursor{ | ||
Step: bstream.StepNewIrreversible, | ||
Block: bstream.NewBlockRef(clock.Id, clock.Number), | ||
LIB: bstream.NewBlockRef(clock.Id, clock.Number), | ||
HeadBlock: bstream.NewBlockRef(clock.Id, clock.Number), | ||
} | ||
} |
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,37 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
|
||
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1" | ||
"github.com/test-go/testify/require" | ||
) | ||
|
||
func TestSortClocksDistributor(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
clocksMap map[uint64]*pbsubstreams.Clock | ||
expectedResult []*pbsubstreams.Clock | ||
}{ | ||
{ | ||
name: "sunny path", | ||
clocksMap: map[uint64]*pbsubstreams.Clock{ | ||
2: {Number: 2, Id: "test2"}, | ||
3: {Number: 3, Id: "test3"}, | ||
1: {Number: 1, Id: "test1"}, | ||
}, | ||
expectedResult: []*pbsubstreams.Clock{ | ||
{Number: 1, Id: "test1"}, | ||
{Number: 2, Id: "test2"}, | ||
{Number: 3, Id: "test3"}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
result := sortClocksDistributor(c.clocksMap) | ||
require.Equal(t, c.expectedResult, result) | ||
}) | ||
} | ||
} |
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,36 @@ | ||
package execout | ||
|
||
import ( | ||
"testing" | ||
|
||
pboutput "github.com/streamingfast/substreams/storage/execout/pb" | ||
|
||
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestExtractClocks(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
file File | ||
clocksDistributor map[uint64]*pbsubstreams.Clock | ||
expectedResult map[uint64]*pbsubstreams.Clock | ||
}{ | ||
{ | ||
name: "sunny path", | ||
file: File{ | ||
ModuleName: "sunny_path", | ||
kv: map[string]*pboutput.Item{"id1": {BlockNum: 1, BlockId: "1"}, "id2": {BlockNum: 2, BlockId: "3"}}, | ||
}, | ||
clocksDistributor: map[uint64]*pbsubstreams.Clock{}, | ||
expectedResult: map[uint64]*pbsubstreams.Clock{1: {Number: 1, Id: "1"}, 2: {Number: 2, Id: "3"}}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
c.file.ExtractClocks(c.clocksDistributor) | ||
require.Equal(t, c.expectedResult, c.clocksDistributor) | ||
}) | ||
} | ||
} |