You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/getting-started/operations.mdx
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -331,4 +331,24 @@ We weren't minting any tokens in our example here and thus didn't make use of `m
331
331
332
332
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.
333
333
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.
`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.
`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`.
`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).
`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
+
334
354
[^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.
from Liqwid's Libs mono repo. It allows one to easily construct various transaction contexts
34
33
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.
38
34
39
35
***Testing of operations (transactions).**
40
36
At this level, one can execute whole operations (transactions)
41
37
an application provides and verifies that they a) can run through and
42
38
b) confirm that some conditions we are interested in are held.
43
39
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)".
45
41
This is the level of testing we discuss in this section.
46
42
You can also make a distinction between testing individual transactions and
47
43
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:
68
64
It is a cluster of three `cardano-node` instances
69
65
that potentially could support all Cardano features,
70
66
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.
75
69
76
70
<Callouttype="info"emoji="⚠️">
77
71
@@ -82,8 +76,6 @@ We will call them *ledger backends* throughout the rest of the section:
82
76
83
77
Fortunately, you can switch easily between two backends with unified testing.
84
78
85
-
TODO: add more information on how CLB/privnet differ.
86
-
87
79
</Callout>
88
80
89
81
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
110
102
## Testing placing a bet
111
103
112
104
<Callouttype="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).
114
106
Mind you we are using [`tasty`](https://hackage.haskell.org/package/tasty) to write tests.
115
107
</Callout>
116
108
@@ -196,7 +188,7 @@ Let's start with the runner to test `placeBet` operation. We won't see anything
196
188
new here.It just uses `asUser action` we just learned to run the operation.
197
189
We need values ofall arguments that our operation takes.We cannot know them, so
198
190
we just takeallof 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
200
192
the addresses of the wallet (`User`) that we provide to `asUser`.
201
193
Once we get the result of the operation, we can build, sign, and submit a transaction.
202
194
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})
321
313
void $ runPlaceBet refScript brp dat bet Nothing w1
322
314
```
323
315
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].
325
317
It allows checking the change of wallet's balance with no caring about transaction and storage fees
326
318
(the latter is also known as minimal ADA - the number of coins that should accompany Cardano native tokens).
327
319
This convenience is possible because Atlas manages its own record of
This section concludes our journey to testing dApps with Atlas.
541
533
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.
543
535
544
536
[^2]: To convey the message better, we have a defined [`(:=)`](https://haddock.atlas-app.io/GeniusYield-Test-Utils.html#v::-61-) pattern synonym:
0 commit comments