Skip to content

Commit 498bca7

Browse files
committed
cli support
1 parent df9d6ee commit 498bca7

File tree

12 files changed

+2261
-687
lines changed

12 files changed

+2261
-687
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aptos-move/move-examples/cli-e2e-tests/common/sources/cli_e2e_tests.move

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,6 @@ module addr::cli_e2e_tests {
6161
weight: u64,
6262
}
6363

64-
// Test structs for struct/enum transaction arguments
65-
66-
/// A simple public struct with copy ability for testing struct arguments
67-
public struct Point has copy, drop {
68-
x: u64,
69-
y: u64,
70-
}
71-
72-
/// A public struct with nested struct fields
73-
public struct Rectangle has copy, drop {
74-
top_left: Point,
75-
bottom_right: Point,
76-
}
77-
78-
/// A public struct with vector field
79-
public struct Data has copy, drop {
80-
values: vector<u64>,
81-
name: String,
82-
}
83-
8464
fun init_module(account: &signer) {
8565
let collection = string::utf8(b"Hero Quest");
8666
collection::create_unlimited_collection(
@@ -383,72 +363,4 @@ module addr::cli_e2e_tests {
383363
assert!(object::is_owner(weapon, account_address), 13);
384364
assert!(object::is_owner(gem, account_address), 14);
385365
}
386-
387-
// Test entry functions for struct/enum transaction arguments
388-
389-
/// Test entry function that takes a Point argument
390-
public entry fun test_struct_point(_account: &signer, p: Point) {
391-
// Verify the point values are valid
392-
assert!(p.x >= 0 && p.y >= 0, 100);
393-
}
394-
395-
/// Test entry function that takes a Rectangle argument
396-
public entry fun test_struct_rectangle(_account: &signer, rect: Rectangle) {
397-
// Verify rectangle dimensions are valid
398-
assert!(rect.bottom_right.x >= rect.top_left.x, 101);
399-
assert!(rect.bottom_right.y >= rect.top_left.y, 102);
400-
}
401-
402-
/// Test entry function that takes Option::Some
403-
public entry fun test_option_some(_account: &signer, opt: Option<u64>) {
404-
// Verify it's Some and has expected value
405-
assert!(option::is_some(&opt), 103);
406-
let value = option::destroy_some(opt);
407-
assert!(value == 100, 104);
408-
}
409-
410-
/// Test entry function that takes Option::None
411-
public entry fun test_option_none(_account: &signer, opt: Option<u64>) {
412-
// Verify it's None
413-
assert!(option::is_none(&opt), 105);
414-
option::destroy_none(opt);
415-
}
416-
417-
/// Test entry function that takes Option<Point>
418-
public entry fun test_option_point(_account: &signer, opt: Option<Point>) {
419-
// Verify it's Some and contains a valid point
420-
assert!(option::is_some(&opt), 106);
421-
let point = option::destroy_some(opt);
422-
assert!(point.x == 50 && point.y == 75, 107);
423-
}
424-
425-
/// Test entry function with mixed primitive and struct arguments
426-
public entry fun test_mixed_args(_account: &signer, num: u64, p: Point, flag: bool) {
427-
assert!(num == 42, 108);
428-
assert!(p.x == 10 && p.y == 20, 109);
429-
assert!(flag == true, 110);
430-
}
431-
432-
/// Test entry function with type arguments and struct arguments
433-
public entry fun test_generic_with_struct<T: drop, U: drop>(
434-
_account: &signer,
435-
p: Point,
436-
value: u64
437-
) {
438-
assert!(p.x == 15 && p.y == 25, 111);
439-
assert!(value == 999, 112);
440-
}
441-
442-
/// Test entry function with Data struct containing vector
443-
public entry fun test_data_struct(_account: &signer, data: Data) {
444-
use std::vector;
445-
446-
// Verify vector contents
447-
assert!(vector::length(&data.values) == 5, 113);
448-
assert!(*vector::borrow(&data.values, 0) == 1, 114);
449-
assert!(*vector::borrow(&data.values, 4) == 5, 115);
450-
451-
// Verify name
452-
assert!(string::bytes(&data.name) == &b"test_data", 116);
453-
}
454366
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "StructEnumArgsTests"
3+
version = "1.0.0"
4+
authors = []
5+
6+
[addresses]
7+
struct_enum_tests = "_"
8+
9+
[dev-addresses]
10+
11+
[dependencies.AptosFramework]
12+
git = "https://github.com/aptos-labs/aptos-core.git"
13+
rev = "mainnet"
14+
subdir = "aptos-move/framework/aptos-framework"
15+
16+
[dev-dependencies]
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/// Test module for struct and enum transaction arguments in CLI.
2+
///
3+
/// This module contains test types and entry functions for testing the CLI's
4+
/// ability to parse and pass struct/enum arguments to Move entry functions.
5+
module struct_enum_tests::struct_enum_tests {
6+
use std::option::{Self, Option};
7+
use std::string::String;
8+
use std::string::Self;
9+
10+
// Test structs for struct transaction arguments
11+
12+
/// A simple public struct with copy ability for testing struct arguments
13+
public struct Point has copy, drop {
14+
x: u64,
15+
y: u64,
16+
}
17+
18+
/// A public struct with nested struct fields
19+
public struct Rectangle has copy, drop {
20+
top_left: Point,
21+
bottom_right: Point,
22+
}
23+
24+
/// A public struct with vector field
25+
public struct Data has copy, drop {
26+
values: vector<u64>,
27+
name: String,
28+
}
29+
30+
// Test enums for enum transaction arguments
31+
32+
/// A public enum for testing enum arguments - simple variants
33+
public enum Color has copy, drop {
34+
Red,
35+
Green,
36+
Blue,
37+
RGB { r: u8, g: u8, b: u8 },
38+
}
39+
40+
/// A public enum with struct-containing variants
41+
public enum Shape has copy, drop {
42+
Circle { center: Point, radius: u64 },
43+
Rectangle { rect: Rectangle },
44+
Point { point: Point },
45+
}
46+
47+
// Test entry functions for struct transaction arguments
48+
49+
/// Test entry function that takes a Point argument
50+
public entry fun test_struct_point(_account: &signer, p: Point) {
51+
// Verify the point values are valid
52+
assert!(p.x > 0 && p.y > 0, 100);
53+
}
54+
55+
/// Test entry function that takes a Rectangle argument
56+
public entry fun test_struct_rectangle(_account: &signer, rect: Rectangle) {
57+
// Verify rectangle dimensions are valid
58+
assert!(rect.bottom_right.x >= rect.top_left.x, 101);
59+
assert!(rect.bottom_right.y >= rect.top_left.y, 102);
60+
}
61+
62+
/// Test entry function that takes Option::Some
63+
public entry fun test_option_some(_account: &signer, opt: Option<u64>) {
64+
// Verify it's Some and has expected value
65+
assert!(option::is_some(&opt), 103);
66+
let value = option::destroy_some(opt);
67+
assert!(value == 100, 104);
68+
}
69+
70+
/// Test entry function that takes Option::None
71+
public entry fun test_option_none(_account: &signer, opt: Option<u64>) {
72+
// Verify it's None
73+
assert!(option::is_none(&opt), 105);
74+
option::destroy_none(opt);
75+
}
76+
77+
/// Test entry function that takes Option<Point>
78+
public entry fun test_option_point(_account: &signer, opt: Option<Point>) {
79+
// Verify it's Some and contains a valid point
80+
assert!(option::is_some(&opt), 106);
81+
let point = option::destroy_some(opt);
82+
assert!(point.x == 50 && point.y == 75, 107);
83+
}
84+
85+
/// Test entry function with mixed primitive and struct arguments
86+
public entry fun test_mixed_args(_account: &signer, num: u64, p: Point, flag: bool) {
87+
assert!(num == 42, 108);
88+
assert!(p.x == 10 && p.y == 20, 109);
89+
assert!(flag == true, 110);
90+
}
91+
92+
/// Test entry function with type arguments and struct arguments
93+
public entry fun test_generic_with_struct<T: drop, U: drop>(
94+
_account: &signer,
95+
p: Point,
96+
value: u64
97+
) {
98+
assert!(p.x == 15 && p.y == 25, 111);
99+
assert!(value == 999, 112);
100+
}
101+
102+
/// Test entry function with Data struct containing vector
103+
public entry fun test_data_struct(_account: &signer, data: Data) {
104+
use std::vector;
105+
106+
// Verify vector contents
107+
assert!(vector::length(&data.values) == 5, 113);
108+
assert!(*vector::borrow(&data.values, 0) == 1, 114);
109+
assert!(*vector::borrow(&data.values, 4) == 5, 115);
110+
111+
// Verify name
112+
assert!(string::bytes(&data.name) == &b"test_data", 116);
113+
}
114+
115+
// Test entry functions for enum transaction arguments
116+
117+
/// Test entry function that takes a simple enum variant (no fields)
118+
public entry fun test_enum_color_simple(_account: &signer, color: Color) {
119+
// Verify it's the Red variant
120+
assert!(color is Color::Red, 120);
121+
}
122+
123+
/// Test entry function that takes an enum variant with fields
124+
public entry fun test_enum_color_rgb(_account: &signer, color: Color) {
125+
// Verify it's the RGB variant with expected values
126+
assert!(color is Color::RGB, 121);
127+
match (color) {
128+
Color::RGB { r, g, b } => {
129+
assert!(r == 255, 122);
130+
assert!(g == 128, 123);
131+
assert!(b == 0, 124);
132+
},
133+
_ => abort 125,
134+
}
135+
}
136+
137+
/// Test entry function that takes a Shape enum with Point variant
138+
public entry fun test_enum_shape_point(_account: &signer, shape: Shape) {
139+
// Verify it's the Point variant
140+
assert!(shape is Shape::Point, 126);
141+
match (shape) {
142+
Shape::Point { point } => {
143+
assert!(point.x == 100, 127);
144+
assert!(point.y == 200, 128);
145+
},
146+
_ => abort 129,
147+
}
148+
}
149+
150+
/// Test entry function that takes a Shape enum with Circle variant
151+
public entry fun test_enum_shape_circle(_account: &signer, shape: Shape) {
152+
// Verify it's the Circle variant
153+
assert!(shape is Shape::Circle, 130);
154+
match (shape) {
155+
Shape::Circle { center, radius } => {
156+
assert!(center.x == 50, 131);
157+
assert!(center.y == 50, 132);
158+
assert!(radius == 25, 133);
159+
},
160+
_ => abort 134,
161+
}
162+
}
163+
164+
/// Test entry function with mixed primitive and enum arguments
165+
public entry fun test_mixed_with_enum(_account: &signer, num: u64, color: Color, p: Point) {
166+
assert!(num == 999, 135);
167+
assert!(color is Color::Green, 136);
168+
assert!(p.x == 10 && p.y == 20, 137);
169+
}
170+
171+
/// Test entry function with Option<Color> enum
172+
public entry fun test_option_enum(_account: &signer, opt: Option<Color>) {
173+
// Verify it's Some and contains Green variant
174+
assert!(option::is_some(&opt), 138);
175+
let color = option::destroy_some(opt);
176+
assert!(color is Color::Green, 139);
177+
}
178+
}

crates/aptos/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ aptos-vm-genesis = { workspace = true }
5252
aptos-vm-logging = { workspace = true }
5353
aptos-vm-types = { workspace = true }
5454
aptos-workspace-server = { workspace = true }
55+
async-recursion = { workspace = true }
5556
async-trait = { workspace = true }
5657
backoff = { workspace = true }
5758
base64 = { workspace = true }

0 commit comments

Comments
 (0)