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

feat(axelar-std-derive): add contractstorage attribute macro #216

Merged
merged 33 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
836c8da
feat(axelar-std-derive): add contractstorage attribute macro
nbayindirli Jan 27, 2025
c6de88f
diff lint
nbayindirli Jan 27, 2025
d19ef40
Merge branch 'main' into feature/storage-macro
nbayindirli Jan 28, 2025
03fdb1b
address comments
nbayindirli Jan 28, 2025
194d3ff
address comments
nbayindirli Jan 28, 2025
d83e509
breakup storage_attributes & add transform_variant doc
nbayindirli Jan 29, 2025
b0e388f
make value_type not optional + add fields_data helper
nbayindirli Jan 29, 2025
46bf998
Merge branch 'main' into feature/storage-macro
nbayindirli Jan 29, 2025
6fadf1e
expect lowercase
nbayindirli Jan 29, 2025
1db666a
improve encapsulation with storage_method on StorageType
nbayindirli Jan 29, 2025
0b30445
add ttl method
nbayindirli Jan 29, 2025
6f93793
account for Option<Option<...>> case on getter with ambiguous type
nbayindirli Jan 29, 2025
483e4d6
add deleter_name
nbayindirli Jan 29, 2025
e9d4500
add goldie on storage layout
nbayindirli Jan 29, 2025
4ad84c4
add testing on optional value type
nbayindirli Jan 29, 2025
2f2a4fb
support module-level public functions
nbayindirli Jan 29, 2025
9d035f3
enum private + public access fns
nbayindirli Jan 29, 2025
586ed70
remove println
nbayindirli Jan 29, 2025
0c0b710
remove semi-dupe test
nbayindirli Jan 29, 2025
2d6f63f
lint
nbayindirli Jan 29, 2025
6874515
remove test_storage_schema_stability
nbayindirli Jan 29, 2025
dbd645c
auto generate goldie test on generated code
nbayindirli Jan 29, 2025
b9f3c6a
lint
nbayindirli Jan 29, 2025
8f6416d
lint
nbayindirli Jan 29, 2025
ecfc0a3
remove dead golden file
nbayindirli Jan 29, 2025
3b26a9d
tests
nbayindirli Jan 29, 2025
875b896
tests
nbayindirli Jan 29, 2025
0162d95
tests
nbayindirli Jan 29, 2025
dfa5608
tests
nbayindirli Jan 29, 2025
1c76718
tests
nbayindirli Jan 29, 2025
5f9c95b
lint
nbayindirli Jan 29, 2025
b22d3b2
tests
nbayindirli Jan 29, 2025
c7576ac
address comments
nbayindirli Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add goldie on storage layout
nbayindirli committed Jan 29, 2025
commit e9d450057a0b7608e460cc842d152919c3277db8
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ goldie = { version = "0.5.0", default-features = false }
hex = { version = "0.4", default-features = false }
paste = { version = "1.0", default-features = false }
proc-macro2 = { version = "1.0", default-features = false }
quote = { version = "1.0", default-features = false }
rand = { version = "0.8.5", default-features = false }
soroban-sdk = { version = "22.0.6" }
soroban-token-sdk = { version = "22.0.6" }
@@ -31,6 +32,7 @@ stellar-example = { version = "^1.0.0", path = "contracts/stellar-example" }
stellar-interchain-token = { version = "^1.0.0", path = "contracts/stellar-interchain-token" }
stellar-interchain-token-service = { version = "^1.0.0", path = "contracts/stellar-interchain-token-service" }
stellar-token-manager = { version = "^1.0.0", path = "contracts/stellar-token-manager" }
syn = { version = "2.0", features = ["full", "extra-traits"] }

[workspace.lints.clippy]
nursery = { level = "warn", priority = -1 }
4 changes: 2 additions & 2 deletions packages/stellar-axelar-std-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@ proc-macro = true
[dependencies]
heck = "0.5"
proc-macro2 = { workspace = true }
quote = "1.0"
syn = { version = "2.0", features = ["full"] }
quote = { workspace = true }
syn = { workspace = true }

[dev-dependencies]

3 changes: 3 additions & 0 deletions packages/stellar-axelar-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -19,8 +19,11 @@ stellar-axelar-std-derive = { workspace = true, optional = true }
goldie = { workspace = true }
hex = { workspace = true }
paste = { workspace = true }
prettyplease = "0.2"
quote = { workspace = true }
soroban-sdk = { workspace = true, features = ["testutils"] }
stellar-axelar-std-derive = { workspace = true }
syn = { workspace = true }

[features]
testutils = ["soroban-sdk/testutils", "dep:hex"]
38 changes: 38 additions & 0 deletions packages/stellar-axelar-std/src/tests/storage.rs
Original file line number Diff line number Diff line change
@@ -3,12 +3,17 @@ use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, String};

use crate as stellar_axelar_std;
use crate::contractstorage;
use crate::std::string::ToString;

#[contract]
pub struct Contract;

mod storage {
use super::*;
use prettyplease;
use quote::quote;
use std::vec;
use syn::parse_quote;

#[contractstorage]
enum DataKey {
@@ -28,6 +33,39 @@ mod storage {
#[value(bool)]
Flag { key: String, owner: Address },
}

#[test]
fn test_storage_schema_stability() {
let expected = quote! {
enum DataKey {
#[instance]
#[value(u32)]
Counter,

#[persistent]
#[value(String)]
Message { sender: Address },

#[temporary]
#[value(Address)]
LastCaller { timestamp: u64 },

#[persistent]
#[value(bool)]
Flag { key: String, owner: Address },
}
};

let syntax: syn::Item = parse_quote! { #expected };

let formatted_expected = prettyplease::unparse(&syn::File {
shebang: None,
attrs: vec![],
items: vec![syntax],
});

goldie::assert!(formatted_expected.to_string());
}
}

#[contractimpl]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum DataKey {
#[instance]
#[value(u32)]
Counter,
#[persistent]
#[value(String)]
Message { sender: Address },
#[temporary]
#[value(Address)]
LastCaller { timestamp: u64 },
#[persistent]
#[value(bool)]
Flag { key: String, owner: Address },
}