Skip to content
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

fix: populate default values for contract_metadata #1249

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mitinarseny
Copy link
Contributor

@mitinarseny mitinarseny commented Oct 14, 2024

Add #[darling(default)] attribute for link and version to make it possible to derive them from env:

#[near(contract_metadata(standard(standard = "nep141", version = "1.0.0")))
struct Contract {}

As current implementation returns an error:

error: expected an expression
 │   --> src/lib.rs:49:1
 │    |
 │ 49 | / #[near(
 │ 50 | |     contract_state,
 │ 51 | |     contract_metadata(standard(standard = "nep141", version = "1.0.0"))
 │ 52 | | )]
 │    | |__^
 │    |
 │    = note: this error originates in the attribute macro `near` (in Nightly builds, run with -Z macro-backtrace for more info)
 │ 
 │ error[E0425]: cannot find value `CONTRACT_SOURCE_METADATA` in this scope
 │   -->src/lib.rs:49:1
 │    |
 │ 49 | / #[near(
 │ 50 | |     contract_state,
 │ 51 | |     contract_metadata(standard(standard = "nep141", version = "1.0.0"))
 │ 52 | | )]
 │    | |__^ not found in this scope
 │    |
 │    = note: this error originates in the attribute macro `::near_sdk::near_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.07%. Comparing base (110a99a) to head (c335cf9).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1249   +/-   ##
=======================================
  Coverage   80.07%   80.07%           
=======================================
  Files         102      102           
  Lines       14598    14598           
=======================================
  Hits        11690    11690           
  Misses       2908     2908           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@near near deleted a comment from github-actions bot Oct 31, 2024
@dj8yfo
Copy link
Collaborator

dj8yfo commented Oct 31, 2024

/compare

Copy link

Contract size report

Sizes are given in bytes.

contract master this branch difference
adder.wasm 71721 71721 +0%
approval_receiver.wasm 89921 89921 +0%
callback_results.wasm 80722 80722 +0%
cross_contract_high_level.wasm 75382 75382 +0%
cross_contract_low_level.wasm 72282 72282 +0%
defi.wasm 94072 94072 +0%
factory_contract_high_level.wasm 169687 169687 +0%
factory_contract_low_level.wasm 167596 167596 +0%
fungible_token.wasm 162187 162187 +0%
lockable_fungible_token.wasm 110405 110405 +0%
mission_control.wasm 109843 109843 +0%
non_fungible_token.wasm 220419 220419 +0%
status_message.wasm 85472 85472 +0%
test_contract.wasm 22991 22991 +0%
token_receiver.wasm 89917 89917 +0%
versioned.wasm 93860 93860 +0%

@akorchyn
Copy link
Collaborator

Hey, first of all, thanks for the contribution.

Please provide example to see how it helps. It would be nice to have a test repo with test contract to make review faster

Copy link
Collaborator

@dj8yfo dj8yfo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frol, judging from Shitzu-Apes/validator-rewards#2, logic has to be changed to such, that if std::env::var("NEP330_LINK") is set, then it should override value from darling. For such cases, when a legacy contract is updated with a link attribute lingering somewhere in src/lib.rs, forgotten or not. What do you think?

@dj8yfo
Copy link
Collaborator

dj8yfo commented Nov 22, 2024

@mitinarseny can you add a unit test, demonstrating how parsing changes prior and after the change? It appears that both with darling(default) and without it a missing link or version are parsed as None, so there's not much changed (non-negatively) with this pr. A unit test would help to clarify this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: NEW❗
Development

Successfully merging this pull request may close these issues.

3 participants