Skip to content

Commit

Permalink
Accept inputs for index module
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Mar 14, 2024
1 parent cf246c3 commit 58d6fee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 8 additions & 2 deletions manifest/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ func (r *manifestConverter) validateManifest(manif *Manifest) error {
return fmt.Errorf("stream %q: 'use' is not allowed for kind 'store'", s.Name)
}
case ModuleKindBlockIndex:
if s.Inputs != nil {
return fmt.Errorf("stream %q: block index module cannot have inputs", s.Name)
if s.Inputs == nil {
return fmt.Errorf("stream %q: block index module should have inputs", s.Name)
}

for _, input := range s.Inputs {
if input.IsParams() {
return fmt.Errorf("stream %q: block index module cannot have params input", s.Name)
}
}

if s.InitialBlock != nil {
Expand Down
24 changes: 17 additions & 7 deletions manifest/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestValidateManifest(t *testing.T) {
manifest: &Manifest{
SpecVersion: "v0.1.0",
Modules: []*Module{
{Name: "basic_index", Kind: "blockIndex", Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
{Name: "basic_index", Kind: "blockIndex", Inputs: []*Input{{Map: "proto:sf.database.v1.changes"}}, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
},
},
expectedError: "",
Expand All @@ -194,27 +194,37 @@ func TestValidateManifest(t *testing.T) {
manifest: &Manifest{
SpecVersion: "v0.1.0",
Modules: []*Module{
{Name: "basic_index", Kind: "blockIndex", Output: StreamOutput{"proto:sf.substreams.test"}},
{Name: "basic_index", Kind: "blockIndex", Inputs: []*Input{{Map: "proto:sf.database.v1.changes"}}, Output: StreamOutput{"proto:sf.substreams.test"}},
},
},
expectedError: "stream \"basic_index\": block index module must have output type 'proto:sf.substreams.index.v1.Keys'",
},
{
name: "block index with inputs",
name: "block index with params input",
manifest: &Manifest{
SpecVersion: "v0.1.0",
Modules: []*Module{
{Name: "basic_index", Kind: "blockIndex", Inputs: []*Input{{Source: "proto:sf.database.v1.changes"}}, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
{Name: "basic_index", Kind: "blockIndex", Inputs: []*Input{{Params: "proto:sf.database.v1.changes"}}, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
},
},
expectedError: "stream \"basic_index\": block index module cannot have params input",
},
{
name: "block index without input",
manifest: &Manifest{
SpecVersion: "v0.1.0",
Modules: []*Module{
{Name: "basic_index", Kind: "blockIndex", Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
},
},
expectedError: "stream \"basic_index\": block index module cannot have inputs",
expectedError: "stream \"basic_index\": block index module should have inputs",
},
{
name: "block index with initialBlock",
manifest: &Manifest{
SpecVersion: "v0.1.0",
Modules: []*Module{
{Name: "basic_index", Kind: "blockIndex", InitialBlock: &initialBlock, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
{Name: "basic_index", Kind: "blockIndex", Inputs: []*Input{{Map: "proto:sf.database.v1.changes"}}, InitialBlock: &initialBlock, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
},
},
expectedError: "stream \"basic_index\": block index module cannot have initial block",
Expand All @@ -227,7 +237,7 @@ func TestValidateManifest(t *testing.T) {
{Name: "basic_index", Kind: "blockIndex", BlockFilter: &BlockFilter{
Module: "my_module",
Query: "test query",
}, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
}, Inputs: []*Input{{Map: "proto:sf.database.v1.changes"}}, Output: StreamOutput{"proto:sf.substreams.index.v1.Keys"}},
},
},
expectedError: "stream \"basic_index\": block index module cannot have block filter",
Expand Down

0 comments on commit 58d6fee

Please sign in to comment.