From 77d859615e625bceb3c92b7dda03ba3fa15e1584 Mon Sep 17 00:00:00 2001 From: cyberpo9t Date: Sat, 23 Mar 2024 14:41:41 +0800 Subject: [PATCH] complete tasks from 100243114 --- student_no.txt | 1 + task1/sources/main.move | 4 ++++ task2/sources/main.move | 25 ++++++++++++++++++++----- task3/sources/m1.move | 7 ++++--- task4/sources/main.move | 3 +++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/student_no.txt b/student_no.txt index 2a6816f..9e9cc77 100644 --- a/student_no.txt +++ b/student_no.txt @@ -1 +1,2 @@ # Please enter your 9-digit student number below. +100243114 \ No newline at end of file diff --git a/task1/sources/main.move b/task1/sources/main.move index 2507060..b378dc2 100644 --- a/task1/sources/main.move +++ b/task1/sources/main.move @@ -6,12 +6,16 @@ module 0x42::Task1 { // 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..b544f60 100644 --- a/task2/sources/main.move +++ b/task2/sources/main.move @@ -1,17 +1,23 @@ // Task2 - drop, copy, store module 0x42::Task2{ - use std::signer; + // 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 { // ... + return Foo { + u, + b + } } #[test] @@ -24,7 +30,7 @@ module 0x42::Task2{ #[test] fun test2(){ let f = gen_Fool(42, true); - let Foo{u,b} = &mut f; + let Foo{u,b: _} = &mut f; *u = 43; assert!(f.u == 43,0); assert!(f.b == true,1); @@ -32,21 +38,27 @@ module 0x42::Task2{ // 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 { // ... + return Soo { + x, + y + } } #[test] fun test3(){ let c = gen_Soo(42, 43); let c2 = copy c; - let Soo{x,y} = &mut c2; + let Soo{x,y: _} = &mut c2; *x = 44; assert!(c.x == 42,0); assert!(c2.x == 44,1); @@ -71,6 +83,9 @@ module 0x42::Task2{ // Define a function gen_Moo that takes an argument: x: u64 and returns a Moo fun gen_Moo(x:u64): Moo { // ... + return Moo { + x + } } #[test] diff --git a/task3/sources/m1.move b/task3/sources/m1.move index e3542c4..42145f1 100644 --- a/task3/sources/m1.move +++ b/task3/sources/m1.move @@ -6,17 +6,18 @@ 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/task4/sources/main.move b/task4/sources/main.move index daa4423..2d4024b 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -13,18 +13,21 @@ module 0x42::Task4 { // 1. create a deleteable object public fun createDeleteableObject(caller: &signer):ConstructorRef { // ... + object::create_object(signer::address_of(caller)) } // TODO // 2. create a named object public fun createNamedObject(caller: &signer):ConstructorRef { // ... + object::create_named_object(caller, NAME) } // TODO // 3. create a sticky object public fun createStickyObject(caller: &signer):ConstructorRef { // ... + object::create_sticky_object(signer::address_of(caller)) } #[test(caller = @0x88)]