From 98e58796f543376f8a4d8bf6e776c9010f98f77d Mon Sep 17 00:00:00 2001 From: inrust Date: Sat, 23 Mar 2024 19:14:08 +0800 Subject: [PATCH] 100243333 exam --- student_no.txt | 1 + task1/sources/main.move | 6 ++---- task2/sources/main.move | 26 +++++++++++--------------- task3/sources/m1.move | 12 +++++------- task3/sources/m2.move | 2 +- task3/sources/m3.move | 2 +- task4/sources/main.move | 14 ++++++++------ 7 files changed, 29 insertions(+), 34 deletions(-) diff --git a/student_no.txt b/student_no.txt index 2a6816f..ae60a70 100644 --- a/student_no.txt +++ b/student_no.txt @@ -1 +1,2 @@ # Please enter your 9-digit student number below. +100243333 \ No newline at end of file diff --git a/task1/sources/main.move b/task1/sources/main.move index 2507060..86e002d 100644 --- a/task1/sources/main.move +++ b/task1/sources/main.move @@ -2,16 +2,14 @@ // Create a struct called Wallet with a single field called balance of type u64. module 0x42::Task1 { - // TODO // Define a struct called Wallet with a single field called balance of type u64. struct Wallet has drop { - // ... + balance: u64 } - // TODO // Define a function called myWallet that returns a Wallet with a balance of 1000. fun myWallet(): Wallet { - // ... + Wallet { balance: 1000 } } #[test] diff --git a/task2/sources/main.move b/task2/sources/main.move index d6746d8..b7cb7b0 100644 --- a/task2/sources/main.move +++ b/task2/sources/main.move @@ -2,16 +2,15 @@ module 0x42::Task2{ use std::signer; - // TODO // Define a struct Foo with two fields: u: u64, b: bool with ability to drop - struct Foo { - // ... + struct Foo has drop { + u: u64, + b: bool } - // TODO // Define a function gen_Fool that takes two arguments: u: u64, b: bool and returns a Foo fun gen_Fool(u:u64, b:bool): Foo { - // ... + Foo {u, b} } #[test] @@ -30,16 +29,15 @@ module 0x42::Task2{ assert!(f.b == true,1); } - // TODO // Define a struct Soo with two fields: x: u64, y: u64 with ability to copy - struct Soo { - // ... + struct Soo has copy { + x: u64, + y: u64 } - // TODO // Define a function gen_Soo that takes two arguments: x: u64, y: u64 and returns a Soo fun gen_Soo(x:u64, y:u64): Soo { - // ... + Soo {x, y} } #[test] @@ -54,15 +52,13 @@ module 0x42::Task2{ let Soo { x: _, y: _ } = c2; } - // TODO // Define a struct Koo with a field: s: Moo with ability - struct Koo { + struct Koo has key { s: Moo } - // TODO // Define a struct Moo with a field: x: u64 with ability - struct Moo { + struct Moo has store { x: u64 } @@ -70,7 +66,7 @@ module 0x42::Task2{ // TODO // Define a function gen_Moo that takes an argument: x: u64 and returns a Moo fun gen_Moo(x:u64): Moo { - // ... + Moo {x} } #[test] diff --git a/task3/sources/m1.move b/task3/sources/m1.move index e3542c4..ee86a29 100644 --- a/task3/sources/m1.move +++ b/task3/sources/m1.move @@ -2,21 +2,19 @@ // Observe the function permissions called in M1, M2, and M3. // modify the visibility of the functions in M1, and set the M1 module visibility. -module 0x42::M1{ +module 0x42::M1 { - // TODO // Define a module friend M2 - friend ; + friend 0x42::M2; + friend 0x42::M3; - // TODO // Define a function num that returns 66 with choose public or friend visibility - fun num():u64 { + public(friend) fun num():u64 { 66 } - // TODO // Define a function num2 that returns 88 with choose public or friend visibility - fun num2():u64 { + public(friend) fun num2():u64 { 88 } } \ No newline at end of file diff --git a/task3/sources/m2.move b/task3/sources/m2.move index 9bfd86c..848d216 100644 --- a/task3/sources/m2.move +++ b/task3/sources/m2.move @@ -1,4 +1,4 @@ -module 0x42::M2{ +module 0x42::M2 { #[test] fun test(){ use 0x42::M1::num; diff --git a/task3/sources/m3.move b/task3/sources/m3.move index 363eba0..645ca32 100644 --- a/task3/sources/m3.move +++ b/task3/sources/m3.move @@ -1,4 +1,4 @@ -module 0x42::M3{ +module 0x42::M3 { #[test] fun test(){ use 0x42::M1::num; diff --git a/task4/sources/main.move b/task4/sources/main.move index daa4423..d74c391 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -9,22 +9,24 @@ module 0x42::Task4 { const NAME:vector = b"myObject"; - // TODO // 1. create a deleteable object public fun createDeleteableObject(caller: &signer):ConstructorRef { - // ... + let caller_addr = signer::address_of(caller); + let constructor_ref = object::create_object(caller_addr); + constructor_ref } - // TODO // 2. create a named object public fun createNamedObject(caller: &signer):ConstructorRef { - // ... + let constructor_ref = object::create_named_object(caller, NAME); + constructor_ref } - // TODO // 3. create a sticky object public fun createStickyObject(caller: &signer):ConstructorRef { - // ... + let caller_addr = signer::address_of(caller); + let constructor_ref = object::create_sticky_object(caller_addr); + constructor_ref } #[test(caller = @0x88)]