-
Notifications
You must be signed in to change notification settings - Fork 509
[Feat] - Add dynamic chain config to template #1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ivokub
merged 10 commits into
Consensys:master
from
thedarkjester:feat/dynamic-chain-config
Jan 14, 2026
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1cb8a20
add dynamic chain config to template
thedarkjester 0020b9c
feat: expand templates with custom options
ivokub 68f676d
test: new Solidity backend options
ivokub f76d036
test: export testdata to check consistency
ivokub 5ec511f
fix: use value receiver
ivokub 5956e92
test: write testdata for contracts with options
ivokub 6e3da1d
test: add output check
ivokub c054e97
fix: ensure consistency
ivokub ed181bf
chore: move imports after pragma
ivokub 38416cb
test: fix fd handling
ivokub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,136 @@ | ||
| package solidity_test | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/consensys/gnark/backend/solidity" | ||
| ) | ||
|
|
||
| func TestSortedImports(t *testing.T) { | ||
| cfg, err := solidity.NewExportConfig( | ||
| solidity.WithImport(strings.NewReader(`import { B } from "b.sol";`)), | ||
| solidity.WithImport(strings.NewReader(`import { A } from "a.sol";`)), | ||
| solidity.WithImport(strings.NewReader(`import { C } from "c.sol";`)), | ||
| ) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| imports := cfg.SortedImports() | ||
| if len(imports) != 3 { | ||
| t.Fatalf("expected 3 imports, got %d", len(imports)) | ||
| } | ||
| if imports[0] != `import { A } from "a.sol";` { | ||
| t.Errorf("expected first import to be A, got %s", imports[0]) | ||
| } | ||
| if imports[1] != `import { B } from "b.sol";` { | ||
| t.Errorf("expected second import to be B, got %s", imports[1]) | ||
| } | ||
| if imports[2] != `import { C } from "c.sol";` { | ||
| t.Errorf("expected third import to be C, got %s", imports[2]) | ||
| } | ||
| } | ||
|
|
||
| func TestInterfaceDeclaration(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| interfaces []string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "no interfaces", | ||
| interfaces: nil, | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "single interface", | ||
| interfaces: []string{"IVerifier"}, | ||
| expected: " is IVerifier", | ||
| }, | ||
| { | ||
| name: "multiple interfaces", | ||
| interfaces: []string{"IVerifier", "IPlonk"}, | ||
| expected: " is IVerifier, IPlonk", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| opts := make([]solidity.ExportOption, 0, len(tt.interfaces)) | ||
| for _, iface := range tt.interfaces { | ||
| opts = append(opts, solidity.WithInterface(strings.NewReader(iface))) | ||
| } | ||
| cfg, err := solidity.NewExportConfig(opts...) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if got := cfg.InterfaceDeclaration(); got != tt.expected { | ||
| t.Errorf("InterfaceDeclaration() = %q, want %q", got, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestWithConstants(t *testing.T) { | ||
| cfg, err := solidity.NewExportConfig( | ||
| solidity.WithConstants(strings.NewReader(" bytes32 private immutable CHAIN_CONFIG;")), | ||
| ) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if cfg.Constants != " bytes32 private immutable CHAIN_CONFIG;" { | ||
| t.Errorf("unexpected constants: %s", cfg.Constants) | ||
| } | ||
| } | ||
|
|
||
| func TestWithConstructor(t *testing.T) { | ||
| constructor := ` constructor(bytes32 config) { | ||
| CHAIN_CONFIG = config; | ||
| }` | ||
| cfg, err := solidity.NewExportConfig( | ||
| solidity.WithConstructor(strings.NewReader(constructor)), | ||
| ) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if cfg.Constructor != constructor { | ||
| t.Errorf("unexpected constructor: %s", cfg.Constructor) | ||
| } | ||
| } | ||
|
|
||
| func TestWithFunctions(t *testing.T) { | ||
| functions := ` function getConfig() external view returns (bytes32) { | ||
| return CHAIN_CONFIG; | ||
| }` | ||
| cfg, err := solidity.NewExportConfig( | ||
| solidity.WithFunctions(strings.NewReader(functions)), | ||
| ) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if cfg.Functions != functions { | ||
| t.Errorf("unexpected functions: %s", cfg.Functions) | ||
| } | ||
| } | ||
|
|
||
| func TestEmptyConfig(t *testing.T) { | ||
| cfg, err := solidity.NewExportConfig() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(cfg.SortedImports()) != 0 { | ||
| t.Error("expected no imports") | ||
| } | ||
| if cfg.InterfaceDeclaration() != "" { | ||
| t.Error("expected empty interface declaration") | ||
| } | ||
| if cfg.Constants != "" { | ||
| t.Error("expected empty constants") | ||
| } | ||
| if cfg.Constructor != "" { | ||
| t.Error("expected empty constructor") | ||
| } | ||
| if cfg.Functions != "" { | ||
| t.Error("expected empty functions") | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.