Skip to content
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

05: setup amman and added initialize game test #5

Merged
merged 6 commits into from
Oct 20, 2022
Merged

Conversation

thlorenz
Copy link
Owner

@thlorenz thlorenz commented Oct 19, 2022

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 ones
you'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.

const PROGRAM_ID = require('./idl/tictactoe.json').metadata.address
{
  // [..]
  validator: {
    programs: [
      {
        label: 'TicTacToe Program',
        programId: PROGRAM_ID,
        deployPath: path.join(localDeployPath, 'tictactoe.so'),
      },
    ],
  }
  // [..]
}

Here we define the program that we will deploy under the PROGRAM_ID loading it from the
provided deployPath.

{
  // [..]
  storage: {
    enabled: false,
  },
  // [..]
}
}

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 run yarn 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.

Screen Shot 2022-10-19 at 9 15 07 PM

Amman Explorer

Head over to amman-explorer and refresh it to have it
sync with amman.

You should see the following:
Screen Shot 2022-10-19 at 9 16 05 PM
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.
Screen Shot 2022-10-19 at 9 18 22 PM
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.

Screen Shot 2022-10-19 at 9 18 52 PM

Screen Shot 2022-10-19 at 9 20 15 PM

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 instance
that 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 and
then 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):

await playerXHandler
  .sendAndConfirmTransaction(tx, [playerXPair], 'tx: init game')
  .assertSuccess(t, [/IX: initialize_game/])

Omitting .assertSuccess(..) here will cause amman to raise an error since it cannot be sure
that you're verifying the transaction otherwise.


previous | next

@thlorenz thlorenz merged commit 67d8b2c into master Oct 20, 2022
@thlorenz thlorenz deleted the amman/setup branch October 20, 2022 03:30
thlorenz added a commit that referenced this pull request Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant