You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 NewGamegame_owner account should be asserted to match the game-owner.json file public key.
The NewGamegame_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.
The text was updated successfully, but these errors were encountered:
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
initialize_leaderboard
instruction handler should initialize theleaderboard
account with theplayers
field set to an empty vector.leaderboard
account should be initialized, if it does not already exist.leaderboard
account should be payed for by thegame_owner
account.leaderboard
account."leaderboard"
and thegame_owner
public key.game_owner
account public key should be asserted to match thegame-owner.json
file public key.game_owner
account owner should be asserted to be the system program.new_game
instruction handler should take aString
argument.new_game
instruction handler should transfer 1 SOL from theuser
account to thegame_owner
account.new_game
instruction handler should add a newPlayer
to the leaderboard with:username
field of the newPlayer
should be set to theString
argument.pubkey
field of the newPlayer
should be set to theuser
account public key.score
field of the newPlayer
should be set to0
.has_payed
field of the newPlayer
should be set totrue
.NewGame
game_owner
account should be asserted to match thegame-owner.json
file public key.NewGame
game_owner
account owner should be asserted to be the system program.add_player_to_leaderboard
instruction handler should take au64
argument.score
set to theu64
argument.has_payed
set tofalse
.PlayerNotFound
should be returned."initializes leaderboard"
it
block should call theinitialize_leaderboard
instruction."initializes leaderboard"
it
block should assert theleaderboard
account equals{ players: [] }
."creates a new game"
it
block should call thenew_game
instruction with ausername
argument of"camperbot"
."creates a new game"
it
block should assert theleaderboard
account has at least one player."creates a new game"
it
block should assert the player has the correctusername
."creates a new game"
it
block should assert the player has the correctpubkey
."creates a new game"
it
block should assert the player has ahasPayed
value oftrue
."creates a new game"
it
block should assert the player has ascore
value of0
."creates a new game"
it
block should assert the balance of theuser
account has decreased by at least 1 SOL."adds a player to the leaderboard"
it
block should call theadd_player_to_leaderboard
instruction with an argument of100
."adds a player to the leaderboard"
it
block should assert a player has ascore
value of100
."adds a player to the leaderboard"
it
block should assert a player has ahasPayed
value offalse
."throws an error when the user has not payed"
it
block should assert thePlayerNotFound
error variant is returned when theuser
account has not payed.The text was updated successfully, but these errors were encountered: