-
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
Showing
5 changed files
with
203 additions
and
1 deletion.
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
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,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 |
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,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))) |
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,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); | ||
// }); | ||
}); |
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,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); | ||
// }); | ||
}); |