Skip to content

Commit

Permalink
Fixed test failures after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Aregnaz Harutyunyan committed Dec 9, 2024
1 parent 7007a29 commit 1e465c4
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 58 deletions.
127 changes: 90 additions & 37 deletions aptos-move/e2e-testsuite/src/tests/automation_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright (c) 2024 Supra.

use std::ops::{Deref, DerefMut};
use aptos_cached_packages::aptos_framework_sdk_builder;
use aptos_language_e2e_tests::account::{Account, AccountData};
use aptos_language_e2e_tests::executor::FakeExecutor;
use aptos_types::transaction::automation::AutomationTransactionPayload;
use aptos_types::transaction::{EntryFunction, ExecutionStatus, SignedTransaction, TransactionOutput, TransactionPayload, TransactionStatus};
use aptos_types::transaction::{
EntryFunction, ExecutionStatus, SignedTransaction, TransactionOutput, TransactionPayload,
TransactionStatus,
};
use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::language_storage::ModuleId;
use move_core_types::vm_status::StatusCode;

use std::ops::{Deref, DerefMut};

struct AutomationTransactionTestContext {
executor: FakeExecutor,
Expand Down Expand Up @@ -39,20 +41,40 @@ impl AutomationTransactionTestContext {
new_account_data
}

fn create_automation_txn_payload(&self, seq_num: u64, inner_payload: EntryFunction, expiry_time: u64, max_gas_amount: u64, gas_price_cap: u64 ) -> SignedTransaction {
fn create_automation_txn_payload(
&self,
seq_num: u64,
inner_payload: EntryFunction,
expiry_time: u64,
max_gas_amount: u64,
gas_price_cap: u64,
) -> SignedTransaction {
let inner_entry_function_bytes =
bcs::to_bytes(&inner_payload).expect("Can't serialize entry function");
self.create_automation_txn_payload_raw(seq_num, inner_entry_function_bytes, expiry_time, max_gas_amount, gas_price_cap)
self.create_automation_txn_payload_raw(
seq_num,
inner_entry_function_bytes,
expiry_time,
max_gas_amount,
gas_price_cap,
)
}

fn create_automation_txn_payload_raw(&self, seq_num: u64, inner_entry_function_bytes: Vec<u8>, expiry_time: u64, max_gas_amount: u64, gas_price_cap: u64 ) -> SignedTransaction {
fn create_automation_txn_payload_raw(
&self,
seq_num: u64,
inner_entry_function_bytes: Vec<u8>,
expiry_time: u64,
max_gas_amount: u64,
gas_price_cap: u64,
) -> SignedTransaction {
let automation_txn_payload = aptos_framework_sdk_builder::automation_registry_register(
inner_entry_function_bytes,
expiry_time,
max_gas_amount,
gas_price_cap,
)
.into_entry_function();
.into_entry_function();
let automation_txn = TransactionPayload::Automation(
AutomationTransactionPayload::EntryFunction(automation_txn_payload),
);
Expand All @@ -75,7 +97,6 @@ impl AutomationTransactionTestContext {
},
_ => panic!("Unexpected transaction status: {output:?}"),
}

}
}

Expand All @@ -93,7 +114,6 @@ impl DerefMut for AutomationTransactionTestContext {
}
}


#[test]
fn check_successful_registration() {
let mut test_context = AutomationTransactionTestContext::new();
Expand All @@ -103,9 +123,22 @@ fn check_successful_registration() {
aptos_framework_sdk_builder::supra_coin_mint(dest_account.address().clone(), 100)
.into_entry_function();

// TODO: Update expiry_time, max_gas_amount, gas_price_cap when
let automation_txn = test_context.create_automation_txn_payload(0, inner_entry_function, 3600, 100, 100);

let view_output = test_context.execute_view_function(
str::parse("0x1::timestamp::now_seconds").unwrap(),
vec![],
vec![],
);
let result = view_output.values.expect("Valid result");
assert_eq!(result.len(), 1);
let now = bcs::from_bytes::<u64>(&result[0]).unwrap();
let expiration_time = now + 4000;
let automation_txn = test_context.create_automation_txn_payload(
0,
inner_entry_function,
expiration_time,
100,
100,
);

let output = test_context.execute_and_apply(automation_txn);
assert_eq!(
Expand Down Expand Up @@ -143,7 +176,8 @@ fn check_registration_from_non_automation_context() {
100,
100,
);
let user_txn_with_register_entry = test_context.txn_sender
let user_txn_with_register_entry = test_context
.txn_sender
.account()
.transaction()
.payload(entry_with_register)
Expand All @@ -154,7 +188,7 @@ fn check_registration_from_non_automation_context() {
match output.status() {
TransactionStatus::Keep(ExecutionStatus::MoveAbort { code, .. }) => {
//ENOT_AUTOMATION_TXN_CONTEXT
assert_eq!(*code, 3);
assert_eq!(*code, 6);
},
_ => panic!("Unexpected transaction status: {output:?}"),
}
Expand All @@ -174,7 +208,8 @@ fn check_automation_txn_with_invalid_payload(test_context: &mut AutomationTransa
let any_entry_function =
aptos_framework_sdk_builder::supra_coin_mint(dest_account.address().clone(), 100)
.into_entry_function();
let user_txn_with_register_entry = test_context.txn_sender
let user_txn_with_register_entry = test_context
.txn_sender
.account()
.transaction()
.payload(TransactionPayload::Automation(
Expand All @@ -184,15 +219,24 @@ fn check_automation_txn_with_invalid_payload(test_context: &mut AutomationTransa
.sign();

let output = test_context.execute_transaction(user_txn_with_register_entry);
AutomationTransactionTestContext::check_miscellaneous_output(output, StatusCode::INVALID_AUTOMATION_PAYLOAD)
AutomationTransactionTestContext::check_miscellaneous_output(
output,
StatusCode::INVALID_AUTOMATION_PAYLOAD,
)
}

fn check_automation_txn_with_invalid_inner_function(test_context: &mut AutomationTransactionTestContext) {
fn check_automation_txn_with_invalid_inner_function(
test_context: &mut AutomationTransactionTestContext,
) {
println!("checking automation txn within invalid inner function");
// Create automation transaction with non-entry-function
let automation_transaction = test_context.create_automation_txn_payload_raw( 0, vec![42;32], 100, 100, 100);
let automation_transaction =
test_context.create_automation_txn_payload_raw(0, vec![42; 32], 100, 100, 100);
let output = test_context.execute_transaction(automation_transaction);
AutomationTransactionTestContext::check_miscellaneous_output(output, StatusCode::FAILED_TO_DESERIALIZE_ARGUMENT);
AutomationTransactionTestContext::check_miscellaneous_output(
output,
StatusCode::FAILED_TO_DESERIALIZE_ARGUMENT,
);

// Create automation transaction with entry-function with invalid arguments.
let dest_account = test_context.new_account_data(0, 0);
Expand All @@ -201,37 +245,46 @@ fn check_automation_txn_with_invalid_inner_function(test_context: &mut Automatio
.into_entry_function()
.into_inner();
let inner_entry_function = EntryFunction::new(m_id, f_id, vec![], vec![]);
let automation_txn = test_context.create_automation_txn_payload(0, inner_entry_function, 3600, 100, 100);
let automation_txn =
test_context.create_automation_txn_payload(0, inner_entry_function, 3600, 100, 100);

let output = test_context.execute_transaction(automation_txn);
AutomationTransactionTestContext::check_miscellaneous_output(output, StatusCode::INVALID_AUTOMATION_INNER_PAYLOAD);
AutomationTransactionTestContext::check_miscellaneous_output(
output,
StatusCode::INVALID_AUTOMATION_INNER_PAYLOAD,
);
}

fn check_automation_txn_with_empty_payload_arguments(test_context: &mut AutomationTransactionTestContext) {
fn check_automation_txn_with_empty_payload_arguments(
test_context: &mut AutomationTransactionTestContext,
) {
println!("checking automation txn within empty payload arguments");
let register_payload =
EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("automation_registry").to_owned(),
),
ident_str!("register").to_owned(),
vec![],
vec![],
);
let register_payload = EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("automation_registry").to_owned(),
),
ident_str!("register").to_owned(),
vec![],
vec![],
);

let automation_txn_payload = TransactionPayload::Automation(
AutomationTransactionPayload::EntryFunction(register_payload),
);
let automation_txn = test_context.txn_sender
let automation_txn = test_context
.txn_sender
.account()
.transaction()
.payload(automation_txn_payload)
.sequence_number(0)
.sign();
let output = test_context.execute_transaction(automation_txn);
AutomationTransactionTestContext::check_miscellaneous_output(output, StatusCode::INVALID_AUTOMATION_PAYLOAD_ARGUMENTS)
AutomationTransactionTestContext::check_miscellaneous_output(
output,
StatusCode::INVALID_AUTOMATION_PAYLOAD_ARGUMENTS,
)
}
8 changes: 8 additions & 0 deletions aptos-move/framework/cached-packages/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ fn main() -> Result<()> {
.join("Move.toml")
.display()
);
println!(
"cargo:rerun-if-changed={}",
prev_dir.join("supra-stdlib").join("sources").display()
);
println!(
"cargo:rerun-if-changed={}",
prev_dir.join("supra-stdlib").join("Move.toml").display()
);
println!(
"cargo:rerun-if-changed={}",
prev_dir.join("supra-framework").join("sources").display()
Expand Down
1 change: 1 addition & 0 deletions aptos-move/framework/src/aptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl ReleaseTarget {
let result = vec![
("move-stdlib", None),
("aptos-stdlib", None),
("supra-stdlib", None),
(
"supra-framework",
Some("cached-packages/src/aptos_framework_sdk_builder.rs"),
Expand Down
Loading

0 comments on commit 1e465c4

Please sign in to comment.