Skip to content

Commit

Permalink
Removed singal constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mqxf committed Nov 4, 2023
1 parent 6d874f9 commit ca70e2d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 23 deletions.
6 changes: 5 additions & 1 deletion examples/constructor/src/scheme/demo_exit_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub fn handle_reply() -> Calls {
Calls::builder().noop()
}

pub fn handle_signal() -> Calls {
Calls::builder().noop()
}

pub fn scheme() -> Scheme {
Scheme::predefined(init(), handle(), handle_reply())
Scheme::predefined(init(), handle(), handle_reply(), handle_signal())
}
11 changes: 10 additions & 1 deletion examples/constructor/src/scheme/demo_exit_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ pub fn handle_reply() -> Calls {
Calls::builder().noop()
}

pub fn handle_signal() -> Calls {
Calls::builder().noop()
}

pub fn scheme(send_before_exit: bool) -> Scheme {
Scheme::predefined(init(send_before_exit), handle(), handle_reply())
Scheme::predefined(
init(send_before_exit),
handle(),
handle_reply(),
handle_signal(),
)
}
6 changes: 5 additions & 1 deletion examples/constructor/src/scheme/demo_ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub fn handle_reply() -> Calls {
Calls::builder().noop()
}

pub fn handle_signal() -> Calls {
Calls::builder().noop()
}

pub fn scheme() -> Scheme {
Scheme::predefined(init(), handle(), handle_reply())
Scheme::predefined(init(), handle(), handle_reply(), handle_signal())
}
11 changes: 10 additions & 1 deletion examples/constructor/src/scheme/demo_proxy_with_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ pub fn handle_reply() -> Calls {
)
}

pub fn handle_signal() -> Calls {
Calls::builder().noop()
}

pub fn scheme(destination: [u8; 32], delay: u32) -> Scheme {
Scheme::predefined(init(destination, delay), handle(), handle_reply())
Scheme::predefined(
init(destination, delay),
handle(),
handle_reply(),
handle_signal(),
)
}
5 changes: 5 additions & 0 deletions examples/constructor/src/scheme/demo_reply_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ pub fn handle_reply(checker: [u8; 32]) -> Calls {
.send_wgas(checker, Arg::bytes(SUCCESS_MESSAGE), 10_000)
}

pub fn handle_signal() -> Calls {
Calls::builder().noop()
}

pub fn scheme(checker: [u8; 32], destination: [u8; 32], gas_to_send: u64) -> Scheme {
Scheme::predefined(
init(),
handle(destination, gas_to_send),
handle_reply(checker),
handle_signal(),
)
}
6 changes: 5 additions & 1 deletion examples/constructor/src/scheme/demo_wait_init_exit_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub fn handle_reply() -> Calls {
.exit(source_var)
}

pub fn handle_signal() -> Calls {
Calls::builder().noop()
}

pub fn scheme() -> Scheme {
Scheme::predefined(init(), handle(), handle_reply())
Scheme::predefined(init(), handle(), handle_reply(), handle_signal())
}
16 changes: 6 additions & 10 deletions examples/constructor/src/scheme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ impl Scheme {
Self::Direct(init.calls())
}

pub fn predefined(init: Calls, handle: Calls, handle_reply: Calls) -> Self {
Self::Predefined(
init.calls(),
handle.calls(),
handle_reply.calls(),
Default::default(),
)
}

pub fn signal(init: Calls, handle: Calls, handle_reply: Calls, handle_signal: Calls) -> Self {
pub fn predefined(
init: Calls,
handle: Calls,
handle_reply: Calls,
handle_signal: Calls,
) -> Self {
Self::Predefined(
init.calls(),
handle.calls(),
Expand Down
37 changes: 29 additions & 8 deletions pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// 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 crate::tests::utils::ProgramCodeKind::Default;
use crate::{
internal::HoldBoundBuilder,
manager::HandleKind,
Expand Down Expand Up @@ -167,7 +168,12 @@ fn value_counter_set_correctly_for_interruptions() {
.send_value(Arg::new([0u8; 32]), Arg::new(vec![]), "value_store")
.wait_for(1);

let scheme = Scheme::predefined(Calls::builder().noop(), handle, Calls::builder().noop());
let scheme = Scheme::predefined(
Calls::builder().noop(),
handle,
Calls::builder().noop(),
Calls::builder().noop(),
);

init_logger();
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -5937,7 +5943,12 @@ fn pause_terminated_exited_program() {
let (_, terminated_pid) = submit_constructor_with_args(
USER_1,
DEFAULT_SALT,
Scheme::predefined(init, Default::default(), Default::default()),
Scheme::predefined(
init,
Default::default(),
Default::default(),
Default::default(),
),
0,
);

Expand Down Expand Up @@ -8555,7 +8566,7 @@ fn demo_constructor_is_demo_ping() {

let handle_reply = Calls::builder().panic("I don't like replies");

let scheme = Scheme::predefined(init, handle, handle_reply);
let scheme = Scheme::predefined(init, handle, handle_reply, Default::default());

// checking init
let (_init_mid, constructor_id) = utils::init_constructor(scheme);
Expand Down Expand Up @@ -14105,7 +14116,12 @@ fn double_read_works() {
.load("read2")
.bytes_eq("is_eq", "read1", "read2")
.if_else("is_eq", noop_branch, panic_branch);
let predefined_scheme = Scheme::predefined(Default::default(), handle, Default::default());
let predefined_scheme = Scheme::predefined(
Default::default(),
handle,
Default::default(),
Default::default(),
);

let (_, pid) = utils::init_constructor(predefined_scheme);

Expand Down Expand Up @@ -14334,7 +14350,7 @@ fn test_send_to_terminated_from_program() {
// Using `USER_2` not to pollute `USER_1` mailbox to make test easier.
USER_2,
b"salt1",
Scheme::predefined(init, handle, Calls::default()),
Scheme::predefined(init, handle, Calls::default(), Calls::default()),
0,
);

Expand All @@ -14351,7 +14367,7 @@ fn test_send_to_terminated_from_program() {
// Using `USER_2` not to pollute `USER_1` mailbox to make test easier.
USER_2,
b"salt2",
Scheme::predefined(Calls::default(), handle, handle_reply),
Scheme::predefined(Calls::default(), handle, handle_reply, Calls::default()),
0,
);

Expand Down Expand Up @@ -14650,7 +14666,7 @@ fn test_gas_info_of_terminated_program() {
let (_, pid_dead) = utils::submit_constructor_with_args(
USER_1,
b"salt1",
Scheme::predefined(init_dead, handle_dead, Calls::default()),
Scheme::predefined(init_dead, handle_dead, Calls::default(), Calls::default()),
0,
);

Expand All @@ -14659,7 +14675,12 @@ fn test_gas_info_of_terminated_program() {
let (_, proxy_pid) = utils::submit_constructor_with_args(
USER_1,
b"salt2",
Scheme::predefined(Calls::default(), handle_proxy, Calls::default()),
Scheme::predefined(
Calls::default(),
handle_proxy,
Calls::default(),
Calls::default(),
),
0,
);

Expand Down

0 comments on commit ca70e2d

Please sign in to comment.