Skip to content

Commit

Permalink
Merge branch 'develop' into chainhooks-edits
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshmiLavanyaKasturi authored Aug 11, 2023
2 parents 3e6bc70 + 6f08dfb commit e5dee72
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 198 deletions.
4 changes: 2 additions & 2 deletions components/clarinet-cli/examples/billboard/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ requirements = []

[contracts.billboard]
path = "contracts/billboard.clar"
clarity_version = 1
epoch = "2.05"
clarity_version = 2
epoch = "2.4"
28 changes: 13 additions & 15 deletions components/clarinet-cli/examples/billboard/contracts/billboard.clar
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
;; billboard contract

;; error consts
(define-constant ERR_STX_TRANSFER u0)
(define-constant ERR_STX_TRANSFER u0)

;; data vars
(define-data-var billboard-message (string-utf8 500) u"Hello World!")
(define-data-var price uint u100)

;; public functions
(define-read-only (get-price)
(var-get price)
(var-get price)
)

(define-read-only (get-message)
(var-get billboard-message)
(var-get billboard-message)
)

(define-public (set-message (message (string-utf8 500)))
(let ((cur-price (var-get price))
(new-price (+ u10 cur-price)))
(let ((cur-price (var-get price)) (new-price (+ u10 cur-price)))
;; pay the contract
(unwrap! (stx-transfer? cur-price tx-sender (as-contract tx-sender)) (err ERR_STX_TRANSFER))

;; pay the contract
(unwrap! (stx-transfer? cur-price tx-sender (as-contract tx-sender)) (err ERR_STX_TRANSFER))
;; update the billboard's message
(var-set billboard-message message)

;; update the billboard's message
(var-set billboard-message message)
;; update the price of setting a message
(var-set price new-price)

;; update the price of setting a message
(var-set price new-price)

;; return the updated price
(ok new-price)
)
;; return the updated price
(ok new-price)
)
)
22 changes: 3 additions & 19 deletions components/clarinet-cli/examples/billboard/tests/billboard_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Clarinet,
Tx,
Chain,
Account,
types,
} from "https://deno.land/x/[email protected]/index.ts";
import { Clarinet, Tx, Chain, Account, types } from "https://deno.land/x/[email protected]/index.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";

Clarinet.test({
Expand All @@ -17,19 +11,9 @@ Clarinet.test({
const balance = assetMaps.assets["STX"][wallet_1.address];

const block = chain.mineBlock([
Tx.contractCall(
"billboard",
"set-message",
[types.utf8("testing")],
wallet_1.address
),
Tx.contractCall("billboard", "set-message", [types.utf8("testing")], wallet_1.address),
Tx.contractCall("billboard", "get-message", [], wallet_1.address),
Tx.contractCall(
"billboard",
"set-message",
[types.utf8("testing...")],
wallet_1.address
),
Tx.contractCall("billboard", "set-message", [types.utf8("testing...")], wallet_1.address),
Tx.contractCall("billboard", "get-message", [], wallet_1.address),
]);

Expand Down
16 changes: 3 additions & 13 deletions components/clarinet-cli/examples/cbtc/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ contract_id = "SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standa

[contracts.cbtc-token]
path = "contracts/cbtc-token.clar"
clarity_version = 1
epoch = "2.05"

[repl]
costs_version = 2
parser_version = 2
clarity_version = 2
epoch = "2.4"

[repl.analysis]
passes = ["check_checker"]

[repl.analysis.check_checker]
strict = false
trusted_sender = true
trusted_caller = false
callee_filter = false
passes = []
13 changes: 6 additions & 7 deletions components/clarinet-cli/examples/cbtc/contracts/cbtc-token.clar
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
(begin
(try! (ft-transfer? cbtc amount sender recipient))
(print memo)
(ok true)
)
(ok true))
(err u4)))

(define-public (get-token-uri)
Expand All @@ -39,10 +38,10 @@
(define-constant AUTHORITY 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5)

(define-public (mint (amount uint) (recipient principal))
(begin
(asserts! (is-eq tx-sender AUTHORITY) (err u0))
(ft-mint? cbtc amount recipient)))
(begin
(asserts! (is-eq tx-sender AUTHORITY) (err u0))
(ft-mint? cbtc amount recipient)))

(define-public (burn (amount uint))
(begin
(ft-burn? cbtc amount tx-sender)))
(begin
(ft-burn? cbtc amount tx-sender)))
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plan:
cost: 8400
path: ".cache/requirements/SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.clar"
clarity-version: 1
epoch: "2.0"
epoch: "2.4"
- id: 1
transactions:
- contract-publish:
Expand All @@ -26,4 +26,4 @@ plan:
path: contracts/cbtc-token.clar
anchor-block-only: true
clarity-version: 1
epoch: "2.05"
epoch: "2.4"
12 changes: 2 additions & 10 deletions components/clarinet-cli/examples/cbtc/tests/cbtc-token_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Clarinet,
Tx,
Chain,
types,
} from "https://deno.land/x/[email protected]/index.ts";
import { Clarinet, Tx, Chain, types } from "https://deno.land/x/[email protected]/index.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";

Clarinet.test({
Expand All @@ -13,10 +8,7 @@ Clarinet.test({
Tx.contractCall(
"cbtc-token",
"mint",
[
types.uint(1000),
types.principal("ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG"),
],
[types.uint(1000), types.principal("ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG")],
"ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5"
),
Tx.contractCall(
Expand Down
11 changes: 8 additions & 3 deletions components/clarinet-cli/examples/counter/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ telemetry = false
[contracts.counter]
path = "contracts/counter.clar"
clarity_version = 1
epoch = "2.05"
epoch = "2.0"

[contracts.counter-2]
path = "contracts/counter-v2.clar"
clarity_version = 2
epoch = "2.1"
epoch = "2.4"

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

[repl.analysis.check_checker]
strict = false
trusted_sender = true
trusted_caller = false
callee_filter = false
28 changes: 19 additions & 9 deletions components/clarinet-cli/examples/counter/contracts/counter-v2.clar
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
(define-data-var counter uint u1)

(define-public (increment (step uint))
(let ((new-val (+ step (var-get counter))))
(var-set counter new-val)
(print { object: "counter", action: "incremented", value: new-val, chain: (slice? "blockstack" u5 u10) })
(ok new-val)))
(let ((new-val (+ step (var-get counter))))
(var-set counter new-val)
(print {
object: "counter",
action: "incremented",
value: new-val,
chain: (slice? "blockstack" u5 u10)
})
(ok new-val)))

(define-public (decrement (step uint))
(let ((new-val (- step (var-get counter))))
(var-set counter new-val)
(print { object: "counter", action: "decremented", value: new-val, chain: (slice? "blockstack" u5 u10) })
(ok new-val)))
(let ((new-val (- step (var-get counter))))
(var-set counter new-val)
(print {
object: "counter",
action: "decremented",
value: new-val,
chain: (slice? "blockstack" u5 u10)
})
(ok new-val)))

(define-read-only (read-counter)
(ok (var-get counter)))
(ok (var-get counter)))
78 changes: 11 additions & 67 deletions components/clarinet-cli/examples/counter/tests/counter_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Clarinet,
Tx,
Chain,
Account,
types,
} from "https://deno.land/x/[email protected]/index.ts";
import { Clarinet, Tx, Chain, Account, types } from "https://deno.land/x/[email protected]/index.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";

Clarinet.test({
Expand All @@ -14,49 +8,19 @@ Clarinet.test({
const wallet_2 = accounts.get("wallet_2")!;

let block = chain.mineBlock([
Tx.contractCall(
"counter",
"increment",
[types.uint(1)],
wallet_1.address
),
Tx.contractCall(
"counter",
"increment",
[types.uint(4)],
wallet_1.address
),
Tx.contractCall(
"counter",
"increment",
[types.uint(10)],
wallet_1.address
),
Tx.contractCall("counter", "increment", [types.uint(1)], wallet_1.address),
Tx.contractCall("counter", "increment", [types.uint(4)], wallet_1.address),
Tx.contractCall("counter", "increment", [types.uint(10)], wallet_1.address),
]);
assertEquals(block.height, 3);
block.receipts[0].result.expectOk().expectUint(2);
block.receipts[1].result.expectOk().expectUint(6);
block.receipts[2].result.expectOk().expectUint(16);

block = chain.mineBlock([
Tx.contractCall(
"counter",
"increment",
[types.uint(1)],
wallet_1.address
),
Tx.contractCall(
"counter",
"increment",
[types.uint(4)],
wallet_1.address
),
Tx.contractCall(
"counter",
"increment",
[types.uint(10)],
wallet_1.address
),
Tx.contractCall("counter", "increment", [types.uint(1)], wallet_1.address),
Tx.contractCall("counter", "increment", [types.uint(4)], wallet_1.address),
Tx.contractCall("counter", "increment", [types.uint(10)], wallet_1.address),
Tx.transferSTX(1, wallet_2.address, wallet_1.address),
]);

Expand All @@ -68,12 +32,7 @@ Clarinet.test({
const result = chain.getAssetsMaps();
assertEquals(result.assets["STX"][wallet_1.address], 99999999999999);

const call = chain.callReadOnlyFn(
"counter",
"read-counter",
[],
wallet_1.address
);
const call = chain.callReadOnlyFn("counter", "read-counter", [], wallet_1.address);
call.result.expectOk().expectUint(31);

"0x0001020304".expectBuff(new Uint8Array([0, 1, 2, 3, 4]));
Expand All @@ -92,24 +51,9 @@ Clarinet.test({
const wallet_1 = accounts.get("wallet_1")!;

const block = chain.mineBlock([
Tx.contractCall(
"counter",
"increment",
[types.uint(1)],
wallet_1.address
),
Tx.contractCall(
"counter",
"increment",
[types.uint(4)],
wallet_1.address
),
Tx.contractCall(
"counter",
"increment",
[types.uint(10)],
wallet_1.address
),
Tx.contractCall("counter", "increment", [types.uint(1)], wallet_1.address),
Tx.contractCall("counter", "increment", [types.uint(4)], wallet_1.address),
Tx.contractCall("counter", "increment", [types.uint(10)], wallet_1.address),
]);
assertEquals(block.height, 103);
block.receipts[0].result.expectOk().expectUint(2);
Expand Down
23 changes: 11 additions & 12 deletions components/clarinet-cli/examples/simple-nft/Clarinet.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

[project]
name = "simple-nft"
cache_dir = "./.cache"
name = 'simple-nft'
description = ''
authors = []
telemetry = false
cache_dir = './.cache'

[contracts.simple-nft]
path = "contracts/simple-nft.clar"
clarity_version = 1
epoch = "2.05"
[[project.requirements]]
contract_id = 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait'

# EXTERNAL CONTRACTS
[contracts.sip-009-trait-ft-standard]
path = "contracts/external/sip-009-nft-trait-standard.clar"
clarity_version = 1
epoch = "2.05"
[contracts.simple-nft]
path = 'contracts/simple-nft.clar'
clarity_version = 2
epoch = 2.4

[repl.analysis]
passes = ["check_checker"]
Expand Down

This file was deleted.

Loading

0 comments on commit e5dee72

Please sign in to comment.