-
Notifications
You must be signed in to change notification settings - Fork 121
feat(ethexe/service): append tests for reply message with call == true
#5224
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
Open
StackOverflowExcept1on
wants to merge
2
commits into
master
Choose a base branch
from
av/ethexe-reply-callback-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+295
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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,54 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.33; | ||
|
|
||
| import {IDemoCallbacks} from "./IDemoCallbacks.sol"; | ||
| import {IMirror} from "src/IMirror.sol"; | ||
|
|
||
| contract DemoCaller is IDemoCallbacks { | ||
| IMirror public immutable VARA_ETH_PROGRAM; | ||
|
|
||
| bool public replyOnMethodNameCalled; | ||
| bool public onErrorReplyCalled; | ||
|
|
||
| event MethodNameReplied(bytes32 messageId); | ||
|
|
||
| event ErrorReplied(bytes32 messageId, bytes payload, bytes4 replyCode); | ||
|
|
||
| error UnauthorizedCaller(); | ||
|
|
||
| constructor(IMirror _varaEthProgram) { | ||
| VARA_ETH_PROGRAM = _varaEthProgram; | ||
| } | ||
|
|
||
| modifier onlyVaraEthProgram() { | ||
| _onlyVaraEthProgram(); | ||
| _; | ||
| } | ||
|
|
||
| function _onlyVaraEthProgram() internal view { | ||
| if (msg.sender != address(VARA_ETH_PROGRAM)) { | ||
| revert UnauthorizedCaller(); | ||
| } | ||
| } | ||
|
|
||
| function methodName(bool isPanic) external returns (bytes32) { | ||
| return VARA_ETH_PROGRAM.sendMessage(abi.encodePacked(isPanic), true); | ||
| } | ||
|
|
||
| /// forge-lint: disable-next-line(mixed-case-function) | ||
| function replyOn_methodName(bytes32 messageId) external onlyVaraEthProgram { | ||
| replyOnMethodNameCalled = true; | ||
|
|
||
| emit MethodNameReplied(messageId); | ||
| } | ||
|
|
||
| function onErrorReply(bytes32 messageId, bytes calldata payload, bytes4 replyCode) | ||
| external | ||
| payable | ||
| onlyVaraEthProgram | ||
| { | ||
| onErrorReplyCalled = true; | ||
|
|
||
| emit ErrorReplied(messageId, payload, replyCode); | ||
| } | ||
| } | ||
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,9 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.33; | ||
|
|
||
| import {ICallbacks} from "src/ICallbacks.sol"; | ||
|
|
||
| interface IDemoCallbacks is ICallbacks { | ||
| /// forge-lint: disable-next-line(mixed-case-function) | ||
| function replyOn_methodName(bytes32 messageId) external; | ||
| } |
Large diffs are not rendered by default.
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
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
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,21 @@ | ||
| [package] | ||
| name = "demo-reply-callback" | ||
| version = "0.1.0" | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
|
|
||
| [dependencies] | ||
| gstd.workspace = true | ||
| gear-workspace-hack.workspace = true | ||
|
|
||
| [build-dependencies] | ||
| gear-wasm-builder.workspace = true | ||
|
|
||
| [features] | ||
| debug = ["gstd/debug"] | ||
| default = ["std"] | ||
| std = [] | ||
| ethexe = ["gstd/ethexe"] |
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,21 @@ | ||
| // This file is part of Gear. | ||
|
|
||
| // Copyright (C) 2021-2025 Gear Technologies Inc. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| fn main() { | ||
| gear_wasm_builder::build(); | ||
| } |
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,30 @@ | ||
| // This file is part of Gear. | ||
|
|
||
| // Copyright (C) 2026 Gear Technologies Inc. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| #![no_std] | ||
|
|
||
| #[cfg(feature = "std")] | ||
| mod code { | ||
| include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| pub use code::WASM_BINARY_OPT as WASM_BINARY; | ||
|
|
||
| #[cfg(not(feature = "std"))] | ||
| mod wasm; |
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 @@ | ||
| // This file is part of Gear. | ||
|
|
||
| // Copyright (C) 2026 Gear Technologies Inc. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use gstd::{msg, prelude::*}; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| extern "C" fn init() {} | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| extern "C" fn handle() { | ||
| let payload = msg::load_bytes().expect("Failed to load payload"); | ||
| let is_panic = payload[0] == 0x01; | ||
StackOverflowExcept1on marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if is_panic { | ||
| panic!(); | ||
| } else { | ||
| let message_id = msg::id().into_bytes(); | ||
|
|
||
| // cast calldata "function replyOn_methodName(bytes32 messageId) external" "0x..." | ||
| let mut payload = [0u8; 36]; | ||
| payload[..4].copy_from_slice(&[0xb5, 0x2a, 0xb5, 0x55]); // DemoCaller.replyOn_methodName.selector | ||
StackOverflowExcept1on marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| payload[4..].copy_from_slice(&message_id); | ||
|
|
||
| msg::reply_bytes(payload, 0).expect("Failed to send reply"); | ||
| } | ||
| } | ||
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.