-
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.
Add some offchain code, plus some tests
- Loading branch information
1 parent
17a9761
commit 747e9f1
Showing
16 changed files
with
35,290 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "bun", | ||
"internalConsoleOptions": "neverOpen", | ||
"request": "launch", | ||
"name": "Debug File", | ||
"program": "${file}", | ||
"cwd": "${workspaceFolder}", | ||
"stopOnEntry": false, | ||
"watchMode": false | ||
}, | ||
{ | ||
"type": "bun", | ||
"internalConsoleOptions": "neverOpen", | ||
"request": "launch", | ||
"name": "Run File", | ||
"program": "${file}", | ||
"cwd": "${workspaceFolder}", | ||
"noDebug": true, | ||
"watchMode": false | ||
}, | ||
{ | ||
"type": "bun", | ||
"internalConsoleOptions": "neverOpen", | ||
"request": "attach", | ||
"name": "Attach Bun", | ||
"url": "ws://localhost:6499/", | ||
"stopOnEntry": false | ||
} | ||
] | ||
} |
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,2 @@ | ||
mkdir -p offchain/types/ | ||
npx @blaze-cardano/blueprint@latest plutus.json -o ./offchain/types/contracts.ts |
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,175 @@ | ||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore | ||
|
||
# Logs | ||
|
||
logs | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Caches | ||
|
||
.cache | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
_.pid | ||
_.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
|
||
web_modules/ | ||
|
||
# TypeScript cache | ||
|
||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
|
||
.stylelintcache | ||
|
||
# Microbundle cache | ||
|
||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
|
||
*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
|
||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
|
||
.parcel-cache | ||
|
||
# Next.js build output | ||
|
||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
||
# public | ||
|
||
# vuepress build output | ||
|
||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
|
||
.temp | ||
|
||
# Docusaurus cache and generated files | ||
|
||
.docusaurus | ||
|
||
# Serverless directories | ||
|
||
.serverless/ | ||
|
||
# FuseBox cache | ||
|
||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
|
||
.dynamodb/ | ||
|
||
# TernJS port file | ||
|
||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
|
||
.vscode-test | ||
|
||
# yarn v2 | ||
|
||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# IntelliJ based IDEs | ||
.idea | ||
|
||
# Finder (MacOS) folder config | ||
.DS_Store |
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,15 @@ | ||
# @sundae/treasury-funds | ||
|
||
To install dependencies: | ||
|
||
```bash | ||
bun install | ||
``` | ||
|
||
To run: | ||
|
||
```bash | ||
bun run index.ts | ||
``` | ||
|
||
This project was created using `bun init` in bun v1.2.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
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,15 @@ | ||
{ | ||
"name": "@sundae/treasury-funds", | ||
"module": "index.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/bun": "latest" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@blaze-cardano/emulator": "^0.3.16", | ||
"@blaze-cardano/sdk": "^0.2.22" | ||
} | ||
} |
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,22 @@ | ||
import { Core } from "@blaze-cardano/sdk" | ||
import { TreasuryTreasuryWithdraw } from "../types/contracts" | ||
|
||
export function loadScript(network: Core.NetworkId) { | ||
const treasuryScript = new TreasuryTreasuryWithdraw() | ||
const credential = { | ||
type: Core.CredentialType.ScriptHash, | ||
hash: treasuryScript.hash(), | ||
} | ||
const rewardAccount = Core.RewardAccount.fromCredential(credential, network) | ||
const scriptAddress = new Core.Address({ | ||
type: Core.AddressType.EnterpriseScript, | ||
networkId: network, | ||
paymentPart: credential, | ||
}) | ||
return { | ||
treasuryScript, | ||
credential, | ||
rewardAccount, | ||
scriptAddress, | ||
} | ||
} |
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,47 @@ | ||
import { beforeEach, describe, test } from 'bun:test'; | ||
import { Blaze, Core, Data, HotWallet, TxBuilder } from '@blaze-cardano/sdk'; | ||
import { Credential } from '@blaze-cardano/core'; | ||
import { Emulator, EmulatorProvider } from "@blaze-cardano/emulator"; | ||
import { expectScriptFailure, makeExpectTxInvalid, makeExpectTxValid, setupBlaze } from './utilities.test'; | ||
import { loadScript } from '../shared'; | ||
|
||
// NOTE: these test are disabled for now, while we wait for blaze to add support for them | ||
describe("miscellaneous", () => { | ||
const amount = 340_000_000_000_000n | ||
const { rewardAccount, credential, treasuryScript } = loadScript(Core.NetworkId.Testnet) | ||
|
||
let emulator: Emulator | ||
let blaze: Blaze<EmulatorProvider, HotWallet> | ||
let refInput: Core.TransactionUnspentOutput | ||
let expectTxValid: (tx: TxBuilder) => Promise<void> | ||
let expectTxInvalid: (tx: TxBuilder) => Promise<void> | ||
beforeEach(async () => { | ||
let setup = await setupBlaze() | ||
emulator = setup.emulator | ||
blaze = setup.blaze | ||
emulator.accounts.set(rewardAccount, amount) | ||
refInput = (await blaze.provider.resolveScriptRef(treasuryScript))! | ||
expectTxValid = makeExpectTxValid(blaze, emulator) | ||
expectTxInvalid = makeExpectTxInvalid(blaze, emulator) | ||
}) | ||
|
||
test.skip("Cannot deregister stake address", async () => { | ||
expectScriptFailure( | ||
blaze.newTransaction() | ||
.addReferenceInput(refInput!) | ||
) | ||
}) | ||
|
||
test.skip("Cannot delegate stake address", async () => { | ||
console.log(refInput.output().scriptRef()?.hash()); | ||
await blaze.newTransaction() | ||
.addReferenceInput(refInput!) | ||
.addDelegation(Credential.fromCore(credential), Core.PoolId("pool1x9q4jf3zwftwygeeulku8xtlywmtmzwxjk2g3fz3j5mlwjqnr3p"), Data.void()) | ||
.complete(); | ||
expectScriptFailure( | ||
blaze.newTransaction() | ||
.addReferenceInput(refInput!) | ||
.addDelegation(Credential.fromCore(credential), Core.PoolId("pool1x9q4jf3zwftwygeeulku8xtlywmtmzwxjk2g3fz3j5mlwjqnr3p"), Data.void()) | ||
) | ||
}) | ||
}) |
Oops, something went wrong.