-
-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Labels
Description
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_leaderboardinstruction handler should initialize theleaderboardaccount with theplayersfield set to an empty vector. - The
leaderboardaccount should be initialized, if it does not already exist. - The initialization of the
leaderboardaccount should be payed for by thegame_owneraccount. - The correct amount of space for 5 players should be allocated for the
leaderboardaccount. - The PDA should be seeded with
"leaderboard"and thegame_ownerpublic key. - The
game_owneraccount public key should be asserted to match thegame-owner.jsonfile public key. - The
game_owneraccount owner should be asserted to be the system program. - The
new_gameinstruction handler should take aStringargument. - The
new_gameinstruction handler should transfer 1 SOL from theuseraccount to thegame_owneraccount. - The
new_gameinstruction handler should add a newPlayerto the leaderboard with: - The
usernamefield of the newPlayershould be set to theStringargument. - The
pubkeyfield of the newPlayershould be set to theuseraccount public key. - The
scorefield of the newPlayershould be set to0. - The
has_payedfield of the newPlayershould be set totrue. - If the leaderboard is full, the player with the lowest score should be replaced.
- The
NewGamegame_owneraccount should be asserted to match thegame-owner.jsonfile public key. - The
NewGamegame_owneraccount owner should be asserted to be the system program. - The
add_player_to_leaderboardinstruction handler should take au64argument. - The player matching the user account public key should be updated with a
scoreset to theu64argument. - The player matching the user account public key should be updated with a
has_payedset tofalse. - If no player matching the user account public key exists and has payed, an Anchor error variant of
PlayerNotFoundshould be returned. - The
"initializes leaderboard"itblock should call theinitialize_leaderboardinstruction. - The
"initializes leaderboard"itblock should assert theleaderboardaccount equals{ players: [] }. - The
"creates a new game"itblock should call thenew_gameinstruction with ausernameargument of"camperbot". - The
"creates a new game"itblock should assert theleaderboardaccount has at least one player. - The
"creates a new game"itblock should assert the player has the correctusername. - The
"creates a new game"itblock should assert the player has the correctpubkey. - The
"creates a new game"itblock should assert the player has ahasPayedvalue oftrue. - The
"creates a new game"itblock should assert the player has ascorevalue of0. - The
"creates a new game"itblock should assert the balance of theuseraccount has decreased by at least 1 SOL. - The
"adds a player to the leaderboard"itblock should call theadd_player_to_leaderboardinstruction with an argument of100. - The
"adds a player to the leaderboard"itblock should assert a player has ascorevalue of100. - The
"adds a player to the leaderboard"itblock should assert a player has ahasPayedvalue offalse. - The
"throws an error when the user has not payed"itblock should assert thePlayerNotFounderror variant is returned when theuseraccount has not payed.