@layerzerolabs/protocol-stellar-v2 0.2.15 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +350 -309
- package/.turbo/turbo-lint.log +146 -108
- package/.turbo/turbo-test.log +1423 -1238
- package/Cargo.lock +12 -0
- package/Cargo.toml +3 -0
- package/contracts/ERROR_SPEC.md +44 -0
- package/contracts/common-macros/src/auth.rs +113 -0
- package/contracts/common-macros/src/contract_ttl.rs +84 -0
- package/contracts/common-macros/src/lib.rs +181 -30
- package/contracts/common-macros/src/lz_contract.rs +83 -0
- package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
- package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
- package/contracts/common-macros/src/tests/mod.rs +2 -2
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
- package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap → common_macros__tests__auth__snapshot_only_auth_preserves_function_signature.snap} +4 -4
- package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap → common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap} +3 -3
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -21
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +2 -2
- package/contracts/common-macros/src/ttl_configurable.rs +19 -34
- package/contracts/common-macros/src/ttl_extendable.rs +36 -0
- package/contracts/common-macros/src/upgradeable.rs +5 -5
- package/contracts/common-macros/src/utils.rs +9 -0
- package/contracts/endpoint-v2/src/constants.rs +4 -4
- package/contracts/endpoint-v2/src/endpoint_v2.rs +38 -40
- package/contracts/endpoint-v2/src/errors.rs +4 -3
- package/contracts/endpoint-v2/src/events.rs +1 -1
- package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
- package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
- package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
- package/contracts/endpoint-v2/src/storage.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +2 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +1 -1
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +1 -1
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +4 -4
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +1 -1
- package/contracts/layerzero-views/src/layerzero_view.rs +3 -6
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +2 -2
- package/contracts/macro-integration-tests/tests/runtime/ownable/{only_owner_guard.rs → only_auth_guard.rs} +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +0 -1
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.rs → only_auth_missing_env.rs} +3 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.stderr → only_auth_missing_env.stderr} +4 -4
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +2 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/{only_owner_env_param_variants.rs → only_auth_env_param_variants.rs} +9 -9
- package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +6 -6
- package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +3 -3
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +9 -9
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +2 -2
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
- package/contracts/message-libs/treasury/src/errors.rs +2 -2
- package/contracts/message-libs/treasury/src/events.rs +1 -1
- package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
- package/contracts/message-libs/treasury/src/storage.rs +1 -1
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
- package/contracts/message-libs/treasury/src/treasury.rs +14 -16
- package/contracts/message-libs/uln-302/src/receive_uln.rs +13 -2
- package/contracts/message-libs/uln-302/src/send_uln.rs +23 -3
- package/contracts/message-libs/uln-302/src/uln302.rs +6 -24
- package/contracts/oapps/counter/Cargo.toml +14 -1
- package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
- package/contracts/oapps/counter/integration_tests/{setup.rs → setup_sml.rs} +48 -80
- package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
- package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
- package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
- package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
- package/contracts/oapps/counter/src/counter.rs +67 -43
- package/contracts/oapps/counter/src/tests/mod.rs +0 -13
- package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
- package/contracts/oapps/oapp/src/errors.rs +5 -1
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +93 -78
- package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
- package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
- package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -17
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -7
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -15
- package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
- package/contracts/oapps/oapp-macros/src/lib.rs +113 -56
- package/contracts/oapps/oft/integration-tests/setup.rs +25 -7
- package/contracts/oapps/oft/src/errors.rs +6 -1
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +8 -8
- package/contracts/oapps/oft/src/extensions/pausable.rs +4 -4
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +5 -5
- package/contracts/oapps/oft/src/lib.rs +4 -2
- package/contracts/oapps/oft/src/oft.rs +24 -64
- package/contracts/oapps/oft/src/oft_impl.rs +201 -0
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -3
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -4
- package/contracts/oapps/oft/src/storage.rs +2 -0
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +36 -22
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +5 -3
- package/contracts/oapps/oft/src/tests/test_decimals.rs +2 -2
- package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +1 -2
- package/contracts/oapps/oft/src/tests/test_utils.rs +45 -23
- package/contracts/oapps/oft/src/types.rs +20 -0
- package/contracts/oapps/oft-std/integration-tests/setup.rs +4 -2
- package/contracts/oapps/oft-std/src/oft.rs +24 -6
- package/contracts/upgrader/src/lib.rs +4 -4
- package/contracts/utils/src/auth.rs +44 -0
- package/contracts/utils/src/errors.rs +27 -5
- package/contracts/utils/src/lib.rs +3 -0
- package/contracts/utils/src/multisig.rs +211 -0
- package/contracts/utils/src/ownable.rs +12 -10
- package/contracts/utils/src/tests/buffer_reader.rs +6 -6
- package/contracts/utils/src/tests/buffer_writer.rs +6 -6
- package/contracts/utils/src/tests/bytes_ext.rs +2 -4
- package/contracts/utils/src/tests/mod.rs +1 -0
- package/contracts/utils/src/tests/multisig.rs +731 -0
- package/contracts/utils/src/tests/option_ext.rs +2 -5
- package/contracts/utils/src/tests/ownable.rs +16 -5
- package/contracts/utils/src/tests/ttl_configurable.rs +27 -16
- package/contracts/utils/src/tests/upgradeable.rs +4 -2
- package/contracts/utils/src/ttl_configurable.rs +23 -8
- package/contracts/utils/src/ttl_extendable.rs +27 -0
- package/contracts/utils/src/upgradeable.rs +2 -0
- package/contracts/workers/dvn/Cargo.toml +1 -1
- package/contracts/workers/dvn/src/auth.rs +7 -7
- package/contracts/workers/dvn/src/dvn.rs +10 -38
- package/contracts/workers/dvn/src/errors.rs +0 -7
- package/contracts/workers/dvn/src/events.rs +1 -14
- package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
- package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
- package/contracts/workers/dvn/src/storage.rs +3 -13
- package/contracts/workers/dvn/src/tests/auth.rs +4 -4
- package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
- package/contracts/workers/dvn/src/tests/setup.rs +5 -5
- package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -6
- package/contracts/workers/executor/src/auth.rs +80 -16
- package/contracts/workers/executor/src/executor.rs +5 -31
- package/contracts/workers/executor/src/storage.rs +2 -9
- package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +3 -6
- package/contracts/workers/executor-helper/Cargo.toml +1 -1
- package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
- package/contracts/workers/price-feed/Cargo.toml +1 -1
- package/contracts/workers/price-feed/src/price_feed.rs +7 -10
- package/contracts/workers/worker/src/errors.rs +4 -0
- package/contracts/workers/worker/src/tests/worker.rs +7 -6
- package/contracts/workers/worker/src/worker.rs +20 -16
- package/package.json +8 -5
- package/sdk/.turbo/turbo-build.log +1 -0
- package/sdk/.turbo/turbo-test.log +1009 -0
- package/sdk/dist/generated/bml.d.ts +65 -8
- package/sdk/dist/generated/bml.js +70 -34
- package/sdk/dist/generated/counter.d.ts +167 -42
- package/sdk/dist/generated/counter.js +86 -45
- package/sdk/dist/generated/dvn.d.ts +282 -229
- package/sdk/dist/generated/dvn.js +119 -81
- package/sdk/dist/generated/dvn_fee_lib.d.ts +142 -67
- package/sdk/dist/generated/dvn_fee_lib.js +64 -24
- package/sdk/dist/generated/endpoint.d.ts +97 -22
- package/sdk/dist/generated/endpoint.js +75 -37
- package/sdk/dist/generated/executor.d.ts +117 -85
- package/sdk/dist/generated/executor.js +102 -59
- package/sdk/dist/generated/executor_fee_lib.d.ts +162 -78
- package/sdk/dist/generated/executor_fee_lib.js +104 -57
- package/sdk/dist/generated/executor_helper.d.ts +133 -21
- package/sdk/dist/generated/executor_helper.js +99 -50
- package/sdk/dist/generated/oft_std.d.ts +233 -55
- package/sdk/dist/generated/oft_std.js +99 -54
- package/sdk/dist/generated/price_feed.d.ts +142 -67
- package/sdk/dist/generated/price_feed.js +64 -24
- package/sdk/dist/generated/sml.d.ts +113 -32
- package/sdk/dist/generated/sml.js +93 -49
- package/sdk/dist/generated/treasury.d.ts +896 -0
- package/sdk/dist/generated/treasury.js +219 -0
- package/sdk/dist/generated/uln302.d.ts +113 -32
- package/sdk/dist/generated/uln302.js +93 -49
- package/sdk/dist/generated/upgrader.d.ts +2 -2
- package/sdk/dist/generated/upgrader.js +1 -1
- package/sdk/dist/index.d.ts +2 -0
- package/sdk/dist/index.js +3 -0
- package/sdk/dist/wasm/blocked-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/blocked-message-lib.js +2 -0
- package/sdk/dist/wasm/counter.d.ts +1 -0
- package/sdk/dist/wasm/counter.js +2 -0
- package/sdk/dist/wasm/dvn-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/dvn-fee-lib.js +2 -0
- package/sdk/dist/wasm/dvn.d.ts +1 -0
- package/sdk/dist/wasm/dvn.js +2 -0
- package/sdk/dist/wasm/endpoint-v2.d.ts +1 -0
- package/sdk/dist/wasm/endpoint-v2.js +2 -0
- package/sdk/dist/wasm/executor-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/executor-fee-lib.js +2 -0
- package/sdk/dist/wasm/executor-helper.d.ts +1 -0
- package/sdk/dist/wasm/executor-helper.js +2 -0
- package/sdk/dist/wasm/executor.d.ts +1 -0
- package/sdk/dist/wasm/executor.js +2 -0
- package/sdk/dist/wasm/layerzero-views.d.ts +1 -0
- package/sdk/dist/wasm/layerzero-views.js +2 -0
- package/sdk/dist/wasm/oft-std.d.ts +1 -0
- package/sdk/dist/wasm/oft-std.js +2 -0
- package/sdk/dist/wasm/price-feed.d.ts +1 -0
- package/sdk/dist/wasm/price-feed.js +2 -0
- package/sdk/dist/wasm/simple-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/simple-message-lib.js +2 -0
- package/sdk/dist/wasm/treasury.d.ts +1 -0
- package/sdk/dist/wasm/treasury.js +2 -0
- package/sdk/dist/wasm/uln302.d.ts +1 -0
- package/sdk/dist/wasm/uln302.js +2 -0
- package/sdk/dist/wasm/upgrader.d.ts +1 -0
- package/sdk/dist/wasm/upgrader.js +2 -0
- package/sdk/dist/wasm.d.ts +15 -0
- package/sdk/dist/wasm.js +15 -0
- package/sdk/package.json +4 -2
- package/sdk/src/index.ts +4 -0
- package/sdk/test/counter-sml.test.ts +376 -0
- package/sdk/test/counter-uln.test.ts +493 -0
- package/sdk/test/{oft.test.ts → oft-sml.test.ts} +185 -310
- package/sdk/test/suites/constants.ts +22 -2
- package/sdk/test/suites/globalSetup.ts +450 -0
- package/sdk/test/suites/localnet.ts +23 -6
- package/sdk/test/upgrader.test.ts +7 -16
- package/sdk/test/utils.ts +558 -85
- package/sdk/vitest.config.ts +21 -0
- package/tools/ts-bindings-gen/src/main.rs +1 -0
- package/turbo.json +2 -0
- package/contracts/common-macros/src/contract_impl.rs +0 -52
- package/contracts/common-macros/src/ownable.rs +0 -41
- package/contracts/common-macros/src/tests/contract_impl.rs +0 -386
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -12
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +0 -50
- package/contracts/oapps/oapp-macros/src/oapp_core.rs +0 -41
- package/contracts/oapps/oapp-macros/src/oapp_full.rs +0 -21
- package/contracts/oapps/oapp-macros/src/oapp_options_type3.rs +0 -31
- package/contracts/oapps/oapp-macros/src/oapp_receiver.rs +0 -48
- package/contracts/oapps/oapp-macros/src/oapp_sender.rs +0 -21
- package/contracts/oapps/oapp-macros/src/util.rs +0 -107
- package/contracts/oapps/oft/src/constants.rs +0 -5
- package/contracts/oapps/oft/src/default_oft_impl.rs +0 -152
- package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
- package/contracts/workers/dvn/src/multisig.rs +0 -157
- package/sdk/test/index.test.ts +0 -375
- /package/sdk/test/suites/{testUpgradeable.ts → dummyContractClient.ts} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
// Global setup runs ONCE before all test files
|
|
6
|
+
globalSetup: './test/suites/globalSetup.ts',
|
|
7
|
+
// Run tests sequentially to avoid conflicts with shared blockchain state
|
|
8
|
+
sequence: {
|
|
9
|
+
concurrent: false,
|
|
10
|
+
},
|
|
11
|
+
// Longer timeouts for blockchain operations
|
|
12
|
+
testTimeout: 120000,
|
|
13
|
+
hookTimeout: 240000,
|
|
14
|
+
// Don't isolate test files - they share the same localnet
|
|
15
|
+
isolate: false,
|
|
16
|
+
// Run test files sequentially
|
|
17
|
+
fileParallelism: false,
|
|
18
|
+
// Stop on first failure
|
|
19
|
+
bail: 1,
|
|
20
|
+
},
|
|
21
|
+
});
|
package/turbo.json
CHANGED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
use crate::utils;
|
|
2
|
-
use proc_macro2::TokenStream;
|
|
3
|
-
use quote::quote;
|
|
4
|
-
use syn::{parse_quote, ImplItem, ItemImpl, Visibility};
|
|
5
|
-
|
|
6
|
-
/// Generates a `#[soroban_sdk::contractimpl]` with automatic instance TTL extension.
|
|
7
|
-
pub fn contract_impl(attr: TokenStream, input: TokenStream) -> TokenStream {
|
|
8
|
-
let mut impl_block: ItemImpl = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse impl block: {}", e));
|
|
9
|
-
|
|
10
|
-
let is_trait_impl = impl_block.trait_.is_some();
|
|
11
|
-
|
|
12
|
-
for item in &mut impl_block.items {
|
|
13
|
-
let ImplItem::Fn(method) = item else { continue };
|
|
14
|
-
|
|
15
|
-
// For trait impls, process all methods; for inherent impls, only public methods
|
|
16
|
-
if !is_trait_impl && !matches!(method.vis, Visibility::Public(_)) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Skip the constructor as TTL config is typically not set during initialization
|
|
21
|
-
if method.sig.ident == "__constructor" {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Skip methods without Env parameter
|
|
26
|
-
let Some(env_param) = utils::find_env_param(&method.sig.inputs) else { continue };
|
|
27
|
-
|
|
28
|
-
// Get a reference to env (handles both `Env` and `&Env` parameter types)
|
|
29
|
-
let env_ref = env_param.as_ref_tokens();
|
|
30
|
-
let env_ident = env_param.ident;
|
|
31
|
-
|
|
32
|
-
// Use fully qualified syntax to call ttl_configs from TtlConfigurable trait
|
|
33
|
-
let extend_ttl_stmt = parse_quote! {
|
|
34
|
-
if let Some(instance_ttl) = utils::ttl_configurable::TtlConfigStorage::instance(#env_ref) {
|
|
35
|
-
#env_ident.storage().instance().extend_ttl(instance_ttl.threshold, instance_ttl.extend_to);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
method.block.stmts.insert(0, extend_ttl_stmt);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if attr.is_empty() {
|
|
42
|
-
quote! {
|
|
43
|
-
#[soroban_sdk::contractimpl]
|
|
44
|
-
#impl_block
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
quote! {
|
|
48
|
-
#[soroban_sdk::contractimpl(#attr)]
|
|
49
|
-
#impl_block
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
use crate::utils;
|
|
2
|
-
use proc_macro2::TokenStream;
|
|
3
|
-
use quote::{quote, ToTokens};
|
|
4
|
-
use syn::{parse_quote, ItemFn, ItemStruct};
|
|
5
|
-
|
|
6
|
-
/// Generates the ownable implementation from the `#[ownable]` attribute macro.
|
|
7
|
-
pub fn generate_ownable_impl(input: TokenStream) -> TokenStream {
|
|
8
|
-
let item_struct: ItemStruct = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse struct: {}", e));
|
|
9
|
-
let name = &item_struct.ident;
|
|
10
|
-
|
|
11
|
-
let ownable_impl = quote! {
|
|
12
|
-
use utils::ownable::OwnableInitializer as _;
|
|
13
|
-
use utils::ownable::Ownable;
|
|
14
|
-
|
|
15
|
-
// Import OwnableInitializer at module level so user code can call Self::init_owner()
|
|
16
|
-
impl utils::ownable::OwnableInitializer for #name {}
|
|
17
|
-
|
|
18
|
-
/// Implement the Ownable trait for the contract with default implementations.
|
|
19
|
-
#[common_macros::contract_impl(contracttrait)]
|
|
20
|
-
impl Ownable for #name {}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
quote! {
|
|
24
|
-
#item_struct
|
|
25
|
-
#ownable_impl
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// Prepends an owner authentication check to a method.
|
|
30
|
-
pub fn prepend_only_owner_check(input: TokenStream) -> TokenStream {
|
|
31
|
-
let mut input_fn: ItemFn = syn::parse2(input).unwrap_or_else(|e| panic!("failed to parse function: {}", e));
|
|
32
|
-
|
|
33
|
-
let env_param = utils::expect_env_param(&input_fn.sig.inputs);
|
|
34
|
-
|
|
35
|
-
// Get a reference to env (handles both `Env` and `&Env` parameter types)
|
|
36
|
-
let env_ref = env_param.as_ref_tokens();
|
|
37
|
-
|
|
38
|
-
// Insert the owner authentication check at the beginning of the function body
|
|
39
|
-
input_fn.block.stmts.insert(0, parse_quote!(utils::ownable::require_owner_auth::<Self>(#env_ref);));
|
|
40
|
-
input_fn.into_token_stream()
|
|
41
|
-
}
|
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
use proc_macro2::TokenStream;
|
|
2
|
-
use quote::quote;
|
|
3
|
-
|
|
4
|
-
use crate::tests::test_helpers::assert_panics_contains;
|
|
5
|
-
|
|
6
|
-
// ============================================
|
|
7
|
-
// Snapshot Test: ContractImpl Code Generation
|
|
8
|
-
// ============================================
|
|
9
|
-
|
|
10
|
-
/// Comprehensive snapshot test covering all contract_impl macro features:
|
|
11
|
-
/// - Inherent impl: public methods with Env (adds TTL), private/pub(crate) methods (skipped)
|
|
12
|
-
/// - Trait impl: all methods with Env get TTL extension
|
|
13
|
-
/// - Qualified Env types (soroban_sdk::Env)
|
|
14
|
-
/// - Env parameter not in first position
|
|
15
|
-
/// - Methods without Env (skipped)
|
|
16
|
-
#[test]
|
|
17
|
-
fn snapshot_generated_contract_impl_code() {
|
|
18
|
-
// Test inherent impl with empty attr
|
|
19
|
-
let empty_attr = TokenStream::new();
|
|
20
|
-
let inherent_input = quote! {
|
|
21
|
-
impl MyContract {
|
|
22
|
-
/// Public method with Env - should have TTL extension
|
|
23
|
-
pub fn public_with_env(env: Env, value: u32) -> u32 {
|
|
24
|
-
value * 2
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// Public method with qualified Env path - should have TTL extension
|
|
28
|
-
pub fn with_qualified_env(env: soroban_sdk::Env) -> u32 {
|
|
29
|
-
42
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/// Public method with Env not as first parameter - should have TTL extension
|
|
33
|
-
pub fn env_second(value: u32, env: &Env) -> u32 {
|
|
34
|
-
value * 2
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/// Public method without Env - should NOT have TTL extension
|
|
38
|
-
pub fn public_without_env(value: u32) -> u32 {
|
|
39
|
-
value * 4
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/// Private method with Env - should NOT have TTL extension (not public)
|
|
43
|
-
fn private_with_env(env: Env, value: u32) -> u32 {
|
|
44
|
-
value * 5
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/// Pub(crate) method with Env - should NOT have TTL extension (not fully public)
|
|
48
|
-
pub(crate) fn pub_crate_with_env(env: Env, value: u32) -> u32 {
|
|
49
|
-
value * 7
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/// Constructor method - should NOT have TTL extension
|
|
53
|
-
pub fn __constructor(env: &Env, value: u32) {
|
|
54
|
-
let _ = value * 2;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
let inherent_result = crate::contract_impl::contract_impl(empty_attr.clone(), inherent_input);
|
|
60
|
-
let inherent_formatted =
|
|
61
|
-
prettyplease::unparse(&syn::parse2::<syn::File>(inherent_result).expect("failed to parse generated code"));
|
|
62
|
-
|
|
63
|
-
// Test trait impl with empty attr
|
|
64
|
-
let trait_input = quote! {
|
|
65
|
-
impl SomeTrait for MyContract {
|
|
66
|
-
/// Trait method with Env - should have TTL extension
|
|
67
|
-
fn trait_method_with_env(env: Env, value: u32) -> u32 {
|
|
68
|
-
value * 2
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/// Trait method without Env - should NOT have TTL extension
|
|
72
|
-
fn trait_method_without_env(value: u32) -> u32 {
|
|
73
|
-
value * 4
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/// Trait method with macro attribute - should have TTL extension
|
|
77
|
-
#[common_macros::only_owner]
|
|
78
|
-
fn trait_method_with_only_owner_attribute(env: Env, value: u32) -> u32 {
|
|
79
|
-
value * 5
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
let trait_result = crate::contract_impl::contract_impl(empty_attr, trait_input);
|
|
85
|
-
let trait_formatted =
|
|
86
|
-
prettyplease::unparse(&syn::parse2::<syn::File>(trait_result).expect("failed to parse generated code"));
|
|
87
|
-
|
|
88
|
-
// Test trait impl with contracttrait attr
|
|
89
|
-
let contracttrait_attr = quote! { contracttrait };
|
|
90
|
-
let contracttrait_input = quote! {
|
|
91
|
-
impl AnotherTrait for MyContract {
|
|
92
|
-
/// Trait method with contracttrait attr - should have TTL extension
|
|
93
|
-
fn contracttrait_method(env: &Env, value: u32) -> u32 {
|
|
94
|
-
value * 3
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
let contracttrait_result = crate::contract_impl::contract_impl(contracttrait_attr, contracttrait_input);
|
|
100
|
-
let contracttrait_formatted =
|
|
101
|
-
prettyplease::unparse(&syn::parse2::<syn::File>(contracttrait_result).expect("failed to parse generated code"));
|
|
102
|
-
|
|
103
|
-
// Combine all for single snapshot
|
|
104
|
-
let combined = format!(
|
|
105
|
-
"// === Inherent Impl (no attr) ===\n\n{}\n\n// === Trait Impl (no attr) ===\n\n{}\n\n// === Trait Impl (contracttrait attr) ===\n\n{}",
|
|
106
|
-
inherent_formatted, trait_formatted, contracttrait_formatted
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
insta::assert_snapshot!(combined);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ============================================
|
|
113
|
-
// Error Cases: Invalid Input
|
|
114
|
-
// ============================================
|
|
115
|
-
|
|
116
|
-
#[test]
|
|
117
|
-
fn test_non_impl_block_input() {
|
|
118
|
-
let invalid_inputs = vec![
|
|
119
|
-
(
|
|
120
|
-
"struct",
|
|
121
|
-
quote! {
|
|
122
|
-
struct MyStruct {
|
|
123
|
-
field: u32,
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
),
|
|
127
|
-
(
|
|
128
|
-
"enum",
|
|
129
|
-
quote! {
|
|
130
|
-
enum MyEnum {
|
|
131
|
-
Variant1,
|
|
132
|
-
Variant2,
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
),
|
|
136
|
-
("function", quote! { fn a_function() {} }),
|
|
137
|
-
("const item", quote! { const A_CONST: u32 = 1; }),
|
|
138
|
-
("type alias", quote! { type AnAlias = u32; }),
|
|
139
|
-
(
|
|
140
|
-
"trait",
|
|
141
|
-
quote! {
|
|
142
|
-
trait ATrait {
|
|
143
|
-
fn method(&self);
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
),
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
for (case, input) in invalid_inputs {
|
|
150
|
-
assert_panics_contains(case, "failed to parse impl block", || {
|
|
151
|
-
crate::contract_impl::contract_impl(TokenStream::new(), input.clone());
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// ============================================
|
|
157
|
-
// Unit Tests: Behavior Verification
|
|
158
|
-
// ============================================
|
|
159
|
-
|
|
160
|
-
/// Verifies that the macro adds #[soroban_sdk::contractimpl] attribute without parentheses when attr is empty
|
|
161
|
-
#[test]
|
|
162
|
-
fn test_adds_soroban_contractimpl_attribute_without_attr() {
|
|
163
|
-
let input = quote! {
|
|
164
|
-
impl MyContract {
|
|
165
|
-
pub fn my_method(env: Env) {}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
let result = crate::contract_impl::contract_impl(TokenStream::new(), input);
|
|
170
|
-
let result_str = result.to_string();
|
|
171
|
-
|
|
172
|
-
// Should have contractimpl without parentheses when attr is empty
|
|
173
|
-
assert!(
|
|
174
|
-
result_str.contains("# [soroban_sdk :: contractimpl]"),
|
|
175
|
-
"should add #[soroban_sdk::contractimpl] attribute without parentheses when attr is empty. Got: {}",
|
|
176
|
-
result_str
|
|
177
|
-
);
|
|
178
|
-
// Should NOT have empty parentheses
|
|
179
|
-
assert!(
|
|
180
|
-
!result_str.contains("contractimpl ()"),
|
|
181
|
-
"should NOT have empty parentheses when attr is empty. Got: {}",
|
|
182
|
-
result_str
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/// Verifies that the macro adds #[soroban_sdk::contractimpl(attr)] when attr is provided
|
|
187
|
-
#[test]
|
|
188
|
-
fn test_adds_soroban_contractimpl_attribute_with_attr() {
|
|
189
|
-
let input = quote! {
|
|
190
|
-
impl SomeTrait for MyContract {
|
|
191
|
-
fn my_method(env: Env) {}
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
let attr = quote! { contracttrait };
|
|
196
|
-
let result = crate::contract_impl::contract_impl(attr, input);
|
|
197
|
-
let result_str = result.to_string();
|
|
198
|
-
|
|
199
|
-
// Should have contractimpl with the attr in parentheses
|
|
200
|
-
assert!(
|
|
201
|
-
result_str.contains("contractimpl (contracttrait)"),
|
|
202
|
-
"should add #[soroban_sdk::contractimpl(contracttrait)] attribute. Got: {}",
|
|
203
|
-
result_str
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/// Expected TTL extension behavior for a test case
|
|
208
|
-
#[derive(Clone)]
|
|
209
|
-
enum TtlExpectation {
|
|
210
|
-
/// TTL extension should NOT be inserted
|
|
211
|
-
None,
|
|
212
|
-
/// TTL extension should be inserted with the given env patterns
|
|
213
|
-
/// - `instance_arg`: pattern in `TtlConfigStorage::instance(...)` (e.g., "& env" for owned, "env" for ref)
|
|
214
|
-
/// - `storage_ident`: identifier for `.storage()` call
|
|
215
|
-
Present { instance_arg: &'static str, storage_ident: &'static str },
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
struct TtlTestCase {
|
|
219
|
-
name: &'static str,
|
|
220
|
-
input: TokenStream,
|
|
221
|
-
expectation: TtlExpectation,
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
impl TtlTestCase {
|
|
225
|
-
fn expect_ttl(
|
|
226
|
-
name: &'static str,
|
|
227
|
-
input: TokenStream,
|
|
228
|
-
instance_arg: &'static str,
|
|
229
|
-
storage_ident: &'static str,
|
|
230
|
-
) -> Self {
|
|
231
|
-
Self { name, input, expectation: TtlExpectation::Present { instance_arg, storage_ident } }
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
fn expect_no_ttl(name: &'static str, input: TokenStream) -> Self {
|
|
235
|
-
Self { name, input, expectation: TtlExpectation::None }
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
fn run(&self) {
|
|
239
|
-
let result = crate::contract_impl::contract_impl(TokenStream::new(), self.input.clone());
|
|
240
|
-
let result_str = result.to_string();
|
|
241
|
-
let has_ttl = result_str.contains("TtlConfigStorage :: instance");
|
|
242
|
-
|
|
243
|
-
match &self.expectation {
|
|
244
|
-
TtlExpectation::None => {
|
|
245
|
-
assert!(!has_ttl, "{}: TTL extension should NOT be present, but was found", self.name);
|
|
246
|
-
}
|
|
247
|
-
TtlExpectation::Present { instance_arg, storage_ident } => {
|
|
248
|
-
assert!(has_ttl, "{}: TTL extension should be present, but was not found", self.name);
|
|
249
|
-
assert!(result_str.contains("extend_ttl"), "{}: should insert extend_ttl call", self.name);
|
|
250
|
-
|
|
251
|
-
let instance_pattern = format!("TtlConfigStorage :: instance ({})", instance_arg);
|
|
252
|
-
assert!(
|
|
253
|
-
result_str.contains(&instance_pattern),
|
|
254
|
-
"{}: expected '{}' in TtlConfigStorage::instance call. Got: {}",
|
|
255
|
-
self.name,
|
|
256
|
-
instance_arg,
|
|
257
|
-
result_str
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
let storage_pattern = format!("{} . storage ()", storage_ident);
|
|
261
|
-
assert!(
|
|
262
|
-
result_str.contains(&storage_pattern),
|
|
263
|
-
"{}: expected '{}.storage()' call",
|
|
264
|
-
self.name,
|
|
265
|
-
storage_ident
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
#[test]
|
|
273
|
-
fn test_ttl_extension_with_owned_env() {
|
|
274
|
-
TtlTestCase::expect_ttl(
|
|
275
|
-
"public method with owned Env",
|
|
276
|
-
quote! {
|
|
277
|
-
impl MyContract {
|
|
278
|
-
pub fn my_method(env: Env) { let x = 1; }
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
"& env", // instance takes reference
|
|
282
|
-
"env", // storage called on ident
|
|
283
|
-
)
|
|
284
|
-
.run();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
#[test]
|
|
288
|
-
fn test_ttl_extension_with_ref_env() {
|
|
289
|
-
TtlTestCase::expect_ttl(
|
|
290
|
-
"public method with ref Env",
|
|
291
|
-
quote! {
|
|
292
|
-
impl MyContract {
|
|
293
|
-
pub fn my_method(env: &Env) { let x = 1; }
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
"env", // instance takes ident directly (already a ref)
|
|
297
|
-
"env",
|
|
298
|
-
)
|
|
299
|
-
.run();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
#[test]
|
|
303
|
-
fn test_ttl_extension_with_custom_env_ident_owned() {
|
|
304
|
-
TtlTestCase::expect_ttl(
|
|
305
|
-
"custom Env identifier (owned)",
|
|
306
|
-
quote! {
|
|
307
|
-
impl MyContract {
|
|
308
|
-
pub fn my_method(my_custom_env: Env) { let x = 1; }
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
"& my_custom_env",
|
|
312
|
-
"my_custom_env",
|
|
313
|
-
)
|
|
314
|
-
.run();
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
#[test]
|
|
318
|
-
fn test_ttl_extension_with_custom_env_ident_ref() {
|
|
319
|
-
TtlTestCase::expect_ttl(
|
|
320
|
-
"custom Env identifier (ref)",
|
|
321
|
-
quote! {
|
|
322
|
-
impl MyContract {
|
|
323
|
-
pub fn my_method(my_custom_env: &Env) { let x = 1; }
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
"my_custom_env",
|
|
327
|
-
"my_custom_env",
|
|
328
|
-
)
|
|
329
|
-
.run();
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
#[test]
|
|
333
|
-
fn test_ttl_extension_for_trait_impl_owned_env() {
|
|
334
|
-
TtlTestCase::expect_ttl(
|
|
335
|
-
"trait impl method with owned Env",
|
|
336
|
-
quote! {
|
|
337
|
-
impl SomeTrait for MyContract {
|
|
338
|
-
fn trait_method(env: Env) { let x = 1; }
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
"& env",
|
|
342
|
-
"env",
|
|
343
|
-
)
|
|
344
|
-
.run();
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
#[test]
|
|
348
|
-
fn test_ttl_extension_for_trait_impl_ref_env() {
|
|
349
|
-
TtlTestCase::expect_ttl(
|
|
350
|
-
"trait impl method with ref Env",
|
|
351
|
-
quote! {
|
|
352
|
-
impl SomeTrait for MyContract {
|
|
353
|
-
fn trait_method(env: &Env) { let x = 1; }
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
"env",
|
|
357
|
-
"env",
|
|
358
|
-
)
|
|
359
|
-
.run();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
#[test]
|
|
363
|
-
fn test_no_ttl_extension_for_private_method() {
|
|
364
|
-
TtlTestCase::expect_no_ttl(
|
|
365
|
-
"private method with Env",
|
|
366
|
-
quote! {
|
|
367
|
-
impl MyContract {
|
|
368
|
-
fn private_method(env: Env) { let x = 1; }
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
)
|
|
372
|
-
.run();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
#[test]
|
|
376
|
-
fn test_no_ttl_extension_without_env_param() {
|
|
377
|
-
TtlTestCase::expect_no_ttl(
|
|
378
|
-
"public method without Env",
|
|
379
|
-
quote! {
|
|
380
|
-
impl MyContract {
|
|
381
|
-
pub fn no_env_method(value: u32) -> u32 { value }
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
)
|
|
385
|
-
.run();
|
|
386
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
source: contracts/common-macros/src/tests/ownable.rs
|
|
3
|
-
assertion_line: 17
|
|
4
|
-
expression: formatted
|
|
5
|
-
---
|
|
6
|
-
pub struct MyContract;
|
|
7
|
-
use utils::ownable::OwnableInitializer as _;
|
|
8
|
-
use utils::ownable::Ownable;
|
|
9
|
-
impl utils::ownable::OwnableInitializer for MyContract {}
|
|
10
|
-
/// Implement the Ownable trait for the contract with default implementations.
|
|
11
|
-
#[common_macros::contract_impl(contracttrait)]
|
|
12
|
-
impl Ownable for MyContract {}
|
package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Runtime tests: `extend_instance_ttl` behavior.
|
|
2
|
-
//
|
|
3
|
-
// Tests covered:
|
|
4
|
-
// - `extend_instance_ttl` exists on `#[ttl_configurable]` contracts and manually extends instance TTL.
|
|
5
|
-
|
|
6
|
-
use common_macros::{ownable, ttl_configurable};
|
|
7
|
-
use soroban_sdk::{
|
|
8
|
-
contract, contractimpl,
|
|
9
|
-
testutils::{storage::Instance as _, Address as _, Ledger as _},
|
|
10
|
-
Address, Env,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
#[contract]
|
|
14
|
-
#[ttl_configurable]
|
|
15
|
-
#[ownable]
|
|
16
|
-
pub struct TestContract;
|
|
17
|
-
|
|
18
|
-
#[contractimpl]
|
|
19
|
-
impl TestContract {
|
|
20
|
-
pub fn init(env: Env, owner: Address) {
|
|
21
|
-
Self::init_owner(&env, &owner);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
#[test]
|
|
26
|
-
fn extend_instance_ttl_extends() {
|
|
27
|
-
let env = Env::default();
|
|
28
|
-
let contract_id = env.register(TestContract, ());
|
|
29
|
-
let client = TestContractClient::new(&env, &contract_id);
|
|
30
|
-
|
|
31
|
-
// Write something to ensure instance storage exists and has a TTL.
|
|
32
|
-
let owner = Address::generate(&env);
|
|
33
|
-
client.init(&owner);
|
|
34
|
-
|
|
35
|
-
let (ttl_before, seq_before) =
|
|
36
|
-
env.as_contract(&contract_id, || (env.storage().instance().get_ttl(), env.ledger().sequence()));
|
|
37
|
-
let live_until = seq_before + ttl_before;
|
|
38
|
-
|
|
39
|
-
// Choose a threshold near the current TTL and extend further.
|
|
40
|
-
let threshold = ttl_before.saturating_sub(1);
|
|
41
|
-
let extend_to = ttl_before + 50;
|
|
42
|
-
|
|
43
|
-
// Set sequence so remaining TTL == threshold (i.e. at the trigger point).
|
|
44
|
-
env.ledger().set_sequence_number(live_until - threshold);
|
|
45
|
-
|
|
46
|
-
client.extend_instance_ttl(&threshold, &extend_to);
|
|
47
|
-
|
|
48
|
-
let ttl_after = env.as_contract(&contract_id, || env.storage().instance().get_ttl());
|
|
49
|
-
assert_eq!(ttl_after, extend_to);
|
|
50
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
use heck::ToSnakeCase;
|
|
2
|
-
use proc_macro2::TokenStream;
|
|
3
|
-
use quote::quote;
|
|
4
|
-
use syn::{Ident, ItemStruct};
|
|
5
|
-
|
|
6
|
-
/// Generates the `OAppCore` trait implementation and adds `#[contract]` + `#[ownable]` to the struct.
|
|
7
|
-
///
|
|
8
|
-
/// When `manual_impl_core` is false, generates an empty `impl OAppCore`
|
|
9
|
-
/// that uses the trait's default implementations for peer management and endpoint access.
|
|
10
|
-
pub fn generate_impl(name: &Ident, item_struct: ItemStruct, manual_impl_core: bool) -> TokenStream {
|
|
11
|
-
// Create a unique module name to avoid import conflicts when multiple structs
|
|
12
|
-
// use oapp macros in the same module. The import must be `OAppCore`
|
|
13
|
-
// (not an alias) because Soroban SDK's #[contractimpl(contracttrait)] generates
|
|
14
|
-
// a macro call `OAppCore!(...)` that needs to resolve to the macro
|
|
15
|
-
// exported by #[contracttrait].
|
|
16
|
-
let impl_mod = syn::Ident::new(&format!("__oapp_impl_{}", name.to_string().to_snake_case()), name.span());
|
|
17
|
-
|
|
18
|
-
let manual_impl = (!manual_impl_core).then(|| {
|
|
19
|
-
quote! {
|
|
20
|
-
#[doc(hidden)]
|
|
21
|
-
mod #impl_mod {
|
|
22
|
-
use super::*;
|
|
23
|
-
// Import types used by OAppCore trait's default implementations
|
|
24
|
-
use soroban_sdk::{Address, BytesN, Env};
|
|
25
|
-
use oapp::oapp_core::OAppCore;
|
|
26
|
-
|
|
27
|
-
#[soroban_sdk::contractimpl(contracttrait)]
|
|
28
|
-
impl OAppCore for #name {}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
quote! {
|
|
34
|
-
#[soroban_sdk::contract]
|
|
35
|
-
#[common_macros::ttl_configurable]
|
|
36
|
-
#[common_macros::ownable]
|
|
37
|
-
#item_struct
|
|
38
|
-
|
|
39
|
-
#manual_impl
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
use crate::{oapp_core, oapp_options_type3, oapp_receiver, oapp_sender, util::ManualImplConfig};
|
|
2
|
-
use proc_macro2::TokenStream;
|
|
3
|
-
use quote::quote;
|
|
4
|
-
use syn::{Ident, ItemStruct};
|
|
5
|
-
|
|
6
|
-
/// Generates the full OApp implementation: Core + Sender + Receiver + OptionsType3.
|
|
7
|
-
///
|
|
8
|
-
/// Combines all OApp components. Use `manual_impl_config` to skip generating
|
|
9
|
-
/// specific trait implementations when custom implementations are needed.
|
|
10
|
-
pub fn generate_impl(name: &Ident, item: ItemStruct, manual_impl_config: ManualImplConfig) -> TokenStream {
|
|
11
|
-
let core_impl = oapp_core::generate_impl(name, item, manual_impl_config.core);
|
|
12
|
-
let sender_impl = oapp_sender::generate_impl(name, manual_impl_config.sender);
|
|
13
|
-
let receiver_impl = oapp_receiver::generate_impl(name, manual_impl_config.receiver);
|
|
14
|
-
let options_type3_impl = oapp_options_type3::generate_impl(name, manual_impl_config.options_type3);
|
|
15
|
-
quote! {
|
|
16
|
-
#core_impl
|
|
17
|
-
#sender_impl
|
|
18
|
-
#receiver_impl
|
|
19
|
-
#options_type3_impl
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
use heck::ToSnakeCase;
|
|
2
|
-
use proc_macro2::TokenStream;
|
|
3
|
-
use quote::quote;
|
|
4
|
-
use syn::Ident;
|
|
5
|
-
|
|
6
|
-
/// Generates the `OAppOptionsType3` trait implementation.
|
|
7
|
-
///
|
|
8
|
-
/// When `manual_impl_options_type3` is false, generates an empty `impl OAppOptionsType3`
|
|
9
|
-
/// that uses the trait's default implementations for enforced options management.
|
|
10
|
-
pub fn generate_impl(name: &Ident, manual_impl_options_type3: bool) -> TokenStream {
|
|
11
|
-
let impl_mod =
|
|
12
|
-
syn::Ident::new(&format!("__oapp_options_type3_impl_{}", name.to_string().to_snake_case()), name.span());
|
|
13
|
-
|
|
14
|
-
let options_type3_impl = (!manual_impl_options_type3).then(|| {
|
|
15
|
-
quote! {
|
|
16
|
-
#[doc(hidden)]
|
|
17
|
-
mod #impl_mod {
|
|
18
|
-
use super::*;
|
|
19
|
-
use soroban_sdk::{Env, Bytes, Vec};
|
|
20
|
-
use oapp::oapp_options_type3::{OAppOptionsType3, EnforcedOptionParam};
|
|
21
|
-
|
|
22
|
-
#[soroban_sdk::contractimpl(contracttrait)]
|
|
23
|
-
impl OAppOptionsType3 for #name {}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
quote! {
|
|
29
|
-
#options_type3_impl
|
|
30
|
-
}
|
|
31
|
-
}
|