Giter Club home page Giter Club logo

Comments (6)

MarvinJanssen avatar MarvinJanssen commented on August 25, 2024 1

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.

LNow avatar LNow commented on August 25, 2024

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.

obycode avatar obycode commented on August 25, 2024

Are the needs in this issue handled by #333?

from clarinet.

moodmosaic avatar moodmosaic commented on August 25, 2024

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.

lgalabru avatar lgalabru commented on August 25, 2024

I think these needs are handled in #333, although a better developer experience would be implemented with #357.

from clarinet.

lgalabru avatar lgalabru commented on August 25, 2024

All the primitives are implemented and available to write such a library, I'll close this issue!

from clarinet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.