Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Dec 5, 2024
1 parent d735d88 commit 1d0fb38
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 67 deletions.
21 changes: 14 additions & 7 deletions gtest/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,11 +867,8 @@ pub mod gbuild {
#[cfg(test)]
mod tests {
use super::Program;

use crate::{Log, ProgramIdWrapper, System, Value, DEFAULT_USER_ALICE, EXISTENTIAL_DEPOSIT};
use demo_constructor::{Arg, Scheme};
use gear_common::Origin;

use gear_core::ids::ActorId;
use gear_core_errors::{ErrorReplyReason, ReplyCode, SimpleExecutionError};

Expand Down Expand Up @@ -1085,7 +1082,7 @@ mod tests {

#[test]
#[should_panic(
expected = "Insufficient balance: user (0x0500000000000000000000000000000000000000000000000000000000000000) \
expected = "Insufficient balance: user (0x0000000000000000000000000500000000000000000000000000000000000000) \
tries to send (1000000000001) value, (4500000000000) gas and ED (1000000000000), while his balance (1000000000000)"
)]
fn fails_on_insufficient_balance() {
Expand Down Expand Up @@ -1446,7 +1443,12 @@ mod tests {
let handle = Calls::builder()
.reserve_gas(10_000_000_000, 5)
.store("reservation")
.reservation_send_value("reservation", user_id.into_origin().0, payload.clone(), 0);
.reservation_send_value(
"reservation",
ActorId::from(user_id).into_bytes(),
payload.clone(),
0,
);
let msg_id = prog.send(user_id, handle);
let res = sys.run_next_block();
assert!(res.succeed.contains(&msg_id));
Expand All @@ -1459,7 +1461,7 @@ mod tests {
let new_prog_id = 4343;
let new_program = Program::from_binary_with_id(&sys, new_prog_id, WASM_BINARY);
let payload = b"sup!".to_vec();
let handle = Calls::builder().send(user_id.into_origin().0, payload.clone());
let handle = Calls::builder().send(ActorId::from(user_id).into_bytes(), payload.clone());
let scheme = Scheme::predefined(
Calls::builder().noop(),
handle,
Expand All @@ -1474,7 +1476,12 @@ mod tests {
let handle = Calls::builder()
.reserve_gas(10_000_000_000, 5)
.store("reservation")
.reservation_send_value("reservation", new_prog_id.into_origin().0, [], 0);
.reservation_send_value(
"reservation",
ActorId::from(new_prog_id).into_bytes(),
[],
0,
);
let msg_id = prog.send(user_id, handle);
let res = sys.run_next_block();
assert!(res.succeed.contains(&msg_id));
Expand Down
2 changes: 1 addition & 1 deletion pallets/gear-builtin/src/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn calculate_gas_info_works() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER) && message.details().is_some() && {
message.destination() == SIGNER.cast() && message.details().is_some() && {
let details = message.details().expect("Value checked above");
details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
Expand Down
42 changes: 21 additions & 21 deletions pallets/gear-builtin/src/tests/bls381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn decoding_error() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::UserspacePanic,
Expand Down Expand Up @@ -137,7 +137,7 @@ fn multi_miller_loop() {

assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::UserspacePanic,
Expand Down Expand Up @@ -172,7 +172,7 @@ fn multi_miller_loop() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -197,7 +197,7 @@ fn multi_miller_loop() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -256,7 +256,7 @@ fn final_exponentiation() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -281,7 +281,7 @@ fn final_exponentiation() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -339,7 +339,7 @@ fn msm_g1() {

assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::UserspacePanic,
Expand Down Expand Up @@ -374,7 +374,7 @@ fn msm_g1() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -399,7 +399,7 @@ fn msm_g1() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -457,7 +457,7 @@ fn msm_g2() {

assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::UserspacePanic,
Expand Down Expand Up @@ -492,7 +492,7 @@ fn msm_g2() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -517,7 +517,7 @@ fn msm_g2() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -574,7 +574,7 @@ fn mul_projective_g1() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -599,7 +599,7 @@ fn mul_projective_g1() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -656,7 +656,7 @@ fn mul_projective_g2() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -681,7 +681,7 @@ fn mul_projective_g2() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -717,7 +717,7 @@ fn aggregate_g1() {
let encoded_points = ark_points.encode();

let payload = Request::AggregateG1 { points: encoded_points }.encode();
let builtin_actor_id: ProgramId = H256::from(ACTOR_ID).cast();
let builtin_actor_id = ACTOR_ID.into();
let gas_info = get_gas_info(builtin_actor_id, payload.clone());

// Check the case of insufficient gas
Expand All @@ -736,7 +736,7 @@ fn aggregate_g1() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -761,7 +761,7 @@ fn aggregate_g1() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down Expand Up @@ -816,7 +816,7 @@ fn map_to_g2affine() {
// An error reply should have been sent.
assert!(System::events().into_iter().any(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
message.destination() == ProgramId::from(SIGNER)
message.destination() == SIGNER.cast()
&& matches!(message.details(), Some(details) if details.to_reply_code()
== ReplyCode::Error(ErrorReplyReason::Execution(
SimpleExecutionError::RanOutOfGas,
Expand All @@ -841,7 +841,7 @@ fn map_to_g2affine() {

let response = match System::events().into_iter().find_map(|e| match e.event {
RuntimeEvent::Gear(pallet_gear::Event::<Test>::UserMessageSent { message, .. }) => {
assert_eq!(message.destination(), ProgramId::from(SIGNER));
assert_eq!(message.destination(), SIGNER.cast());
assert!(matches!(message.details(), Some(details) if matches!(details.to_reply_code(), ReplyCode::Success(..))));

Some(message.payload_bytes().to_vec())
Expand Down
12 changes: 7 additions & 5 deletions pallets/gear-debug/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::*;
use crate::mock::*;
use common::{self, event::MessageEntry, CodeStorage, Origin as _};
use common::{self, event::MessageEntry, CodeStorage, Origin};
use frame_support::assert_ok;
use gear_core::{
ids::{prelude::*, CodeId, MessageId, ProgramId},
Expand Down Expand Up @@ -251,7 +251,7 @@ fn debug_mode_works() {
DispatchKind::Handle,
StoredMessage::new(
message_id_1,
1.into(),
1.cast(),
program_id_1,
Default::default(),
0,
Expand All @@ -263,7 +263,7 @@ fn debug_mode_works() {
DispatchKind::Handle,
StoredMessage::new(
message_id_2,
1.into(),
1.cast(),
program_id_2,
Default::default(),
0,
Expand Down Expand Up @@ -356,10 +356,12 @@ fn get_last_program_id() -> ProgramId {
}

#[track_caller]
fn maybe_last_message(account: u64) -> Option<UserMessage> {
fn maybe_last_message(account: impl Origin) -> Option<UserMessage> {
let account = account.cast();

System::events().into_iter().rev().find_map(|e| {
if let super::mock::RuntimeEvent::Gear(Event::UserMessageSent { message, .. }) = e.event {
if message.destination() == account.into() {
if message.destination() == account {
Some(message)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions pallets/gear-scheduler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ fn wl_cost_for(amount_of_blocks: u64) -> u128 {
gas_price(<Pallet<Test> as Scheduler>::CostsPerBlock::waitlist() * amount_of_blocks)
}

fn dispatch_from(src: impl Into<ProgramId>) -> StoredDispatch {
fn dispatch_from(src: impl Origin) -> StoredDispatch {
StoredDispatch::new(
DispatchKind::Handle,
StoredMessage::new(
H256::random().cast(),
src.into(),
src.cast(),
H256::random().cast(),
Default::default(),
0,
Expand Down
Loading

0 comments on commit 1d0fb38

Please sign in to comment.