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

[build-an-anchor-leaderboard]: add tests #174

Open
34 tasks
ShaunSHamilton opened this issue May 22, 2023 · 0 comments
Open
34 tasks

[build-an-anchor-leaderboard]: add tests #174

ShaunSHamilton opened this issue May 22, 2023 · 0 comments

Comments

@ShaunSHamilton
Copy link
Member

Some of the user stories for the Build an Anchor Leaderboard integrated project do not have corresponding tests. The original approach I was taking would have made the tests take 5 - 20 min to run, which is not ideal.

As such, it would be ideal if a better testing methodology could be found, whilst still keeping the project permissible; this is not a practice project where a Camper can be told what code to put where, this is an integrated project where Campers just need to accomplish "integrated-style user stories".

Tests

Click
  • The initialize_leaderboard instruction handler should initialize the leaderboard account with the players field set to an empty vector.
  • The leaderboard account should be initialized, if it does not already exist.
  • The initialization of the leaderboard account should be payed for by the game_owner account.
  • The correct amount of space for 5 players should be allocated for the leaderboard account.
  • The PDA should be seeded with "leaderboard" and the game_owner public key.
  • The game_owner account public key should be asserted to match the game-owner.json file public key.
  • The game_owner account owner should be asserted to be the system program.
  • The new_game instruction handler should take a String argument.
  • The new_game instruction handler should transfer 1 SOL from the user account to the game_owner account.
  • The new_game instruction handler should add a new Player to the leaderboard with:
  • The username field of the new Player should be set to the String argument.
  • The pubkey field of the new Player should be set to the user account public key.
  • The score field of the new Player should be set to 0.
  • The has_payed field of the new Player should be set to true.
  • If the leaderboard is full, the player with the lowest score should be replaced.
  • The NewGame game_owner account should be asserted to match the game-owner.json file public key.
  • The NewGame game_owner account owner should be asserted to be the system program.
  • The add_player_to_leaderboard instruction handler should take a u64 argument.
  • The player matching the user account public key should be updated with a score set to the u64 argument.
  • The player matching the user account public key should be updated with a has_payed set to false.
  • If no player matching the user account public key exists and has payed, an Anchor error variant of PlayerNotFound should be returned.
  • The "initializes leaderboard" it block should call the initialize_leaderboard instruction.
  • The "initializes leaderboard" it block should assert the leaderboard account equals { players: [] }.
  • The "creates a new game" it block should call the new_game instruction with a username argument of "camperbot".
  • The "creates a new game" it block should assert the leaderboard account has at least one player.
  • The "creates a new game" it block should assert the player has the correct username.
  • The "creates a new game" it block should assert the player has the correct pubkey.
  • The "creates a new game" it block should assert the player has a hasPayed value of true.
  • The "creates a new game" it block should assert the player has a score value of 0.
  • The "creates a new game" it block should assert the balance of the user account has decreased by at least 1 SOL.
  • The "adds a player to the leaderboard" it block should call the add_player_to_leaderboard instruction with an argument of 100.
  • The "adds a player to the leaderboard" it block should assert a player has a score value of 100.
  • The "adds a player to the leaderboard" it block should assert a player has a hasPayed value of false.
  • The "throws an error when the user has not payed" it block should assert the PlayerNotFound error variant is returned when the user account has not payed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant