-
Notifications
You must be signed in to change notification settings - Fork 51
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
contracts: no lords burn during donkey production for wonders #2164
Changes from 2 commits
8563ce6
d67c472
5b24fd6
eec2479
5291e1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ mod realm_systems { | |
use eternum::models::quest::{Quest, QuestBonus}; | ||
use eternum::models::realm::{ | ||
Realm, RealmCustomTrait, RealmCustomImpl, RealmResourcesTrait, RealmResourcesImpl, | ||
RealmNameAndAttrsDecodingTrait, RealmNameAndAttrsDecodingImpl | ||
RealmNameAndAttrsDecodingTrait, RealmNameAndAttrsDecodingImpl, RealmReferenceImpl | ||
}; | ||
use eternum::models::resources::{ | ||
DetachedResource, Resource, ResourceCustomImpl, ResourceCustomTrait, ResourceFoodImpl, ResourceFoodTrait | ||
|
@@ -94,7 +94,7 @@ mod realm_systems { | |
// create realm | ||
let mut coord: Coord = InternalRealmLogicImpl::get_new_location(ref world); | ||
let (entity_id, realm_produced_resources_packed) = InternalRealmLogicImpl::create_realm( | ||
ref world, owner, realm_id, resources, order, 0, coord | ||
ref world, owner, realm_id, resources, order, 0, wonder, coord | ||
); | ||
|
||
// collect lords attached to season pass and bridge into the realm | ||
|
@@ -278,9 +278,12 @@ mod realm_systems { | |
resources: Array<u8>, | ||
order: u8, | ||
level: u8, | ||
wonder: u8, | ||
coord: Coord | ||
) -> (ID, u128) { | ||
// create realm | ||
|
||
let has_wonder = RealmReferenceImpl::wonder_mapping(wonder.into()) != "None"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Implementation is correct but has a potential issue The wonder mapping implementation shows that checking against "None" is the correct way to determine if a realm has a wonder, as "None" is indeed returned for wonder value 1. However, there's a potential issue where the function panics for wonder value 0, which might need to be handled differently depending on the business logic.
🔗 Analysis chainVerify wonder mapping implementation The implementation checks if the wonder mapping returns "None" to determine if a realm has a wonder. Let's verify the wonder mapping implementation. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the wonder mapping implementation
# Look for the wonder mapping function definition and its possible return values
ast-grep --pattern 'fn wonder_mapping($wonder: $_) -> $_'
Length of output: 59 Script: #!/bin/bash
# Let's try a broader search for wonder_mapping using ripgrep
rg "wonder_mapping" -A 5 -B 5
Length of output: 1772 |
||
let realm_produced_resources_packed = RealmResourcesImpl::pack_resource_types(resources.span()); | ||
let entity_id = world.dispatcher.uuid(); | ||
let now = starknet::get_block_timestamp(); | ||
|
@@ -302,7 +305,8 @@ mod realm_systems { | |
realm_id, | ||
produced_resources: realm_produced_resources_packed, | ||
order, | ||
level | ||
level, | ||
has_wonder | ||
} | ||
); | ||
world.write_model(@Position { entity_id: entity_id.into(), x: coord.x, y: coord.y, }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ fn spawn_realm(ref world: WorldStorage, realm_id: ID, coord: Coord) -> ID { | |
let produced_resources = array![]; | ||
let order = 1; | ||
let (realm_entity_id, _realm_produced_resources_packed) = InternalRealmLogicImpl::create_realm( | ||
ref world, owner, realm_id, produced_resources, order, 0, coord.into() | ||
ref world, owner, realm_id, produced_resources, order, 0, 1, coord.into() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make the wonder parameter configurable and document its purpose. The hardcoded value Consider this improvement: - ref world, owner, realm_id, produced_resources, order, 0, 1, coord.into()
+ ref world, owner, realm_id, produced_resources, order, 0, has_wonder: bool, coord.into() And update the function signature: -fn spawn_realm(ref world: WorldStorage, realm_id: ID, coord: Coord) -> ID {
+/// Spawns a test realm
+/// # Arguments
+/// * `world` - The world storage
+/// * `realm_id` - The ID of the realm to spawn
+/// * `coord` - The coordinates where to spawn the realm
+/// * `has_wonder` - Whether the realm has a wonder (affects lords burning during donkey production)
+fn spawn_realm(ref world: WorldStorage, realm_id: ID, coord: Coord, has_wonder: bool) -> ID { Additionally, consider adding a convenience helper: /// Spawns a test realm with a wonder
fn spawn_realm_with_wonder(ref world: WorldStorage, realm_id: ID, coord: Coord) -> ID {
spawn_realm(ref world, realm_id, coord, true)
} |
||
); | ||
|
||
realm_entity_id | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add test cases for realms with wonders
The mock realm correctly initializes
has_wonder
tofalse
, but test coverage for wonder-related functionality is missing. Consider adding test cases that:has_wonder: true
)has_wonder
and decoded wonder attributes