Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions student_no.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Please enter your 9-digit student number below.
100243120
10 changes: 6 additions & 4 deletions task1/sources/main.move
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@

// Task1 - Struct
// Create a struct called Wallet with a single field called balance of type u64.
module 0x42::Task1 {
use std::debug;

// TODO
// Define a struct called Wallet with a single field called balance of type u64.
struct Wallet has drop {
// ...
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]
fun test_wallet() {
let wallet = myWallet();
assert!(wallet.balance == 1000, 0);
}
}
}
31 changes: 15 additions & 16 deletions task2/sources/main.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ module 0x42::Task2{
use std::signer;

// TODO
// Define a struct Foo with two fields: u: u64, b: bool with ability to drop
struct Foo {
// ...
// Define a struct Foo with two fields:a u: u64, b: bool with ability to drop
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]
Expand All @@ -32,14 +33,15 @@ module 0x42::Task2{

// TODO
// Define a struct Soo with two fields: x: u64, y: u64 with ability to copy
struct Soo {
// ...
struct Soo has drop, 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 {
// ...
fun gen_Soo(x:u64, y:u64):Soo {
Soo{x, y}
}

#[test]
Expand All @@ -50,34 +52,31 @@ module 0x42::Task2{
*x = 44;
assert!(c.x == 42,0);
assert!(c2.x == 44,1);
let Soo { x: _, y: _ } = c;
let Soo { x: _, y: _ } = c2;
}

// TODO
// Define a struct Koo with a field: s: Moo with ability
struct Koo {
struct Koo has drop{
s: Moo
}

// TODO
// Define a struct Moo with a field: x: u64 with ability
struct Moo {
struct Moo has copy, drop{
x: u64
}


// TODO
// Define a function gen_Moo that takes an argument: x: u64 and returns a Moo
fun gen_Moo(x:u64): Moo {
// ...
fun gen_Moo(x:u64):Moo {
Moo{x}
}

#[test]
fun test4(){
let s = gen_Moo(42);
let k = Koo{s: s};
assert!(k.s.x == 42,0);
let Koo { s: Moo { x: _ } } = k;
}
}
}
11 changes: 4 additions & 7 deletions task3/sources/m1.move
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Tasl3 - module

// 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{

// TODO
// Define a module friend M2
friend ;
friend 0x42::M2;

// TODO
// Define a function num that returns 66 with choose public or friend visibility
fun num():u64 {
public 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
}
}
}
22 changes: 15 additions & 7 deletions task4/sources/main.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// 2. Create a named object
// 3. Create a sticky object
module 0x42::Task4 {
use aptos_framework::object::{Self, ConstructorRef};
use std::debug::print;
use aptos_framework::object;
use aptos_framework::object::{Object, ConstructorRef, ObjectCore};

use std::signer;

Expand All @@ -13,40 +15,46 @@ module 0x42::Task4 {
// 1. create a deleteable object
public fun createDeleteableObject(caller: &signer):ConstructorRef {
// ...
let caller_addr = signer::address_of(caller);
let obj = object::create_object(caller_addr);
obj
}

// TODO
// 2. create a named object
public fun createNamedObject(caller: &signer):ConstructorRef {
// ...
let obj = object::create_named_object(caller, NAME);
obj
}

// TODO
// 3. create a sticky object
public fun createStickyObject(caller: &signer):ConstructorRef {
// ...
let caller_addr = signer::address_of(caller);
let obj = object::create_sticky_object(caller_addr);
obj
}

#[test(caller = @0x88)]
fun testCreateDeleteableObject(caller: &signer) {
let obj = createDeleteableObject(caller);
assert!( object::address_from_constructor_ref(&obj) == @0xe46a3c36283330c97668b5d4693766b8626420a5701c18eb64026075c3ec8a0a, 1);
let delete_ref = object::generate_delete_ref(&obj);
aptos_framework::object::delete(delete_ref);
}

#[test(caller = @0x88)]
fun testCreateNamedObject(caller: &signer) {
let obj = createNamedObject(caller);
assert!( object::address_from_constructor_ref(&obj) == @0x833ab2477b9a8f6d4388d8c8a05b7617a864c622a8c96ecfc38fa6a40aa07247, 1);
print(&obj);
}

#[test(caller = @0x88)]
fun testCreateStickyObject(caller: &signer) {
let obj = createStickyObject(caller);
let obj2 = createStickyObject(caller);
assert!( object::address_from_constructor_ref(&obj) == @0xe46a3c36283330c97668b5d4693766b8626420a5701c18eb64026075c3ec8a0a, 1);
assert!( object::address_from_constructor_ref(&obj2) == @0xfab16b00983f01e5c2b7682472a4f4c3e5929fbba987958570b6290c02817df2, 1);

print(&obj);
print(&obj2);
}
}
}