Skip to content

Commit

Permalink
fix: scaffold day 7 exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Aug 26, 2024
1 parent 966e34d commit 11478ef
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = []
telemetry = false
cache_dir = './.cache'
requirements = []

[contracts.ex3-01]
path = 'contracts/ex3-01.clar'
clarity_version = 2
Expand Down Expand Up @@ -46,6 +45,15 @@ path = 'contracts/ex6-02.clar'
clarity_version = 2
epoch = 2.5

[contracts.ex7-01]
path = 'contracts/ex7-01.clar'
clarity_version = 2
epoch = 2.5

[contracts.ex7-02]
path = 'contracts/ex7-02.clar'
clarity_version = 2
epoch = 2.5
[repl.analysis]
passes = ['check_checker']

Expand Down
60 changes: 60 additions & 0 deletions contracts/ex7-01.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

;; title: ex7-01
;; version:
;; summary:
;; description:

;; traits
;;

;; BUG: NO TRAIT?

;; token definitions
;;

(define-fungible-token SimpleToken u1000000)

;; constants
;;

;; data vars
;;

(define-data-var tokenName (string-utf8 32) u"SimpleToken")

;; data maps
;;

;; public functions
;;

(define-public (mint (amount uint) (recipient principal))
(ft-mint? SimpleToken amount recipient)
)


(define-public (transfer (amount uint) (sender principal) (recipient principal))
(ft-transfer? SimpleToken amount sender recipient)
)

(define-public (burn (amount uint) (burner principal))
(ft-burn? SimpleToken amount burner)
)

;; read only functions
;;

(define-read-only (get-balance (account principal))
(ft-get-balance SimpleToken account)
)

(define-read-only (get-total-supply)
(ft-get-supply SimpleToken)
)

;; private functions
;;

;; Test cases
;; (mint u100 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5) ;; This should fail
;; (burn u10 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5) ;; This should fail
92 changes: 92 additions & 0 deletions contracts/ex7-02.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

;; title: ex7-02
;; version:
;; summary:
;; description:

;; traits
;;

;; BUG: NO TRAIT?

;; token definitions
;;

(define-fungible-token FaucetToken)

;; constants
;;

(define-constant CONTRACT_OWNER tx-sender)
(define-constant TOKEN_NAME "The Faucet")
(define-constant TOKEN_SYMBOL "DRIP")
(define-constant TOKEN_DECIMALS u6)
(define-constant CLAIM_AMOUNT u100000000) ;; 100 tokens with 6 decimals
(define-constant BLOCKS_BETWEEN_CLAIMS u144) ;; Approximately 24 hours (assuming 10-minute block times)

;; data vars
;;

;; data maps
;;

(define-map LastClaimedAtBlock principal uint)

;; public functions
;;

;; SIP-010 functions: transfer

(define-public (claim)
;; Implement the claim function
(ok true)
)

;; read only functions
;;

;; SIP-010 functions: get-name, get-symbol, get-decimals, get-balance, get-total-supply, get-token-uri

(define-read-only (time-until-next-claim (user principal))
;; Implement the time check function
u0
)

;; private functions
;;

(define-private (is-claim-allowed (user principal))
;; Implement the claim allowance check
true
)

;; Test cases

;; Test SIP-010 functions
;; (print (get-name))
;; (print (get-symbol))
;; (print (get-decimals))
;; (print (get-balance tx-sender))
;; (print (get-total-supply))
;; (print (get-token-uri))

;; Test claim function
;; (print (claim))
;; (print (get-balance tx-sender))
;; (print (claim)) ;; Should fail if called twice in a row

;; Test time-until-next-claim function
;; (print (time-until-next-claim tx-sender))

;; Test transfer function
;; (define-constant recipient 'ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK)
;; (print (transfer u50000000 tx-sender recipient none))
;; (print (get-balance tx-sender))
;; (print (get-balance recipient))

;; Advanced test: Multiple users
;; (define-constant user2 'ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG)
;; (print (as-contract (transfer CLAIM_AMOUNT tx-sender user2 none)))
;; (print (get-balance user2))
;; (print (as-contract (claim)))
;; (print (as-contract (time-until-next-claim tx-sender)))
21 changes: 21 additions & 0 deletions tests/ex7-01.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import { describe, expect, it } from "vitest";

const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;

/*
The test below is an example. To learn more, read the testing documentation here:
https://docs.hiro.so/stacks/clarinet-js-sdk
*/

describe("example tests", () => {
it("ensures simnet is well initalised", () => {
expect(simnet.blockHeight).toBeDefined();
});

// it("shows an example", () => {
// const { result } = simnet.callReadOnlyFn("counter", "get-counter", [], address1);
// expect(result).toBeUint(0);
// });
});
21 changes: 21 additions & 0 deletions tests/ex7-02.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import { describe, expect, it } from "vitest";

const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;

/*
The test below is an example. To learn more, read the testing documentation here:
https://docs.hiro.so/stacks/clarinet-js-sdk
*/

describe("example tests", () => {
it("ensures simnet is well initalised", () => {
expect(simnet.blockHeight).toBeDefined();
});

// it("shows an example", () => {
// const { result } = simnet.callReadOnlyFn("counter", "get-counter", [], address1);
// expect(result).toBeUint(0);
// });
});

0 comments on commit 11478ef

Please sign in to comment.