Closed cwastche closed 3 months ago
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
eternum | โ Failed (Inspect) | Jul 2, 2024 2:29pm |
โฑ๏ธ Estimated effort to review [1-5] | 4 |
๐งช Relevant tests | Yes |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The change_guild_access function in contracts/src/systems/guild/contracts.cairo does not check if the is_public parameter is actually different from the current state before updating. This could lead to unnecessary state changes and gas usage. |
Data Integrity: In contracts/src/systems/guild/contracts.cairo , the leave_guild function sets guild_member.guild_entity_id to 0 and guild_member.join_ts to 0 after a member leaves. However, it does not clear other potentially sensitive data related to the member. Consider reviewing what data should be cleared to prevent stale or sensitive data from persisting. | |
Error Handling: The join_guild function in contracts/src/systems/guild/contracts.cairo increases the population count without prior checks for maximum capacity until after the increment. This could lead to situations where the population temporarily exceeds the maximum capacity, which might not be intended. |
Category | Suggestion | Score |
Possible bug |
Add capacity check before allowing a new member to join a guild___ **Add validation in thejoin_guild function to check if the guild is already at maximum capacity before allowing a new member to join. This prevents exceeding the guild's population capacity.** [contracts/src/systems/guild/contracts.cairo [101-113]](https://github.com/BibliothecaDAO/eternum/pull/1040/files#diff-df441b7afbca46c8a1c411bcd2c2c28ded66187d59f0a43d8ece0958a5e8645cR101-R113) ```diff fn join_guild(ref world: IWorldDispatcher, guild_entity_id: u128) { let caller_address = starknet::get_caller_address(); let guild = get!(world, guild_entity_id, Guild); if (!guild.is_public) { get!(world, (caller_address, guild_entity_id), GuildWhitelist).assert_is_whitelisted(); } let mut population = get!(world, guild_entity_id, Population); + if population.population >= population.capacity { + throw!("Guild is at maximum capacity"); + } population.increase_population(1, guild_population_config.base_population); population.assert_within_capacity(0); set!(world, (GuildMember { address: caller_address, guild_entity_id: guild_entity_id, join_ts: current_ts }, population)); } ``` Suggestion importance[1-10]: 10Why: This validation is crucial to prevent exceeding the guild's population capacity, addressing a potential bug. | 10 |
Ensure
___
**In the | 9 | |
Ensure proper initialization of the
___
**Ensure that the | 8 | |
Add a type check for
___
**Add a check to ensure | 8 | |
Possible issue |
Handle potential undefined values in
___
**Ensure that the | 9 |
Performance |
Optimize the
___
**Consider checking if the | 8 |
Maintainability |
Use a constant for population checks to enhance code maintainability___ **Replace the hardcoded population check with a constant or configurable value to enhanceflexibility and maintainability of the code.** [client/src/hooks/helpers/useGuilds.tsx [45]](https://github.com/BibliothecaDAO/eternum/pull/1040/files#diff-4a6ae30a3969851b248ce9c56e472b99b3f3ae1a4598fd3610e91aadc0899fa0R45-R45) ```diff -const guilds = useEntityQuery([Has(Guild), NotValue(Population, { population: 0 })]); +const MIN_POPULATION = 1; // Define this constant at a higher scope or configuration file +const guilds = useEntityQuery([Has(Guild), NotValue(Population, { population: MIN_POPULATION })]); ``` Suggestion importance[1-10]: 7Why: Replacing hardcoded values with constants improves code maintainability and flexibility. This suggestion is beneficial for future modifications and readability. | 7 |
Enhancement |
Add a docstring to the
___
**It's recommended to add a docstring to the new struct | 7 |
User description
Add max capacity to guilds
PR Type
Enhancement, Tests
Description
creation_ts
andjoin_ts
fields toGuild
andGuildMember
schemas.Population
schema withGuild
and updated related components and hooks.Changes walkthrough ๐
18 files
contractComponents.ts
Add timestamps to Guild and GuildMember schemas
client/src/dojo/contractComponents.ts
creation_ts
andjoin_ts
fields toGuild
andGuildMember
schemas.types
arrays to reflect new fields.useGuilds.tsx
Integrate Population schema with Guild data
client/src/hooks/helpers/useGuilds.tsx
Population
schema withGuild
.Population
.GuildInvites.tsx
Update GuildInvites to use new GuildWhitelist type
client/src/ui/components/worldmap/guilds/GuildInvites.tsx
GuildWhitelist
type.GuildMembers.tsx
Update GuildMembers to use new GuildMember type
client/src/ui/components/worldmap/guilds/GuildMembers.tsx - Updated type imports and usage to reflect new `GuildMember` type.
Guilds.tsx
Update Guilds component to show population and capacity
client/src/ui/components/worldmap/guilds/Guilds.tsx
Guild
type.MyGuild.tsx
Update MyGuild to use population data
client/src/ui/components/worldmap/guilds/MyGuild.tsx - Updated to use `population` instead of `memberCount`.
Whitelist.tsx
Update Whitelist to use new GuildWhitelist type
client/src/ui/components/worldmap/guilds/Whitelist.tsx
GuildWhitelist
type.index.ts
Add guild population configuration setup
config/index.ts - Added `setGuildPopulationConfig` to configuration setup.
index.ts
Add function to set guild population configuration
sdk/packages/eternum/src/config/index.ts - Added `setGuildPopulationConfig` function.
global.ts
Add base guild population capacity constant
sdk/packages/eternum/src/constants/global.ts - Added `BASE_GUILD_POPULATION_CAPACITY` constant.
index.ts
Add methods for guild access and population configuration
sdk/packages/eternum/src/provider/index.ts
change_guild_access
andset_guild_population_config
methods.provider.ts
Add interfaces for guild access and population configuration
sdk/packages/eternum/src/types/provider.ts
ChangeGuildAccess
andSetGuildPopulationConfigProps
.system_models.json
Include Population in GUILD_SYSTEMS
contracts/scripts/system_models.json - Added `Population` to `GUILD_SYSTEMS`.
constants.cairo
Add guild population config ID constant
contracts/src/constants.cairo - Added `GUILD_POPULATION_CONFIG_ID` constant.
config.cairo
Add GuildPopulationConfig model
contracts/src/models/config.cairo - Added `GuildPopulationConfig` model.
guild.cairo
Add timestamps to Guild and GuildMember models
contracts/src/models/guild.cairo - Added `creation_ts` to `Guild` and `join_ts` to `GuildMember`.
contracts.cairo
Add method to set guild population config in config systems
contracts/src/systems/config/contracts.cairo - Added `set_guild_population_config` method to `config_systems`.
contracts.cairo
Add guild access change and population management
contracts/src/systems/guild/contracts.cairo
change_guild_access
method.changes.
1 files
tests.cairo
Add tests for guild access and population management
contracts/src/systems/guild/tests.cairo - Added tests for guild access change and population management.