forked from ALCOVE-LAB/Move-Exam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
flex
committed
Mar 12, 2024
0 parents
commit f0333b6
Showing
15 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Aptos Move Exam | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
|
||
- name: Install Aptos CLI | ||
run: bash -c "curl -fsSL "https://aptos.dev/scripts/install_cli.py" | python3" | ||
|
||
- name: Install Dependencies | ||
run: pip install supabase | ||
|
||
- name: Run Aptos Move Test | ||
run: python ${{ github.workspace }}/scripts/exam.py | ||
working-directory: ${{ github.workspace }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build | ||
tests | ||
.pdm-python | ||
*.pyc | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# aptos-homework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 🏆 Welcome to Aptos Challenge | ||
|
||
## 📝 Tasks | ||
|
||
1. [task1](/task1) - Struct | ||
2. [task2](/taks2) - Struct ability | ||
3. [task3](/taks3) - Modules | ||
4. [task4](/taks4) - Object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import sys | ||
from subprocess import run | ||
|
||
from supabase import Client, create_client | ||
|
||
url: str = os.environ.get("SUPABASE_URL") | ||
key: str = os.environ.get("SUPABASE_KEY") | ||
supabase: Client = create_client(url, key) | ||
|
||
|
||
POINTS = {"task1": 25, "task2": 25, "task3": 25, "task4": 25} | ||
|
||
|
||
def get_student_no(): | ||
no_file = open("student_no.txt", "r").readlines() | ||
student_no = 0 | ||
for line in no_file: | ||
no = line.strip() | ||
if no.startswith("#"): | ||
continue | ||
|
||
if no.isnumeric() and len(no) == 9: | ||
student_no = no | ||
print(f"Found valid student number: {no}") | ||
break | ||
|
||
return student_no | ||
|
||
|
||
def execute_test(): | ||
results = {} | ||
for task, points in POINTS.items(): | ||
print(f"Executing {task}...") | ||
p = run(["/root/.local/bin/aptos", "move", "test"], check=True, cwd=f"{task}") | ||
if p.returncode != 0: | ||
print(f"Error executing task {task}") | ||
results[task] = 0 | ||
else: | ||
print(f"Task {task} executed successfully") | ||
results[task] = points | ||
|
||
return results | ||
|
||
|
||
def main(): | ||
student_no = get_student_no() | ||
if student_no == 0: | ||
print("Cannot find valid student number") | ||
sys.exit(1) | ||
|
||
results = execute_test() | ||
score = sum(results.values()) | ||
data, count = ( | ||
supabase.table("homework") | ||
.insert({"student_no": student_no, "score": score}) | ||
.execute() | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "task1" | ||
version = "1.0.0" | ||
authors = [] | ||
|
||
[addresses] | ||
|
||
[dev-addresses] | ||
|
||
[dependencies.AptosFramework] | ||
git = "https://github.com/aptos-labs/aptos-core.git" | ||
rev = "mainnet" | ||
subdir = "aptos-move/framework/aptos-framework" | ||
|
||
[dev-dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Task1 - Struct | ||
// 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 { | ||
// ... | ||
} | ||
|
||
// TODO | ||
// Define a function called myWallet that returns a Wallet with a balance of 1000. | ||
fun myWallet(): Wallet { | ||
// ... | ||
} | ||
|
||
#[test] | ||
fun test_wallet() { | ||
let wallet = myWallet(); | ||
assert!(wallet.balance == 1000, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "task2" | ||
version = "1.0.0" | ||
authors = [] | ||
|
||
[addresses] | ||
|
||
[dev-addresses] | ||
|
||
[dependencies.AptosFramework] | ||
git = "https://github.com/aptos-labs/aptos-core.git" | ||
rev = "mainnet" | ||
subdir = "aptos-move/framework/aptos-framework" | ||
|
||
[dev-dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Task2 - drop, copy, store | ||
module 0x42::Task2{ | ||
use std::signer; | ||
|
||
// TODO | ||
// Define a struct Foo with two fields: u: u64, b: bool with ability to drop | ||
struct Foo { | ||
// ... | ||
} | ||
|
||
// 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) { | ||
// ... | ||
} | ||
|
||
#[test] | ||
fun test(){ | ||
let f = gen_Fool(42, true); // need to drop f | ||
assert!(f.u == 42,0); | ||
assert!(f.b == true,1); | ||
} | ||
|
||
#[test] | ||
fun test2(){ | ||
let f = gen_Fool(42, true); | ||
let Foo{u,b} = &mut f; | ||
*u = 43; | ||
assert!(f.u == 43,0); | ||
assert!(f.b == true,1); | ||
} | ||
|
||
// TODO | ||
// Define a struct Soo with two fields: x: u64, y: u64 with ability to copy | ||
struct Soo { | ||
// ... | ||
} | ||
|
||
// 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) { | ||
// ... | ||
} | ||
|
||
#[test] | ||
fun test3(){ | ||
let c = gen_Soo(42, 43); | ||
let c2 = copy c; | ||
let Soo{x,y} = &mut c2; | ||
*x = 44; | ||
assert!(c.x == 42,0); | ||
assert!(c2.x == 44,1); | ||
} | ||
|
||
// TODO | ||
// Define a struct Koo with a field: s: Moo with ability | ||
struct Koo { | ||
s: Moo | ||
} | ||
|
||
// TODO | ||
// Define a struct Moo with a field: x: u64 with ability | ||
struct Moo { | ||
x: u64 | ||
} | ||
|
||
|
||
// TODO | ||
// Define a function gen_Moo that takes an argument: x: u64 and returns a Moo | ||
fun gen_Moo(x:u64) { | ||
// ... | ||
} | ||
|
||
#[test] | ||
fun test4(){ | ||
let s = gen_Moo(42); | ||
let k = Koo{s: s}; | ||
assert!(k.s.x == 42,0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "task3" | ||
version = "1.0.0" | ||
authors = [] | ||
|
||
[addresses] | ||
|
||
[dev-addresses] | ||
|
||
[dependencies.AptosFramework] | ||
git = "https://github.com/aptos-labs/aptos-core.git" | ||
rev = "mainnet" | ||
subdir = "aptos-move/framework/aptos-framework" | ||
|
||
[dev-dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Tasl3 - module | ||
module 0x42::M1{ | ||
|
||
// TODO | ||
// Define a module friend M2 | ||
friend; | ||
|
||
// TODO | ||
// Define a function num that returns 66 with choose public or friend visibility | ||
fun num():u64 { | ||
66 | ||
} | ||
|
||
// TODO | ||
// Define a function num2 that returns 88 with choose public or friend visibility | ||
fun num2():u64 { | ||
88 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module 0x42::M2{ | ||
#[test] | ||
fun test(){ | ||
use 0x42::M1::num; | ||
let n = num(); | ||
assert!(n == 66, 1); | ||
} | ||
|
||
#[test] | ||
fun test2(){ | ||
use 0x42::M1::num2; | ||
|
||
let n = num2(); | ||
assert!(n == 88, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0x42::M3{ | ||
#[test] | ||
fun test(){ | ||
use 0x42::M1::num; | ||
|
||
let n = num(); | ||
assert(n == 66,0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "task4" | ||
version = "1.0.0" | ||
authors = [] | ||
|
||
[addresses] | ||
|
||
[dev-addresses] | ||
|
||
[dependencies.AptosFramework] | ||
git = "https://github.com/aptos-labs/aptos-core.git" | ||
rev = "mainnet" | ||
subdir = "aptos-move/framework/aptos-framework" | ||
|
||
[dev-dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Task4 - Object | ||
// 1. Create a deleteable object | ||
// 2. Create a named object | ||
// 3. Create a sticky object | ||
module 0x42::Task4 { | ||
use std::debug::print; | ||
use aptos_framework::object; | ||
use aptos_framework::object::{Object, ConstructorRef, ObjectCore}; | ||
|
||
use std::signer; | ||
|
||
const NAME:vector<u8> = b"myObject"; | ||
|
||
// TODO | ||
// 1. create a deleteable object | ||
public fun createDeleteableObject(caller: &signer):ConstructorRef { | ||
// ... | ||
} | ||
|
||
// TODO | ||
// 2. create a named object | ||
public fun createNamedObject(caller: &signer):ConstructorRef { | ||
// ... | ||
} | ||
|
||
// TODO | ||
// 3. create a sticky object | ||
public fun createStickyObject(caller: &signer):ConstructorRef { | ||
// ... | ||
} | ||
|
||
#[test(caller = @0x88)] | ||
fun testCreateDeleteableObject(caller: &signer) { | ||
let obj = createDeleteableObject(caller); | ||
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); | ||
print(&obj); | ||
} | ||
|
||
#[test(caller = @0x88)] | ||
fun testCreateStickyObject(caller: &signer) { | ||
let obj = createStickyObject(caller); | ||
let obj2 = createStickyObject(caller); | ||
print(&obj); | ||
print(&obj2); | ||
} | ||
} |