Skip to content

Commit

Permalink
chore: update cbtc example (#36)
Browse files Browse the repository at this point in the history
* chore: update cbtc example

* tests: add unit tests to the cbtc example

* ci: split tests and example tests

* ci: rename ci jobs

* ci: fix cbtc tests

* ci: fix cbtc tests

---------

Co-authored-by: Hugo Caillard <[email protected]>
  • Loading branch information
Ludo Galabru and hugocaillard authored Mar 18, 2024
1 parent ff31bba commit 2c56988
Show file tree
Hide file tree
Showing 15 changed files with 2,482 additions and 148 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/run-unit-tests.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@ on:
branches: [ "main" ]

jobs:
build:
unit-tests:
runs-on: ubuntu-latest


strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test

cbtc-unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
Expand All @@ -26,4 +42,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
working-directory: ./example/cbtc
- run: npm test
working-directory: ./example/cbtc
9 changes: 9 additions & 0 deletions example/cbtc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
**/settings/Testnet.toml
.requirements/
history.txt

# Ignore Node and NPM files. Added by the clarinet-sdk migration.
logs
*.log
npm-debug.log*
coverage
*.info
costs-reports.json
node_modules
7 changes: 3 additions & 4 deletions example/cbtc/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

{
"deno.enable": true,
"files.eol": "\n"
}
"deno.enable": false,
"files.eol": "\n"
}
14 changes: 13 additions & 1 deletion example/cbtc/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ telemetry = false
contract_id = "SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-tokens-v1"

[[project.requirements]]
contract_id = "SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1"
contract_id = "ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2"

[[project.requirements]]
contract_id = "ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v1"

[[project.requirements]]
contract_id = "ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v2"

[[project.requirements]]
contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1'

[[project.requirements]]
contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1'

[contracts.cbtc-token]
path = "contracts/cbtc-token.clar"
Expand Down
9 changes: 9 additions & 0 deletions example/cbtc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,12 @@ and
```bash
clarinet deployment apply -p deployments/unwrap-btc.devnet-plan.yaml
```

## Run the unit tests

Install the npm dependencies and run the test:

```bash
npm install
npm test
```
22 changes: 19 additions & 3 deletions example/cbtc/contracts/cbtc-pool.clar
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@
(ok { stx-in: stx-in, cbtc-sats-out: cbtc-sats-out } )))

(define-private (update-and-read-stx-price-from-pyth (stx-price-feed (buff 2048)))
(let ((updated-prices-ids (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 verify-and-update-price stx-price-feed) (err u0)))
(let ((updated-prices-ids (unwrap!
(contract-call? 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2 verify-and-update-price-feeds
stx-price-feed
{
pyth-storage-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1,
pyth-decoder-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1,
wormhole-core-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v2
})
(err u0)))
(price (unwrap! (element-at? updated-prices-ids u0) (err u404))))
(ok price)))

(define-private (update-and-read-btc-price-from-pyth (btc-price-feed (buff 2048)))
(let ((updated-prices-ids (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 verify-and-update-price btc-price-feed) (err u0)))
(let ((updated-prices-ids (unwrap!
(contract-call? 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2 verify-and-update-price-feeds
btc-price-feed
{
pyth-storage-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1,
pyth-decoder-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1,
wormhole-core-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v2
})
(err u0)))
(price (unwrap! (element-at? updated-prices-ids u0) (err u404))))
(ok price)))

Expand All @@ -53,6 +69,6 @@
(read-price-from-pyth 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43))

(define-private (read-price-from-pyth (price-id (buff 32)))
(let ((feed (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 read-price price-id) (err u0)))
(let ((feed (unwrap! (contract-call? 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2 read-price-feed price-id 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1) (err u0)))
(price (get price feed)))
(ok (to-uint price))))
180 changes: 69 additions & 111 deletions example/cbtc/deployments/default.simnet-plan.yaml

Large diffs are not rendered by default.

Loading

0 comments on commit 2c56988

Please sign in to comment.