|
| 1 | +// Copyright © Aptos Foundation |
| 2 | +// Parts of the project are originally copyright © Meta Platforms, Inc. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +use super::new_test_context_with_orderless_flags; |
| 6 | +use aptos_api_test_context::{current_function_name, TestContext}; |
| 7 | +use rstest::rstest; |
| 8 | +use serde_json::json; |
| 9 | +use std::path::PathBuf; |
| 10 | + |
| 11 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 12 | +#[rstest( |
| 13 | + use_txn_payload_v2_format, |
| 14 | + use_orderless_transactions, |
| 15 | + case(false, false), |
| 16 | + case(true, false), |
| 17 | + case(true, true) |
| 18 | +)] |
| 19 | +async fn test_signed_ints(use_txn_payload_v2_format: bool, use_orderless_transactions: bool) { |
| 20 | + let mut context = new_test_context_with_orderless_flags( |
| 21 | + current_function_name!(), |
| 22 | + use_txn_payload_v2_format, |
| 23 | + use_orderless_transactions, |
| 24 | + ); |
| 25 | + let mut account = context.create_account().await; |
| 26 | + let account_addr = account.address(); |
| 27 | + |
| 28 | + // Publish packages |
| 29 | + let named_addresses = vec![("account".to_string(), account_addr)]; |
| 30 | + let txn = futures::executor::block_on(async move { |
| 31 | + let path = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")) |
| 32 | + .join("../aptos-move/move-examples/signed_int/calculator"); |
| 33 | + TestContext::build_package_with_latest_language(path, named_addresses) |
| 34 | + }); |
| 35 | + context.publish_package(&mut account, txn).await; |
| 36 | + |
| 37 | + let state_resource = format!("{}::{}::{}", account_addr, "calculator", "State"); |
| 38 | + let state = &context |
| 39 | + .gen_resource(&account_addr, &state_resource) |
| 40 | + .await |
| 41 | + .unwrap()["data"]; |
| 42 | + |
| 43 | + println!("[Result] state: {:?}", state); |
| 44 | + |
| 45 | + context |
| 46 | + .api_execute_entry_function( |
| 47 | + &mut account, |
| 48 | + &format!("0x{}::calculator::number", account_addr.to_hex()), |
| 49 | + json!([]), |
| 50 | + json!(["0"]), |
| 51 | + ) |
| 52 | + .await; |
| 53 | + |
| 54 | + let state = &context |
| 55 | + .gen_resource(&account_addr, &state_resource) |
| 56 | + .await |
| 57 | + .unwrap()["data"]; |
| 58 | + |
| 59 | + println!("[Result] state: {:?}", state); |
| 60 | + |
| 61 | + context |
| 62 | + .api_execute_entry_function( |
| 63 | + &mut account, |
| 64 | + &format!("0x{}::calculator::add", account_addr.to_hex()), |
| 65 | + json!([]), |
| 66 | + json!(["2"]), |
| 67 | + ) |
| 68 | + .await; |
| 69 | + |
| 70 | + let state = &context |
| 71 | + .gen_resource(&account_addr, &state_resource) |
| 72 | + .await |
| 73 | + .unwrap()["data"]; |
| 74 | + |
| 75 | + println!("[Result] state: {:?}", state); |
| 76 | + |
| 77 | + context |
| 78 | + .api_execute_entry_function( |
| 79 | + &mut account, |
| 80 | + &format!("0x{}::calculator::sub", account_addr.to_hex()), |
| 81 | + json!([]), |
| 82 | + json!(["-2"]), |
| 83 | + ) |
| 84 | + .await; |
| 85 | + |
| 86 | + let state = &context |
| 87 | + .gen_resource(&account_addr, &state_resource) |
| 88 | + .await |
| 89 | + .unwrap()["data"]; |
| 90 | + |
| 91 | + println!("[Result] state: {:?}", state); |
| 92 | + |
| 93 | + context |
| 94 | + .api_execute_entry_function( |
| 95 | + &mut account, |
| 96 | + &format!("0x{}::calculator::mul", account_addr.to_hex()), |
| 97 | + json!([]), |
| 98 | + json!(["2"]), |
| 99 | + ) |
| 100 | + .await; |
| 101 | + |
| 102 | + let state = &context |
| 103 | + .gen_resource(&account_addr, &state_resource) |
| 104 | + .await |
| 105 | + .unwrap()["data"]; |
| 106 | + |
| 107 | + println!("[Result] state: {:?}", state); |
| 108 | + |
| 109 | + context |
| 110 | + .api_execute_entry_function( |
| 111 | + &mut account, |
| 112 | + &format!("0x{}::calculator::div", account_addr.to_hex()), |
| 113 | + json!([]), |
| 114 | + json!(["3"]), |
| 115 | + ) |
| 116 | + .await; |
| 117 | + |
| 118 | + let state = &context |
| 119 | + .gen_resource(&account_addr, &state_resource) |
| 120 | + .await |
| 121 | + .unwrap()["data"]; |
| 122 | + |
| 123 | + println!("[Result] state: {:?}", state); |
| 124 | +} |
0 commit comments