Skip to content

Commit

Permalink
upgrade tests
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed Apr 18, 2024
1 parent 0504fac commit 303a002
Show file tree
Hide file tree
Showing 51 changed files with 1,657 additions and 1,097 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@

**/settings/Mainnet.toml
**/settings/Testnet.toml
.cache/**
history.txt

coverage
*.info
costs-reports.json
node_modules

# Logs
logs
*.log
Expand Down
61 changes: 55 additions & 6 deletions Clarinet.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,78 @@

[project]
name = "friedger-smart-contracts"
description = ""
authors = []
telemetry = false
cache_dir = "./.cache"
requirements = [
{ contract_id = "SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait" },
{ contract_id = "SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard" },
]

[contracts.history]
path = "contracts/experiments/history.clar"
depends_on = []

[contracts.flip-coin]
path = "contracts/experiments/flip-coin.clar"
depends_on = []

[contracts.flip-coin-tax-office]
path = "contracts/experiments/flip-coin-tax-office.clar"
depends_on = []

[contracts.flip-coin-delegate]
path = "contracts/experiments/flip-coin-delegate.clar"
depends_on = ["flip-coin"]

[contracts.flip-coin-jackpot]
path = "contracts/experiments/flip-coin-jackpot.clar"
depends_on = ["flip-coin", "flip-coin-tax-office"]

[contracts.flip-coin-at-two]
path = "contracts/experiments/flip-coin-at-two.clar"
depends_on = ["flip-coin", "flip-coin-tax-office", "flip-coin-jackpot"]

[notebooks]
[contracts.perishable-token]
path = "contracts/tokens/perishable-token.clar"

[contracts.panic]
path = "contracts/experiments/panic.clar"

[contracts.beeple]
path = "contracts/tokens/beeple.clar"

[contracts.fungible-token]
path = "contracts/tokens/fungible-token.clar"

[contracts.trait-conversion]
path = "contracts/experiments/trait-conversion.clar"
clarity_version = 2
epoch = "2.1"

[contracts.trait-conversion-router]
path = "contracts/experiments/trait-conversion-router.clar"
clarity_version = 2
epoch = "2.1"


## Test contracts
[contracts.perishable-token_test]
path = "test/perishable-token_test.clar"
clarity_version = 2
epoch = "2.1"

[contracts.trait-conversion-router_test]
path = "test/trait-conversion-router_test.clar"
clarity_version = 2
epoch = "2.1"


## REPL
[repl.analysis]
passes = ["check_checker"]
check_checker = { trusted_sender = false, trusted_caller = false, callee_filter = false }

# Check-checker settings:
# trusted_sender: if true, inputs are trusted after tx_sender has been checked.
# trusted_caller: if true, inputs are trusted after contract-caller has been checked.
# callee_filter: if true, untrusted data may be passed into a private function without a
# warning, if it gets checked inside. This check will also propagate up to the
# caller.
# More informations: https://www.hiro.so/blog/new-safety-checks-in-clarinet
86 changes: 0 additions & 86 deletions Stacks.toml

This file was deleted.

11 changes: 11 additions & 0 deletions contracts/experiments/trait-conversion-router.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; routes the call with the correct tokens
(define-public (transfer-two (amount uint) (recipient principal))
(contract-call? .trait-conversion transfer-two
{token: .fungible-token }
{token: .beeple}
amount recipient))

(define-constant default-list (list {token: .fungible-token, amount: u1, recipient: (as-contract tx-sender)}))

(define-public (transfer-many-default)
(if true (contract-call? .trait-conversion transfer-many default-list) (err u1)))
19 changes: 19 additions & 0 deletions contracts/experiments/trait-conversion.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(use-trait nft-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
(use-trait ft-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)

(define-public (transfer-two (ft-contract {token: <ft-trait>}) (nft-contract {token: <nft-trait>}) (amount uint) (recipient principal))
(let ((ft (get token ft-contract))
(nft (get token nft-contract)))
(try! (contract-call? ft transfer amount tx-sender recipient none))
(try! (contract-call? nft transfer amount tx-sender recipient))
(ok true)))

(define-public (transfer-many (fts (list 10 {token: <ft-trait>, amount: uint, recipient: principal})))
(ok (map transfer-many-iter fts)))

(define-private (transfer-many-iter (transfer {token: <ft-trait>, amount: uint, recipient: principal}))
(let ((ft (get token transfer)))
(contract-call? ft transfer (get amount transfer) tx-sender (get recipient transfer) none)))

(define-read-only (to-ft-trait (ft <ft-trait>))
ft)
60 changes: 34 additions & 26 deletions contracts/tokens/fungible-token.clar
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@

;; Storage
(define-map allowances
((spender principal) (owner principal))
((allowance uint)))
{spender: principal, owner: principal}
{allowance: uint})
(define-data-var total-supply uint u0)

;; Internals

;; Total number of tokens in existence.
(define-private (get-total-supply)
(var-get total-supply))
(define-read-only (get-total-supply)
(ok (var-get total-supply)))

;; Internals

;; Gets the amount of tokens that an owner allowed to a spender.
(define-private (allowance-of (spender principal) (owner principal))
(begin
(default-to u0
(get allowance
(map-get? allowances ((spender spender) (owner owner))))))
)
(default-to u0
(get allowance
(map-get? allowances {spender: spender, owner: owner}))))

;; Transfers tokens to a specified principal.
(define-private (transfer (amount uint) (sender principal) (recipient principal) )
(match (ft-transfer? fungible-token amount sender recipient)
result (ok true)
error (err false))
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(ft-transfer? fungible-token amount sender recipient)
)

;; Decrease allowance of a specified spender.
Expand All @@ -53,8 +49,8 @@
true
(begin
(map-set allowances
((spender spender) (owner owner))
((allowance (- allowance amount))))
{spender: spender, owner: owner}
{allowance: (- allowance amount)})
true))))

;; Internal - Increase allowance of a specified spender.
Expand All @@ -64,15 +60,15 @@
false
(begin
(map-set allowances
((spender spender) (owner owner))
((allowance (+ allowance amount))))
{spender: spender, owner: owner}
{allowance: (+ allowance amount)})
true))))

;; Public functions

;; Transfers tokens to a specified principal.
(define-public (transfer-token (amount uint) (recipient principal) )
(transfer amount tx-sender recipient)
(transfer amount tx-sender recipient none)
)

;; Transfers tokens to a specified principal, performed by a spender
Expand All @@ -82,7 +78,7 @@
(if (or (> amount allowance) (<= amount u0))
(err false)
(if (and
(unwrap! (transfer amount owner recipient) (err false))
(unwrap! (transfer amount owner recipient none) (err false))
(decrease-allowance amount tx-sender owner))
(ok true)
(err false)))))
Expand All @@ -103,22 +99,34 @@
(ok 0)
(err false))))

(define-public (balance-of (owner principal))
(define-read-only (get-balance (owner principal))
(begin
(print owner)
(ok (ft-get-balance fungible-token owner))
)
)

(define-read-only (get-decimals)
(ok u0))

(define-read-only (get-name)
(ok "ft"))

(define-read-only (get-symbol)
(ok "FT"))

(define-read-only (get-token-uri)
(ok none))

;; Mint new tokens.
(define-private (mint (amount uint) (account principal))
(if (<= amount u0)
(err false)
(begin
(var-set total-supply (+ (var-get total-supply) amount))
(ft-mint? fungible-token amount account)
(unwrap! (ft-mint? fungible-token amount account) (err false))
(ok amount))))

;; Initialize the contract
(begin
(mint u200 'ST398K1WZTBVY6FE2YEHM6HP20VSNVSSPJTW0D53M)
(mint u100 'ST1JDEC841ZDWN9CKXKJMDQGP5TW1AM10B7EV0DV9))
(try! (mint u200 'ST398K1WZTBVY6FE2YEHM6HP20VSNVSSPJTW0D53M))
(try! (mint u100 'ST1JDEC841ZDWN9CKXKJMDQGP5TW1AM10B7EV0DV9))
6 changes: 2 additions & 4 deletions contracts/tokens/perishable-token.clar
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(define-map tokens ((token-id uint))
((last-tick uint))
)
(define-map tokens {token-id: uint} {last-tick: uint})

(define-non-fungible-token perishable-token uint)
(define-data-var next-id uint u1)
Expand Down Expand Up @@ -51,7 +49,7 @@

(define-read-only (perished (token-id uint))
(match (map-get? tokens {token-id: token-id})
monster (ok (not (is-last-tick-young (get last-tick monster))))
token (ok (not (is-last-tick-young (get last-tick token))))
(err err-invalid-token-id)
)
)
Expand Down
Loading

0 comments on commit 303a002

Please sign in to comment.