Fix some minor group-related bugs

Incorrect column names when saving a group ban.

Missing column in LeaveGroupTransactions.

More stringent validity checks in group-kick, group-ban and remove-group-admin.

Added loads more tests to cover group actions.
This commit is contained in:
catbref
2020-06-24 11:24:19 +01:00
parent ec1954bae1
commit 448e984995
12 changed files with 769 additions and 27 deletions

View File

@@ -530,7 +530,7 @@ public class HSQLDBDatabaseUpdates {
// Leave group
stmt.execute("CREATE TABLE LeaveGroupTransactions (signature Signature, leaver QortalPublicKey NOT NULL, group_id GroupID NOT NULL, "
+ "member_reference Signature, admin_reference Signature, " + TRANSACTION_KEYS + ")");
+ "member_reference Signature, admin_reference Signature, previous_group_id GroupID, " + TRANSACTION_KEYS + ")");
// Kick from group
stmt.execute("CREATE TABLE GroupKickTransactions (signature Signature, admin QortalPublicKey NOT NULL, "
@@ -618,6 +618,11 @@ public class HSQLDBDatabaseUpdates {
stmt.execute("CREATE TABLE PublicizeTransactions (signature Signature, nonce INT NOT NULL, " + TRANSACTION_KEYS + ")");
break;
case 20:
// XXX Bug-fix, but remove when we build new genesis
stmt.execute("ALTER TABLE LeaveGroupTransactions ADD COLUMN IF NOT EXISTS previous_group_id GroupID");
break;
default:
// nothing to do
return false;

View File

@@ -828,7 +828,7 @@ public class HSQLDBGroupRepository implements GroupRepository {
HSQLDBSaver saveHelper = new HSQLDBSaver("GroupBans");
saveHelper.bind("group_id", groupBanData.getGroupId()).bind("offender", groupBanData.getOffender()).bind("admin", groupBanData.getAdmin())
.bind("banned", groupBanData.getBanned()).bind("reason", groupBanData.getReason()).bind("expiry", groupBanData.getExpiry())
.bind("banned_when", groupBanData.getBanned()).bind("reason", groupBanData.getReason()).bind("expires_when", groupBanData.getExpiry())
.bind("reference", groupBanData.getReference());
try {

View File

@@ -72,7 +72,11 @@ public class GroupBanTransaction extends Transaction {
Account offender = getOffender();
// Can't ban another admin unless the group owner
// Can't ban group owner
if (offender.getAddress().equals(groupData.getOwner()))
return ValidationResult.INVALID_GROUP_OWNER;
// Can't ban another admin unless admin is the group owner
if (!admin.getAddress().equals(groupData.getOwner()) && this.repository.getGroupRepository().adminExists(groupId, offender.getAddress()))
return ValidationResult.INVALID_GROUP_OWNER;

View File

@@ -74,7 +74,11 @@ public class GroupKickTransaction extends Transaction {
if (!groupRepository.joinRequestExists(groupId, member.getAddress()) && !groupRepository.memberExists(groupId, member.getAddress()))
return ValidationResult.NOT_GROUP_MEMBER;
// Can't kick another admin unless the group owner
// Can't kick group owner
if (member.getAddress().equals(groupData.getOwner()))
return ValidationResult.INVALID_GROUP_OWNER;
// Can't kick another admin unless kicker is the group owner
if (!admin.getAddress().equals(groupData.getOwner()) && groupRepository.adminExists(groupId, member.getAddress()))
return ValidationResult.INVALID_GROUP_OWNER;

View File

@@ -76,6 +76,10 @@ public class RemoveGroupAdminTransaction extends Transaction {
if (!this.repository.getGroupRepository().adminExists(groupId, admin.getAddress()))
return ValidationResult.NOT_GROUP_ADMIN;
// Check admin is not group owner
if (admin.getAddress().equals(groupData.getOwner()))
return ValidationResult.INVALID_GROUP_OWNER;
// Check creator has enough funds
if (owner.getConfirmedBalance(Asset.QORT) < this.removeGroupAdminTransactionData.getFee())
return ValidationResult.NO_BALANCE;