Skip to content

Commit ccd7e85

Browse files
committed
docs(#98): update testing section, improve previous sections
1 parent 7f4d5ad commit ccd7e85

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/module/home/components/DescriptionSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ const RightRow = styled(Grid)(({ theme }) => ({
234234
},
235235
}));
236236

237-
const IllustrationWrapper = styled(Grid)(({ }) => ({
237+
const IllustrationWrapper = styled(Grid)(({}) => ({
238238
margin: "0 auto",
239239
}));
240240

src/pages/getting-started/operations.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,24 @@ We weren't minting any tokens in our example here and thus didn't make use of `m
331331

332332
We haven't made use of withdrawals, stake certificates and stake validators in our example. A sample illustration is provided in [this](https://github.com/geniusyield/atlas/blob/main/tests-privnet/GeniusYield/Test/Privnet/Stake.hs) privnet test.
333333

334+
## Monad hierarchy
335+
336+
In Atlas we have hierarchy of monads with increasing level of capabilities. We already introduced `GYTxQueryMonad`. Besides it, we also have following monads. Don't worry if it appears overwhelming, they are mainly there for advanced usage and you would very rarely need to bother about their internals.
337+
338+
### [`GYTxUserQueryMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxUserQueryMonad)
339+
340+
`GYTxQueryMonad` is a super-class of [`GYTxUserQueryMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxUserQueryMonad). It is to be used for queries which have access to user's wallet details, such as change address, used addresses and so on. Please have a look at it's haddock entry [here](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxUserQueryMonad) to see for available functions.
341+
342+
### [`GYTxBuilderMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxBuilderMonad)
343+
344+
`GYTxUserQueryMonad` is a superclass of [`GYTxBuilderMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxBuilderMonad). Purpose of `GYTxBuilderMonad` is to allow for functions related to transaction building. This however could have been part of `GYTxUserQueryMonad` but is separate only to allow for different custom transaction building strategy to be used as default. As we will soon see, in our code, we would use [`buildTxBody`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#v:buildTxBody) to build for transaction, and that would be possible only if we are working inside `GYTxBuilderMonad`.
345+
346+
### [`GYTxMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxMonad)
347+
348+
`GYTxBuilderMonad` is a superclass of [`GYTxMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxMonad). Different between `GYTxMonad` and `GYTxBuilderMonad` is that former allows for signing of transactions, thus it requires access to user's private key. The main function we would encounter from this class is [`signAndSubmitConfirmed`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#v:signAndSubmitConfirmed).
349+
350+
### [`GYTxGameMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxMonad)
351+
352+
`GYTxMonad` is a superclass of [`GYTxGameMonad`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#t:GYTxMonad). This monad allows for simulating multiple users, and is mainly used for testing. We touch more on it in our [testing](./testing) section.
353+
334354
[^1]: This is making use of _"singletons"_ and one can read about it from the "Dependent Types" chapter (the last one) in [Thinking with Types](https://thinkingwithtypes.com/) book.

src/pages/getting-started/testing.mdx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,28 @@ plenty of techniques and approaches. Let's focus on __levels__ at which we can
1616
perform testing:
1717

1818
* **Testing of UPLC functions.** You may want to verify that individual functions
19-
your validators or minting policies consist of, indeed hold some properties. This is
19+
your validators consist of, indeed hold some properties. This is
2020
useful if your on-chain logic is convoluted and involves complex computations.
2121
This level is tightly coupled to the language you use to build your smart contracts
22-
so you should consult the documentation.
22+
so you should consult the respective documentation.
2323

2424
* **Testing of individual contracts (script level).**
2525
You might want to verify that the on-chain contracts you developed behave as expected
26-
in isolation just by calling them with hand-constructed arguments for datum,
27-
redeemer, and script context (since they are just functions after all)
26+
in isolation just by calling them with hand-constructed arguments (like script context) since they are just functions after all
2827
and checking the results. Here again, you can use language-specific tools.
2928
But in case your contracts are already compiled down to UPLC code,
3029
you will need a special testing framework to do that.
3130
Atlas currently doesn't provide such a thing, but there exist some projects of help,
3231
namely [liqwid-context-builder](https://github.com/Liqwid-Labs/liqwid-libs/tree/main/plutarch-context-builder)
3332
from Liqwid's Libs mono repo. It allows one to easily construct various transaction contexts
3433
and verify a result that a particular script evaluates.
35-
Testing of individual contracts proved to be very fruitful for both simple
36-
and complex applications since it discovers bugs at very early stages
37-
even before operations are defined.
3834

3935
* **Testing of operations (transactions).**
4036
At this level, one can execute whole operations (transactions)
4137
an application provides and verifies that they a) can run through and
4238
b) confirm that some conditions we are interested in are held.
4339
A nice thing to know about Atlas is that it allows you to reuse the code for operations
44-
you created in the previous step [Operations over Contract](./operations.mdx).
40+
you created in the previous step, "[Operations over Contract](./operations.mdx)".
4541
This is the level of testing we discuss in this section.
4642
You can also make a distinction between testing individual transactions and
4743
testing a flow of transactions, but in practice, it proves to be hard
@@ -68,10 +64,8 @@ We will call them *ledger backends* throughout the rest of the section:
6864
It is a cluster of three `cardano-node` instances
6965
that potentially could support all Cardano features,
7066
including staking and governance.
71-
The main downside of a privnet is that testing time is significantly bigger
72-
(minutes not seconds even for simple tests).
73-
So it's practically impossible to have a fresh network for every test case
74-
but rather for the whole test suite run.
67+
The main downside of a privnet is that testing time is significantly bigger and since spawning a testnet is a time-consuming operation, it's practically impossible to have a fresh network for every test case
68+
but rather we prefer single testnet for the whole test suite run.
7569

7670
<Callout type="info" emoji="⚠️">
7771

@@ -82,8 +76,6 @@ We will call them *ledger backends* throughout the rest of the section:
8276

8377
Fortunately, you can switch easily between two backends with unified testing.
8478

85-
TODO: add more information on how CLB/privnet differ.
86-
8779
</Callout>
8880

8981
Now that we know what the two backends available are,
@@ -110,7 +102,7 @@ Let's run through an example test suite to get the idea and figure out its detai
110102
## Testing placing a bet
111103

112104
<Callout type="warning" emoji="📃">
113-
You can find the entire code for this example [here](https://github.com/geniusyield/atlas/blob/main/tests-unified/GeniusYield/Test/Unified/BetRef/).
105+
You can find the entire code for this example [here](https://github.com/geniusyield/atlas-examples/tree/main/bet-ref/tests).
114106
Mind you we are using [`tasty`](https://hackage.haskell.org/package/tasty) to write tests.
115107
</Callout>
116108

@@ -196,7 +188,7 @@ Let's start with the runner to test `placeBet` operation. We won't see anything
196188
new here. It just uses `asUser action` we just learned to run the operation.
197189
We need values of all arguments that our operation takes. We cannot know them, so
198190
we just take all of them as arguments to the runner itself, except the address as
199-
it can be obtained using `ownAddresses` function. This function gives back all
191+
it can be obtained using [`ownAddresses`](https://haddock.atlas-app.io/GeniusYield-TxBuilder-Class.html#v:ownAddresses) function. This function gives back all
200192
the addresses of the wallet (`User`) that we provide to `asUser`.
201193
Once we get the result of the operation, we can build, sign, and submit a transaction.
202194
Here, again, the wallet we specified to `asUser` action is used to sign it
@@ -321,7 +313,7 @@ firstBetTest betUntil betReveal betStep dat bet (testWallets -> ws@Wallets{w1})
321313
void $ runPlaceBet refScript brp dat bet Nothing w1
322314
```
323315

324-
The code almost verbatim repeats what we just said using the function `withWalletBalancesCheckSimple`[^1].
316+
The code almost verbatim repeats what we just said using the function [`withWalletBalancesCheckSimple`](https://haddock.atlas-app.io/GeniusYield-Test-FeeTracker.html#v:withWalletBalancesCheckSimple)[^1].
325317
It allows checking the change of wallet's balance with no caring about transaction and storage fees
326318
(the latter is also known as minimal ADA - the number of coins that should accompany Cardano native tokens).
327319
This convenience is possible because Atlas manages its own record of
@@ -539,7 +531,7 @@ placeBetTests setup = testGroup "Place bet"
539531

540532
This section concludes our journey to testing dApps with Atlas.
541533

542-
[^1]: If you were to have fine-grained control over balance change, use `withWalletBalancesCheck` instead.
534+
[^1]: If you were to have fine-grained control over balance change, use [`withWalletBalancesCheck`](https://haddock.atlas-app.io/GeniusYield-Test-Utils.html#v:withWalletBalancesCheck) instead.
543535

544536
[^2]: To convey the message better, we have a defined [`(:=)`](https://haddock.atlas-app.io/GeniusYield-Test-Utils.html#v::-61-) pattern synonym:
545537

0 commit comments

Comments
 (0)