-
Notifications
You must be signed in to change notification settings - Fork 9
Additions to compiled_contracts table
#41
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
637c721
Add migration `20260224135405_support_old_solc_output.sql`
manuelwedler 6165611
Add migration `20260224171441_add_transientStorageLayout.sql`
manuelwedler 10c2454
Add migration `20260225083159_add_additional_input_to_compiled_contra…
manuelwedler 46926f2
Add tests for new migrations
manuelwedler 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
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
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,41 @@ | ||
| -- migrate:up | ||
|
|
||
| /* | ||
| Make 'userdoc', 'devdoc' and 'storageLayout' optional in the compilation artifacts, | ||
| because older solc versions do not output them. | ||
| See https://github.com/argotorg/sourcify/issues/2296 | ||
| */ | ||
|
|
||
| CREATE OR REPLACE FUNCTION validate_compilation_artifacts(obj jsonb) | ||
| RETURNS boolean AS | ||
| $$ | ||
| BEGIN | ||
| RETURN | ||
| is_jsonb_object(obj) AND | ||
| validate_json_object_keys( | ||
| obj, | ||
| array ['abi', 'sources'], | ||
| array ['userdoc', 'devdoc', 'storageLayout'] | ||
| ) AND | ||
| validate_compilation_artifacts_abi(obj -> 'abi') AND | ||
| validate_compilation_artifacts_sources(obj -> 'sources'); | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| -- migrate:down | ||
|
|
||
| CREATE OR REPLACE FUNCTION validate_compilation_artifacts(obj jsonb) | ||
| RETURNS boolean AS | ||
| $$ | ||
| BEGIN | ||
| RETURN | ||
| is_jsonb_object(obj) AND | ||
| validate_json_object_keys( | ||
| obj, | ||
| array ['abi', 'userdoc', 'devdoc', 'sources', 'storageLayout'], | ||
| array []::text[] | ||
| ) AND | ||
| validate_compilation_artifacts_abi(obj -> 'abi') AND | ||
| validate_compilation_artifacts_sources(obj -> 'sources'); | ||
| END; | ||
| $$ LANGUAGE plpgsql; |
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,39 @@ | ||
| -- migrate:up | ||
|
|
||
| /* | ||
| Allow storing the new compiler output field `transientStorageLayout`. | ||
| */ | ||
|
|
||
| CREATE OR REPLACE FUNCTION validate_compilation_artifacts(obj jsonb) | ||
| RETURNS boolean AS | ||
| $$ | ||
| BEGIN | ||
| RETURN | ||
| is_jsonb_object(obj) AND | ||
| validate_json_object_keys( | ||
| obj, | ||
| array ['abi', 'sources'], | ||
| array ['userdoc', 'devdoc', 'storageLayout', 'transientStorageLayout'] | ||
| ) AND | ||
| validate_compilation_artifacts_abi(obj -> 'abi') AND | ||
| validate_compilation_artifacts_sources(obj -> 'sources'); | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| -- migrate:down | ||
|
|
||
| CREATE OR REPLACE FUNCTION validate_compilation_artifacts(obj jsonb) | ||
| RETURNS boolean AS | ||
| $$ | ||
| BEGIN | ||
| RETURN | ||
| is_jsonb_object(obj) AND | ||
| validate_json_object_keys( | ||
| obj, | ||
| array ['abi', 'sources'], | ||
| array ['userdoc', 'devdoc', 'storageLayout'] | ||
| ) AND | ||
| validate_compilation_artifacts_abi(obj -> 'abi') AND | ||
| validate_compilation_artifacts_sources(obj -> 'sources'); | ||
| END; | ||
| $$ LANGUAGE plpgsql; |
36 changes: 36 additions & 0 deletions
36
migrations/20260225083159_add_additional_input_to_compiled_contracts.sql
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,36 @@ | ||
| -- migrate:up | ||
|
|
||
| /* | ||
| Add `additional_input` column to `compiled_contracts` to store compiler options | ||
| that appear at the top level of standard JSON input but are not part of the `settings` field. | ||
| Currently restricted to `storage_layout_overrides`, used by Vyper. | ||
| See https://github.com/vyperlang/vyper/pull/4370 | ||
| */ | ||
|
|
||
| CREATE OR REPLACE FUNCTION validate_additional_input(obj jsonb) | ||
| RETURNS boolean AS | ||
| $$ | ||
| BEGIN | ||
| RETURN obj IS NULL OR ( | ||
| is_jsonb_object(obj) AND | ||
| validate_json_object_keys( | ||
| obj, | ||
| array []::text[], | ||
| array ['storage_layout_overrides'] | ||
| ) | ||
| ); | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| ALTER TABLE compiled_contracts | ||
| ADD COLUMN additional_input jsonb; | ||
|
|
||
| ALTER TABLE compiled_contracts | ||
| ADD CONSTRAINT additional_input_json_schema | ||
| CHECK (validate_additional_input(additional_input)); | ||
|
|
||
| -- migrate:down | ||
|
|
||
| ALTER TABLE compiled_contracts DROP CONSTRAINT IF EXISTS additional_input_json_schema; | ||
| ALTER TABLE compiled_contracts DROP COLUMN IF EXISTS additional_input; | ||
| DROP FUNCTION IF EXISTS validate_additional_input(jsonb); |
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
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,49 @@ | ||
| from helpers import * | ||
|
|
||
|
|
||
| @pytest.fixture(scope='function', autouse=True) | ||
| def setup(connection, dummy_code): | ||
| dummy_code.insert(connection) | ||
|
|
||
|
|
||
| class TestAdditionalInput: | ||
| def test_null_succeeds(self, connection, dummy_code, dummy_compiled_contract): | ||
| # additional_input defaults to SQL NULL when not set | ||
| dummy_compiled_contract.insert(connection, dummy_code.code_hash, dummy_code.code_hash) | ||
|
|
||
| def test_storage_layout_overrides_succeeds(self, connection, dummy_code, dummy_compiled_contract): | ||
| dummy_compiled_contract.additional_input = { | ||
| "storage_layout_overrides": { | ||
| "x": {"slot": "0x0", "type": "uint256", "n_slots": 1} | ||
| } | ||
| } | ||
| dummy_compiled_contract.insert(connection, dummy_code.code_hash, dummy_code.code_hash) | ||
|
|
||
| def test_empty_object_succeeds(self, connection, dummy_code, dummy_compiled_contract): | ||
| dummy_compiled_contract.additional_input = {} | ||
| dummy_compiled_contract.insert(connection, dummy_code.code_hash, dummy_code.code_hash) | ||
|
|
||
| def test_unknown_key_fails(self, connection, dummy_code, dummy_compiled_contract): | ||
| dummy_compiled_contract.additional_input = {"unknown_key": {}} | ||
| check_constraint_fails( | ||
| lambda: dummy_compiled_contract.insert( | ||
| connection, dummy_code.code_hash, dummy_code.code_hash), | ||
| 'additional_input_json_schema') | ||
|
|
||
| def test_unknown_key_alongside_valid_key_fails(self, connection, dummy_code, dummy_compiled_contract): | ||
| dummy_compiled_contract.additional_input = { | ||
| "storage_layout_overrides": {}, | ||
| "unknown_key": {} | ||
| } | ||
| check_constraint_fails( | ||
| lambda: dummy_compiled_contract.insert( | ||
| connection, dummy_code.code_hash, dummy_code.code_hash), | ||
| 'additional_input_json_schema') | ||
|
|
||
| @pytest.mark.parametrize("value", ["a string", [1, 2], 42], ids=["string", "array", "number"]) | ||
| def test_non_object_type_fails(self, value, connection, dummy_code, dummy_compiled_contract): | ||
| dummy_compiled_contract.additional_input = value | ||
| check_constraint_fails( | ||
| lambda: dummy_compiled_contract.insert( | ||
| connection, dummy_code.code_hash, dummy_code.code_hash), | ||
| 'additional_input_json_schema') | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test data here does not accurately reflect the actual Vyper
storage_layout_overridesstructure. Per vyper/pull/4370, the format maps file path → variable name →{slot, type, n_slots}(two nesting levels), but the test collapses this to one level (treating"x"as a file path with a direct{slot, type, n_slots}value instead of a variable name map).Since
validate_additional_inputintentionally does not validate the inner structure ofstorage_layout_overrides, the constraint test itself is still correct — but the test data is misleading. Suggest updating to:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment from Claude.
I think we are missing one level of mapping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Claude is just being stupid here.
We have
"contracts/foo.vy"->"x"->{"slot": "0x0", "type": "uint256", "n_slots": 1}what matches Claude's suggested type
file path → variable name → {slot, type, n_slots}