Skip to content

Commit

Permalink
1-indexing of stat IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
zomglings committed Aug 20, 2023
1 parent 796a3be commit 47497ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cli/web3cli/StatBlock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Code generated by moonworm : https://github.com/bugout-dev/moonworm
# Moonworm version : 0.7.0
# Code generated by moonworm : https://github.com/moonstream-to/moonworm
# Moonworm version : 0.7.1

import argparse
import json
Expand Down
22 changes: 15 additions & 7 deletions cli/web3cli/test_statblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def test_admin_can_create_stat(self):
- describeStat
"""
num_stats_0 = self.statblock.num_stats()
stat_name = f"stat_{num_stats_0}"
stat_name = f"stat_{num_stats_0 + 1}"
tx_receipt = self.statblock.create_stat(stat_name, {"from": self.administrator})
num_stats_1 = self.statblock.num_stats()

self.assertEqual(num_stats_1, num_stats_0 + 1)

stat_description = self.statblock.describe_stat(num_stats_0)
stat_description = self.statblock.describe_stat(num_stats_1)
self.assertEqual(stat_description, stat_name)

stat_created_events = _fetch_events_chunk(
Expand All @@ -122,7 +122,7 @@ def test_admin_can_create_stat(self):

event = stat_created_events[0]
self.assertEqual(event["event"], "StatCreated")
self.assertEqual(event["args"]["statID"], num_stats_0)
self.assertEqual(event["args"]["statID"], num_stats_1)
self.assertEqual(event["args"]["descriptor"], stat_name)
self.assertEqual(event["address"], self.statblock.address)

Expand Down Expand Up @@ -165,7 +165,9 @@ def test_admin_can_assign_stats(self):
num_assignable_stats = 3
num_stats_0 = self.statblock.num_stats()

stat_ids = [i for i in range(num_stats_0, num_stats_0 + num_assignable_stats)]
stat_ids = [
i + 1 for i in range(num_stats_0, num_stats_0 + num_assignable_stats)
]

for i in stat_ids:
stat_name = f"stat_{i}"
Expand Down Expand Up @@ -318,7 +320,9 @@ def test_admin_can_batch_assign_stats(self):
num_assignable_stats = 3
num_stats_0 = self.statblock.num_stats()

stat_ids = [i for i in range(num_stats_0, num_stats_0 + num_assignable_stats)]
stat_ids = [
i + 1 for i in range(num_stats_0, num_stats_0 + num_assignable_stats)
]

for i in stat_ids:
stat_name = f"stat_{i}"
Expand Down Expand Up @@ -444,7 +448,9 @@ def test_nonadmin_cannot_assign_stats(self):
num_assignable_stats = 3
num_stats_0 = self.statblock.num_stats()

stat_ids = [i for i in range(num_stats_0, num_stats_0 + num_assignable_stats)]
stat_ids = [
i + 1 for i in range(num_stats_0, num_stats_0 + num_assignable_stats)
]

for i in stat_ids:
stat_name = f"stat_{i}"
Expand Down Expand Up @@ -488,7 +494,9 @@ def test_nonadmin_cannot_batch_assign_stats(self):
num_assignable_stats = 3
num_stats_0 = self.statblock.num_stats()

stat_ids = [i for i in range(num_stats_0, num_stats_0 + num_assignable_stats)]
stat_ids = [
i + 1 for i in range(num_stats_0, num_stats_0 + num_assignable_stats)
]

for i in stat_ids:
stat_name = f"stat_{i}"
Expand Down
2 changes: 1 addition & 1 deletion contracts/stats/StatBlock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract StatBlock is IStatBlock {
isAdministrator(msg.sender),
"StatBlock.createStat: msg.sender must be an administrator of the StatBlock"
);
statID = NumStats++;
statID = ++NumStats;
StatDescriptor[statID] = descriptor;
emit StatCreated(statID, descriptor);
}
Expand Down

0 comments on commit 47497ec

Please sign in to comment.