Comments (6)
Sure, we can do that, just like we can also construct transactions manually. A library simply makes it easier. It definitely does not have to (should not?) be part of the built-in clarity/index.ts
file.
Furthermore, I do not like the idea of mixing languages so I rather not write Clarity snippets in TS files unless I absolutely have to. Having an exposed API gives us more type safety.
With the new Clarinet features coming out, we might want to explore different approaches as well.
from clarinet.
I'm not convinced in 100% if we need a separate TS API for creating mocks.
For test purposes we can create various types of test doubles without any extra API.
Example:
Clarinet.test({
name: "returns the ticket price",
preSetup(): Tx[] {
let mockOracleCode = `
(define-public (price (arg1 (string-ascii 24)) (arg2 (string-ascii 24)) (arg3 uint))
(ok u2000000)
)
`;
return [
Tx.deployContract(
"imaginary-oracle-v1",
mockOracleCode,
"SP000000000000000000002Q6VF78"
),
];
},
async fn(chain: Chain, accounts: Map<string, Account>) {
let deployer = accounts.get("deployer")!;
let wallet_1 = accounts.get("wallet_1")!;
let block = chain.mineBlock([
Tx.contractCall(
`SP000000000000000000002Q6VF78.imaginary-oracle-v1`,
"price",
[types.ascii("usd"), types.ascii("stx"), types.uint(5)],
wallet_1.address
),
]);
console.table(block.receipts[0]);
},
});
from clarinet.
Are the needs in this issue handled by #333?
from clarinet.
Are the needs in this issue handled by #333?
Partially, or perhaps implicitly.
- With #333 instead of
preSetup
you'd include the contract-call transactions at deployment time, for all tests. - With the idea proposed by @MarvinJanssen you'd (explicitly) setup Mocks and Stubs, similar to @LNow's approach, for each test.
(If we move forward with this, the correct terminology matters, as in this snippet the Test Double is actually a Stub, not a Mock.)
from clarinet.
I think these needs are handled in #333, although a better developer experience would be implemented with #357.
from clarinet.
All the primitives are implemented and available to write such a library, I'll close this issue!
from clarinet.
Related Issues (20)
- Devnet should work offline if the Docker images exist locally
- Support unit tests written in Clarity - `#[test]` HOT 2
- Use Stacks node v2.5 for the local testnet HOT 2
- calling `getMapEntry` in Clarinet SDK for non-existent entry returns error instead of `Cl.none` HOT 3
- Can't find variable `simnet` when running tests using `bun test` HOT 3
- Deployment plan misses dependency HOT 3
- Doubling down on security analysis HOT 2
- Handle Clarity 3 HOT 1
- Consolidate regtest and devnet functionality
- Generate a typescript client lib for contracts
- unable to trigger deployment error HOT 6
- How to pass in the default.testnet-plan.yaml - list 5 (optional principal) parameter HOT 2
- Creating a new Clarinet project in the local folder breaks devnet HOT 1
- Add electrs docker container to devnet start HOT 1
- Add advance_stacks_tip and advance_burnchain_tip in simnet
- create `clarinet platform` commands HOT 2
- running clarinet in the background HOT 3
- Mainnet Execution Simulation HOT 7
- Include tx cost in transaction receipts HOT 1
- Make it available for NixOS HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clarinet.