-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions about testing smart contracts #16
Comments
I managed to get some basic tests working using my test :: (E.MonadEmulator m) => m ()
test = do
let w1 = W.knownMockWallet 1
w2 = W.knownMockWallet 2
transact (W.mockWalletAddress w1) [W.paymentPrivateKey w1] $
TransactionParams
{ tokens = []
, outputs =
[ Output { outputAddress = W.mockWalletAddress w2
, outputValue = L.lovelaceToValue 100000000000000
, outputDatum = PlutusTx.NoOutputDatum
, outputReferenceScript = C.ReferenceScriptNone
}
]
} I could then just call it using |
Actually, the Should I make this its own github issue? |
Thanks for your interesting comments! These are sensible requests. At the moment I unfortunately can't promise these will be fixed soon. |
All good! I know you guys are busy and I managed to find work-arounds for the above features. If you ever do find yourself with time, I would actually prefer if you prioritized my other issue since I have not been able to find a work-around for that one. I appreciate the reply and I apologize for the rant-like nature of this issue 😅 |
In plutus-apps v1.2.0, there was the
EmulatorTrace
monad that allowed for creating arbitrary unit test scenarios. I was able to create general purpose endpoints like those in this module. I could then just create scenarios that submitted one transaction after another where I would test whether the last transaction in the scenario passed or failed. Here is an example module that used this approach (it submits one arbitrary transaction after another in a single unit test). The benefit of this approach was that it worked for all smart contracts and all transactions; I didn't need to create other endpoints just to see how other smart contract executions or transaction inputs would impact the contract I was testing. Even testing for double satisfaction was very straightforward.In the process of trying to migrate away from plutus-apps v1.2.0, I have been trying to convert my smart contract tests to follow the examples here. However, after reading through a lot of the documentation and trying it out, it seems the tests make heavy use of modeling internal state and actions which does not seem appropriate for my use case. Ultimately, a blockchain action is just a transaction and the state is the current UTxO set, so I would rather just be able to specify what transaction to submit next like I did with
EmulatorTrace
. I tried usingContractModel
like this (using a dummy state and a singleTransact
action) but the types don't seem to allow for this (see bottom of comment for example code). While quickcheck-contractmodel'sThreatModel
does not seem to require modeling internal state, it seems very limited in what it can do (e.g., AFAICT it doesn't support testing reference script usage). Even the dynamic logic unit tests seem to require modeling internal state and actions.The reason why I don't think modeling state and actions is the right approach for me (and arguably others) is that it makes it very difficult to test smart contract composability. All of my DApps (DEX, lending/borrowing, options trading, secondary market) are composable with each other and all other DApps within a single transaction. They are also composable with themselves within a single transaction (you can use 25 swaps from the DEX in a single transaction). Having to model the state and actions of all possible compositions just doesn't seem feasible and also doesn't seem necessary; I just want to know whether or not a transaction fails after a given series of previous transactions. Being able to just specify what transaction to submit next is IMO infinitely easier. I do think there is a place for property based testing like those in the examples, but unit tests like those I described seem to be more useful to me as a DApp developer.
So my questions are:
EmulatorTrace
?What I've tried
But the above results in various
Missing instance of HasVariables for non-Generic type ...
errors.The text was updated successfully, but these errors were encountered: