Skip to content

Commit dac7a55

Browse files
committed
cli support
1 parent df9d6ee commit dac7a55

File tree

7 files changed

+1876
-509
lines changed

7 files changed

+1876
-509
lines changed

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ module addr::cli_e2e_tests {
8181
name: String,
8282
}
8383

84+
/// A public enum for testing enum arguments - simple variants
85+
public enum Color has copy, drop {
86+
Red,
87+
Green,
88+
Blue,
89+
RGB { r: u8, g: u8, b: u8 },
90+
}
91+
92+
/// A public enum with struct-containing variants
93+
public enum Shape has copy, drop {
94+
Circle { center: Point, radius: u64 },
95+
Rectangle { rect: Rectangle },
96+
Point { point: Point },
97+
}
98+
8499
fun init_module(account: &signer) {
85100
let collection = string::utf8(b"Hero Quest");
86101
collection::create_unlimited_collection(
@@ -389,7 +404,7 @@ module addr::cli_e2e_tests {
389404
/// Test entry function that takes a Point argument
390405
public entry fun test_struct_point(_account: &signer, p: Point) {
391406
// Verify the point values are valid
392-
assert!(p.x >= 0 && p.y >= 0, 100);
407+
assert!(p.x > 0 && p.y > 0, 100);
393408
}
394409

395410
/// Test entry function that takes a Rectangle argument
@@ -451,4 +466,68 @@ module addr::cli_e2e_tests {
451466
// Verify name
452467
assert!(string::bytes(&data.name) == &b"test_data", 116);
453468
}
469+
470+
// Test entry functions for enum transaction arguments
471+
472+
/// Test entry function that takes a simple enum variant (no fields)
473+
public entry fun test_enum_color_simple(_account: &signer, color: Color) {
474+
// Verify it's the Red variant
475+
assert!(color is Color::Red, 120);
476+
}
477+
478+
/// Test entry function that takes an enum variant with fields
479+
public entry fun test_enum_color_rgb(_account: &signer, color: Color) {
480+
// Verify it's the RGB variant with expected values
481+
assert!(color is Color::RGB, 121);
482+
match (color) {
483+
Color::RGB { r, g, b } => {
484+
assert!(r == 255, 122);
485+
assert!(g == 128, 123);
486+
assert!(b == 0, 124);
487+
},
488+
_ => abort 125,
489+
}
490+
}
491+
492+
/// Test entry function that takes a Shape enum with Point variant
493+
public entry fun test_enum_shape_point(_account: &signer, shape: Shape) {
494+
// Verify it's the Point variant
495+
assert!(shape is Shape::Point, 126);
496+
match (shape) {
497+
Shape::Point { point } => {
498+
assert!(point.x == 100, 127);
499+
assert!(point.y == 200, 128);
500+
},
501+
_ => abort 129,
502+
}
503+
}
504+
505+
/// Test entry function that takes a Shape enum with Circle variant
506+
public entry fun test_enum_shape_circle(_account: &signer, shape: Shape) {
507+
// Verify it's the Circle variant
508+
assert!(shape is Shape::Circle, 130);
509+
match (shape) {
510+
Shape::Circle { center, radius } => {
511+
assert!(center.x == 50, 131);
512+
assert!(center.y == 50, 132);
513+
assert!(radius == 25, 133);
514+
},
515+
_ => abort 134,
516+
}
517+
}
518+
519+
/// Test entry function with mixed primitive and enum arguments
520+
public entry fun test_mixed_with_enum(_account: &signer, num: u64, color: Color, p: Point) {
521+
assert!(num == 999, 135);
522+
assert!(color is Color::Green, 136);
523+
assert!(p.x == 10 && p.y == 20, 137);
524+
}
525+
526+
/// Test entry function with Option<Color> enum
527+
public entry fun test_option_enum(_account: &signer, opt: Option<Color>) {
528+
// Verify it's Some and contains Green variant
529+
assert!(option::is_some(&opt), 138);
530+
let color = option::destroy_some(opt);
531+
assert!(color is Color::Green, 139);
532+
}
454533
}

0 commit comments

Comments
 (0)