05: setup amman and added initialize game test #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
previous | next
Summary
In this PR we setup amman to run our program in a local test validator and we added a test
that interacts with it by invoking the initialize game instruction.
Amman Config
Most options set in the
.ammanrc.js
default to reasonable values, so let's go over the onesyou're most likely going to change for your case.
Amman reads this config and adjusts the way it provisions the local test validator, relay and
more to this configuration.
Here we define the program that we will deploy under the
PROGRAM_ID
loading it from theprovided
deployPath
.Here we instruct _amman- that we won't be using mock storage since we're not uploading any
NFTs.
Startup Amman
From inside the
./ts
folder runyarn amman:start
.Amman will log information to the terminal regarding the startup. Keep this terminal open as
amman will log data about executed transactions here as well once we run our tests.
Amman Explorer
Head over to amman-explorer and refresh it to have it
sync with amman.
You should see the following:
NOTE that at this point it is not showing any Recent Transactions ... yet.
Running your Tests
Run
yarn t
from inside the./ts
folder and you should see the following.The top terminal shows the logs amman prints and the bottom terminal shows the test output.
Use the Amman Explorer to diagnose the transactions that the tests executed and then come back here to have a closer look at the code.
Tests and How they Interact with Amman
Have a look at
./test/utils/amman.ts
to see how simple it is to setup an amman instancethat we use to talk to the amman and test validator.
The tests inside
./tests/tictactoe.ts
were updated to setup the first player, the game pda andthen execute the transaction to initialize the TicTacToe game.
I recommend you to read through that code and particularly pay attention to how it interacts
with amman, i.e. to label account addresses.
When you send a transaction via the amman transaction handler, it turns off
preflight
checks in order to ensure that faulty transactions still run in the validator and are available
for inspection inside the Amman Explorer.
For that reason it also requires you to assert that the transaction succeeded (or failed):
Omitting
.assertSuccess(..)
here will cause amman to raise an error since it cannot be surethat you're verifying the transaction otherwise.
previous | next