Skip to content

Commit e6e5d87

Browse files
committed
Major refactor, listing important pieces:
- Conversation has now a generic type constraint on ConversationState, so some common state can be shared (this breaks the fact that converation should be agnostic, but make the overall work within codegen easier by sharing lot's of logic) - Added a BaseConversationState that everyone can embedded to gain much of the standard state management needed for a new codegen - Added Pre & Post shared flow that can be used by the various codegen - Improved sink choice flow to report instructions within the standard finish instructions - Improved Docker compose file render, now added to project standard files - UserLocalFile can now report the error that happened on the client, if any - Fixed a bunch of Rust warnings in generated code - Fixed NEAR hello world to actually work - Fixed Starknet Events to compile properly - Move integration to use testcontainers for easier Docker management
1 parent de0600d commit e6e5d87

174 files changed

Lines changed: 2179 additions & 10220 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ jobs:
5454
username: ${{ github.actor }}
5555
password: ${{ secrets.GITHUB_TOKEN }}
5656

57-
- name: Run Tests
58-
run: go test -v ./... -timeout 1800s
59-
6057
- name: Build
6158
run: go build ./...
59+
60+
- name: Run Tests
61+
run: go test -v ./... -timeout 1800s

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ Install reflex `go install github.com/cespare/reflex@latest` and do
1616
reflex -c .reflex
1717
```
1818

19+
### Integration Tests
20+
21+
Requires Docker, simply do:
22+
23+
```
24+
RUN_INTEGRATION_TESTS=true INTEGRATION_TESTS_IN_DOCKER=true go test ./tests -v -parallel 6
25+
```
26+
27+
You can try with higher value for parallel (controls how many tests runs in parallel). I had errors with the default value (`GOMAXPROCS`) and changing it to `-parallel 6` made it work properly.
28+
29+
It's possible to set `INTEGRATION_TESTS_IN_DOCKER=false` to run the tests on your machine directly, less recommended because this is not how the GitHub CI is configured, but should has a faster runtime.
30+
1931
## Principles
2032

2133
You write a `Conversation` (or `Convo` for short) struct.
Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
1-
package base
1+
package codegen
22

33
import (
44
"strings"
55

66
registry "github.com/pinax-network/graph-networks-libs/packages/golang/lib"
77
networks "github.com/streamingfast/firehose-networks"
8-
codegen "github.com/streamingfast/substreams-codegen"
98
)
109

11-
var _ codegen.ConversationState = (*ConversationState)(nil)
10+
var _ ConversationState = (*BaseConversationState)(nil)
1211

1312
// ConversationState implements common fields to implement the ConversationState interface
14-
type ConversationState struct {
13+
type BaseConversationState struct {
1514
Name string `json:"name"`
1615
// ChainName while named with `name` does contain actually the network registry chain ID.
1716
ChainName string `json:"chainName"`
17+
18+
// SubstreamsSinkChoice holds the user's choice of Substreams sink.
19+
SubstreamsSinkChoice *SubstreamsSinkChoice `json:"substreamsSinkChoice,omitempty"`
20+
}
21+
22+
func (p *BaseConversationState) GetSubstreamsSinkChoice() *SubstreamsSinkChoice {
23+
return p.SubstreamsSinkChoice
1824
}
1925

20-
func (p *ConversationState) IsValidChainInput(input string) bool {
21-
return networks.GetSubstreamsRegistry().Has(input)
26+
func (p *BaseConversationState) SetSubstreamsSinkChoice(choice SubstreamsSinkChoice) {
27+
p.SubstreamsSinkChoice = &choice
2228
}
2329

2430
// GetChainName implements codegen.ConversationState.
25-
func (p *ConversationState) GetChainName() string {
31+
func (p *BaseConversationState) GetChainName() string {
2632
return p.ChainName
2733
}
2834

35+
// SetChainName implements codegen.ConversationState.
36+
func (p *BaseConversationState) SetChainName(name string) {
37+
p.ChainName = name
38+
}
39+
40+
// SetProjectName implements ConversationState.
41+
func (p *BaseConversationState) SetProjectName(name string) {
42+
p.Name = name
43+
}
44+
2945
// GetModuleName implements codegen.ConversationState.
30-
func (p *ConversationState) GetModuleName() string {
46+
func (p *BaseConversationState) GetModuleName() string {
3147
return strings.ReplaceAll(p.Name, "-", "_")
3248
}
3349

50+
// Generate implements codegen.ConversationState, generate nothing by defaults for now.
51+
func (p *BaseConversationState) Generate() ReturnGenerate {
52+
return ReturnGenerate{
53+
Err: nil,
54+
ProjectFiles: make(map[string][]byte, 0),
55+
}
56+
}
57+
3458
// GetChainNetwork is a legacy name used in templates that returns the Substreams
3559
// value that should be put in the `network` field of the `substreams.yaml` file.
3660
// It uses the ChainName field to lookup the network in the registry and return
3761
// its FullName. If ChainName is empty or the config cannot be found, an empty
3862
// string is returned.
39-
func (p *ConversationState) GetChainNetwork() string {
63+
func (p *BaseConversationState) GetChainNetwork() string {
4064
if network := p.FindNetworkFromChainName(); network != nil {
4165
return network.ID
4266
}
@@ -46,17 +70,21 @@ func (p *ConversationState) GetChainNetwork() string {
4670
// GetChainNetwork returns the chain config from the registry based on the ChainName field.
4771
// If ChainName is empty, nil is returned right away, otherwise it attempts to find the config
4872
// in the registry by doing `networks.GetSubstreamsRegistry().Find(p.ChainName)`.
49-
func (p *ConversationState) FindNetworkFromChainName() *registry.Network {
73+
func (p *BaseConversationState) FindNetworkFromChainName() *registry.Network {
5074
if p.ChainName == "" {
5175
return nil
5276
}
5377

5478
return networks.GetSubstreamsRegistry().Find(p.ChainName)
5579
}
5680

81+
func (p *BaseConversationState) GetChainDisplayName() string {
82+
return p.ChainDisplayName()
83+
}
84+
5785
// ChainDisplayName returns the display name of the chain from the registry based on the ChainName field.
5886
// If ChainName is empty or the config cannot be found, an empty string is returned.
59-
func (p *ConversationState) ChainDisplayName() string {
87+
func (p *BaseConversationState) ChainDisplayName() string {
6088
if network := p.FindNetworkFromChainName(); network != nil {
6189
return network.FullName
6290
}
@@ -65,7 +93,7 @@ func (p *ConversationState) ChainDisplayName() string {
6593

6694
// ChainExplorerLink returns the explorer link of the chain from the registry based on the ChainName field.
6795
// If ChainName is empty or the config cannot be found, an empty string is returned.
68-
func (p *ConversationState) ChainExplorerLink() string {
96+
func (p *BaseConversationState) ChainExplorerLink() string {
6997
if network := p.FindNetworkFromChainName(); network != nil && len(network.ExplorerUrls) > 0 {
7098
return network.ExplorerUrls[0]
7199
}
@@ -74,9 +102,13 @@ func (p *ConversationState) ChainExplorerLink() string {
74102
}
75103

76104
// IsChainTestnet returns true if the chain is a testnet according to the registry information.
77-
func (p *ConversationState) IsChainTestnet() bool {
105+
func (p *BaseConversationState) IsChainTestnet() bool {
78106
if network := p.FindNetworkFromChainName(); network != nil {
79107
return network.NetworkType == registry.Testnet
80108
}
81109
return false
82110
}
111+
112+
func (c *BaseConversationState) IsValidChainInput(input string) bool {
113+
return networks.GetSubstreamsRegistry().Find(input) != nil
114+
}

chains/filter.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package chains
2+
3+
import (
4+
"regexp"
5+
6+
registry "github.com/pinax-network/graph-networks-libs/packages/golang/lib"
7+
networks "github.com/streamingfast/firehose-networks"
8+
)
9+
10+
var solanaNetworkRegexp = regexp.MustCompile(`^solana`)
11+
var nearNetworkRegexp = regexp.MustCompile(`^near`)
12+
var tronNetworkRegexp = regexp.MustCompile(`^tron`)
13+
var stellarNetworkRegexp = regexp.MustCompile(`^stellar`)
14+
15+
func SolanaNetworks() []*registry.Network {
16+
return excludeSolanaAccounts(networks.GetSubstreamsRegistry().Search(solanaNetworkRegexp))
17+
}
18+
19+
func NearNetworks() []*registry.Network {
20+
return networks.GetSubstreamsRegistry().Search(nearNetworkRegexp)
21+
}
22+
23+
func TronNetworks() []*registry.Network {
24+
return networks.GetSubstreamsRegistry().Search(tronNetworkRegexp)
25+
}
26+
27+
func StellarNetworks() []*registry.Network {
28+
return networks.GetSubstreamsRegistry().Search(stellarNetworkRegexp)
29+
}
30+
31+
func excludeSolanaAccounts(networks []*registry.Network) []*registry.Network {
32+
var filteredNetworks []*registry.Network
33+
for _, net := range networks {
34+
if net.ID == "solana-accounts" {
35+
continue
36+
}
37+
filteredNetworks = append(filteredNetworks, net)
38+
}
39+
return filteredNetworks
40+
}

0 commit comments

Comments
 (0)